src/views/dnc/base/modules/ProductStructure/ProductStructureMainTop.vue
@@ -1,18 +1,23 @@
<template>
  <a-tabs v-model="activeTabKey" @contextmenu.native="e=>e.preventDefault()"
          v-if="Object.keys(currentTreeNodeInfo).length!==0">
    <a-tab-pane :key="1" tab="NC文档" v-if="currentTreeNodeInfo.type===5||currentTreeNodeInfo.type===6">
      <NcDocumentTableList ref="ncDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                           @handleTableContextMenuOpen="handleTableContextMenuOpen" :size="tableContainerSize"/>
    </a-tab-pane>
  <div v-if="currentTreeNodeInfo.type!==4">
    <a-tabs v-model="activeTabKey" @contextmenu.native="e=>e.preventDefault()" @change="handleTabChange"
            v-if="Object.keys(currentTreeNodeInfo).length!==0">
      <a-tab-pane :key="1" tab="NC文档" v-if="currentTreeNodeInfo.type===5||currentTreeNodeInfo.type===6">
        <NcDocumentTableList ref="ncDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                             @handleTableContextMenuOpen="handleTableContextMenuOpen" :size="tableContainerSize"/>
      </a-tab-pane>
    <a-tab-pane :key="1" tab="其他文档" v-else>
      <OtherDocumentTableList ref="otherDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                              @handleTableContextMenuOpen="handleTableContextMenuOpen" :size="tableContainerSize"/>
    </a-tab-pane>
      <a-tab-pane :key="2" tab="其他文档">
        <OtherDocumentTableList ref="otherDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                                @handleTableContextMenuOpen="handleTableContextMenuOpen" :size="tableContainerSize"/>
      </a-tab-pane>
    </a-tabs>
    <TableContextMenu :tableRowInfo="currentRightClickedTableRowInfo" ref="tableContextMenuRef"/>
  </a-tabs>
    <DocumentBatchDeleteModal :currentDocumentInfo="currentRightClickedTableRowInfo" :size="tableContainerSize"
                              @reloadDocumentListData="reloadDocumentListData" ref="documentBatchDeleteModalRef"/>
  </div>
