<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <el-form
        ref="select"
        :model="select"
        style="background-color: #fff"
        label-width="100px"
      >
        <el-row>
          <!-- 一层 -->
          <el-col :span="4">
            <el-form-item :label="'转出编号'">
              <el-input v-model="select.memberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'转出姓名'">
              <el-input v-model="select.memberName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'接收编号'">
              <el-input v-model="select.toMemberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'接收姓名'">
              <el-input v-model="select.toMemberName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'接收钱包'">
              <el-select
                v-model="select.pkAccount"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in accountList"
                  :key="item.pkId"
                  :label="item.accountName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'接收钱包'">
              <el-select
                v-model="select.pkToAccount"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in accountList"
                  :key="item.pkId"
                  :label="item.accountName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'交易备注'">
              <el-input v-model="select.remarks" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'单据编号'">
              <el-input v-model="select.transferCode" clearable />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item :label="'转账日期'">
              <el-date-picker
                v-model="creationTime"
                value-format="yyyy-MM-dd"
                type="daterange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                @change="changeTime"
              />
            </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
            v-has-buttons="['TransferDetailsExport']"
            size="small"
            class="thebtn2"
            @click="handleExport"
          > {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          ref="mainTable"
          v-loading="loading"
          :data="tableData"
          height="680px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            width="50"
          />
          <el-table-column
            v-if="dataList[1].key"
            align="center"
            prop="memberCode"
            :label="'转出编号'"
            min-width="120px"
          />
          <el-table-column
            v-if="dataList[2].key"
            align="center"
            prop="memberName"
            :label="'转出姓名'"
          />
          <el-table-column
            v-if="dataList[3].key"
            align="center"
            prop="pkAccountVal"
            :label="'转出钱包'"
          />
          <el-table-column
            v-if="dataList[4].key"
            align="center"
            prop="transferMoney"
            :formatter="stateFormat"
            label="转账金额(¥)"
            width="140"
          />

          <el-table-column
            v-if="dataList[6].key"
            align="center"
            prop="serviceCharge"
            :formatter="stateFormat"
            :label="'转账手续费' +'(¥)'"
            width="140"
          />

          <el-table-column
            v-if="dataList[8].key"
            align="center"
            prop="toMemberCode"
            :label="'接收编号'"
            min-width="120px"
          />
          <el-table-column
            v-if="dataList[9].key"
            align="center"
            prop="toMemberName"
            :label="'接收姓名'"
          />
          <el-table-column
            v-if="dataList[10].key"
            align="center"
            prop="pkToAccountVal"
            :label="'接收钱包'"
          />
          <el-table-column
            v-if="dataList[11].key"
            align="center"
            prop="issuedAmount"
            :formatter="stateFormat"
            label="接收金额(¥)"
            width="120"
          />

          <el-table-column
            v-if="dataList[13].key"
            align="center"
            prop="exchangeRate"
            :label="'汇率'"
          />
          <el-table-column
            v-if="dataList[14].key"
            align="center"
            prop="creationTime"
            :label="'转账日期'"
            min-width="160px"
          />
          <el-table-column
            v-if="dataList[15].key"
            align="center"
            prop="remarks"
            :label="'交易备注'"
          />
          <el-table-column
            v-if="dataList[16].key"
            align="center"
            prop="transferCode"
            :label="'单据编号'"
            min-width="170px"
          />
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                style="color: #FFAD41"
                type="text"
                size="small"
                @click="toFixed(scope.row.pkId)"
              >
                {{ '导出' }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/financialCase.js'
import { stateFormat } from '@/utils/numberToCurrency'
import { mapGetters } from 'vuex'
import { getRoleMenu } from '@/api/notice'

export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许'
      } else {
        return '禁止'
      }
    }
  },
  data() {
    return {
      moren: 'transferDetails',
      topList: [
        {
          name: '转账明细',
          path: 'transferDetails'
        }
      ],
      creationTime: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading: false,
      accountList: [],
      tradeTypeList: [],
      dataList: [
        {
          name: 'pkCountryName',
          key: ''
        },
        {
          name: 'memberCode',
          key: ''
        },
        {
          name: 'memberName',
          key: ''
        },
        {
          name: 'pkAccountVal',
          key: ''
        },
        {
          name: 'transferMoney',
          key: ''
        },
        {
          name: 'settleTransferMoney',
          key: ''
        },
        {
          name: 'serviceCharge',
          key: ''
        },
        {
          name: 'settleServiceCharge',
          key: ''
        },
        {
          name: 'toMemberCode',
          key: ''
        },
        {
          name: 'toMemberName',
          key: ''
        },
        {
          name: 'pkToAccountVal',
          key: ''
        },
        {
          name: 'issuedAmount',
          key: ''
        },
        {
          name: 'settleIssuedAmount',
          key: ''
        },
        {
          name: 'exchangeRate',
          key: ''
        },
        {
          name: 'creationTime',
          key: ''
        },
        {
          name: 'remarks',
          key: ''
        },
        {
          name: 'transferCode',
          key: ''
        }
      ]
    }
  },
  computed: {
    ...mapGetters(['getUser'])
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
    this.getUserRole()
  },
  methods: {
    getUserRole() {
      getRoleMenu('TransferDetails').then((res) => {
        this.dataList.forEach((item) => {
          res.data.forEach((items) => {
            if (item.name == items) {
              item.key = items
            }
            // this.flag = true
          })
        })
      })
    },
    stateFormat,
    reset() {
      this.select = {}
      this.creationTime = []
      this.getDataList()
    },
    getData() {
      api.pkBdAccountList().then((res) => {
        this.accountList = res.rows
      })
      api.getTradeType().then((res) => {
        this.tradeTypeList = res.data
      })
    },
    changeTime(val) {
      this.select.startDate = val[0]
      this.select.endDate = val[1]
    },
    // 点击修改
    toFixed(id) {},
    getDataList() {
      this.loading = true
      api
        .transferList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          res.rows.forEach((item) => {
            item.nationalFlag2 = this.getUser.country.nationalFlag2
          })
          this.tableData = res.rows
          this.total = res.total
          this.loading = false
          this.$nextTick(() => {
            this.$refs.mainTable.doLayout()
          })
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/member/manager/transfer/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">
::v-deep .el-range-editor.el-input__inner{
  width: 100%;
}
::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;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
          width: 68px;
          height: 32px;
        }
      }
      .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;
}

</style>
