<template>
  <el-dialog
    :title="title"
    :visible.sync="entListVisible"
    width="90vw"
    top="153px"
    custom-class="dialog-abnormal-list"
  >
    <edit-table
      v-if="entListVisible"
      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 v-if="showNoDataMessage" class="no-data-message">请输入条件进行查询！</div>

    <div slot="footer">
      <el-button type="primary" plain @click="entListVisible = false">取消</el-button>
      <el-button type="primary" @click="confirm">办理</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getIsUserProp } from '@/api/susnate'
import { listBaseinfo } from '@/api/susnate'
import EditTable from '@/plugins/EasyComponent/EditTable'
export default {
  components: {
    EditTable
  },
  props: {
    type: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  data() {
    return {
      entListVisible: false,
      isExSearch: false,
      tableData: [],
      selected: [],
      showNoDataMessage: false, // 新增属性
      fields: [
        {
          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: 'regorgCn',
          span: 6,
          isView: false,
          tableProps: {
            width: '200px',
            formatter: (row, column, cellValue, index) => {
              return `${row.regorgCn || ''}`
            }
          },
          showInForm: false
        },
        {
          type: 'input',
          label: '法定代表人',
          prop: 'lerep',
          span: 6,
          tableProps: {
            formatter: (row, column, cellValue, index) => {
              return `${row.name || ''}`
            }
          },
          showInForm: false
        },
        {
          type: 'input',
          label: '经营地址',
          prop: 'dom',
          span: 10,
          tableProps: {
            showOverflowTooltip: true,
            formatter: (row, column, cellValue, index) => {
              return `${row.dom || ''}`
            }
          },
          showInForm: false
        },
        {
          type: 'input',
          label: '属地机关',
          prop: 'localadmCn',
          span: 6,
          isView: false,
          tableProps: {
            width: '200px',
            formatter: (row, column, cellValue, index) => {
              return `${row.localadmCn || ''}`
            }
          },
          showInForm: false
        }
      ],
      searchFormProp: {
        formConfig: {
          labelWidth: '100px',
          labelPosition: 'right',
          gutter: 32
        }
      },
      tableProp: {
        emitLoadOnCreate: true,
        tableConfig: {
          selection: true,
          // eslint-disable-next-line no-mixed-spaces-and-tabs
      	  tableSelectionProps: {
            reserveSelection: true,
            selectable: (row, index) => {
              return this.selected.length === 0 || this.selected[0] === row
            }
            // eslint-disable-next-line no-mixed-spaces-and-tabs
		      },
          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: {
    title() {
      return '市场主体信息'
    }
  },
  created() {
    // // 判断是否是管理员
    // getIsUserProp().then(res => {
    //   this.data = {
    //     ...this.data,
    //     userProp: res.userProp
    //   }
    // })
  },
  methods: {
    open() {
      this.selected = []
      this.entListVisible = true
    },
    searchLoader(pageParam, parseSearchFormData, instance) {
      const { searchUscc, entName } = parseSearchFormData
      return listBaseinfo({
        size: pageParam.size,
        current: pageParam.current,
        entity: {
          ...parseSearchFormData
        }
      }).then((data) => {
        this.showNoDataMessage = !searchUscc && !entName
        return {
          tableData: data.data.records,
          total: data.data.total
        }
      })
    },
    confirm() {
      this.$emit('confirm', this.selected)
      this.entListVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
.no-data-message {
  color: red;
  text-align: center; /* 可选：让文字居中 */
  font-size: 16px;     /* 可选：设置字体大小 */
  margin-top: 20px;    /* 可选：增加顶部间距 */
}
</style>
