<template>
  <el-dialog
    title="删除主体"
    :visible.sync="visible"
    width="80%"
    top="100px"
  >
    <easy-table
      ref="deleteTable"
      v-model="tableData"
      :fields="fields"
      :table-config="tableConfig"
      :emit-load-on-create="true"
      :on-load="loadData"
    />
    <div slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="danger" @click="confirmDelete">确定删除</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { xrForceDeregisterSpeListByBizSeqNo } from '@/api/force'

export default {
  data() {
    return {
      visible: false,
      tableData: [],
      fields: [
        {
          type: 'input',
          label: '统一社会信用代码/注册号',
          prop: 'uniscId',
          tableProps: {
            showOverflowTooltip: true,
            width: '220px',
            formatter: (row, column, cellValue, index) => {
              return `${row.uniscId || row.regNo || ''}`
            }
          }
        },
        {
          type: 'input',
          label: '主体名称',
          prop: 'entName',
          tableProps: {
            showOverflowTooltip: true,
            width: '300px',
            formatter: (row, column, cellValue, index) => {
              return `${row.entName || ''}`
            }
          }
        },
        {
          type: 'input',
          label: '登记机关',
          prop: 'regOrgCn',
          tableProps: {
            showOverflowTooltip: true
          }
        },
        {
          type: 'input',
          label: '法定代表人',
          prop: 'leRep',
          tableProps: {
            showOverflowTooltip: true,
            formatter: (row, column, cellValue, index) => {
              return `${row.leRep || ''}`
            }
          }
        },
        {
          type: 'select',
          label: '主体状态',
          prop: 'opState',
          optionsBaseCode: 'TY01',
          tableProps: {
            showOverflowTooltip: true
          }
        }
      ],
      tableConfig: {
        selection: true,
        showIndex: true,
        indexWidth: '100px',
        showPagination: true,
        tableProps: {
          headerCellStyle: { background: '#F5F5F5!important', color: '#333333!important', padding: '0px' },
          headerRowStyle: { height: '48px' },
          rowStyle: { height: '48px' },
          cellStyle: { padding: '16px 0', color: '#333' }
        }
      }
    }
  },
  methods: {
    open() {
      this.visible = true
    },
    loadData(pageParam) {
      return xrForceDeregisterSpeListByBizSeqNo({
        size: pageParam.size,
        current: pageParam.current,
        bizSeqNo: this.$route.query.bizSeqNo,
        forceType: '1'
      }).then((data) => {
        return {
          tableData: data,
          total: data.length
        }
      })
    },
    confirmDelete() {
      const selectedRows = this.$refs.deleteTable.getSelection()
      this.$emit('confirm', selectedRows)
      this.visible = false
    }
  }
}
</script>
