import { formatMoney } from '@/utils/index'
export default {
  data() {
    return {
      total: 0,
      loading: false,
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '业务编号',
          prop: 'businessNumber',
          showTooltip: true
        },
        {
          label: '项目名称',
          showTooltip: true,
          prop: 'businessName'
        },
        {
          label: '主企业名称',
          prop: 'supplierName',
          showTooltip: true,
          width: 120
        },
        {
          label: '核心企业名称',
          prop: 'customerName',
          showTooltip: true,
          width: 120
        },
        {
          label: '贸易平台',
          prop: 'platformName',
          showTooltip: true
        },
        {
          label: '开票金额（元）',
          prop: 'openAmount',
          showTooltip: true,
          render: (h, row) => {
            return <div>{ formatMoney(row.openAmount) }</div>
          }
        },
        {
          label: '当前阶段',
          prop: 'taskName',
          showTooltip: true
        },
        {
          label: '状态',
          prop: 'status.name',
          showTooltip: true
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              {
                msg: '查看',
                icon: 'iconfont icon-orange icon-a-Group957',
                power: 'projectNumber:delete',
                category: 'see'
              },
              {
                msg: '编辑',
                icon: 'iconfont icon-orange icon-a-Group8151',
                power: 'projectNumber:delete',
                category: 'edit',
                rowPower: ['提交申请']
              },
              {
                msg: '查看发票',
                icon: 'iconfont icon-orange icon-a-Group8141',
                power: 'projectNumber:delete',
                category: 'seeInvoice'
              },
              {
                msg: '下载发票',
                icon: 'iconfont icon-orange icon-Union',
                power: 'projectNumber:delete',
                category: 'downloadInvoice',
                style: 'display: inline-block; transform: scale(0.65)'
              }
            ]
            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: 200
        }
      ]
    }
  },
  computed: {
    tablePower() {
      return ({ item, row }) => {
        const { rowPower } = item
        if (rowPower) {
          if (rowPower.includes(row.taskName)) {
            return true
          }
        } else {
          return true
        }
      }
    }
  }
}
