export default {
  data() {
    return {
      total: 0,
      loading: false,
      tableData: [],
      tableOptions: {
        sortTable: true,
        maxHeight: 'calc(100vh - 406px)',
        height: 'calc(100vh - 406px)'
      },
      columns: [
        {
          label: '序号',
          index: true,
          width: 50
        },
        {
          label: '资方名称',
          prop: 'institutionName',
          showTooltip: true
        },
        {
          label: '客户名称',
          prop: 'customerName',
          showTooltip: true
        },
        {
          label: '合同编号',
          prop: 'contractNumber',
          showTooltip: true
        },
        {
          label: '批次号',
          prop: 'quotaDisburseBatch'
        },
        {
          label: '放款金额',
          prop: '',
          showTooltip: true,
          render: (h, row) => {
            return (
              <span>{ row.loanAmountTotal }   { row.currencyCode }</span>
            )
          }
        },
        {
          label: '放款日期',
          prop: '',
          render: (h, row) => {
            if (row.loanDateList && row.loanDateList.length) {
              return row.loanDateList.map(item => {
                return (<div>{ item }</div>)
              })
            }
            return h('span', '')
          }
        },
        {
          label: '到期日',
          prop: 'expireDate',
          showTooltip: true
        },
        {
          label: '状态',
          prop: 'status.name',
          showTooltip: true,
          render: (h, row) => {
            return (
              <span>{ row.status ? row.status.name : '' }</span>
            )
          }
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              {
                msg: '时间进度轴',
                icon: 'iconfont icon-timeAxis',
                tabPower: ['all', 'pending'],
                category: 'timeAxis'
              },
              {
                msg: '审核',
                icon: 'iconfont icon-xiugai',
                tabPower: ['pending'],
                satausPower: ['待审核'],
                category: 'approval'
              },
              {
                msg: '编辑',
                icon: 'iconfont icon-xiugai',
                tabPower: ['pending'],
                satausPower: ['待编辑'],
                category: 'edit'
              },
              {
                msg: '查看',
                icon: 'iconfont icon-Magnifier',
                tabPower: ['all', 'pending'],
                power: 'viewFinancialCustomer',
                category: 'see'
              },
              {
                msg: '资料下载',
                icon: 'iconfont icon-xiazai',
                power: 'downloadCustomerFile',
                tabPower: ['all'],
                satausPower: ['通过'],
                category: 'download'
              },
              {
                msg: '上传合同清单',
                icon: 'iconfont icon-shangchuandaochu',
                power: 'uploadContractFile',
                tabPower: ['all'],
                satausPower: ['通过'],
                category: 'contract'
              }
            ]
            const options = btnList.map(item => {
              return (
                this.tablePower({ item, tab: this.activeName, row }) &&
                <el-tooltip class='item' effect='dark' content={item.msg} placement='top' >
                  <span class='table-icon-box' v-power={item.power}>
                    <i class={item.icon} onClick={() => { this.handlerOperate(item.category, row) }}></i>
                  </span>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          },
          width: 200
        }
      ]
    }
  },
  computed: {
    tablePower() {
      return ({ item, tab, row }) => {
        const { tabPower, rowPower, power, satausPower } = item
        if (power && !this.btnPermission.includes(power)) {
          return false
        }
        if (rowPower && (!row.taskName || !rowPower.includes(row.taskName))) {
          return false
        }
        if (satausPower && (!row.status || !row.status.name || !satausPower.includes(row.status.name))) {
          return false
        }
        if (satausPower && satausPower.includes(row.status.name) && row.buttonFlag === false && item.msg === '上传合同清单') {
          return false
        }
        if (tabPower && !tabPower.includes(tab)) {
          return false
        }
        return true
      }
    },
    getTableOptions() {
      if (this.activeName === 'all') {
        return {
          sortTable: true,
          maxHeight: 'calc(100vh - 406px)',
          height: 'calc(100vh - 406px)'
        }
      }
      // if (this.total > 0) {
      //   return {
      //     sortTable: true,
      //     maxHeight: 'calc(100vh - 360px)',
      //     height: 'calc(100vh - 360px)'
      //   }
      // }
      return {
        sortTable: true,
        maxHeight: 'calc(100vh - 406px)',
        height: 'calc(100vh - 406px)'
      }
    }
  }
}
