import { formatMoney } from '@/utils/index'
export default {
  data() {
    return {
      loading: false,
      tableOptions: {
        maxHeight: 'calc(100vh - 336px)',
        height: 'calc(100vh - 336px)'
      },
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '入账/出账日期',
          prop: 'gmtCreate',
          width: 150,
          showTooltip: true,
          render: (h, row) => {
            const btnList = row.cashFlowManageBankVo || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.gmtCreate} placement='top'>
                  <div class='one-ellipsis'>
                    {item.gmtCreate}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '开户银行名称',
          showTooltip: true,
          prop: 'bankName',
          width: 300,
          render: (h, row) => {
            const btnList = row.cashFlowManageBankVo || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.bankName} placement='top'>
                  <div class='one-ellipsis'>
                    {item.bankName}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '卡号',
          showTooltip: true,
          prop: 'bankAccount',
          width: 200,
          render: (h, row) => {
            const btnList = row.cashFlowManageBankVo || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.bankAccount} placement='top'>
                  <div class='one-ellipsis'>
                    {item.bankAccount}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '企业名称',
          prop: 'companyName',
          showTooltip: true
        },
        {
          label: '出入账类型',
          prop: 'otherDutyName',
          showTooltip: true,
          width: 100,
          render: (h, row) => {
            return <div>{ row.entryOutType === '1' ? '入账' : '出账' }</div>
          }
        },
        {
          label: '金额类型',
          prop: 'cashTypeDict.name',
          showTooltip: true
        },
        {
          label: '金额',
          prop: 'amount',
          showTooltip: true,
          render: (h, row) => {
            return <div>{ formatMoney(row.amount) }</div>
          }
        },
        {
          label: '状态',
          prop: 'cashStatus',
          showTooltip: true,
          render: (h, row) => {
            return <div>{ row.cashStatus === '1' ? '已创建' : row.cashStatus === '2' ? '已分配' : row.cashStatus === '3' ? '待处理' : '已完成' }</div>
          }
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              // {
              //   msg: '时间进度轴',
              //   icon: 'iconfont icon-timeAxis',
              //   power: '',
              //   // tabPower: ['all', 'pending'],
              //   category: 'timeAxis'
              // },
              {
                msg: '查看',
                icon: 'iconfont icon-Magnifier',
                power: 'showFinancial',
                // tabPower: ['all'],
                // rowPower: [],
                category: 'see'
              },
              {
                msg: '修改',
                icon: 'iconfont icon-xiugai',
                power: 'editFinancial',
                category: 'edit',
                rowPower: ['4']
              },
              {
                msg: '删除',
                icon: 'iconfont icon-shanchu',
                power: 'deleteFinancial',
                category: 'delete'
              }
            ]
            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, item.msg) }}></i>
                  </span>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          },
          width: 150
        }
      ]
    }
  },
  computed: {
    formatMoney() {
      return (val) => {
        return formatMoney(val)
      }
    },
    tablePower() {
      return ({ item, row }) => {
        const { rowPower } = item
        if (rowPower) {
          // entryOutType 出入帐类型 1--入账 2--出账 出账只存在查看按钮
          if (rowPower.includes(row.cashStatus) || row.entryOutType === '2') {
            return false
          }
          // 入账且状态为已分配不展示编辑按钮
          if (row.entryOutType === '1' && row.cashStatus !== '1') {
            return false
          }
          return true
        } else {
          return true
        }
      }
    }
  }
}