</template>
<script>
@@ -20,16 +25,18 @@
  import NcDocumentTableList from './Document/NcDocumentTableList'
  import OtherDocumentTableList from './Document/OtherDocumentTableList'
  import TableContextMenu from '../../../common/TableContextMenu'
  import DocumentBatchDeleteModal from '../../../common/DocumentBatchDeleteModal'
  export default {
    name: 'ProductStructureMainTop',
    components: { TableContextMenu, OtherDocumentTableList, NcDocumentTableList },
    components: { DocumentBatchDeleteModal, TableContextMenu, OtherDocumentTableList, NcDocumentTableList },
    data() {
      return {
        activeTabKey: 1,
        activeTabKey: 2,
        tableContainerSize: 'small',
        currentRightClickedTableRowInfo: {},
        currentTreeNodeInfo: {}
        currentTreeNodeInfo: {},
        hasLoadedDataTabKeyArray: []
      }
    },
    created() {
@@ -60,17 +67,34 @@
        // 从树组件接受树节点信息后从父组件流入子组件
        this.currentTreeNodeInfo = treeNodeInfo
        // 清空上一节点已经加载过得文档列表tabKey
        this.hasLoadedDataTabKeyArray = []
        if (treeNodeInfo.type === 5 || treeNodeInfo.type === 6) {
          this.activeTabKey = 1
          this.$nextTick(() => {
            if (this.$refs.ncDocumentTableListRef) this.$refs.ncDocumentTableListRef.loadData(1)
          })
        } else {
          this.activeTabKey = 2
          this.$nextTick(() => {
            if (this.$refs.otherDocumentTableListRef) this.$refs.otherDocumentTableListRef.loadData(1)
          })
        }
        this.hasLoadedDataTabKeyArray.push(this.activeTabKey)
      },
      /**
       * tab栏切换时触发
       * @param activeTabKey 切换后的tabKey
       */
      handleTabChange(activeTabKey) {
        if (!this.hasLoadedDataTabKeyArray.includes(activeTabKey)) {
          this.$nextTick(() => {
            if (this.$refs.otherDocumentTableListRef) this.$refs.otherDocumentTableListRef.loadData(1)
          })
          // 阻止接口在同一文档一次点击内多次触发
          this.hasLoadedDataTabKeyArray.push(activeTabKey)
        }
      },
      /**
       * 文档以及NC程序导入/出库/入库成功后触发重新加载文档列表
       * @param docClassCode 文档类别
@@ -86,13 +110,11 @@
        }
      },
      /**
       * 点击下载时触发下载当前文档
       */
      // 下载当前右键选中文档
      handleDownload() {
        const that = this
        const { docId, docName } = this.currentRightClickedTableRowInfo
        dncApi.downloadDocumentApi({ id: docId, docName })
        dncApi.downloadDocumentApi({ docId, docName })
          .then(res => {
            if (res && !res.success) {
              that.$notification.error({
@@ -109,24 +131,69 @@
          })
      },
      // 删除当前右键选中文档
      handleDelete() {
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        const that = this
        that.$confirm({
          title: '提示',
          content: `删除后不可取消,确认删除吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.deleteDocumentApi(docId)
              .then((res) => {
                if (res.success) {
                  that.$notification.success({
                    message: '消息',
                    description: res.message
                  })
                  that.reloadDocumentListData({ docClassCode: param, attributionId })
                } else {
                  that.$notification.warning({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel: () => {
            that.$destroyAll()
          }
        })
      },
      /**
       * 点击出库时触发当前文档出库
       * 点击批量删除后出现弹窗
       * @param modalTitle 弹窗标题
       */
      handleBatchRemove(modalTitle) {
        if (!this.$refs.documentBatchDeleteModalRef) return
        this.$refs.documentBatchDeleteModalRef.title = modalTitle
        this.$refs.documentBatchDeleteModalRef.visible = true
      },
      /**
       * 出库当前右键选中文档
       * @param menuLabel
       */
      handlePull(menuLabel) {
        const that = this
        const { docId, docName, param, attributionId } = this.currentRightClickedTableRowInfo
        this.$confirm({
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.documentOutboundApi({ id: docId, docName })
            dncApi.documentOutboundApi({ docId, docName })
              .then(res => {
                console.log('res------------------', res)
                if (res.success) {
                  this.reloadDocumentListData({ docClassCode: param, attributionId })
                  that.reloadDocumentListData({ docClassCode: param, attributionId })
                  that.$notification.success({
                    message: '消息',
                    description: `${menuLabel}成功`
@@ -144,18 +211,24 @@
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel: () => {
            that.$destroyAll()
          }
        })
      },
      /**
       * 点击取消出库时触发当前文档取消出库
       * 取消出库当前右键选中文档
       * @param menuLabel
       */
      handleCancelPull(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        this.$confirm({
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
@@ -182,19 +255,24 @@
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel() {
            that.$destroyAll()
          }
        })
      },
      /**
       * 点击发布时触发当前文档发布
       * 发布当前右键选中文档
       * @param menuLabel
       */
      handlePublish(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        this.$confirm({
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
@@ -222,18 +300,24 @@
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel() {
            that.$destroyAll()
          }
        })
      },
      /**
       * 点击重新发布时触发当前文档重新发布退回上一版本
       * 重新发布当前右键选中文档并重新发布退回上一文档版本
       * @param menuLabel
       */
      handleRepublish(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        this.$confirm({
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
@@ -260,18 +344,24 @@
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel() {
            that.$destroyAll()
          }
        })
      },
      /**
       * 点击归档时触发当前文档归档且后续无法继续发布或归档
       * 重归档当前右键选中文档且后续无法继续发布或归档
       * @param menuLabel
       */
      handlePigeonhole(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        this.$confirm({
        that.$confirm({
          title: '提示',
          content: `${menuLabel}后不可取消,确认${menuLabel}吗?`,
          okText: '确认',
@@ -298,13 +388,17 @@
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel() {
            that.$destroyAll()
          }
        })
      },
      /**
       * 控制右键菜单点击关闭
       */
      // 控制右键菜单关闭
      handleMenuClose() {
        this.$refs.tableContextMenuRef.menuVisible = false
        document.body.removeEventListener('click', this.handleMenuClose)