export default {
  data() {
    return {
      total: 20,
      loading: false,
      tableData: [],
      tableOptions: {
        sortTable: true,
        maxHeight: 'calc(100vh - 406px)',
        height: 'calc(100vh - 406px)'
      },
      allTableColumns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '业务编号',
          prop: 'businessNumber',
          showTooltip: true
        },
        {
          label: '保理合同编号',
          showTooltip: true,
          prop: 'contractNumber'
        },
        {
          label: '支用批次',
          prop: 'quotaDisburseBatch'
        },
        {
          label: '项目名称',
          prop: 'projectName',
          showTooltip: true
        },
        {
          label: '主企业名称',
          prop: 'supplierName',
          showTooltip: true
        },
        {
          label: '核心企业名称',
          prop: 'customerName',
          showTooltip: true
        },
        {
          label: '贸易平台',
          prop: 'platformName',
          showTooltip: true
        },
        {
          label: '应退金额',
          prop: 'settlementAmount',
          showTooltip: true
        },
        {
          label: '实退金额',
          prop: 'openAmount',
          showTooltip: true
        },
        {
          label: '剩余应退金额',
          prop: 'financingAmount',
          showTooltip: true
        },
        {
          label: '资产状态',
          prop: 'coreStatusStr',
          showTooltip: true
        },
        {
          label: '当前阶段',
          prop: 'taskName',
          showTooltip: true
        },
        {
          label: '执行人',
          prop: 'executor'
        },
        {
          label: '状态',
          prop: 'statusStr',
          showTooltip: true
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              {
                msg: '时间进度轴',
                icon: 'iconfont icon-timeAxis',
                power: '',
                tabPower: ['all', 'pending'],
                category: 'timeAxis'
              },
              {
                msg: '退款申请',
                icon: 'iconfont icon-xiugai',
                power: 'applyRefund',
                tabPower: ['all'],
                category: 'edit',
                rowPower: []
              },
              {
                msg: '查看',
                icon: 'iconfont icon-Magnifier',
                power: 'viewRefundManagement',
                tabPower: ['all'],
                // rowPower: ['保证方式确认'],
                category: 'see'
              }
            ]
            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: 120
        }
      ],
      reFoundTableColumns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '退款编号',
          prop: 'paymentNo',
          showTooltip: true
        },
        {
          label: '业务编号',
          prop: 'businessNumber',
          showTooltip: true
        },
        {
          label: '保理合同编号',
          showTooltip: true,
          prop: 'contractNumber'
        },
        {
          label: '支用批次',
          prop: 'quotaDisburseBatch',
          showTooltip: true
        },
        {
          label: '项目名称',
          prop: 'projectName',
          showTooltip: true
        },
        {
          label: '主企业名称',
          prop: 'supplierName',
          showTooltip: true
        },
        {
          label: '核心企业名称',
          prop: 'customerName',
          showTooltip: true
        },
        {
          label: '贸易平台',
          prop: 'platformName',
          showTooltip: true
        },
        {
          label: '剩余应退金额',
          prop: 'financingAmount',
          showTooltip: true
        },
        {
          label: '资产状态',
          prop: 'coreStatusStr',
          showTooltip: true
        },
        {
          label: '当前阶段',
          prop: 'taskName',
          showTooltip: true
        },
        {
          label: '状态',
          prop: 'statusStr',
          showTooltip: true
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              {
                msg: '时间进度轴',
                icon: 'iconfont icon-timeAxis',
                power: '',
                tabPower: ['all', 'pending'],
                category: 'timeAxis'
              },
              {
                msg: '编辑',
                icon: 'iconfont icon-xiugai',
                power: '',
                tabPower: ['pending'],
                // rowPower: [''],
                category: 'edit'
              },
              {
                msg: '查看',
                icon: 'iconfont icon-Magnifier',
                power: 'viewRefundManagement',
                tabPower: ['all', 'pending'],
                // rowPower: [''],
                category: 'see'
              }
            ]
            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: 120
        }
      ]
    }
  },
  computed: {
    tablePower() {
      return ({ item, tab, row }) => {
        const { tabPower, rowPower } = item
        if (rowPower) {
          // 退款申请
          if (tabPower.includes(tab) && (row.financingAmount > 0 && (!row.taskName || row.taskName === null))) {
            return true
          }
        } else {
          if (tabPower.includes(tab)) {
            return true
          }
        }
      }
    },
    getTableColumns() {
      if (this.activeName === 'all') {
        return this.allTableColumns
      }
      return this.reFoundTableColumns
    },
    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 - 306px)',
        height: 'calc(100vh - 306px)'
      }
    }
  }
}
