<template>
  <div class="divide-accounts-manage">
    <div class="search">
      <div class="left" />
      <div class="right">
        <div>
          <el-input v-model="search.businessNo" placeholder="请输入业务编号" clearable />
        </div>
        <div>
          <el-select v-model="search.status" placeholder="请选择状态" clearable>
            <el-option
              v-for="item in constant.ledgerStatus"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </div>
        <div>
          <el-input v-model="search.customerName" placeholder="请输入项目名称/主企业名称/核心企业名称" clearable />
        </div>
        <div class="right-btn">
          <el-button type="primary" @click="fetchData('search')">查询</el-button>
        </div>
      </div>
    </div>
    <cy-comm-table
      ref="commTable"
      v-loading="loading"
      style="margin-top: 10px;"
      :columns="columns"
      :data="tableData"
      :count="total"
      parent-component="DivideAccountsManage"
    />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getList } from '@/api/mySettlement/divideAccountsManage'
import { formatMoney } from '@/utils/index'
export default {
  name: 'DivideAccountsManage',
  data() {
    return {
      loading: false,
      tableData: [],
      search: {
        businessNo: '',
        status: '',
        customerName: ''
      },
      total: 0,
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '分账单号',
          prop: 'ledgerNumber',
          showTooltip: true
        },
        {
          label: '核心企业名称',
          showTooltip: true,
          prop: 'enterprise',
          render: (h, row) => {
            const btnList = row.assignVoList || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.enterprise} placement='top'>
                  <div class='one-ellipsis'>
                    {item.enterprise}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },

        {
          label: '项目名称',
          prop: 'projectName',
          render: (h, row) => {
            const btnList = row.assignVoList || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.projectName} placement='top'>
                  <div class='one-ellipsis'>
                    {item.projectName}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '保理合同编号',
          prop: 'taskName',
          render: (h, row) => {
            const btnList = row.assignVoList || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.contractNo} placement='top'>
                  <div class='one-ellipsis'>
                    {item.contractNo}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '支用批次',
          prop: 'quotaDisburseBatch',
          render: (h, row) => {
            const btnList = row.assignVoList || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.quotaDisburseBatch} placement='top'>
                  <div class='one-ellipsis'>
                    {item.quotaDisburseBatch}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '入账金额（元）',
          prop: 'ledgerAmount',
          showTooltip: true,
          render: (h, row) => {
            return <div>{ formatMoney(row.ledgerAmount) }</div>
          }
        },
        {
          label: '状态',
          prop: 'ledgerStatusDict.name',
          showTooltip: true
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              {
                msg: '查看',
                icon: 'iconfont icon-orange icon-a-Group957',
                power: 'projectNumber:delete',
                category: 'see',
                rowPower: ['已完成']
              }
            ]
            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 class={item.icon} onClick={() => { this.handlerOperate(item.category, row) }}></i>
                  </span>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          },
          width: 80
        }
      ]
    }
  },
  computed: {
    ...mapGetters(['constant']),
    tablePower() {
      return ({ item, row }) => {
        const { rowPower } = item
        if (rowPower) {
          if (rowPower.includes(row.ledgerStatusDict.name)) {
            return true
          }
        } else {
          return true
        }
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  created() {
    this.$store.dispatch('getConstant', ['ledgerStatus'])
  },
  methods: {
    fetchData(type) {
      if (type === 'search') {
        this.page = 1
        this.size = 10
      }
      this.loading = true
      const params = {
        ...this.search,
        page: this.page || 1,
        rows: this.size || 10
      }
      getList(params).then(({ data }) => {
        this.tableData = data.rows
        this.total = data.records
        this.loading = false
      })
    },
    handlerOperate(type, row) {
      this.$router.push({
        name: 'MySettlementDivideAccountsSee',
        params: { id: row.id },
        query: {
          module: '分账管理',
          type,
          supplierId: row.supplierId
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.divide-accounts-manage {

}
</style>
