export default {
  data() {
    return {
      total: 0,
      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'],
                rowPower: ['模板初审', '模板复审', '变更初审', '变更复审', '信息审核', '签署审核', '变更签署审核', '变更审核', '销售合同创建'],
                category: 'edit'
              },
              {
                msg: '查看',
                icon: 'iconfont icon-Magnifier',
                tabPower: ['all'],
                power: 'viewSalesContract',
                category: 'see'
              },
              {
                msg: '销售合同下载',
                icon: 'iconfont icon-xiazai',
                power: 'downloadAllSalesContractFile',
                tabPower: ['all'],
                satausPower: ['已完成'],
                category: 'downloadContract'
              },
              {
                msg: '出证文件下载',
                icon: 'iconfont icon-xiazai',
                power: 'downloadSalesReport',
                tabPower: ['all'],
                satausPower: ['已完成'],
                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, 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 (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)'
      }
    }
  }
}
