<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2023-10-09 15:37:13
-->
<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>
    <view class="kuang"
          v-for="(item,index) in tableData"
          :key="index">
      <table class="tftable"
             border="1">
        <tr v-if="allTxt.memberCode">
          <td align="right">{{ '会员编号' }}</td>
          <td align="left">{{ item.memberCode }}</td>
        </tr>
        <tr v-if="allTxt.memberName">
          <td align="right">{{ '会员姓名' }}</td>
          <td align="left">{{ item.memberName }}</td>
        </tr>
        <tr v-if="allTxt.phone">
          <td align="right">{{ '联系方式' }}</td>
          <td align="left">{{ item.phone }}</td>
        </tr>
        <tr v-if="menuList[1].checked == true && allTxt.registerGradeVal">
          <td align="right">{{ '注册等级' }}</td>
          <td align="left">{{ item.registerGradeVal }}</td>
        </tr>
        <tr v-if="menuList[2].checked == true && allTxt.settleGradeVal">
          <td align="right">{{ '结算等级' }}</td>
          <td align="left">{{ item.settleGradeVal }}</td>
        </tr>
        <tr v-if="menuList[3].checked == true && allTxt.awardsVal">
          <td align="right">{{ '荣誉奖衔' }}</td>
          <td align="left">{{ item.awardsVal }}</td>
        </tr>
        <tr v-if="menuList[4].checked == true && allTxt.sexVal">
          <td align="right">{{ '性别' }}</td>
          <td align="left">{{ item.sexVal }}</td>
        </tr>
        <tr v-if="menuList[5].checked == true && allTxt.birthDate">
          <td align="right">{{ '出生日期' }}</td>
          <td align="left">{{ item.birthDate }}</td>
        </tr>
        <tr v-if="menuList[6].checked == true && allTxt.cardTypeVal">
          <td align="right">{{ '证件类型' }}</td>
          <td align="left">{{ item.cardTypeVal }}</td>
        </tr>
        <tr v-if="menuList[7].checked == true && allTxt.idCard">
          <td align="right">{{ '证件号码' }}</td>
          <td align="left">{{ item.idCard }}</td>
        </tr>
        <tr v-if="menuList[8].checked == true && allTxt.idFront">
          <td align="right">{{ '证件(正面)' }}</td>
          <td align="left"> <img :src="item.idFront"
                 style="width: 44px;height: 44px;border-radius: 4px" /></td>
        </tr>
        <tr v-if="menuList[9].checked == true && allTxt.idBack">
          <td align="right">{{ '证件(反面)' }}</td>
          <td align="left"> <img :src="item.idFront"
                 style="width: 44px;height: 44px;border-radius: 4px" /></td>
        </tr>
        <tr v-for="ctem in menuList"
            v-if="ctem.checked && ctem.id != 0 && ctem.id < 19&allTxt[ctem.prop]">
          <td align="right">{{ ctem.text}}</td>
          <td align="left">{{ item[ctem.prop] }}</td>
        </tr>
        <tr v-if="allTxt.certificationTime">
          <td align="right">{{ '认证日期' }}</td>
          <td align="left">{{ item.certificationTime }}</td>
        </tr>
        <tr v-if="allTxt.creationTime">
          <td align="right">{{ '创建日期' }}</td>
          <td align="left">{{ item.creationTime }}</td>
        </tr>
        <tr v-if="allTxt.payTime">
          <td align="right">{{ '支付日期' }}</td>
          <td align="left">{{ item.payTime }}</td>
        </tr>
        <tr v-if="allTxt.directPushNumber">
          <td align="right">{{ '修改直推次数' }}</td>
          <td align="left">{{ item.directPushNumber }}</td>
        </tr>
      </table>
    </view>
    <!-- 侧边弹框 -->
    <u-popup :show="isFont"
             mode="right"
             @close="isFont=false">
      <view class="che">
        <u-checkbox-group v-model="selectAll"
                          @change="getAll"
                          placement="column"
                          activeColor="#ED1D25">
          <u-checkbox :customStyle="{marginBottom: '8px'}"
                      v-for="(item, index) in allList"
                      :key="index"
                      :label="item.text"
                      :name="item.id">
          </u-checkbox>
        </u-checkbox-group>
        <u-checkbox-group v-model="selected"
                          @change="getMenu"
                          placement="column"
                          activeColor="#ED1D25">
          <u-checkbox :customStyle="{marginBottom: '8px'}"
                      v-for="(item, index) in menuList"
                      :key="index"
                      v-show="index!=0"
                      :label="item.text"
                      :name="item.id">
          </u-checkbox>
        </u-checkbox-group>
      </view>
    </u-popup>
    <!-- 顶部搜索 -->
    <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.phone"></u--input>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'荣誉奖衔'">
                <picker :range="awardsList"
                        range-key="awardsName"
                        @change="bindPickerChange3">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.pkAwardsVal"
                            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="gradeRangList"
                        range-key="gradeName"
                        @change="bindPickerChange1">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.pkRegisterGradeVal"
                            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="gradeRangList"
                        range-key="gradeName"
                        @change="bindPickerChange2">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.pkSettleGradeVal"
                            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="cardList"
                        range-key="label"
                        @change="bindPickerChange4">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.idTypeVal"
                            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.idCard"></u--input>
              </u-form-item>
            </u-col>
          </u-row>
          <u-row gutter="10">
            <u-col span="6">
              <u-form-item :label="'出生日期'"
                           @click="isDataTime=true">
                <u--input disabled
                          fontSize="12"
                          disabledColor="#ffffff"
                          v-model="select.birthDate"
                          suffixIcon="arrow-down"
                          suffixIconStyle="font-size: 12px;"></u--input>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'性别'">
                <picker :range="sexList"
                        range-key="label"
                        @change="bindPickerChange5">
                  <u--input disabled
                            fontSize="12"
                            disabledColor="#ffffff"
                            v-model="select.sexVal"
                            suffixIcon="arrow-down"
                            suffixIconStyle="font-size: 12px;"></u--input>
                </picker>
              </u-form-item>
            </u-col>
          </u-row>
          <u-row gutter="10">
            <u-col span="12">
              <u-form-item :label="'收货地址'"
                           @click='getDiqu'>
                <u--input disabled
                          fontSize="12"
                          disabledColor="#ffffff"
                          v-model="select.diqu"
                          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="详细地址">
                <u--input fontSize="12"
                          v-model="select.address"></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.bankName"></u--input>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'支行名称'">
                <u--input fontSize="12"
                          v-model="select.subBankName"></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.cardNumber"></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.creationTimeVal0"
                          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.creationTimeVal1"
                          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=2">
                <u--input disabled
                          fontSize="12"
                          disabledColor="#ffffff"
                          v-model="select.creationTimeVal2"
                          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-popup>
    <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-datetime-picker :show="isDataTime"
                       @confirm="getBirth"
                       @cancel="isDataTime = false"
                       :minDate="minDate"
                       :maxDate="todayData"
                       v-model="birthDate"
                       mode="date"></u-datetime-picker>
    <!-- 悬浮球 -->
    <drag-button />
    <export-ball ref="exportBall"
                 v-hasButtons="['realInfoExport']"
                 @handleExport="handleExport" />
    <!-- 选择地址 -->
    <v-address ref="address"
               :defaultCode="defaultCode"
               @addressData="addressData"></v-address>
  </view>
