<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    width="90vw"
    top="153px"
    custom-class="dialog-abnormal-list"
  >
    <edit-table
      v-if="visible"
      v-model="tableData"
      :table-prop="tableProp"
      :fields="fields"
      :show-search-form="true"
      row-key="pripid"
      :search-form-prop="searchFormProp"
      :search-loader="searchLoader"
      :selected.sync="selected"
    />
    <div slot="footer">
      <el-button type="primary" plain @click="visible = false">取消</el-button>
      <el-button type="primary" @click="confirm">办理</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { entSeriousIllegalPage, getIsUserProp, listRpeiExeInfo } from '@/api/illegal'
export default {
  props: {
    type: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  data() {
    return {
      visible: false,
      tableData: [],
      selected: [],
      params: '',
      searchFormProp: {
        formConfig: {
          labelWidth: '100px',
          labelPosition: 'right',
          gutter: 32
        }
      },
      tableProp: {
        emitLoadOnCreate: true,
        tableConfig: {
          rowKey: 'illegallistid',
          selection: true,
          tableSelectionProps: {
            reserveSelection: true,
            selectable: (row, index) => {
              return this.selected.length === 0 || this.selected[0] === row
            }
          },
          disableSelectAll: false,
          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' }
          }
        }
      }
    }
  },
  computed: {
    // eslint-disable-next-line vue/return-in-computed-property
    title() {
      if (this.params === 'add') {
        return '重整计划或者和解协议需要暂时屏蔽失信的企业信息'
      } else if (this.params === 'update') {
        return '企业破产重整计划或者和解协议执行信息'
      }
    },
    fields() {
      return [
        {
          type: 'input',
          label: '统一社会信用代码/注册号',
          prop: 'searchUscc',
          span: 8,
          tableProps: {
            showOverflowTooltip: true,
            formatter: (row, column, cellValue, index) => {
              return `${row.uniscid || row.regno || ''}`
            }
          }
        },
        {
          type: 'input',
          label: ({ meta }) => {
            return meta.isSearchForm ? '主体名称（精确）' : '主体名称'
          },
          prop: 'entname',
          span: 8,
          tableProps: {
            showOverflowTooltip: true,
            formatter: (row, column, cellValue, index) => {
              return `${row.entname || ''}`
            }
          }
        },
        {
          type: 'buttons',
          showInTable: false,
          hiddenLabel: true,
          label: '搜索操作',
          prop: '搜索操作',
          span: 8,
          formItemProp: {
            labelWidth: '0px'
          },
          buttons: [
            {
              label: '查询',
              type: 'primary',
              handler: (scope) => {
                const { meta } = scope
                const { _editTable } = meta
                const { editTableInstance } = _editTable
                editTableInstance.search()
              }
            },
            {
              label: '重置',
              type: 'primary',
              buttonProps: {
                plain: true
              },
              handler: (scope) => {
                const { meta } = scope
                const { _editTable } = meta
                const { editTableInstance } = _editTable
                editTableInstance.search({
                  reset: true
                })
              }
            }
          ]
        },
        {
          type: 'input',
          label: '列入严重违法企业名单原因',
          prop: 'serillreaString',
          span: 8,
          tableProps: {
            showOverflowTooltip: true
          },
          showInForm: false,
          showInTable: () => {
            return this.params === 'add'
          }
        },
        {
          type: 'date-picker',
          label: '列入日期',
          prop: 'abntime',
          showInForm: false,
          showInTable: () => {
            return this.params === 'add'
          }
        },
        {
          type: 'select',
          label: '执行状态',
          prop: 'exeState',
          tableSort: 3,
          span: 6,
          showInForm: false,
          options: () => {
            return [
              { label: '执行期间', value: '1' },
              { label: '执行完毕', value: '2' },
              { label: '未执行成功', value: '3' }
            ]
          },
          showInTable: () => {
            return this.params === 'update'
          }
        },
        {
          type: 'date-picker',
          label: '执行日期',
          prop: 'exeDate',
          showInForm: false,
          showInTable: () => {
            return this.params === 'update'
          }
        }
      ]
    }
  },
  created() {
    // 判断是否是管理员
    getIsUserProp().then(res => {
      this.data = {
        ...this.data,
        userProp: res.userProp
      }
    })
  },
  methods: {
    open(params) {
      // 可以接收传递的参数
      this.params = params || {}
      this.selected = []
      this.visible = true
    },
    searchLoader(pageParam, parseSearchFormData, instance) {
      if (this.params === 'add') { // 申请屏蔽失信的情况查尚在列严的主体
        return entSeriousIllegalPage({
          size: pageParam.size,
          current: pageParam.current,
          entity: {
            ...parseSearchFormData
          }
        }).then((data) => {
          return {
            tableData: data.records,
            total: data.total
          }
        })
      } else if (this.params === 'update') { // 修改办理状态的情况查重整计划或者和解协议执行信息
        return listRpeiExeInfo({
          size: pageParam.size,
          current: pageParam.current,
          entity: {
            ...parseSearchFormData
          }
        }).then((data) => {
          return {
            tableData: data.records,
            total: data.total
          }
        })
      }
    },
    confirm() {
      this.$emit('confirm', {
        selected: this.selected,
        params: this.params
      })
      this.visible = false
    }
  }
}
</script>
<style lang="scss" scoped>
.no-data-message {
  color: red;
  text-align: center; /* 可选：让文字居中 */
  font-size: 16px;     /* 可选：设置字体大小 */
  margin-top: 20px;    /* 可选：增加顶部间距 */
}
</style>
