<template>
  <div class="divide-accounts-manage">
    <router-view />
    <template v-if="!$route.params.id">
      <div class="search">
        <div class="left"></div>
        <div class="right">
          <div>
            <el-input v-model="search.searchNumber" style="width: 250px" placeholder="请输入业务编号/保理合同编号" clearable />
          </div>
          <div>
            <el-input v-model="search.fastSearch" style="width: 300px" placeholder="请输入项目名称/主企业名称/核心企业名称" clearable></el-input>
          </div>
          <div class="leftBtn">
            <el-button type="primary" @click="fetchData">查询</el-button>
          </div>
        </div>
      </div>
      <cy-comm-table
        ref="commTable"
        v-loading="loading"
        :columns="columns"
        :data="tableData"
        :count="total"
        :table-options="tableOptions"
      />
    </template>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { ledgerdoList } from '@/api/divideAccountsManage/divideAccountsManage'
export default {
  name: 'DivideAccountsManage',
  data() {
    return {
      search: {
        searchNumber: '',
        fastSearch: ''
      },
      total: 0,
      loading: false,
      tableData: [
        // { userName: '1111', statusName: '处理中' },
        // { userName: '1111', statusName: '已完成' }
      ],
      tableOptions: {
        maxHeight: 'calc(100vh - 336px)',
        height: 'calc(100vh - 336px)'
      },
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '分账单号',
          prop: 'ledgerNumber',
          showTooltip: true
        },
        {
          label: '业务编号',
          showTooltip: true,
          prop: 'businessNumber',
          render: (h, row) => {
            const btnList = row.assignVoList || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.businessNumber} placement='top'>
                  <div class='one-ellipsis'>
                    {item.businessNumber}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '保理合同编号',
          showTooltip: true,
          prop: 'userName',
          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: '支用批次',
          showTooltip: true,
          prop: 'userName',
          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: '项目名称',
          showTooltip: true,
          prop: 'userTypeName',
          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: 'otherDutyName',
          showTooltip: true,
          render: (h, row) => {
            const btnList = row.assignVoList || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.mainEnterprise} placement='top'>
                  <div class='one-ellipsis'>
                    {item.mainEnterprise}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '核心企业名称',
          prop: 'otherDutyName',
          showTooltip: true,
          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: 'taskName',
          showTooltip: true,
          render: (h, row) => {
            const btnList = row.assignVoList || []
            const options = btnList.map(item => {
              return (
                <el-tooltip class='item' effect='dark' content={item.platformName} placement='top'>
                  <div class='one-ellipsis'>
                    {item.platformName}
                  </div>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        },
        {
          label: '入账金额（元）',
          prop: 'ledgerAmount',
          showTooltip: true,
          width: 120
        },
        {
          label: '状态',
          prop: 'ledgerStatusDict.name',
          showTooltip: true
        },
        {
          label: '操作',
          show: true,
          render: (h, row) => {
            const btnList = [
              {
                msg: '处理',
                icon: 'iconfont icon-xiugai',
                power: 'editLedger',
                rowPower: ['待处理'],
                category: 'edit'
              },
              {
                msg: '查看',
                icon: 'iconfont icon-Magnifier',
                power: 'viewLedger',
                rowPower: ['已完成'],
                category: 'see'
              }
            ]
            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' v-power={item.power}>
                    <i class={item.icon} onClick={() => { this.handlerOperate(item.category, row) }}></i>
                  </span>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          },
          width: 100
        }
      ]
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ]),
    tablePower() {
      return ({ item, tab, row }) => {
        const { tabPower, rowPower } = item
        if (rowPower) {
          if (rowPower.includes(row.ledgerStatusDict.name)) {
            return true
          }
        } else {
          if (tabPower.includes(tab)) {
            return true
          }
        }
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.loading = true
      const params = {
        ...this.search,
        page: this.page || 1,
        rows: this.size || 10
      }
      ledgerdoList(params).then(response => {
        this.tableData = response.rows
        this.loading = false
        this.total = response.records
      })
    },
    handlerOperate(type, row) {
      this.$router.push({
        name: 'DivideAccountEdit',
        params: {
          id: row.id
        },
        query: {
          type
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