</template>

<script>
import address from '@/components/address.vue'
import * as api from '@/api/information'
import { isLocals, isLocalSymbol } from '@/util/numberToCurrency'
export default {
  components: {
    'v-address': address,
  },
  data() {
    return {
      defaultCode: [],
      select: {},
      isTop: false,
      isData: false,
      isDataTime: false,
      selectAll: [0],
      selected: [],
      isFont: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
      },
      tableData: [],
      allList: [
        {
          id: 0,
          text: '全选',
          checked: false,
        },
      ],
      menuList: [
        {
          id: 0,
          text: '全选',
          checked: false,
        },
        {
          id: 31,
          text: '注册等级',
          checked: true,
          prop: 'pkRegisterGrade',
        },
        {
          id: 32,
          text: '结算等级',
          checked: true,
          prop: 'pkSettleGrade',
        },
        {
          id: 42,
          text: '荣誉奖衔',
          checked: true,
          prop: 'pkAwards',
        },
        {
          id: 33,
          text: '性别',
          checked: true,
          prop: 'sexVal',
        },
        {
          id: 34,
          text: '出生日期',
          checked: true,
          prop: 'birthDate',
        },
        {
          id: 35,
          text: '证件类型',
          checked: true,
          prop: 'cardTypeVal',
        },
        {
          id: 36,
          text: '证件号码',
          checked: true,
          prop: 'idCard',
        },
        {
          id: 37,
          text: '证件(正面)',
          checked: true,
          prop: 'idCardJust',
        },
        {
          id: 38,
          text: '证件(反面)',
          checked: true,
          prop: 'idCardBack',
        },
        {
          id: 9,
          text: '省',
          checked: true,
          prop: 'provinceName',
        },
        {
          id: 10,
          text: '市',
          checked: true,
          prop: 'cityName',
        },
        {
          id: 11,
          text: '区/县',
          checked: true,
          prop: 'countyName',
        },
        {
          id: 12,
          text: '详细地址',
          checked: true,
          prop: 'address',
        },
        {
          id: 13,
          text: '银行名称',
          checked: true,
          prop: 'bankName',
        },
        {
          id: 14,
          text: '支行名称',
          checked: true,
          prop: 'subBankName',
        },
        {
          id: 15,
          text: '开户姓名',
          checked: true,
          prop: 'accountName',
        },
        {
          id: 16,
          text: '预留电话',
          checked: true,
          prop: 'reservedPhone',
        },
        {
          id: 17,
          text: '银行卡号',
          checked: true,
          prop: 'cardNumber',
        },
      ],
      allTxt: {},
      gradeRangList: [],
      awardsList: [],
      cardList: [],
      calendar: {
        minDate: '',
        maxDate: '',
        monthNum: 25,
      },
      minDate: '',
      todayData: '',
      birthDate: '',
      sexList: [],
    }
  },
  onLoad(options) {
    //查询会员信息
    this.getMemberList()
    // 获取字段权限
    this.getUserRole()
    // 获取下拉
    this.getData()
    this.chooseTimed()
    this.getAll([0])
    this.todayData = Date.now()
    this.minDate = Number(new Date('1950-01-01'))
  },
  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.getgradeRanglist().then((res) => {
        this.gradeRangList = res.data
      })
      // 荣誉奖衔下拉选
      api.getAwardsListChiose().then((res) => {
        this.awardsList = res.rows
      })
      // 证件类型
      api.getCardType().then((res) => {
        this.cardList = res.data
      })
      // 性别
      api.getSex().then((res) => {
        this.sexList = res.data
      })
    },
    getDiqu() {
      this.$refs.address.setShow()
    },
    getBirth(e) {
      this.select.birthDate = this.$moment(e.value).format('YYYY-MM-DD')
      this.isDataTime = false
    },
    // 全选
    getAll(e) {
      if (e.length > 0) {
        this.menuList.forEach((item) => {
          this.$set(item, 'checked', true)
          this.selected.push(item.id)
        })
      } else {
        this.menuList.forEach((item) => {
          this.$set(item, 'checked', false)
        })
        this.$set(this, 'selected', [])
      }
    },
    // 单选
    getMenu(e) {
      this.menuList.forEach((item) => {
        this.$set(item, 'checked', false)
        e.forEach((ctem) => {
          if (item.id == ctem) {
            this.$set(item, 'checked', true)
          }
        })
      })
      if (e.length == this.menuList.length) {
        this.$set(this, 'selectAll', [0])
      } else {
        this.$set(this, 'selectAll', [])
      }
    },
    getUserRole() {
      api.getRoleMenu('RealInfo').then((res) => {
        let obj = {}
        res.data.forEach((item) => {
          obj[item] = 1
        })
        this.allTxt = obj
      })
    },
    onReachBottom() {
      this.queryParams.pageNum++
      this.getMemberList()
    },
    //查询会员信息
    getMemberList() {
      api
        .memberRealInfo(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.total = res.total
          this.tableData = this.tableData.concat(res.rows)
        })
    },
    getList1() {
      this.tableData = []
      this.queryParams.pageNum = 1
      this.isTop = false
      this.getMemberList()
    },
    reset() {
      this.select = {}
    },
    handleExport() {
      let url = '/member/manager/member/real-info-export'
      let obj = Object.assign({}, this.select, this.queryParams)
      this.$refs.exportBall.handleExport(
        url,
        obj,
        `${'真实信息'}${new Date().getTime()}`
      )
    },
    bindPickerChange1(e) {
      this.$set(
        this.select,
        'pkRegisterGradeVal',
        this.gradeRangList[e.detail.value].gradeName
      )
      this.$set(
        this.select,
        'pkRegisterGrade',
        this.gradeRangList[e.detail.value].pkId
      )
    },
    bindPickerChange2(e) {
      this.$set(
        this.select,
        'pkSettleGradeVal',
        this.gradeRangList[e.detail.value].gradeName
      )
      this.$set(
        this.select,
        'pkSettleGrade',
        this.gradeRangList[e.detail.value].pkId
      )
    },
    bindPickerChange3(e) {
      this.$set(
        this.select,
        'pkAwardsVal',
        this.awardsList[e.detail.value].awardsName
      )
      this.$set(this.select, 'pkAwards', this.awardsList[e.detail.value].pkId)
    },
    bindPickerChange4(e) {
      this.$set(this.select, 'idTypeVal', this.cardList[e.detail.value].label)
      this.$set(this.select, 'idType', this.cardList[e.detail.value].value)
    },
    bindPickerChange5(e) {
      this.$set(this.select, 'sexVal', this.sexList[e.detail.value].label)
      this.$set(this.select, 'sex', this.sexList[e.detail.value].value)
    },
    confirm(e) {
      if (this.setTime == 0) {
        this.$set(this.select, 'startCertificationTime', e[0])
        this.$set(this.select, 'endCertificationTime', e[e.length - 1])
        this.$set(
          this.select,
          'creationTimeVal0',
          e[0] + ' 至 ' + e[e.length - 1]
        )
      } else if (this.setTime == 1) {
        this.$set(this.select, 'startCreationTime', e[0])
        this.$set(this.select, 'endCreationTime', e[e.length - 1])
        this.$set(
          this.select,
          'creationTimeVal1',
          e[0] + ' 至 ' + e[e.length - 1]
        )
      } else {
        this.$set(this.select, 'startPayTime', e[0])
        this.$set(this.select, 'endPayTime', e[e.length - 1])
        this.$set(
          this.select,
          'creationTimeVal2',
          e[0] + ' 至 ' + e[e.length - 1]
        )
      }
      this.isData = false
    },
    addressData(diqu, obj) {
      this.select.diqu = diqu
      this.select.pkProvince = obj.province
      this.select.pkCity = obj.city
      this.select.pkCounty = obj.county
      this.$forceUpdate()
    },
  },
}
</script>

<style lang="scss" scoped>
.content {
  background: #f9f9f9;
  // padding: 20rpx;
}
.header_a {
  position: fixed;
  width: 100%;
}
.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 {
  background: #f9f9f9;
  border-radius: 10px 10px 10px 10px;
  margin: 20rpx;
}
.tftable {
  font-size: 12px;
  border-collapse: collapse;
  border-radius: 10px;
  width: 100%;
  background: #fff;
  border: 1px solid #f9f9f9;
  // margin-top: 20rpx;
  // border-right:1px solid #ccc;border-bottom:1px solid #F00;
  outline: none;
  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;
  }
}
.che {
  padding: 20rpx 40rpx;
}
.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;
}
</style>