<!--
 * @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="form"
        :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-select
                v-model="select.vertexId"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in vertexList"
                  :key="item.pkId"
                  :label="item.vertexName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'团队名称'">
              <el-select
                v-model="select.teamId"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in memberTeamList"
                  :key="item.pkId"
                  :label="item.teamName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'血缘代数'">
              <el-input v-model="select.plevel" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'安置层数'">
              <el-input v-model="select.slevel" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col style="display: flex">
            <el-col :span="4">
              <div class="searchbox" style="margin-left: 30px">
                <el-button class="my_search" @click="getDataList()"> {{ '搜索' }}</el-button>
                <el-button class="my_reset" @click="reset"> {{ '重置' }}</el-button>
              </div>
            </el-col>
          </el-col>
        </el-row>

      </el-form>
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            v-hasButtons="['WalletDetailssExport']"
            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="55"
          />
          <el-table-column
            align="center"
            width="120"
            prop="memberCode"
            :label="'会员编号'"
          />
          <el-table-column
            align="center"
            prop="memberName"
            :label="'会员姓名'"
          />
          <el-table-column
            align="center"
            prop="vertexName"
            :label="'体系名称'"
            min-width="120px"
          />
          <el-table-column
            align="center"
            prop="teamName"
            :label="'团队名称'"
          />
          <el-table-column
            align="center"
            prop="plevel"
            :label="'血缘代数'"
          />
          <el-table-column
            align="center"
            prop="slevel"
            :label="'安置层数'"
          />
          <el-table-column
            v-if="showData.account1"
            align="center"
            prop="account1"
            :formatter="stateFormat"
            :label="'消费余额'+'(¥)'"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount1"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount1"
            :label="'可用消费'+'(¥)'"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount1"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount1"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount1"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount1"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account2"
            align="center"
            :formatter="stateFormat"
            prop="account2"
            :label="'现金余额'+'(¥)'"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount2"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount2"
            :label="'可用现金'+'(¥)'"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount2"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount2"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount2"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount2"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account3"
            align="center"
            :formatter="stateFormat"
            prop="account3"
            :label="'政策余额'+'(¥)'"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount3"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount3"
            :label="'可用政策'+'(¥)'"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount3"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount3"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount3"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount3"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account4"
            align="center"
            :formatter="stateFormat"
            prop="account4"
            :label="`${'奖金余额'}(${isLocalSymbol()})`"
            width="140"
          />

          <el-table-column
            v-if="showData.availableAccount4"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount4"
            :label="`${'可用奖金'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.submitAccount4"
            align="center"
            :formatter="stateFormat"
            prop="submitAccount4"
            :label="`${'可提奖金'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount4"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount4"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount4"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount4"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockWithdrawAccount4"
            align="center"
            :formatter="stateFormat"
            prop="lockWithdrawAccount4"
            :label="`${'禁止提现'}(${isLocalSymbol()})`"
            width="140"
          />
          <!-- 弟弟 -->
          <el-table-column
            v-if="showData.account5"
            align="center"
            prop="account5"
            :formatter="stateFormat"
            :label="`${'重消余额'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount5"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount5"
            :label="`${'可用重消'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount5"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount5"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount5"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount5"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <!-- 弟弟 -->
          <el-table-column
            v-if="showData.account6"
            align="center"
            :formatter="stateFormat"
            prop="account6"
            :label="`${'积分余额'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount6"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount6"
            :label="`${'可用积分'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount6"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount6"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount6"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount6"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <!-- 弟弟 -->
          <el-table-column
            v-if="showData.account7"
            align="center"
            :formatter="stateFormat"
            prop="account7"
            :label="`${'鼓励余额'}${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount7"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount7"
            :label="`${'可用鼓励'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount7"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount7"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount7"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount7"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <!-- 弟弟 -->
          <el-table-column
            v-if="showData.account8"
            align="center"
            :formatter="stateFormat"
            prop="account8"
            :label="`${'复购券余额'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount8"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount8"
            :label="`${'可用复购券'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount8"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount8"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount8"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount8"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account9"
            align="center"
            :formatter="stateFormat"
            prop="account9"
            :label="'全球积分余额' +'(￥)'"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount9"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount9"
            :label="'可用全球积分'"
            width="140"
          />

          <el-table-column
            v-if="showData.lockTransferAccount9"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount9"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account10"
            align="center"
            :formatter="stateFormat"
            prop="account10"
            :label="'车奖积分余额'"
            width="140"
          />

          <el-table-column
            v-if="showData.availableAccount10"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount10"
            :label="'可用车奖积分'"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount10"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount10"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockTransferAccount10"
            align="center"
            :formatter="stateFormat"
            prop="lockTransferAccount10"
            :label="`${'禁止转账'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account11"
            align="center"
            :formatter="stateFormat"
            prop="account11"
            :label="`${'直播代金券'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount11"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount11"
            :label="`可用直播代金券(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account12"
            align="center"
            :formatter="stateFormat"
            prop="account12"
            :label="`${'乐学代金券'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount12"
            align="center"
            :formatter="stateFormat"
            prop="account11"
            :label="`可用乐学代金券(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.account13"
            align="center"
            :formatter="stateFormat"
            prop="account13"
            :label="`${'海豆余额'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.availableAccount13"
            align="center"
            :formatter="stateFormat"
            prop="availableAccount13"
            :label="`${'可用海豆'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            v-if="showData.lockAccount13"
            align="center"
            :formatter="stateFormat"
            prop="lockAccount13"
            :label="`${'禁止消费'}(${isLocalSymbol()})`"
            width="140"
          />
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
            width="100"
          >
            <template slot-scope="scope">
              <el-button
                v-has-buttons="['WalletDetailssExport']"
                class="button-s"
                type="text"
                size="small"
                style="color: #FFAD41"
                @click="handleExportAlone(scope.row.pkId)"
              >
                {{ '导出' }}
              </el-button>
              <el-button
                style="color: #E70DEC"
                type="text"
                class="button-s"
                size="small"
                @click="toDetails(scope.row.memberCode)"
              >
                {{ '查看' }}
              </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 { getenumsAccount } from '@/api/financial'
