<template>
  <view class="content">
    <view class="header">
      <view class="headernei" @click="isTop = true">
        <img src="@/assets/images/search.png" alt="" />
      </view>
    </view>
    <view class="kuang" v-for="(item, index) in tableData" :key="index">
      <table class="tftable" border="1">
        <tr   v-if="dataList[0].key">
          <td align="right">{{ '国家' }}</td>
          <td align="left">
            <view class="theflex">
              <view style="margin-right: 8rpx">
                <img
                  style="width: 46rpx; height: 32rpx"
                  :src="item.pkCountryIcon"
                  alt=""
              /></view>
              <view>{{ item.pkCountryName }}</view>
            </view>
          </td>
        </tr>
        <tr   v-if="dataList[1].key">
          <td align="right">{{ '会员编号' }}</td>
          <td align="left">{{ item.memberCode }}</td>
        </tr>
        <tr v-if="dataList[2].key">
          <td align="right">{{ '会员姓名' }}</td>
          <td align="left">{{ item.memberName }}</td>
        </tr>
        <tr v-if="dataList[3].key">
          <td align="right">{{ '钱包类型' }}</td>
          <td align="left">{{ item.pkAccountVal }}</td>
        </tr>
        <tr v-if="dataList[4].key">
          <td align="right">{{ '交款方式' }}</td>
          <td align="left">{{ item.paymentMethodVal }}</td>
        </tr>
        <tr v-if="dataList[5].key">
          <td align="right">{{ '充前余额' + `(${isLocalSymbol()})` }}</td>
          <td align="left">
            {{ item.paymentBeforeBalance | toThousandthAndKeepDecimal }}
          </td>
        </tr>
        <tr v-if="dataList[6].key">
          <td align="right">{{ '充值金额' + `(${isLocalSymbol()})` }}</td>
          <td align="left">
            {{ item.paymentAmount | toThousandthAndKeepDecimal }}
          </td>
        </tr>
        <tr v-if="dataList[7].key">
          <td align="right">{{ '当前余额' + `(${isLocalSymbol()})` }}</td>
          <td align="left">
            {{ item.paymentBalance | toThousandthAndKeepDecimal }}
          </td>
        </tr>
        <tr v-if="dataList[8].key">
          <td align="right">{{ '充值金额' + `(${isLocals()})` }}</td>
          <td align="left">{{ item.settlePaymentAmount }}</td>
        </tr>
        <tr v-if="dataList[9].key">
          <td align="right">{{ '汇率' }}</td>
          <td align="left">{{ item.exchangeRate }}</td>
        </tr>
        <tr  v-if="dataList[10].key">
          <td align="right">{{ '单据编号' }}</td>
          <td align="left">{{ item.rechargeCode }}</td>
        </tr>
        <tr  v-if="dataList[11].key">
          <td align="right">{{ '充值批次' }}</td>
          <td align="left">{{ item.batch }}</td>
        </tr>
        <tr   v-if="dataList[12].key">
          <td align="right">{{ '操作人' }}</td>
          <td align="left">{{ item.creator }}</td>
        </tr>
        <tr   v-if="dataList[13].key">
          <td align="right">{{ '充值日期' }}</td>
          <td align="left">{{ item.creationTime }}</td>
        </tr>
        <tr    v-if="dataList[14].key">
          <td align="right">{{ '操作备注' }}</td>
          <td align="left">{{ item.remarks }}</td>
        </tr>
        <tr    v-if="dataList[15].key">
          <td align="right">{{ '审核人' }}</td>
          <td align="left">{{ item.approverName }}</td>
        </tr>
        <tr   v-if="dataList[16].key">
          <td align="right">{{ '审核日期' }}</td>
          <td align="left">{{ item.approveTime }}</td>
        </tr>

        <tr  v-if="dataList[17].key">
          <td align="right">{{ '审核状态' }}</td>
          <td align="left">
            <span v-if="item.approveState == 2" style="color: #28ce0e">{{
              item.approveStateVal
            }}</span>
            <span v-else style="color: #dd2020">{{
              item.approveStateVal
            }}</span>
          </td>
        </tr>
      </table>
    </view>

    <!-- 顶部搜索 -->
    <u-popup :show="isTop" mode="top" @close="isTop = false">
      <view class="tt">
        <u--form
          labelPosition="left"
          labelWidth="auto"
          :model="select"
          ref="uForm"
        >
          <u-row gutter="10">
            <u-col span="6">
              <u-form-item :label="'会员编号'">
                <u--input fontSize="12" v-model="select.memberCode"></u--input>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'会员姓名'">
                <u--input fontSize="12" v-model="select.memberName"></u--input>
              </u-form-item>
            </u-col>
          </u-row>

          <u-row gutter="10">
            <u-col span="6">
              <u-form-item :label="'钱包类型'">
                <picker
                  :range="accountList"
                  range-key="accountName"
                  @change="bindPickerChange1"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.accountName"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'交款方式'">
                <picker
                  :range="paymentList"
                  range-key="label"
                  @change="bindPickerChange2"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.paymentMethodName"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
          </u-row>
          <u-row gutter="10">
            <u-col span="6">
              <u-form-item :label="'审核状态'">
                <picker
                  :range="shStateList"
                  range-key="label"
                  @change="bindPickerChange3"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.shStateVal"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'充值批次'">
                <u--input fontSize="12" v-model="select.batch"></u--input>
              </u-form-item>
            </u-col>
          </u-row>
          <u-row gutter="10">
            <u-col span="6">
              <u-form-item :label="'操作人'">
                <picker
                  :range="creatorList"
                  range-key="memberName"
                  @change="bindPickerChange4"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.creatorVal"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'操作备注'">
                <u--input fontSize="12" v-model="select.remarks"></u--input>
              </u-form-item>
            </u-col>
          </u-row>
          <u-row gutter="10">
            <u-col span="12">
              <u-form-item
                :label="'创建日期'"
                @click="(isData = true), (setTime = 0)"
              >
                <u--input
                  disabled
                  fontSize="12"
                  disabledColor="#ffffff"
                  v-model="select.creationTimeVal"
                  suffixIcon="arrow-down"
                  suffixIconStyle="font-size: 12px;"
                ></u--input>
              </u-form-item>
            </u-col>
          </u-row>
          <u-row gutter="10">
            <u-col span="12">
              <u-form-item
                :label="'支付日期'"
                @click="(isData = true), (setTime = 1)"
              >
                <u--input
                  disabled
                  fontSize="12"
                  disabledColor="#ffffff"
                  v-model="select.payVal"
                  suffixIcon="arrow-down"
                  suffixIconStyle="font-size: 12px;"
                ></u--input>
              </u-form-item>
            </u-col>
          </u-row>
        </u--form>
        <view class="footer">
          <u-button
            @click="getList1"
            color="#C8161D"
            text="搜索"
            class="btnn"
            v-hasButtons="['RechargeSearch']"
          ></u-button>
          <u-button @click="reset" text="重置"></u-button>
        </view>
      </view>
    </u-popup>
    <u-calendar
      @close="isData = false"
      :closeOnClickOverlay="true"
      :show="isData"
      mode="range"
      @confirm="confirm"
      :allowSameDay="true"
      :maxDate="calendar.maxDate"
      :minDate="calendar.minDate"
      :monthNum="calendar.monthNum"
    ></u-calendar>
    <!-- 悬浮球 -->
    <drag-button />
    <export-ball v-hasButtons="['RechargeDetailExport']" ref="exportBall" @handleExport="handleExport" />
  </view>
