<template>
  <div class="app-container">
    <search-form
      :list-loading="listLoading"
      @change="searchHandle"
    />
    <table-list
      :list-loading="listLoading"
      :data="tableData2"
      :columns="listConfig"
      :current-page="currentPage"
      :page-size="pageSize"
      :total-records="totalRecords"
      @currentChange="pageHandle"
      @sizeChange="sizeChange"
    />
    <!-- :isAdd="true"
      @add="openPopup" -->
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Auth'
import PopupEdit from './components/popup/AuthEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'user.admuserauthlist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        if (item.auth_state === '1') item.authstateIs1 = true
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '推荐人', prop: 'referrer' },
        { label: '认证渠道', prop: 'group_type', type: 'flag', flags: arrToObj(this.$dictData.group_type) }, 
        { label: '昵称', prop: 'nickname' },
        { label: '渠道码', prop: 'dept_code' },
        { label: '手机号', prop: 'phone' },
        { label: '身份认证', prop: 'auth_state', type: 'tag', tags: arrToObj(this.$dictData.auth_state), tagTypeObj: {'1': 'success', '2': 'warning', '3': 'danger', '4': 'info'}  }, 
        { label: '绑定微信', prop: 'bind_wechat', type: 'tag', tags: arrToObj(this.$dictData.sys_yesno), tagTypeObj: {'1': 'success', '2': 'danger'} },
        { label: '身份证号', prop: 'id_number', fullShow: true, minWidth: 90 },
        { label: 'ID正面', prop: 'id_card_front', type: 'img' },
        { label: 'ID反面', prop: 'id_card_revers', type: 'img' },
        { label: '银行卡号', prop: 'bank_number', fullShow: true },
        { label: '银行卡正面', prop: 'bank_card', type: 'img' },
        { label: '营业执照', prop: 'busines_licens', type: 'img' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 70, type: 'handle2', operations:
          [
            { label: '审核', func: this.openPopup, btnType: 'primary', hide: 'authstateIs1' },
          ]
        }
      ]
    }
  },
  methods: {
    openPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isDtlShow = true
    },
    closePopup(obj) {
      if (obj) {
        const params = obj
        let apiStr = 'admuserauthedit'
        if (this.curObj.group_type == 1) apiStr = 'admdeptauthedit'
        this.$api.user[apiStr]({
          ...params
        }).then(data => {
          this.$msgs('操作成功')
          this.fetchData()
          this.isDtlShow = false
        })
      } else {
        this.isDtlShow = false
      }
    }
  }
}
</script>
