export default {
  data() {
    return {
      total: 20,
      loading: false,
      tableData: [],
      tableOptions: {
        sortTable: true,
        maxHeight: 'calc(100vh - 406px)',
        height: 'calc(100vh - 406px)'
      },
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '采购合同编号',
          prop: 'contractNumber',
          showTooltip: true,
          width: 150
        },
        {
          label: '业务编号',
          prop: 'businessNumber',
          showTooltip: true,
          width: 150
        },
        {
          label: '项目名称',
          showTooltip: true,
          prop: 'projectName',
          width: 150
        },
        {
          label: '主企业名称',
          prop: 'supplierName',
          width: 120,
          showTooltip: true
        },
        {
          label: '核心企业名称',
          prop: 'customerName',
          width: 120,
          showTooltip: true
        },
        {
          label: '贸易平台',
          prop: 'platformName',
          showTooltip: true
        },
        {
          label: '当前阶段',
          prop: 'taskName',
          showTooltip: true
        },
        {
          label: '执行人',
          prop: 'executor',
          showTooltip: true
        },
        {
          label: '状态',
          prop: 'status.name',
          showTooltip: true
        },
        {
          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'],
                category: 'edit'
              },
              {
                msg: '查看',
                icon: 'iconfont icon-Magnifier',
                tabPower: ['all', 'pending'],
                power: 'viewPurchContract',
                category: 'see'
              },
              {
                msg: '采购合同下载',
                icon: 'iconfont icon-xiazai',
                power: 'downloadAllPurchFile',
                tabPower: ['all'],
                rowPower: ['已完成'],
                category: 'downloadContract'
              },
              {
                msg: '出证文件下载',
                icon: 'iconfont icon-xiazai',
                power: 'downloadReportUrl',
                tabPower: ['all'],
                rowPower: ['已完成'],
                category: 'downloadFile'
              }
            ]
            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'>
                    <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 } = item
        if (power && !this.btnPermission.includes(power)) {
          return false
        }
        if (rowPower && (!row.status || !row.status.name || !rowPower.includes(row.status.name))) {
          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 - 306px)',
        height: 'calc(100vh - 306px)'
      }
    }
  }
}