import topBar from '@/components/topBar'
import * as api from '@/api/financialCase.js'
import { mapGetters } from 'vuex'
import { isLocalSymbol, stateFormat } from '@/utils/numberToCurrency'
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许'
      } else {
        return '禁止'
      }
    }
  },
  data() {
    return {
      creationTime: [],
      select: {
        pkMemberTeam: []
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        pkAccounts: [] // 币种选择
      },
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading: false,
      accountList: [],
      vertexList: [],
      memberTeamList: [],
      enumsAccountList: [],
      moren: 'walletDetails',
      topList: [
        {
          name: '钱包明细',
          path: 'walletDetails'
        }
      ],
      showData: {}
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
    this.getenumsAccount()
    this.getOthers()
  },
  computed: {
    ...mapGetters(['getUser'])
  },
  methods: {
    isLocalSymbol,
    stateFormat,
    getOthers() {
      api.listField().then((res) => {
        const obj = {}
        res.data.forEach((ele) => {
          obj[ele] = true
        })
        this.showData = obj
      })
    },
    changeAccount() {
      this.titelList = []
      this.queryParams.pkAccounts.forEach((ele) => {
        this.enumsAccountList.forEach((item) => {
          if (ele == item.pkId) {
            this.titelList.push({ value: ele, label: item.accountName })
          }
        })
      })
      this.getDataList()
    },
    getenumsAccount() {
      getenumsAccount().then((res) => {
        this.enumsAccountList = res.rows
      })
    },
    reset() {
      this.select = {}
      this.getDataList()
    },
    getData() {
      api.pkBdAccountList().then((res) => {
        this.accountList = res.rows
      })
      api.getvertexValue().then((res) => {
        this.vertexList = res.data
      })
      api.getmemberTeamList().then((res) => {
        this.memberTeamList = res.rows
      })
    },
    changeTime(val) {
      this.select.startDate = val[0]
      this.select.endDate = val[1]
    },
    toDetails(id) {
      this.$router.push({
        path: 'walletDetails/details',
        query: {
          memberCode: id
        }
      })
    },
    // 点击修改
    toFixed(id) {},
    getDataList() {
      this.loading = true
      api
        .accountList(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/account/export',
          Object.assign({}, this.queryParams, this.select),
          `${'钱包明细'}${new Date().getTime()}.xlsx`
        )
      })
    },
    handleExportAlone(id) {
      console.log('%c [ id ]-468', 'font-size:13px; background:#34e86c; color:#78ffb0;', id)
      this.$confirm('是否确认导出当前数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/member/manager/account/export',
          { pkIds: [id] },
          `${'钱包明细'}${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">
.button-s{
  padding: 3px 0;
}
::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;
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}
</style>
