<template>
  <div class="app-container">
    <div class="search_con m-b-28">

      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

        <el-form-item label="订单编号" prop="otcOrderNo">
          <el-input v-model="queryParams.otcOrderNo" placeholder="请输入订单编号" clearable size="medium"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="用户名称" prop="appealUserName">
          <el-input v-model="queryParams.appealUserName" placeholder="请输入用户名称" clearable size="medium"
            @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item label="类型" prop="tradeType">
        <el-select v-model="queryParams.tradeType" placeholder="请选择类型" clearable size="medium">
          <el-option
            v-for="dict in tradeTypeStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

        <el-form-item label="状态" prop="appealStatus">
          <el-select size="medium" v-model="queryParams.appealStatus" placeholder="请选择状态" clearable>
            <el-option v-for="dict in appealStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue" />
          </el-select>
        </el-form-item>

        <el-form-item label="下单时间">
                <el-date-picker v-model="dateRange" size="medium" style="width: 340px" value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                    :unlink-panels="true" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
            </el-form-item>


        <el-form-item>
          <el-button type="primary" size="medium" @click="handleQuery">搜索</el-button>
          <el-button size="medium" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="bg bg-white">

      <el-row :gutter="10" class="m-b-16">
        <!-- <el-col :span="1.5">
          <el-button type="primary" size="medium" @click="handleAdd"
            v-hasPermi="['otc:otcAppealOrder:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" size="medium" :disabled="single" @click="handleUpdate"
            v-hasPermi="['otc:otcAppealOrder:edit']">修改</el-button>
        </el-col> -->
        <!--      <el-col :span="1.5">-->
        <!--        <el-button-->
        <!--          type="danger"-->
        <!--          plain-->
        <!--          icon="el-icon-delete"-->
        <!--          size="mini"-->
        <!--          :disabled="multiple"-->
        <!--          @click="handleDelete"-->
        <!--          v-hasPermi="['otc:otcAppealOrder:remove']"-->
        <!--        >删除</el-button>-->
        <!--      </el-col>-->
        <el-col :span="1.5">
          <el-button type="primary" size="medium" @click="handleExport"
            v-hasPermi="['otc:otcAppealOrder:export']">导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="otcAppealOrderList" @selection-change="handleSelectionChange">
        <el-table-column label="订单编号" align="center" prop="crateTime" width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.otcOrderNo}}</span>
          </template>
        </el-table-column>
        <el-table-column label="用户名称" align="center" prop="crateTime" width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.appealUserName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="交易类型" align="center" prop="crateTime" width="100">
          <template slot-scope="scope">
            <span :style="{color:scope.row.order.tradeType=='sell'?'rgba(231, 53, 53, 1)':'rgba(9, 186, 122, 1)'}">{{ scope.row.order.tradeType=='sell'?'出售':'购买' }}</span>
          </template>
        </el-table-column>

        <el-table-column label="交易币种" align="center" prop="crateTime" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.order.coin }}</span>
          </template>
        </el-table-column>

        <el-table-column label="交易数量" align="center" prop="crateTime" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.order.realityCoinNum  }}</span>
          </template>
        </el-table-column>

        <el-table-column label="交易单价" align="center" prop="crateTime" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.order.legalCurrency   }}</span>
          </template>
        </el-table-column>
        <el-table-column label="交易总价" align="center" prop="crateTime" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.order.realityLegalNums    }}</span>
          </template>
        </el-table-column>
        <el-table-column label="法币币种" align="center" prop="crateTime" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.order.limitCoin}}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" align="center" prop="crateTime" width="180">
          <template slot-scope="scope">
            <span :style="classObje(scope.row.order.appealStatus)">{{ appealStatusFormat(scope.row.order)}}</span>
          </template>
        </el-table-column>
       
        <el-table-column label="下单时间" align="center" prop="crateTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--          <el-button v-if="scope.row.appealImgUrl!=''"-->
            <!--            size="mini"-->
            <!--            type="text"-->
            <!--            icon="el-icon-edit"-->
            <!--            @click="handleUpdate(scope.row)"-->
            <!--            v-hasPermi="['otc:otcAppealOrder:edit']"-->
            <!--          >申诉凭证</el-button>-->
            <el-button v-if="scope.row.appealStatus == 'in_appeal'" size="mini" type="text"
              @click="handleApple(scope.row)" v-hasPermi="['otc:otcAppealOrder:edit']">审核处理</el-button>

            <el-button size="mini" type="text" @click="handleView(scope.row)">详情</el-button>

            <!--          <el-button-->
            <!--            size="mini"-->
            <!--            type="text"-->
            <!--            icon="el-icon-delete"-->
            <!--            @click="handleDelete(scope.row)"-->
            <!--            v-hasPermi="['otc:otcAppealOrder:remove']"-->
            <!--          >删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>


    <!-- 添加或修改OTC申诉订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <!--        <el-form-item label="订单编号" prop="otcOrderId">-->
        <!--          <el-input v-model="form.otcOrderId" placeholder="请输入订单编号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="订单号" prop="otcOrderNo">-->
        <!--          <el-input v-model="form.otcOrderNo" placeholder="请输入订单号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="本申诉订单号" prop="otcAppealNo">-->
        <!--          <el-input v-model="form.otcAppealNo" placeholder="请输入本申诉订单号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="申诉备注" prop="appealRemark">-->
        <!--          <el-input v-model="form.appealRemark" type="textarea" placeholder="请输入内容" />-->
        <!--        </el-form-item>-->
        <el-form-item label="申诉图片" prop="appealImgUrl">
          <img v-image-preview v-for="dict in form.listUrl" v-if="form.appealImgUrl" :src="dict" class="avatar"
            style="width: 150px" height="150px" @click="previewImage(dict)">
          <!--          <el-input v-model="form.appealImgUrl" type="textarea" placeholder="请输入内容" />-->
        </el-form-item>
        <!--        <el-form-item label="申诉状态">-->
        <!--          <el-radio-group v-model="form.appealStatus">-->
        <!--            <el-radio label="1">请选择字典生成</el-radio>-->
        <!--          </el-radio-group>-->
        <!--          <el-select v-model="form.appealStatus" placeholder="请选择申诉状态" clearable size="small">-->
        <!--            <el-option-->
        <!--              v-for="dict in appealStatusOptions"-->
        <!--              :key="dict.dictValue"-->
        <!--              :label="dict.dictLabel"-->
        <!--              :value="dict.dictValue"-->
        <!--            />-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="创建时间" prop="createTime">-->
        <!--          <el-date-picker clearable size="small"-->
        <!--            v-model="form.createTime"-->
        <!--            type="date"-->
        <!--            value-format="yyyy-MM-dd"-->
        <!--            placeholder="选择创建时间">-->
        <!--          </el-date-picker>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="申诉终端" prop="terminalSource">-->
        <!--          <el-input v-model="form.terminalSource" placeholder="请输入申诉终端" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="申诉方用户编号" prop="appealUserId">-->
        <!--          <el-input v-model="form.appealUserId" placeholder="请输入申诉方用户编号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="被申诉方编号" prop="beAppealUserId">-->
        <!--          <el-input v-model="form.beAppealUserId" placeholder="请输入被申诉方编号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="审核描述" prop="appealDesc">-->
        <!--          <el-input v-model="form.appealDesc" type="textarea" placeholder="请输入内容" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 申诉OTC申诉订单对话框 -->
    <el-dialog :title="title" :visible.sync="openApple" width="700px" append-to-body>
      <el-form ref="form" :model="formApple" :rules="rulesApple" label-width="120px">
        <el-form-item label="订单编号" prop="otcOrderId" hidden="hidden">
          <el-input v-model="formApple.otcOrderId" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="申诉方" prop="tradeType">
          <el-select v-model="formApple.tradeType" placeholder="申诉方" disabled="disabled">
            <el-option v-for="dict in appealTradeTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue" />
          </el-select>
        </el-form-item>
        <el-form-item label="申诉方昵称" prop="appealUserName">
          <el-input v-model="formApple.appealUserName" placeholder="请输入申诉人昵称" />
        </el-form-item>
        <el-form-item label="申诉缘由" prop="appealRemark">
          <el-input v-model="formApple.appealRemark" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="被申诉方昵称" prop="beAppealUserName">
          <el-input v-model="formApple.beAppealUserName" placeholder="请输入被申诉方昵称" />
        </el-form-item>
        <el-form-item label="申诉图片" prop="appealImgUrl">
          <img v-image-preview v-for="dict in formApple.listUrl"  :src="dict" class="avatar"
            style="width: 150px" height="150px" @click="previewImage(dict)" v-if="formApple.listUrl.length">
        </el-form-item>
        
        <el-form-item label="申诉状态">
          <el-radio-group v-model="formApple.appealStatus">
            <el-radio label="success_appeal">申诉成功</el-radio>
            <el-radio label="fail_appeal">申诉失败</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核描述" prop="appealDesc">
          <el-input v-model="formApple.appealDesc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormApple">确 定</el-button>
        <el-button @click="cancelApple">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOtcAppealOrder, getOtcAppealOrder, delOtcAppealOrder, addOtcAppealOrder, updateOtcAppealOrder, exportOtcAppealOrder, appleOtcAppealOrder } from "@/api/otc/otcAppealOrder";

