<template>
  <div class="relation-disburse-details">
    <div class="company-form">
      <div>
        <div class="required">出资方：</div>
        <div>
          <el-input v-model="ruleForm.name" placeholder="请输入出资方" disabled></el-input>
        </div>
      </div>
    </div>
    <cy-comm-table
      ref="commTable"
      v-loading="loading"
      style="margin-top: 20px"
      :columns="columns"
      :data="tableData"
      :count="count"
    />
  </div>
</template>

<script>
import { getRelationDisburseDetails, relationDisbursDetailsDele } from '@/api/capitalManage/relationDisburse'
export default {
  data() {
    return {
      ruleForm: {
        name: ''
      },
      loading: false,
      tableData: [],
      count: 0,
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '授信主体',
          prop: 'creditSubjectName',
          showTooltip: true
        },
        {
          label: '项目经理',
          showTooltip: true,
          prop: 'projectManager'
        },
        {
          label: '业务编号',
          showTooltip: true,
          prop: 'businessNo'
        },
        {
          label: '合同编号',
          showTooltip: true,
          prop: 'contractNo'
        },
        {
          label: '批次号',
          showTooltip: true,
          prop: 'quotaDisburseBatch'
        },
        {
          label: '放款金额',
          showTooltip: true,
          prop: 'loadRecordList'
        },
        {
          label: '放款日期',
          showTooltip: true,
          prop: 'loadRecordList'
        },
        {
          label: '到期日',
          showTooltip: true,
          prop: 'loanInfoVo.expireDate'
        },
        {
          label: '操作',
          render: (h, row) => {
            const btnList = [
              {
                msg: '删除',
                icon: 'iconfont icon-shanchu',
                rowPower: [],
                power: 'deleteEnterprise',
                category: 'delete'
              }
            ]
            const options = btnList.map(item => {
              // this.tablePower({ item, row }) &&
              return (
                <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>
          }
        }
      ]
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      const { id, institutionName } = this.$route.query
      this.ruleForm.name = institutionName
      this.loading = true
      const params = {
        institutionId: id,
        page: this.page || 1,
        rows: this.size || 10
      }
      getRelationDisburseDetails(params).then(({ data: { rows, records }}) => {
        this.loading = false
        this.tableData = rows
        this.count = records
      })
    },
    handlerOperate(type, row) {
      if (type === 'delete') {
        this.modifyClick(row)
      }
    },
    modifyClick(row) {
      this.$confirm('确认删除该绑定关系么？', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        const { relationCustomerId, relationCustomerDisburseId } = row
        const params = {
          Loading: true,
          relationCustomerId: relationCustomerId || '',
          relationCustomerDisburseId: relationCustomerDisburseId || ''
        }
        relationDisbursDetailsDele(params).then(() => {
          this.fetchData()
          this.$message.success('删除该绑定关系成功')
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.relation-disburse-details {
  .company-form {
    & > div {
      & > div:first-child {
        line-height: 46px;
        font-size: 14px;
        font-weight: bold;
        &.required:before {
          content: '*';
          color: #F56C6C;
          margin-right: 4px;
          font-size: 12px;
        }
      }
    }
  }
}

</style>
