<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2023-10-16 13:59:22
-->
<template>
  <view class="content">
    <view class="header_a">
      <view class="header">
        <img @click="isTop=true"
             src="@/assets/images/search.png"
             alt="">
        <!-- <img @click="isFont=true"
           src="@/assets/images/change.png"
           alt=""> -->
      </view>
    </view>
    <view class="zhan"></view>
    <!-- table -->
    <view class="kuang"
          v-for="(item,index) in tableData"
          :key="index">
      <table class="tftable"
             border="1">
        <tr>
          <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>
          <td align="right">{{ '会员编号' }}</td>
          <td align="left">{{ item.memberCode }}</td>
        </tr>
        <tr>
          <td align="right">{{ '会员姓名' }}</td>
          <td align="left">{{ item.memberName }}</td>
        </tr>
        <tr>
          <td align="right">{{ '交易类型' }}</td>
          <td align="left">{{ item.businessTypeVal }}</td>
        </tr>
        <tr>
          <td align="right">{{ '交易金额' }}({{ isLocalSymbol() }})</td>
          <td align="left">{{ item.businessMoney }}</td>
        </tr>
        <tr>
          <td align="right">实际支付金额(¥)</td>
          <td align="left">{{ item.payMoney }}</td>
        </tr>
        <tr>
          <td align="right">{{ '支付渠道' }}</td>
          <td align="left">{{ item.payChannelVal }}</td>
        </tr>
        <tr>
          <td align="right">{{ '支付方式' }}</td>
          <td align="left">{{ item.payTypeVal }}</td>
        </tr>
        <tr>
          <td align="right">{{ '支付状态' }}</td>
          <td align="left">{{ item.payStatusVal }}</td>
        </tr>
        <tr>
          <td align="right">{{ '下单日期' }}</td>
          <td align="left">{{ item.creationTime }}</td>
        </tr>
        <tr>
          <td align="right">{{ '支付日期' }}</td>
          <td align="left">{{ item.payTime }}</td>
        </tr>
        <tr>
          <td align="right">{{ '单据编号' }}</td>
          <td align="left">{{ item.businessCode }}</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="'交易金额'">
                <u--input fontSize="12"
                          v-model="select.businessMoney"></u--input>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'交易类型'">
                <picker :range="tradeTypeList"
                        range-key="label"
                        @change="bindPickerChange1">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.businessTypeVal"
                            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="channelList"
                        range-key="label"
                        @change="bindPickerChange2">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.payChannelVal"
                            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="peyTypeList"
                        range-key="label"
                        @change="bindPickerChange3">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.payTypeVal"
                            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="statusList"
                        range-key="label"
                        @change="bindPickerChange4">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.payStatusVal"
                            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.businessCode"></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.payTimeVal"
                          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"></u-button>
          <u-button @click="reset"
                    text="重置"></u-button>
        </view>
      </view>
      <u-calendar @close="isData = false"
                  :closeOnClickOverlay="true"
                  :show="isData"
                  :allowSameDay="true"
                  mode="range"
                  :maxDate="calendar.maxDate"
                  :minDate="calendar.minDate"
                  :monthNum="calendar.monthNum"
                  @confirm="confirm"></u-calendar>
    </u-popup>
    <!-- 悬浮球 -->
    <drag-button />
    <export-ball ref="exportBall"
    v-hasButtons="['OnlinePayDetailsExport']"

                 @handleExport="handleExport" />
  </view>
</template>

<script>
import * as api from '@/api/financial'