</template>
  
  <script>
import * as api from "@/api/financial";
import { isLocals, isLocalSymbol } from "@/util/numberToCurrency";
import { getRoleMenu } from '@/api/information'
export default {
  data() {
    return {
      select: {},
      isTop: false,
      isData: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
      },
      tableData: [],
      accountList: [], //钱包类型
      paymentList: [], //交款方式
      shStateList: [], //审核状态
      creatorList: [], //操作人列表
      userCountry: {},
      dataList: [
        {
          name: 'pkCountryName',
          key: ''
        },
        {
          name: 'memberCode',
          key: ''
        },
        {
          name: 'memberName',
          key: ''
        },
        {
          name: 'pkAccountVal',
          key: ''
        },
        {
          name: 'paymentMethodVal',
          key: ''
        },
        {
          name: 'paymentBeforeBalance',
          key: ''
        },
        {
          name: 'paymentAmount',
          key: ''
        },
        {
          name: 'paymentBalance',
          key: ''
        },
        {
          name: 'settlePaymentAmount',
          key: ''
        },
        {
          name: 'exchangeRate',
          key: ''
        },
        {
          name: 'rechargeCode',
          key: ''
        },
        {
          name: 'batch',
          key: ''
        },
        {
          name: 'creator',
          key: ''
        },
        {
          name: 'creationTime',
          key: ''
        },
        {
          name: 'remarks',
          key: ''
        },
        {
          name: 'approverName',
          key: ''
        },
        {
          name: 'approveTime',
          key: ''
        },
        {
          name: 'approveStateVal',
          key: ''
        }
      ],
      calendar: {
        minDate: "",
        maxDate: "",
        monthNum: 25,
      },
    };
  },
  onLoad(options) {
    if (uni.getStorageSync("userAll")) {
      this.userCountry = JSON.parse(uni.getStorageSync("userAll")).country;
    }
    //查询会员信息
    this.getSearch();

    // 获取下拉
    this.getData();
    this.chooseTimed();
    this.getUserRole();
  },
  methods: {
    isLocalSymbol,
    isLocals,
    getUserRole() {
      getRoleMenu('RechargeDetail').then((res) => {
        this.dataList.forEach((item) => {
          res.data.forEach((items) => {
            if (item.name == items) {
              item.key = items
            }
            // this.flag = true
          })
        })
      })
    },
     // 设置默认日期，最大值为今天，最小值为去年今天
     chooseTimed() {
      let date = new Date()
      let year = date.getFullYear()
      let month = date.getMonth() + 1
      let day = date.getDate()
      if (month <= 9) {
        month = '0' + month
      }
      if (day <= 9) {
        day = '0' + day
      }
      let minyear = year - 1
      let maxyear = year + 1
      this.calendar.minDate = minyear + '-' + month + '-' + day
      this.calendar.maxDate = maxyear + '-' + month + '-' + day
    },
    getData() {
      //钱包类型
      api.getenumsAccount().then((res) => {
        this.accountList = res.rows;
      });
      //交款方式
      api.getpaymentType().then((res) => {
        this.paymentList = res.data;
      });
      //审核状态
      api.getApproveStatus().then((res) => {
        this.shStateList = res.data;
      });
      //   操作人列表
      api.getCreatorList().then((res) => {
        this.creatorList = res.data;
      });
    },

    onReachBottom() {
      this.queryParams.pageNum++;
      this.getSearch();
    },
    getSearch() {
      api
        .getrechageList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.total = res.total;
          this.lastData = res.rows[res.rows.length - 1];
          let arr = JSON.parse(JSON.stringify(res.rows));
          arr = arr.filter(function (v, i, ar) {
            return i !== ar.length - 1;
          });
          this.tableData = this.tableData.concat(arr);
          // this.tableData = this.tableData.concat(res.rows);
          this.tableData.forEach((item) => {
            item.pkCountryName = this.userCountry.shortName;
            item.pkCountryIcon = this.userCountry.nationalFlag2;
          });
        });
    },
    getList1() {
      this.tableData = [];
      this.queryParams.pageNum = 1;
      this.isTop = false;
      this.getSearch();
    },
    reset() {
      this.select = {};
      this.getSearch();
    },
    handleExport() {
      let url = "/member/manager/recharge/export";
      let obj = Object.assign({}, this.select, this.queryParams);
      this.$refs.exportBall.handleExport(url, obj, '充值明细');
    },
    bindPickerChange1(e) {
      this.$set(
        this.select,
        "accountName",
        this.accountList[e.detail.value].accountName
      );
      this.$set(
        this.select,
        "pkAccount",
        this.accountList[e.detail.value].pkId
      );
    },
    bindPickerChange2(e) {
      this.$set(
        this.select,
        "paymentMethodName",
        this.paymentList[e.detail.value].label
      );
      this.$set(
        this.select,
        "paymentMethod",
        this.paymentList[e.detail.value].value
      );
    },
    bindPickerChange3(e) {
      this.$set(
        this.select,
        "shStateVal",
        this.shStateList[e.detail.value].label
      );
      this.$set(
        this.select,
        "approveState",
        this.shStateList[e.detail.value].value
      );
    },
    bindPickerChange4(e) {
      this.$set(
        this.select,
        "creatorVal",
        this.creatorList[e.detail.value].memberName
      );
      this.$set(
        this.select,
        "creator",
        this.creatorList[e.detail.value].pkCreator
      );
    },
    confirm(e) {
      if (this.setTime == 0) {
        this.$set(this.select, "startDate", e[0]);
        this.$set(this.select, "endDate", e[e.length - 1]);
        this.$set(
          this.select,
          "creationTimeVal",
          e[0] + " 至 " + e[e.length - 1]
        );
      } else {
        this.$set(this.select, "startApproveTime", e[0]);
        this.$set(this.select, "endApproveTime", e[e.length - 1]);
        this.$set(this.select, "payVal", e[0] + " 至 " + e[e.length - 1]);
      }

      this.isData = false;
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.content {
  background: #f9f9f9;
  padding: 20rpx 24rpx;
}
.header {
  background: #ffffff;
  box-shadow: 0px 2px 10px 0px rgba(204, 204, 204, 0.4);
  border-radius: 20rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20rpx;
  .headernei {
    background: rgba(216, 216, 216, 0);
    border-radius: 64rpx;
    opacity: 1;
    border: 2rpx solid #259dfe;
    width: 100%;
    padding: 22rpx 20rpx;
    img {
      width: 24rpx;
      height: 24rpx;
    }
  }
}
.kuang {
  background: #ffffff;
  box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(204, 204, 204, 0.4);
  border-radius: 20rpx;
  margin-bottom: 20rpx;
}
.tftable {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
  border: 1px solid #f9f9f9;
  margin-top: 20rpx;
  td {
    font-size: 24rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #999;
    padding: 20rpx 40rpx;
    width: 50%;
  }
  tr :nth-child(2) {
    color: #333333;
    font-size: 26rpx;
  }
  .theflex {
    display: flex;
    align-items: center;
  }
}
.che {
  padding: 20rpx 40rpx;
}
.tt {
  padding: 20rpx;
  margin-top: 20px;
  font-size: 24rpx;
}
::v-deep .u-transition {
  z-index: 998 !important;
}
.footer {
  display: flex;
  align-items: center;
  padding: 20rpx 60rpx;
  font-size: 24rpx;
  .btnn {
    margin-right: 40rpx;
  }
}
::v-deep .u-input {
  padding: 0 9px !important;
}
::v-deep .u-form-item__body__left__content__label {
  font-size: 12px;
}
::v-deep .u-form-item__body {
  padding: 5px 0;
}
</style>