<!--
 * @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=""
        label-width="100px"
      >
        <el-row style="background-color: #fff;">
          <!-- 一层 -->
          <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.tradeAmount" clearable />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4">
            <el-form-item :label="'备注'">
              <el-input clearable  v-model="select.remarks"></el-input>
            </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.tradeType"
                clearable
                placeholder=""
              >
                <el-option
                  v-for="item in tradeTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'单据编号'">
              <el-input v-model="select.sourceCode" 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: 40px" @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="['ConsumptionDetailsExport']"
            size="small"
            class="thebtn1"
            @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="55"
          />

          <el-table-column
            v-if="dataList[1].key"
            align="center"
            prop="memberCode"
            label="会员编号"
            width="110"
          />
          <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="tradeTypeVal"
            label="交易类型"
            width="140"
          />
          <el-table-column
            v-if="dataList[5].key"
            align="center"
            prop="tradeBeforeBalance"
            :formatter="stateFormat"
            :label="'历史余额'+`(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="dataList[7].key"
            align="center"
            prop="tradeAmount"
            :formatter="stateFormat"
            :label="'交易金额'+`(${isLocalSymbol()})`"
            width="100"
          />
          <el-table-column
            v-if="dataList[6].key"
            align="center"
            prop="tradeBalance"
            :formatter="stateFormat"
            :label="'当前余额'+`(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="dataList[11].key"
            align="center"
            prop="exchangeRate"
            :label="'汇率'"
          />

          <el-table-column
            v-if="dataList[12].key"
            align="center"
            prop="creationTime"
            :label="'交易日期'"
            width="160"
          />
          <el-table-column
            v-if="dataList[13].key"
            align="center"
            prop="sourceCode"
            label="单据编号"
            width="170"
          />
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                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 { mapGetters } from 'vuex'

import { isLocals, isLocalSymbol, stateFormat } from '@/utils/numberToCurrency'
import { getRoleMenu } from '@/api/notice'
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许'
      } else {
        return '禁止'
      }
    }
  },
  data() {
    return {
      moren: 'consumptionDetails',
      topList: [
        {
          name: '消费明细',
          path: 'consumptionDetails'
        }
      ],
      creationTime: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      total: 0,
      dialogVisible: false,
      loading: false,
      tableData: [],
      accountList: [],
      tradeTypeList: [],
      dataList: [
        {
          name: 'pkCountryName',
          key: ''
        },
        {
          name: 'memberCode',
          key: ''
        },
        {
          name: 'memberName',
          key: ''
        },
        {
          name: 'pkAccountVal',
          key: ''
        },
        {
          name: 'tradeTypeVal',
          key: ''
        },
        {
          name: 'tradeBeforeBalance',
          key: ''
        },
        {
          name: 'tradeBalance',
          key: ''
        },
        {
          name: 'tradeAmount',
          key: ''
        },
        {
          name: 'settleTradeBeforeBalance',
          key: ''
        },
        {
          name: 'settleTradeBalance',
          key: ''
        },
        {
          name: 'settleTradeAmount',
          key: ''
        },
        {
          name: 'exchangeRate',
          key: ''
        },
        {
          name: 'creationTime',
          key: ''
        },
        {
          name: 'sourceCode',
          key: ''
        }
      ]
    }
  },
  computed: {
    ...mapGetters(['getUser'])
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
    this.getUserRole()
  },
  methods: {
    isLocalSymbol,
    isLocals,
    getUserRole() {
      getRoleMenu('ConsumptionDetails').then((res) => {
        this.dataList.forEach((item) => {
          res.data.forEach((items) => {
            if (item.name == items) {
              item.key = items
            }
            // this.flag = true
          })
        })
      })
    },
    reset() {
      this.select = {}
      this.creationTime = []
      this.getDataList()
    },
    stateFormat,
    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
        .tradeList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          res.rows.forEach((item) => {
            item.nationalFlag2 = this.getUser.country.nationalFlag2
          })
          this.tableData = res.rows
          this.loading = false
          this.$nextTick(() => {
            this.$refs.mainTable.doLayout()
          })
          this.total = res.total
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/member/manager/trade/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: 0px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #FFAD41;
          color: #ffffff;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          background: #ffad41;
          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;
}
</style>