import { isLocals, isLocalSymbol } from '@/util/numberToCurrency'
export default {
  data() {
    return {
      select: {},
      isData: false,
      isTop: false,
      setTime: 0,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
      },
      tableData: [],
      accountList: [],
      tradeTypeList: [],
      userCountry: {},
      calendar: {
        minDate: '',
        maxDate: '',
        monthNum: 25,
      },
      statusList: [],
      channelList: [],
      peyTypeList: [
        {
          value: '1',
          label: '支付宝',
        },
        {
          value: '2',
          label: '微信',
        },
        {
          value: '3',
          label: '银行卡',
        },
      ],
    }
  },
  onLoad(options) {
    if (uni.getStorageSync('userAll')) {
      this.userCountry = JSON.parse(uni.getStorageSync('userAll')).country
    }
    this.getData()
    this.chooseTimed()
  },
  onShow() {
    this.getSearch()
  },
  onPullDownRefresh() {
    this.getList1()
  },
  methods: {
    isLocalSymbol,
    isLocals,
    // 设置默认日期，最大值为今天，最小值为去年今天
    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.businessType().then((res) => {
        this.tradeTypeList = res.data
      })
      api.payChannel().then((res) => {
        this.channelList = res.data
      })
      api.payStatus().then((res) => {
        this.statusList = res.data
      })
    },
    bindPickerChange1(e) {
      this.$set(
        this.select,
        'businessTypeVal',
        this.tradeTypeList[e.detail.value].label
      )
      this.$set(
        this.select,
        'businessType',
        this.tradeTypeList[e.detail.value].value
      )
    },
    bindPickerChange2(e) {
      this.$set(
        this.select,
        'payChannelVal',
        this.channelList[e.detail.value].label
      )
      this.$set(
        this.select,
        'payChannel',
        this.channelList[e.detail.value].value
      )
    },
    bindPickerChange3(e) {
      this.$set(
        this.select,
        'payTypeVal',
        this.peyTypeList[e.detail.value].label
      )
      this.$set(
        this.select,
        'payType',
        this.peyTypeList[e.detail.value].value
      )
    },
    bindPickerChange4(e) {
      this.$set(
        this.select,
        'payStatusVal',
        this.statusList[e.detail.value].label
      )
      this.$set(
        this.select,
        'payStatus',
        this.statusList[e.detail.value].value
      )
    },
    onReachBottom() {
      this.queryParams.pageNum++
      this.getSearch()
    },
    //查询会员信息
    getSearch() {
      api
        .onlineList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          uni.stopPullDownRefresh()
          this.total = res.total
          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.tableData = []
      this.getSearch()
    },
    reset() {
      this.select = {}
    },
    handleExport() {
      let url = '/pay/manage/online-payment/export'
      let obj = Object.assign({}, this.select, this.queryParams)
      this.$refs.exportBall.handleExport(url, obj, `${'在线支付明细'}`)
    },
    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, 'creationTime', [e[0], e[e.length - 1]])
        this.$set(
          this.select,
          'creationTimeVal',
          e[0] + ' 至 ' + e[e.length - 1]
        )
      } else {
        this.$set(this.select, 'payTime', [e[0], e[e.length - 1]])
        this.$set(this.select, 'payTimeVal', e[0] + ' 至 ' + e[e.length - 1])
      }
      this.isData = false
    },
  },
}
</script>
<style lang="scss" scoped>
.content {
  background: #f9f9f9;
  // padding: 20rpx;
}
.header_a {
  position: fixed;
  width: 100%;
  z-index: 1;
}
.header {
  margin: 20rpx;
  background: #ffffff;
  box-shadow: 0px 2px 10px 0px rgba(204, 204, 204, 0.4);
  border-radius: 10px 10px 10px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 30rpx 40rpx;
  img {
    width: 24px;
    height: 24px;
  }
}
.zhan {
  height: 130rpx;
}
.kuang {
  margin: 20rpx;
  background: #f9f9f9;
  border-radius: 10px 10px 10px 10px;
}
.table_f {
  display: flex;
  uni-button {
    margin: 20rpx 10rpx;
  }
}
.tftable {
  font-size: 12px;
  border-collapse: collapse;
  border-radius: 10px;
  width: 100%;
  background: #fff;
  border: 1px solid #f9f9f9;
  margin-top: 20rpx;
  td {
    font-size: 11px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #999;
    padding: 20rpx 40rpx;
    width: 50%;
    // height: 60px;
    border-left: 1px solid #333;
    border-bottom: 1px solid #333;
  }
  td:nth-child(odd) {
    border-left: 1px solid #f9f9f9;
  }
  tr :nth-child(2) {
    color: #333333;
  }
}
.tt {
  padding: 20rpx;
  margin-top: 40px;
}
::v-deep .u-transition {
  z-index: 998 !important;
}
.footer {
  display: flex;
  align-items: center;
  padding: 20rpx 60rpx;
  .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;
}
.theflex {
  display: flex;
  align-items: center;
}
</style>