// import { formatMoney } from '@/utils/index'
import { getFailList, reGetAuthQrcode } from '@/api/accountCenter/openInfoManage'
export default {
  data() {
    return {
      total: 0,
      loading: false,
      columns: [
        // {
        //   label: '序号',
        //   index: true
        // },
        {
          label: '客户名称',
          prop: 'customerName',
          showTooltip: true
        },
        {
          label: '客户号',
          showTooltip: true,
          prop: 'customerNumber'
        },
        {
          label: '客户状态',
          prop: 'customerStatus',
          showTooltip: true
        },
        {
          label: '客户类别',
          prop: 'customerType',
          showTooltip: true,
          render: (h, row) => {
            return (<span>{row.customerType === 0 ? '企业' : row.customerType === 1 ? '个体工商户' : '个人'} </span>)
          }
        },
        {
          label: '阶段',
          prop: 'stageStr',
          showTooltip: true
        },
        {
          label: '退回原因',
          prop: 'reason',
          showTooltip: true
        },
        {
          label: '核验状态',
          prop: 'verificationStatus',
          showTooltip: true
        },
        {
          label: '创建时间',
          prop: 'gmtCreate',
          showTooltip: true
        },
        {
          label: '法人授权状态',
          prop: 'userAtuhSts',
          showTooltip: true,
          width: 120
        },
        {
          label: '提示',
          showTooltip: true,
          render: (h, row) => {
            if (row.customerStatus === '生效') {
              if (row.userAtuhSts === '待用户授权') {
                return <div>去授权</div>
              } else if (row.userAtuhSts === '银行审核中' || row.userAtuhSts === '授权失败') {
                return <div>联系客户</div>
              }
            }
          }
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              {
                msg: '查看',
                icon: 'iconfont icon-orange icon-a-Group957',
                power: '',
                category: 'see'
              },
              {
                msg: '编辑',
                icon: 'iconfont icon-orange icon-a-Group8151',
                power: '',
                category: 'edit',
                rowPower: ['暂存', '审批退回']
              },
              {
                msg: '去授权',
                icon: 'iconfont icon-orange icon-a-Group1022',
                power: '',
                category: 'auth',
                rowPower: ['待用户授权']
              },
              {
                msg: '核验失败原因',
                icon: 'iconfont icon-orange icon-icon-active',
                power: '',
                category: 'reason',
                rowPower: ['开户失败']
              }
            ]
            const options = btnList.map(item => {
              return (
                this.tablePower({ item, row }) &&
                <el-tooltip class='item' effect='dark' content={item.msg} placement='top' >
                  <span class='table-icon-box'>
                    <i style={item.style} class={item.icon} onClick={() => { this.handlerOperate(item.category, row) }}></i>
                  </span>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          },
          width: 170
        }
      ],
      reasonColumns: [{
        label: '序号',
        index: true,
        width: 200
      },
      {
        label: '报错原因',
        prop: 'reason',
        showTooltip: true
      }],
      reasonList: [],
      timeReduce: 48 * 60 * 60 * 1000
    }
  },
  computed: {
    tablePower() {
      return ({ item, row }) => {
        const { rowPower } = item
        if (rowPower) {
          if (item.category === 'auth') {
            return row.qrCode && row.customerStatus === '生效' && rowPower.includes(row.userAtuhSts)
          } else if (item.category === 'reason') {
            return rowPower.includes(row.customerStatus)
          } else {
            if (rowPower.includes(row.stageStr)) {
              return true
            }
          }
        } else {
          return true
        }
      }
    }
  },
  methods: {
    handlerOperate(type, row) {
      if (type === 'see' || type === 'edit' || type === 'add') {
        this.$router.push({
          name: 'OpenInfoManageDetails',
          params: { id: row.id },
          query: {
            type
          }
        })
      } else if (type === 'auth') {
        this.authActiveInfo = []
        // 去授权 -- 这里做一个判断，如果二维码认证时间过期 需要重新调用生成二维码接口
        const nowTimeTemp = new Date().getTime()
        const qrCodeValidTime = new Date(row.qrCodeEffectTime).getTime() + this.timeReduce

        if (qrCodeValidTime - nowTimeTemp <= 0) {
          this.resetQrCodeUri(row)
        } else {
          this.authActiveInfo.push({
            qrCodeEffectTime: row.qrCodeEffectTime,
            qrCode: row.qrCode,
            authenticator: row.authenticator
          })
          console.log(this.authActiveInfo, 7777)
          this.$refs.authorizationRef.openDialog(true)
        }
      } else if (type === 'reason') {
        // 核验失败原因
        this.$refs.failreasonDialog.show = true
        getFailList({ id: row.id }).then((data) => {
          this.reasonList = data.data.map(item => {
            return {
              reason: item
            }
          })
        })
      }
    },
    async resetQrCodeUri(curRow) {
      this.authActiveInfo = []
      const res = await reGetAuthQrcode({ id: curRow.id })

      if (res.success) {
        if ('noticeInfoList' in res.data) {
          this.authActiveInfo = res.data.noticeInfoList
        } else if (Array.isArray(res.data)) {
          this.authActiveInfo = res.data
        } else {
          this.authActiveInfo.push({
            qrCodeEffectTime: res.data.qrCodeEffectTime,
            qrCode: res.data.qrCode,
            authenticator: res.data.authenticator
          })
        }
        this.$refs.authorizationRef.openDialog(true)
      }
    }
  }
}
