<template>
  <a-modal
    :body-style="bodyStyle"
    title="选择审计事项"
    :destroy-on-close="true"
    :visible="visible"
    width="700px"
    :confirm-loading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <div :class="$style.selectDiv">
      <audit-matters-tree
        ref="auditMattersModalTree"
        :frame-id="frameId"
        :tree-data-type="treeDataType"
        :is-frame-copy="true"
        @treeSelect="treeSelect"
        @checkedKeys="checkedKeys"
        @checking="checking"
      ></audit-matters-tree>
    </div>
  </a-modal>
</template>

<script>
import auditMattersTree from '../../../../matters/template/audit-matters-tree.vue'
import components from './_import-components/iam-audit-import-matters-import'
function checkIn(list, node) {
  let indexNum = -1
  list.forEach((item, index) => {
    if (item.id === node) {
      indexNum = index
    }
  })
  return indexNum
}
export default {
  name: 'IamAuditImportMatters',
  metaInfo: {
    title: '选择审计事项',
  },
  components: {
    ...components,
    auditMattersTree,
  },
  props: {
    // 弹出窗显示参数
    visible: {
      type: Boolean,
      default: false,
    },
    // frameId
    frameId: {
      type: Number,
      default: -1,
    },
  },
  data() {
    return {
      confirmLoading: true,
      bodyStyle: {
        padding: 0,
      },
      treeDataType: '',
      checkednode: [],
    }
  },
  created() {},
  methods: {
    checking(flag) {
      if (flag) {
        this.confirmLoading = true
      } else {
        this.confirmLoading = false
      }
    },
    handleOk(e) {
      this.$parent.visible = !this.$parent.visible
      this.$refs.auditMattersModalTree.mmTree()
      // 获取选中的数据
      this.$emit('sxhandleOk', this.$refs.auditMattersModalTree.newtree)
      // 根据选中的数据展示 左边的表单
    },
    handleCancel(e) {
      this.$emit('handleCancel')
    },

    treeSelect(allCheckNode, checkNode) {
      // 判断当前点击节点是否为选中状态
      const indexNum = checkIn(this.checkednode, checkNode.node.dataRef.id)
      if (indexNum === -1) {
        this.checkednode.push(checkNode.node.dataRef)
      } else {
        this.checkednode.splice(indexNum, 1)
      }
    },
    checkedKeys(checkNode, allCheckNode) {
      this.checkednode = []
      allCheckNode.forEach((item) => {
        this.checkednode.push(item.data.props)
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.select-div {
  height: 500px;
  padding: 10px 20px;
}
</style>