export default {
  name: "OtcAppealOrder",
  components: {
  },
  computed:{
        classObje(status){
            return(status)=>{
            if(status=='in_appeal'){
                return {'color':'rgba(231, 53, 53, 1)'}
            }
            if(status=='success_appeal'){
                return {'color':'rgba(9, 186, 122, 1)'}
            }
            }
        }
    },
  data() {
    return {
      tradeTypeStatusOptions: [],
      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // OTC申诉订单表格数据
      otcAppealOrderList: [],
      appealStatusOptions: [],
      terminalSourceOptions: [],
      appealTradeTypeOptions: [],

      // 弹出层标题
      title: "",
      titleApple: "",
      // 是否显示弹出层
      open: false,
      openApple: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        otcOrderId: null,
        tradeType:null,
        otcOrderNo: null,
        otcAppealNo: null,
        appealRemark: null,
        appealImgUrl: null,
        appealStatus: null,
        terminalSource: null,
        appealUserId: null,
        beAppealUserId: null,
        appealDesc: null,
        payee:null,
        appealUserName:null,
      },
      // 表单参数
      form: {},
      formApple: {
        listUrl:[]
      },
      rules: {

      },
      // 表单校验
      rulesApple: {
        appealStatus: [
          { required: true, message: "请选择审核状态", trigger: "blur" }
        ],
        appealDesc: [
          { required: true, message: "审核描述不能为空", trigger: "blur" }
        ],
      },
      // 预览
      srcList: ["http://118.25.187.239:9099/img/adImg/557097620301025280.jpg"],
    };
  },
  created() {
    this.getList();
    this.getDicts("trade_type").then(response => {
      this.tradeTypeStatusOptions = response.data;
      this.tradeTypeStatusOptions.unshift({
        dictLabel:'全部',
        dictValue:null,
      });
    });
    this.getDicts("appeal_status").then(response => {
      this.appealStatusOptions = response.data;
      this.appealStatusOptions.unshift({
        dictLabel:'全部',
        dictValue:null,
      });
   
    });
    this.getDicts("terminal_source").then(response => {
      this.terminalSourceOptions = response.data;
      this.terminalSourceOptions.unshift({
        dictLabel:'全部',
        dictValue:null,
      });
    });
    this.getDicts("appeal_trade_type").then(response => {
      this.appealTradeTypeOptions = response.data;
      this.appealTradeTypeOptions.unshift({
        dictLabel:'全部',
        dictValue:null,
      });
    });
  },
  methods: {
    handleView(row) {
      this.$router.push(
        {
          name: 'appealDetail', params: { row: row }
        })
    },
    // 预览图片
    previewImage(abUrl) {
      this.srcList[0] = abUrl;
    },
    /** 查询OTC申诉订单列表 */
    getList() {
      this.loading = true;
      listOtcAppealOrder(this.addSESDateRange(this.queryParams, this.dateRange)).then(response => {
        this.otcAppealOrderList = response.rows;
        this.total = Number(response.total);
        this.loading = false;
      });
    },
    terminalSourceFormat(row, column) {
      return this.selectDictLabel(this.terminalSourceOptions, row.terminalSource);
    },
    appealStatusFormat(row, column) {
      return this.selectDictLabel(this.appealStatusOptions, row.appealStatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openApple=false
      this.reset();
    },
    // 取消按钮
    cancelApple() {
      this.openApple = false;
      this.resetApple();
    },
    // 表单重置
    reset() {
      this.form = {
      };
      this.dateRange = [];
      this.resetForm("form");
    },
    // 表单重置
    resetApple() {
      this.formApple = {

      };
      this.dateRange = [];
      this.resetForm("formApple");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加OTC申诉订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOtcAppealOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改OTC申诉订单";
      });
    },
    /** 申诉按钮操作 */
    handleApple(row) {
      this.resetApple();
      const id = row.id || this.ids
      getOtcAppealOrder(id).then(response => {
        this.formApple = response.data;
        this.openApple = true;
        this.title = "OTC申诉订单处理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOtcAppealOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOtcAppealOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 审核提交 */
    submitFormApple() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          appleOtcAppealOrder(this.formApple).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.openApple = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除OTC申诉订单编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delOtcAppealOrder(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有OTC申诉订单数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportOtcAppealOrder(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
