<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">
      <a-tabs v-model="activeKey" default-active-key="1" class="sd-has-table ">
        <a-tab-pane key="1" tab="内部项目">
          <AuditNbSelectproject ref="nbproject" @listSelected="listSelected"></AuditNbSelectproject>
        </a-tab-pane>
        <a-tab-pane key="2" tab="外部项目" force-render>
          <AuditWbSelectproject ref="wbproject" @listSelected="listSelected"></AuditWbSelectproject>
        </a-tab-pane>
      </a-tabs>
    </a-card>
  </a-modal>
</template>

<script>
import { Modal } from 'ant-design-vue'
import AuditNbSelectproject from './audit-nb-selectproject.vue'
import AuditWbSelectproject from './audit-wb-selectproject.vue'
import components from './_import-components/audit-selectproject-modal-import'

export default {
  name: 'AuditSelectprojectModal',
  metaInfo: {
    title: 'AuditSelectprojectModal',
  },
  components: {
    ...components,
    AuditNbSelectproject,
    AuditWbSelectproject,
  },
  props: {
    // 弹出窗标题
    title: {
      type: String,
      default: '请选择',
    },
    // 弹出窗宽度
    modalWidth: {
      type: String,
      default: '1200px',
    },
    // 弹出窗显示参数
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      activeKey: '1', // 选中页签
      bodyStyle: {
        padding: 0,
        minHeight: '700px',
      },
    }
  },
  methods: {
    listSelected(record, index) {
      this.$emit('listMxSelected', index, record, this.activeKey)
      this.$emit('close')
    },
    handleOk(e) {
      // this.$parent.visible = !this.$parent.visible
      // this.$parent.visibleY = !this.$parent.visibleY
      // 列表选择事件，返回选择的数据
      if (this.activeKey === '1') {
        if (this.$refs.nbproject.$refs.NBDataTable.getSelectedRowKeys().length === 0) {
          Modal.warning({
            title: '提示',
            content: '请选择项目!',
          })
          return false
        }
        this.$emit(
          'listMxSelected',
          this.$refs.nbproject.$refs.NBDataTable.getSelectedRowKeys(),
          this.$refs.nbproject.$refs.NBDataTable.getSelectedRows(),
          '1'
        )
      } else {
        if (this.$refs.wbproject.$refs.WBDataTable.getSelectedRowKeys().length === 0) {
          Modal.warning({
            title: '提示',
            content: '请选择项目!',
          })
          return false
        }
        this.$emit(
          'listMxSelected',
          this.$refs.wbproject.$refs.WBDataTable.getSelectedRowKeys(),
          this.$refs.wbproject.$refs.WBDataTable.getSelectedRows(),
          '2'
        )
      }

      this.$emit('close')
    },
    handleCancel(e) {
      // this.$parent.visible = !this.$parent.visible
      // this.$parent.visibleY = !this.$parent.visibleY
      this.$emit('close')
    },
  },
}
</script>

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