<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <el-form-item label="交易类型" prop="appealStatus">
         <el-select v-model="queryParams.tradeType" placeholder="请选择交易类型" clearable size="small">
           <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="storeId">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入商家昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="币种" prop="coin">
        <el-input
          v-model="queryParams.coin"
          placeholder="请输入币种"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


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


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['otc:otcStoreOrder:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['otc:otcStoreOrder: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:otcStoreOrder:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['otc:otcStoreOrder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="otcStoreOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="流水编号" align="center" prop="id" />-->
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="交易类型" align="center" prop="tradeType"   :formatter="tradeTypeFormat" />
<!--      <el-table-column label="商家编号" align="center" prop="storeId" />-->
      <el-table-column label="商家昵称" align="center" prop="storeName" />
      <el-table-column label="币种" align="center" prop="coin" />
<!--      <el-table-column label="币种数量" align="center" prop="coinNum" />-->
      <el-table-column label="实际币种数量" align="center" prop="realityCoinNum" />
      <el-table-column label="剩余数量" align="center" prop="remainNum" />
      <el-table-column label="法币价格" align="center" prop="legalCurrency" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" :formatter="orderStatusFormat" />
<!--      <el-table-column label="最小限额" align="center" prop="minLimit" />-->
<!--      <el-table-column label="最大限额" align="center" prop="maxLimit" />-->
      <el-table-column label="法币币种" align="center" prop="limitCoin" />
<!--      <el-table-column label="类型" align="center" prop="feeType"  :formatter="feeTypeFormat"/>-->
      <el-table-column label="手续费" align="center" prop="fee" />
<!--      <el-table-column label="费率" align="center" prop="feeRate" />-->
      <el-table-column label="已扣除手续费" align="center" prop="deductedFee" />
<!--      <el-table-column label="收款方式多个逗号分割" align="center" prop="walletType" />-->
      <el-table-column label="交易说明" align="center" prop="transactionDesc" />
      <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-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['otc:otcStoreOrder:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['otc:otcStoreOrder:edit']"
          >详情</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['otc:otcStoreOrder: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"
    />

    <!-- 添加或修改otc订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="交易类型" prop="tradeType">
          <el-select v-model="form.tradeType" placeholder="请选择交易类型">
<!--            <el-option label="请选择字典生成" value="" />-->
            <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="storeId">-->
<!--          <el-input v-model="form.storeId" placeholder="请输入商家编号" />-->
<!--        </el-form-item>-->
        <el-form-item label="商家昵称" prop="storeId">
          <el-input v-model="form.storeName" placeholder="请输入商家编号" />
        </el-form-item>
        <el-form-item label="币种" prop="coin">
          <el-input v-model="form.coin" placeholder="请输入币种" />
        </el-form-item>
        <el-form-item label="币种数量" prop="coinNum">
          <el-input v-model="form.coinNum" placeholder="请输入币种数量" />
        </el-form-item>
        <el-form-item label="实际币种数量" prop="realityCoinNum">
          <el-input v-model="form.realityCoinNum" placeholder="请输入实际币种数量" />
        </el-form-item>
        <el-form-item label="剩余数量" prop="remainNum">
          <el-input v-model="form.remainNum" placeholder="请输入剩余数量" />
        </el-form-item>
        <el-form-item label="法币价格" prop="legalCurrency">
          <el-input v-model="form.legalCurrency" placeholder="请输入法币价格" />
        </el-form-item>
        <el-form-item label="订单状态">
<!--          <el-radio-group v-model="form.orderStatus">-->
<!--            <el-radio label="1">请选择字典生成</el-radio>-->
<!--          </el-radio-group>-->
          <el-select v-model="form.orderStatus" placeholder="订单状态">
            <el-option
              v-for="dict in orderStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="最小限额" prop="minLimit">
          <el-input v-model="form.minLimit" placeholder="请输入最小限额" />
        </el-form-item>
        <el-form-item label="最大限额" prop="maxLimit">
          <el-input v-model="form.maxLimit" placeholder="请输入最大限额" />
        </el-form-item>
        <el-form-item label="限额币种" prop="limitCoin">
          <el-input v-model="form.limitCoin" placeholder="请输入限额币种" />
        </el-form-item>
        <el-form-item label="手续费类型：" prop="feeType">
          <el-select v-model="form.feeType" placeholder="手续费类型">
<!--            <el-option label="请选择字典生成" value="" />-->
            <el-option
              v-for="dict in feeTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="手续费" prop="fee">
          <el-input v-model="form.fee" placeholder="请输入手续费" />
        </el-form-item>
        <el-form-item label="手续费率" prop="feeRate">
          <el-input v-model="form.feeRate" placeholder="手续费率" />
        </el-form-item>
        <el-form-item label="已扣除手续费" prop="deductedFee">
          <el-input v-model="form.deductedFee" placeholder="请输入已扣除手续费" />
        </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="walletType">-->
<!--            <el-input v-model="form.walletType" placeholder="收款方式" />-->
<!--        </el-form-item>-->
        <el-form-item label="收款方式" prop="walletType">
          <el-input v-model="form.walletTypeName" placeholder="收款方式" />
        </el-form-item>
        <el-form-item label="交易说明" prop="transactionDesc">
          <el-input v-model="form.transactionDesc" 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>
  </div>
</template>

<script>
import { listOtcStoreOrder, getOtcStoreOrder, delOtcStoreOrder, addOtcStoreOrder, updateOtcStoreOrder, exportOtcStoreOrder } from "@/api/otc/otcStoreOrder";

export default {
  name: "OtcStoreOrder",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // otc订单信息表格数据
      otcStoreOrderList: [],
      feeTypeOptions: [],
        orderStatusOptions: [],
           tradeTypeStatusOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        tradeType: null,
        storeId: null,
        coin: null,
        coinNum: null,
        realityCoinNum: null,
        remainNum: null,
        legalCurrency: null,
        orderStatus: null,
        minLimit: null,
        maxLimit: null,
        limitCoin: null,
        feeType: null,
        fee: null,
        feeRate: null,
        deductedFee: null,
        walletType: null,
        transactionDesc: null,
        storeName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNo: [
          { required: true, message: "订单编号不能为空", trigger: "blur" }
        ],
        storeId: [
          { required: true, message: "商家编号不能为空", trigger: "blur" }
        ],
        coin: [
          { required: true, message: "币种不能为空", trigger: "blur" }
        ],
        coinNum: [
          { required: true, message: "币种数量不能为空", trigger: "blur" }
        ],
        realityCoinNum: [
          { required: true, message: "实际币种数量不能为空", trigger: "blur" }
        ],
        legalCurrency: [
          { required: true, message: "法币价格不能为空", trigger: "blur" }
        ],
        orderStatus: [
          { required: true, message: "订单状态(挂单中 pending_order、已锁住is_lock、已完成 close、已取消 cancel、待放行released,申诉中in_appeal）不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("order_status").then(response => {
      this.orderStatusOptions = response.data;
    });

    this.getDicts("fee_type").then(response => {
      this.feeTypeOptions = response.data;
    });
    this.getDicts("trade_type").then(response => {
      this.tradeTypeStatusOptions = response.data;
    });

  },
  methods: {
    /** 查询otc订单信息列表 */
    getList() {
      this.loading = true;
      listOtcStoreOrder(this.queryParams).then(response => {
        this.otcStoreOrderList = response.rows;
        this.total = Number(response.total);
        this.loading = false;
      });
    },
  orderStatusFormat(row, column) {
       return this.selectDictLabel(this.orderStatusOptions, row.orderStatus);
    },

    feeTypeFormat(row, column) {

       return this.selectDictLabel(this.feeTypeOptions, row.feeType);
    },

    tradeTypeFormat(row, column) {

       return this.selectDictLabel(this.tradeTypeStatusOptions, row.tradeType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        tradeType: null,
        storeId: null,
        coin: null,
        coinNum: null,
        realityCoinNum: null,
        remainNum: null,
        legalCurrency: null,
        orderStatus: "0",
        minLimit: null,
        maxLimit: null,
        limitCoin: null,
        feeType: null,
        fee: null,
        feeRate: null,
        deductedFee: null,
        createTime: null,
        updateTime: null,
        walletType: null,
        transactionDesc: null,
        walletTypeName:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      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
      getOtcStoreOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改otc订单信息";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getOtcStoreOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查询otc订单信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOtcStoreOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOtcStoreOrder(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除otc订单信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOtcStoreOrder(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有otc订单信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOtcStoreOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
