<template>
  <a-modal
    :body-style="bodyStyle"
    :title="title"
    :destroy-on-close="true"
    :visible="visible"
    :width="modalWidth"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-card :bordered="false" :class="$style.newcard">
      <!-- 列表 -->
      <sd-data-table-ex
        ref="findDataTable"
        :show-advance-btn="true"
        form-id="iamExternalFind"
        page-id="audit/externalProject/iamExternalFind"
        :pagination="{ pageSize: 10 }"
        :filter-expressions="filterExpressions"
        :check-type="'checkbox'"
        :columns="columns"
        :show-advance-query="false"
        :search-fields="['projectTitle', 'projectCode']"
        show-selection
        :process-res="processRes"
        @onChange="onChange"
      >
      </sd-data-table-ex>
    </a-card>
  </a-modal>
</template>

<script>
import { Modal } from 'ant-design-vue'
import components from './_import-components/audit-selectwbfind-modal-import'
const columns = [
  {
    title: '序号',
    dataIndex: 'sortNumber',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '问题Id',
    dataIndex: 'id',
    width: '80px',
    sdHidden: true,
  },
  { dataIndex: 'findTitle', title: '问题名称', width: '80px' },
  { dataIndex: 'findCode', title: '问题编号' },
  { dataIndex: 'responsibleDeptName', title: '责任部门' },
  { dataIndex: 'rectProjectId', sdHidden: false },
  { dataIndex: 'findDesc', sdHidden: false },
  { dataIndex: 'findType', sdHidden: false },
  { dataIndex: 'suggestionType', sdHidden: false },
  { dataIndex: 'suggestion', sdHidden: false },
  { dataIndex: 'responsibleDept', sdHidden: false },
  { dataIndex: 'businessProcess', sdHidden: false },
  { dataIndex: 'whetherOrderDuty', sdHidden: false },
  { dataIndex: 'orderDutyAsk', sdHidden: false },
  { dataIndex: 'rectStatus', sdHidden: false },
]
export default {
  name: 'AuditSelectwbfindModal',
  metaInfo: {
    title: 'AuditSelectwbfindModal',
  },
  components: {
    ...components,
  },
  props: {
    // 弹出窗标题
    title: {
      type: String,
      default: '选择发现问题',
    },
    // 弹出窗宽度
    modalWidth: {
      type: String,
      default: '100%',
    },
    // 弹出窗显示参数
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      columns,
      bodyStyle: {
        padding: 0,
      },
      filterExpressions: [],
    }
  },
  methods: {
    handleOk(e) {
      if (this.$refs.findDataTable.getSelectedRowKeys().length === 0) {
        Modal.warning({
          title: '提示',
          content: '请选择项目!',
        })
        return false
      }
      this.$emit(
        'Selectedfind',
        this.$refs.findDataTable.getSelectedRowKeys(),
        this.$refs.findDataTable.getSelectedRows()
      )
      this.$emit('closefind')
    },
    handleCancel(e) {
      // this.$parent.visible = !this.$parent.visible
      // this.$parent.visibleY = !this.$parent.visibleY
      this.$emit('closefind')
    },
    processRes(data) {
      let index = 0
      data.data.forEach((item) => {
        item.id = this.$refs.findDataTable.localPagination.current + '-' + index
        index++
      })
      return data
    },
    // 翻页操作
    onChange(pagination, filters, sorter) {
      this.pageSize = pagination.pageSize
      this.startPosition = (pagination.current - 1) * pagination.pageSize
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
