<!--
 * @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="$t('MN_F_T_565')">
              <el-input clearable
                        v-model="select.bankAccountName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('w_0294')">
              <el-select clearable
                         :placeholder="$t('CK_KS_38')"
                         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="$t('MN_F_T_568')">
              <el-select clearable
                         :placeholder="$t('CK_KS_38')"
                         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="$t('MN_F_11')">
              <el-select clearable
                         :placeholder="$t('CK_KS_38')"
                         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="$t('CK_KS_41')"
                      prop="bankCode">
          <el-select clearable
                     :placeholder="$t('w_0270')"
                     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="$t('CK_KS_41')">
              <el-input clearable
                        v-model="select.bankName"></el-input>
            </el-form-item> -->
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MN_F_T_538')">
              <el-input clearable
                        v-model="select.bankAccountNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MN_F_T_541')">
              <el-input clearable
                        v-model="select.remark"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MN_F_T_522')">
              <el-input clearable
                        v-model="select.approver"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MN_F_T_526')">
              <el-input clearable
                        v-model="select.approverRemark"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('w_0296')">
              <el-input clearable
                        v-model="select.agentCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MN_F_T_569')">
              <el-input clearable
                        v-model="select.thirdNum"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MN_F_T_570')">
              <el-input clearable
                        v-model="select.bankNum"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('w_0439')">
              <el-date-picker v-model="select.creationTime"
                              value-format="yyyy-MM-dd"
                              type="daterange"
                              :range-separator="$t('w_0139')"
                              :start-placeholder="$t('CK_KS_4')"
                              :end-placeholder="$t('CK_KS_5')">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('MN_F_Y_4')">
              <el-date-picker v-model="select.approverTime"
                              value-format="yyyy-MM-dd"
                              type="daterange"
                              :range-separator="$t('w_0139')"
                              :start-placeholder="$t('CK_KS_4')"
                              :end-placeholder="$t('CK_KS_5')">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('w_0440')">
              <el-date-picker v-model="select.agentTime"
                              value-format="yyyy-MM-dd"
                              type="daterange"
                              :range-separator="$t('w_0139')"
                              :start-placeholder="$t('CK_KS_4')"
                              :end-placeholder="$t('CK_KS_5')">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button class="my_search"
                       style="margin-left:30px"
                       @click="getDataList"> {{ $t('MN_T_2') }}</el-button>
            <el-button class="my_reset"
                       @click="reset"> {{ $t('MN_T_3') }}</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">{{$t('w_0328')}}</el-button>
          <el-button size="small"
                     @click="handleExport"
                     v-has-buttons="['jdToPayExport']"
                     class="thebtn4"> {{ $t('MN_T_8') }}</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="$t('MN_F_T_565')">
          </el-table-column>
          <el-table-column align="center"
                           prop="bankName"
                           :label="$t('CK_KS_41')">
          </el-table-column>
          <el-table-column align="center"
                           prop="bankAccountNo"
                           :label="$t('MN_F_T_538')">
          </el-table-column>
          <el-table-column align="center"
                           prop="biz"
                           :label="$t('w_0294')">
          </el-table-column>

          <!-- lll -->
          <el-table-column align="center"
                           prop="agentAmount"
                           :formatter="stateFormat"
                           :label="$t('MY_WAL_26')+`(${isLocalSymbol()})`" width="150">
          </el-table-column>
          <el-table-column align="center"
                           prop="creationTime"
                           :label="$t('w_0439')">
          </el-table-column>
          <el-table-column align="center"
                           prop="remark"
                           :label="$t('MN_F_T_541')">
          </el-table-column>
          <el-table-column align="center"
                           prop="agentStatusVal"
                           :label="$t('MN_F_T_568')">
          </el-table-column>
          <el-table-column align="center"
                           prop="errorMsg"
                           :label="$t('MN_F_T_573')">
          </el-table-column>
          <el-table-column align="center"
                           prop="approver"
                           :label="$t('MN_F_T_522')">
          </el-table-column>
          <el-table-column align="center"
                           prop="approverTime"
                           :label="$t('MN_F_Y_4')">
          </el-table-column>
          <el-table-column align="center"
                           prop="approverRemark"
                           :label="$t('MN_F_T_526')">
          </el-table-column>
          <el-table-column align="center"
                           prop="approvalStatusVal"
                           :label="$t('MN_F_11')">
          </el-table-column>
          <el-table-column align="center"
                           prop="agentTime"
                           :label="$t('w_0440')">
          </el-table-column>
          <el-table-column align="center"
                           prop="agentCode"
                           :label="$t('w_0296')">
          </el-table-column>
          <el-table-column align="center"
                           prop="thirdNum"
                           :label="$t('MN_F_T_569')">
          </el-table-column>
          <el-table-column align="center"
                           prop="bankNum"
                           :label="$t('MN_F_T_570')">
          </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="$t('w_0328')"
               :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="$t('MN_F_T_550')">
          <el-input disabled
                    v-model="form.money"></el-input>
        </el-form-item>
        <el-form-item :label="$t('CK_KS_41')"
                      prop="bankCode">
          <el-select clearable
                     :placeholder="$t('w_0270')"
                     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="$t('MN_F_T_538')"
                      prop="bankAccountNo">
          <el-input :placeholder="$t('S_C_70')"
                    v-model="form.bankAccountNo"></el-input>
        </el-form-item>
        <el-form-item  :label="$t('MN_F_T_565')"
                      prop="bankAccountName">
          <el-input :placeholder="$t('MN_F_T_566')"
                    v-model="form.bankAccountName"></el-input>
        </el-form-item>
        <el-form-item :label="$t('w_0294')"
                      prop="biz">
          <el-select clearable
                     :placeholder="$t('MN_F_T_567')"
                     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="$t('MY_WAL_26')"
                      prop="agentAmount">
          <el-input :placeholder="$t('S_C_70')"
                    v-model="form.agentAmount"></el-input>
        </el-form-item>
        <el-form-item :label="$t('MY_WAL_22')">
          <el-input :placeholder="$t('S_C_70')"
                    v-model="form.agentRemark"></el-input>
        </el-form-item>
        <el-form-item :label="$t('MN_F_T_575')"
                      prop="agentChannel">
          <el-select clearable
                     :placeholder="$t('MN_F_T_574')"
                     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">{{$t('ENU_P_TYPE0')}}</el-button>
        <el-button class="submit"
                   @click="saveForm">{{ $t('ENU_TRADE_T_200') }}</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: this.$t('MN_F_T_90'),
          path: 'cashDetails',
        },
        {
          name: this.$t('MN_F_T_91'),
          path: 'jdToPay',
        },
      ],
      centerDialogVisible: false,
      form: {
        money: '',
      },
      rules: {
        bankCode: [
          { required: true, message: this.$t('w_0270'), trigger: 'blur' },
        ],
        bankAccountNo: [
          { required: true, message: this.$t('MN_F_T_576'), trigger: 'blur' },
        ],
        bankAccountName: [
          { required: true, message: this.$t('MN_F_T_566'), trigger: 'blur' },
        ],
        agentAmount: [
          { required: true, message: this.$t('MN_F_T_577'), trigger: 'blur' },
        ],
        biz: [{ required: true, message: this.$t('MN_F_T_567'), trigger: 'change' }],
        agentChannel: [
          { required: true, message: this.$t('MN_F_T_574'), trigger: 'change' },
        ],
      },
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      tableData: [],
      loading:false,
      // 账户类型
      eAgentBiz: [
        {
          value: 'B2B',
          label: this.$t('MN_F_T_578'),
        },
        {
          value: 'B2C',
          label: this.$t('MN_F_T_579'),
        },
      ],
      // 提现状态
      eAgentStatus: [
        {
          value: 0,
          label: this.$t('MN_F_T_580'),
        },
        {
          value: 1,
          label: this.$t('MN_F_T_581'),
        },
        {
          value: 2,
          label: this.$t('MN_F_T_582'),
        },
      ],
      // 审核状态
      eAgentApprovalStatus: [
        {
          value: 1,
          label: this.$t('ENU_APPROVE_S_3'),
        },
        {
          value: 2,
          label: this.$t('ENU_R_A_O_2'),
        },
        {
          value: 3,
          label: this.$t('ENU_R_A_O_3'),
        },
      ],
      // 银行列表
      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: this.$t('ENU_PAY_CHA_4'),
        },
      ],
    }
  },
  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( this.$t('MN_F_T_407'), this.$t('MN_F_T_304'), {
        confirmButtonText: this.$t('w_0035'),
        cancelButtonText: this.$t('ENU_P_TYPE0'),
        type: 'warning',
      }).then((_) => {
        this.download(
          '/pay/manage/jd-agent/export',
          Object.assign({}, this.queryParams, this.select),
          `${this.$t('MN_F_T_92')}${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>
