<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar v-if="topList.length > 0"
            :topList="topList"
            :moren="moren"></topBar>
    <div class="main">
      <el-form ref="select"
               :model="select"
               style="padding:10px 10px 10px 0;background-color: #fff"
               label-width="100px">
        <el-row>
          <!-- 一层 -->
          <el-col :span="4">
            <el-form-item  :label="'收款人'">
              <el-input clearable
                        v-model="select.bankAccountName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'账户类型'">
              <el-select clearable
                         :placeholder="'请选择'"
                         v-model="select.biz">
                <el-option v-for="item in eAgentBiz"
                           :key="item.value"
                           :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'提现状态'">
              <el-select clearable
                         :placeholder="'请选择'"
                         v-model="select.agentStatus">
                <el-option v-for="item in eAgentStatus"
                           :key="item.value"
                           :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'审核状态'">
              <el-select clearable
                         :placeholder="'请选择'"
                         v-model="select.approvalStatus">
                <el-option v-for="item in eAgentApprovalStatus"
                           :key="item.value"
                           :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">

          <el-form-item :label="'银行名称'"
                      prop="bankCode">
          <el-select clearable
                     :placeholder="'请选择银行名称'"
                     v-model="select.bankCode">
            <el-option v-for="item in eAgentBankList"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item :label="'银行名称'">
              <el-input clearable
                        v-model="select.bankName"></el-input>
            </el-form-item> -->
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'银行账户'">
              <el-input clearable
                        v-model="select.bankAccountNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'提现备注'">
              <el-input clearable
                        v-model="select.remark"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'审核人'">
              <el-input clearable
                        v-model="select.approver"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'审核备注'">
              <el-input clearable
                        v-model="select.approverRemark"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'单据编号'">
              <el-input clearable
                        v-model="select.agentCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'三方订单号'">
              <el-input clearable
                        v-model="select.thirdNum"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'银行流水号'">
              <el-input clearable
                        v-model="select.bankNum"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'提现日期'">
              <el-date-picker v-model="select.creationTime"
                              value-format="yyyy-MM-dd"
                              type="daterange"
                              :range-separator="'至'"
                              :start-placeholder="'开始日期'"
                              :end-placeholder="'结束日期'">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'审核日期'">
              <el-date-picker v-model="select.approverTime"
                              value-format="yyyy-MM-dd"
                              type="daterange"
                              :range-separator="'至'"
                              :start-placeholder="'开始日期'"
                              :end-placeholder="'结束日期'">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'到账日期'">
              <el-date-picker v-model="select.agentTime"
                              value-format="yyyy-MM-dd"
                              type="daterange"
                              :range-separator="'至'"
                              :start-placeholder="'开始日期'"
                              :end-placeholder="'结束日期'">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button class="my_search"
                       style="margin-left:30px"
                       @click="getDataList"> {{ '搜索' }}</el-button>
            <el-button class="my_reset"
                       @click="reset"> {{ '重置' }}</el-button>
          </el-col>
        </el-row>
      </el-form>
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small"
                     @click="openDig()"
                     v-has-buttons="['jdToPayAdd']"
                     class="thebtn1">{{'添加'}}</el-button>
          <el-button size="small"
                     @click="handleExport"
                     v-has-buttons="['jdToPayExport']"
                     class="thebtn4"> {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table :data="tableData"
        v-loading="loading"
                  height="600px"
                  style="width: 100%"
                  :header-cell-style="{ background: '#EEEEEE' }"
                  :row-class-name="tableRowClassName"
                  @selection-change="handleSelectionChange">
          <el-table-column type="selection"
                           width="55"> </el-table-column>
          <el-table-column align="center"
                           prop="bankAccountName"
                            :label="'收款人'">
          </el-table-column>
          <el-table-column align="center"
                           prop="bankName"
                           :label="'银行名称'">
          </el-table-column>
          <el-table-column align="center"
                           prop="bankAccountNo"
                           :label="'银行账户'">
          </el-table-column>
          <el-table-column align="center"
                           prop="biz"
                           :label="'账户类型'">
          </el-table-column>

          <!-- lll -->
          <el-table-column align="center"
                           prop="agentAmount"
                           :formatter="stateFormat"
                           :label="'提现金额'+`(${isLocalSymbol()})`" width="150">
          </el-table-column>
          <el-table-column align="center"
                           prop="creationTime"
                           :label="'提现日期'">
          </el-table-column>
          <el-table-column align="center"
                           prop="remark"
                           :label="'提现备注'">
          </el-table-column>
          <el-table-column align="center"
                           prop="agentStatusVal"
                           :label="'提现状态'">
          </el-table-column>
          <el-table-column align="center"
                           prop="errorMsg"
                           :label="'失败描述'">
          </el-table-column>
          <el-table-column align="center"
                           prop="approver"
                           :label="'审核人'">
          </el-table-column>
          <el-table-column align="center"
                           prop="approverTime"
                           :label="'审核日期'">
          </el-table-column>
          <el-table-column align="center"
                           prop="approverRemark"
                           :label="'审核备注'">
          </el-table-column>
          <el-table-column align="center"
                           prop="approvalStatusVal"
                           :label="'审核状态'">
          </el-table-column>
          <el-table-column align="center"
                           prop="agentTime"
                           :label="'到账日期'">
          </el-table-column>
          <el-table-column align="center"
                           prop="agentCode"
                           :label="'单据编号'">
          </el-table-column>
          <el-table-column align="center"
                           prop="thirdNum"
                           :label="'三方订单号'">
          </el-table-column>
          <el-table-column align="center"
                           prop="bankNum"
                           :label="'银行流水号'">
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getDataList" />
    <el-dialog :title="'添加'"
               :visible.sync="centerDialogVisible"
               width="30%"
               :close-on-click-modal="false"
               center>
      <el-form ref="form"
               :rules="rules"
               :model="form"
               label-width="auto">
        <el-form-item :label="'可提金额'">
          <el-input disabled
                    v-model="form.money"></el-input>
        </el-form-item>
        <el-form-item :label="'银行名称'"
                      prop="bankCode">
          <el-select clearable
                     :placeholder="'请选择银行名称'"
                     v-model="form.bankCode">
            <el-option v-for="item in eAgentBankList"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'银行账户'"
                      prop="bankAccountNo">
          <el-input :placeholder="'请输入'"
                    v-model="form.bankAccountNo"></el-input>
        </el-form-item>
        <el-form-item  :label="'收款人'"
                      prop="bankAccountName">
          <el-input :placeholder="'请输入收款人'"
                    v-model="form.bankAccountName"></el-input>
        </el-form-item>
        <el-form-item :label="'账户类型'"
                      prop="biz">
          <el-select clearable
                     :placeholder="'请选择账户类型'"
                     v-model="form.biz">
            <el-option v-for="item in eAgentBiz"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'提现金额'"
                      prop="agentAmount">
          <el-input :placeholder="'请输入'"
                    v-model="form.agentAmount"></el-input>
        </el-form-item>
        <el-form-item :label="'备注'">
          <el-input :placeholder="'请输入'"
                    v-model="form.agentRemark"></el-input>
        </el-form-item>
        <el-form-item :label="'渠道'"
                      prop="agentChannel">
          <el-select clearable
                     :placeholder="'请选择渠道'"
                     v-model="form.agentChannel">
            <el-option v-for="item in qudaoList"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="centerDialogVisible = false" class="cancels">{{'取消'}}</el-button>
        <el-button class="submit"
                   @click="saveForm">{{ '提现' }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/financialCase.js'
import {isLocalSymbol} from "@/utils/numberToCurrency";
export default {
  name: 'jdToPay',
  components: {
    topBar,
  },
  data() {
    return {
      moren: 'jdToPay',
      topList: [
        {
          name: '提现明细',
          path: 'cashDetails',
        },
        {
          name: '京东代付',
          path: 'jdToPay',
        },
      ],
      centerDialogVisible: false,
      form: {
        money: '',
      },
      rules: {
        bankCode: [
          { required: true, message: '请选择银行名称', trigger: 'blur' },
        ],
        bankAccountNo: [
          { required: true, message: '请输入银行账户', trigger: 'blur' },
        ],
        bankAccountName: [
          { required: true, message: '请输入收款人', trigger: 'blur' },
        ],
        agentAmount: [
          { required: true, message: '请输入提现金额', trigger: 'blur' },
        ],
        biz: [{ required: true, message: '请选择账户类型', trigger: 'change' }],
        agentChannel: [
          { required: true, message: '请选择渠道', trigger: 'change' },
        ],
      },
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      tableData: [],
      loading:false,
      // 账户类型
      eAgentBiz: [
        {
          value: 'B2B',
          label: '对公',
        },
        {
          value: 'B2C',
          label: '对私',
        },
      ],
      // 提现状态
      eAgentStatus: [
        {
          value: 0,
          label: '未提现',
        },
        {
          value: 1,
          label: '提现成功',
        },
        {
          value: 2,
          label: '提现失败',
        },
      ],
      // 审核状态
      eAgentApprovalStatus: [
        {
          value: 1,
          label: '审核中',
        },
        {
          value: 2,
          label: '审核通过',
        },
        {
          value: 3,
          label: '审核驳回',
        },
      ],
      // 银行列表
      eAgentBankList: [
        {
          value: 'ICBC',
          label: '工商银行',
        },
        {
          value: 'CCB',
          label: '建设银行',
        },
        {
          value: 'BOC',
          label: '中国银行',
        },
        {
          value: 'ABC',
          label: '农业银行',
        },
        {
          value: 'BOCO',
          label: '交通银行',
        },
        {
          value: 'POST',
          label: '邮政储蓄银行',
        },
        {
          value: 'CMBCHINA',
          label: '招商银行',
        },
        {
          value: 'SPDB',
          label: '浦发银行',
        },
        {
          value: 'ECITIC',
          label: '中信银行',
        },
        {
          value: 'CIB',
          label: '兴业银行',
        },
        {
          value: 'CEB',
          label: '光大银行',
        },
        {
          value: 'SZCB',
          label: '平安银行',
        },
        {
          value: 'CGB',
          label: '广发银行',
        },
        {
          value: 'CMBC',
          label: '民生银行',
        },
        {
          value: 'HXB',
          label: '华夏银行',
        },
      ],
      qudaoList: [
        {
          value: 4,
          label: '京东',
        },
      ],
    }
  },
  mounted() {
    // 获取列表
    this.getDataList()
  },
  methods: {
    isLocalSymbol,
    getQueryBalance() {
      api.queryBalance().then((res) => {
        this.form.money = res.data
      })
    },
    saveForm() {
      // 银行名称 form.bankCode
      // 账户类型 form.biz
      // 渠道 form.agentChannel
      this.eAgentBankList.forEach((item) => {
        if (item.value == this.form.bankCode) {
          this.form.bankName = item.label
        }
      })
      this.eAgentBiz.forEach((item) => {
        if (item.value == this.form.biz) {
          this.form.bizVal = item.label
        }
      })
      this.qudaoList.forEach((item) => {
        if (item.value == this.form.agentChannel) {
          this.form.agentChannelVal = item.label
        }
      })
      this.$router.push({
        path: 'jdZxqc',
        query: {
          data: JSON.stringify(this.form),
          index: 601,
        },
      })
    },
    openDig() {
      //查询余额
      this.getQueryBalance()
      this.centerDialogVisible = true
    },
    reset() {
      this.select = {}
      this.creationTime = []
      this.creationTime1 = []
      this.getDataList()
    },
    getDataList() {
      this.loading = true
      api
        .jdAgentList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm( '是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then((_) => {
        this.download(
          '/pay/manage/jd-agent/export',
          Object.assign({}, this.queryParams, this.select),
          `${'消费明细'}${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    },
  },
}
</script>
<style scoped lang="scss">
.submit{
  width: 209px;
  height: 48px;
  background: #c8161d;
  border-radius: 5px;
  color: #fff;
  font-size: 18px;
  border-color: #c8161d;
  margin-left: 20px;
}
.cancels{
  width: 209px;
  height: 48px;
  background: #CCCCCC;
  border-radius: 5px;
  color: #fff;
  font-size: 18px;
  border-color: #ccc;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .maintop {
      display: flex;
      padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
          width: 68px;
          height: 32px;
        }
        .thebtn4 {
          background: #ffad41;
          color: #ffffff;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          background: #c73030;
          color: #ffffff;
        }
        .thebtn3 {
          background: #6962f6;
          color: #ffffff;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .tem {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
.gth {
  text-align: center;
  margin-bottom: 30px;
  img {
    width: 87px;
    height: 78px;
    margin-bottom: 10px;
  }
}
::v-deep .el-input.is-disabled .el-input__inner{
  color: #333;
}
</style>
