cuilei
2025-06-24 a22a69946912221dab4d32987dda6c4c8ba3c5d8
src/views/dnc/base/modules/DeviceStructure/DeviceStructureMainTop.vue
@@ -1,422 +1,434 @@
<template>
  <a-tabs v-model="activeTabKey" @change="handleTabChange" @contextmenu.native="e=>e.preventDefault()"
          v-if="Object.keys(currentTreeNodeInfo).length!==0">
    <a-tab-pane :key="1" tab="发送">
      <HasSentDocumentTableList ref="hasSentDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                                @handleTableContextMenuOpen="handleTableContextMenuOpen" :size="tableContainerSize"/>
    </a-tab-pane>
  <div>
    <a-tabs v-model="activeTabKey" @change="handleTabChange" @contextmenu.native="e=>e.preventDefault()"
            v-if="Object.keys(currentTreeNodeInfo).length!==0">
      <a-tab-pane :key="1" tab="发送">
        <HasSentDocumentTableList ref="hasSentDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                                  :currentTypeOfDevice="currentTypeOfDevice"
                                  @handleTableContextMenuOpen="handleTableContextMenuOpen" :size="tableContainerSize"/>
      </a-tab-pane>
    <a-tab-pane :key="2" tab="接收">
      <HasReceivedDocumentTableList ref="hasReceivedDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                                    @handleTableContextMenuOpen="handleTableContextMenuOpen"
                                    :size="tableContainerSize"/>
    </a-tab-pane>
      <a-tab-pane :key="2" tab="接收">
        <HasReceivedDocumentTableList ref="hasReceivedDocumentTableListRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                                      :currentTypeOfDevice="currentTypeOfDevice"
                                      @handleTableContextMenuOpen="handleTableContextMenuOpen"
                                      :size="tableContainerSize"/>
      </a-tab-pane>
    </a-tabs>
    <TableContextMenu :tableRowInfo="currentRightClickedTableRowInfo" ref="tableContextMenuRef"/>
    <DocumentBatchDeleteModal :currentDocumentInfo="currentRightClickedTableRowInfo" :size="tableContainerSize"
                              @reloadDocumentListData="reloadDocumentListData" ref="documentBatchDeleteModalRef"/>
  </a-tabs>
  </div>
</template>
<script>
  import dncApi from '@/api/dnc'
  import TableContextMenu from '../../../common/TableContextMenu'
  import HasSentDocumentTableList from './Document/HasSentDocumentTableList'
  import HasReceivedDocumentTableList from './Document/HasReceivedDocumentTableList'
  import DocumentBatchDeleteModal from '../../../common/DocumentBatchDeleteModal'
import dncApi from '@/api/dnc'
import TableContextMenu from '../../../common/TableContextMenu'
import HasSentDocumentTableList from './Document/HasSentDocumentTableList'
import HasReceivedDocumentTableList from './Document/HasReceivedDocumentTableList'
import DocumentBatchDeleteModal from '../../../common/DocumentBatchDeleteModal'
import { postAction } from '@api/manage'
  export default {
    name: 'DeviceStructureMainTop',
    components: { DocumentBatchDeleteModal, HasReceivedDocumentTableList, HasSentDocumentTableList, TableContextMenu },
    props: {
      currentTreeNodeInfo: {
        type: Object
      }
    },
    data() {
      return {
        activeTabKey: 1,
        tableContainerSize: 'small',
        currentRightClickedTableRowInfo: {},
        hasLoadedDataTabKeyArray: []
      }
    },
    created() {
      this.$bus.$on('reloadDocumentListData', this.reloadDocumentListData)
      this.$bus.$on('tableMenuItemMethodTrigger', this.triggerCorrespondingMethod)
    },
    methods: {
      /**
       * 控制右键菜单开启
       * @param record 当前表格行信息
       */
      handleTableContextMenuOpen(record) {
        this.currentRightClickedTableRowInfo = Object.assign({}, record)
        this.$refs.tableContextMenuRef.currentMenuLevel = record.param
        this.$refs.tableContextMenuRef.menuStyle.top = event.clientY + 'px'
        this.$refs.tableContextMenuRef.menuStyle.left = event.clientX + 'px'
        this.$refs.tableContextMenuRef.menuVisible = true
        document.body.addEventListener('click', this.handleMenuClose)
      },
export default {
  name: 'DeviceStructureMainTop',
  components: { DocumentBatchDeleteModal, HasReceivedDocumentTableList, HasSentDocumentTableList, TableContextMenu },
  props: {
    currentTreeNodeInfo: {
      type: Object
    }
  },
  data() {
    return {
      activeTabKey: 1,
      tableContainerSize: 'small',
      currentTypeOfDevice: 7,// 产品结构树中定义的设备层级type为7
      currentRightClickedTableRowInfo: {},
      hasLoadedDataTabKeyArray: [],
      url:{
      /**
       * 当树组件选中设备层级节点时触发获取已发送文档列表
       * @param treeNodeInfo 树节点信息
       */
      loadHasSentDocumentListData(treeNodeInfo) {
        this.$nextTick(() => {
          if (this.$refs.hasSentDocumentTableListRef) {
            this.$refs.hasSentDocumentTableListRef.loadData(1)
            this.hasLoadedDataTabKeyArray.push(this.activeTabKey)
          }
        })
      },
      /**
       * tab标签切换时触发
       * @param activeTabKey 当前已激活tab的key
       */
      handleTabChange(activeTabKey) {
        this.$bus.$emit('handleSwitchDeviceDocClassCode', activeTabKey)
        if (activeTabKey && !this.hasLoadedDataTabKeyArray.includes(activeTabKey)) {
          if (activeTabKey === 1) {
            this.$nextTick(() => {
              if (this.$refs.hasSentDocumentTableListRef) this.$refs.hasSentDocumentTableListRef.loadData(1)
            })
          } else {
            this.$nextTick(() => {
              if (this.$refs.hasReceivedDocumentTableListRef) this.$refs.hasReceivedDocumentTableListRef.loadData(1)
            })
          }
          this.hasLoadedDataTabKeyArray.push(activeTabKey)
        }
      },
      /**
       * 文档以及NC程序导入/出库/入库/删除成功后触发重新加载文档列表
       * @param docClassCode 文档类别
       * @param attributionId 节点Id
       */
      reloadDocumentListData({ docClassCode, attributionId }) {
        // 如果上传的文档不是所属于当前所展示节点的文档则不重新获取文档列表
        if (this.currentTreeNodeInfo.key !== attributionId) return
        if (docClassCode === 'SEND') {
          if (this.$refs.hasSentDocumentTableListRef) this.$refs.hasSentDocumentTableListRef.loadData(1)
        } else {
          if (this.$refs.hasReceivedDocumentTableListRef) this.$refs.hasReceivedDocumentTableListRef.loadData(1)
        }
      },
      // 下载当前右键选中文档
      handleDownload() {
        const that = this
        const { docId, docName } = this.currentRightClickedTableRowInfo
        dncApi.downloadDocumentApi({ docId, docName })
          .then(res => {
            if (res && !res.success) {
              that.$notification.error({
                message: '消息',
                description: res.message
              })
            }
          })
          .catch(err => {
            that.$notification.error({
              message: '消息',
              description: err.message
            })
          })
      },
      // 删除当前右键选中文档
      handleDelete() {
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        const that = this
        that.$confirm({
          title: '提示',
          content: `删除后不可取消,确认删除吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.deleteDeviceRelativeDocumentApi({ docId, attributionId })
              .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
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.documentOutboundApi({ docId, docName })
              .then(res => {
                console.log('res------------------', res)
                if (res.success) {
                  this.reloadDocumentListData({ docClassCode: param, attributionId })
                  that.$notification.success({
                    message: '消息',
                    description: `${menuLabel}成功`
                  })
                } else {
                  that.$notification.error({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .catch(err => {
                that.$notification.error({
                  message: '消息',
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel: () => {
            that.$destroyAll()
          }
        })
      },
      /**
       * 发布当前右键选中文档
       * @param menuLabel
       */
      handleCancelPull(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.documentCancelOutboundApi(docId)
              .then(res => {
                if (res.success) {
                  this.reloadDocumentListData({ docClassCode: param, attributionId })
                  that.$notification.success({
                    message: '消息',
                    description: res.message
                  })
                } else {
                  that.$notification.error({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .catch(err => {
                that.$notification.error({
                  message: '消息',
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel: () => {
            that.$destroyAll()
          }
        })
      },
      /**
       * 点击发布时触发当前文档发布
       * @param menuLabel
       */
      handlePublish(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.documentPublishApi(docId)
              .then(res => {
                if (res.success) {
                  this.reloadDocumentListData({ docClassCode: param, attributionId })
                  this.$bus.$emit('reloadMainBottomTableData', 'documentVersion')
                  that.$notification.success({
                    message: '消息',
                    description: res.message
                  })
                } else {
                  that.$notification.error({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .catch(err => {
                that.$notification.error({
                  message: '消息',
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel: () => {
            that.$destroyAll()
          }
        })
      },
      /**
       * 重新发布当前右键选中文档并重新发布退回上一文档版本
       * @param menuLabel
       */
      handleRepublish(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        that.$confirm({
          title: '提示',
          content: `确认${menuLabel}吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.documentRepublishApi(docId)
              .then(res => {
                if (res.success) {
                  this.reloadDocumentListData({ docClassCode: param, attributionId })
                  that.$notification.success({
                    message: '消息',
                    description: res.message
                  })
                } else {
                  that.$notification.error({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .catch(err => {
                that.$notification.error({
                  message: '消息',
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel: () => {
            that.$destroyAll()
          }
        })
      },
      /**
       * 重归档当前右键选中文档且后续无法继续发布或归档
       * @param menuLabel
       */
      handlePigeonhole(menuLabel) {
        const that = this
        const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
        that.$confirm({
          title: '提示',
          content: `${menuLabel}后不可取消,确认${menuLabel}吗?`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            dncApi.documentPigeonholeApi(docId)
              .then(res => {
                if (res.success) {
                  this.reloadDocumentListData({ docClassCode: param, attributionId })
                  that.$notification.success({
                    message: '消息',
                    description: res.message
                  })
                } else {
                  that.$notification.error({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .catch(err => {
                that.$notification.error({
                  message: '消息',
                  description: err.message
                })
              })
              .finally(() => {
                that.$destroyAll()
              })
          },
          onCancel: () => {
            that.$destroyAll()
          }
        })
      },
      // 重置tabKey并且释放加载文档列表的接口
      releaseLoadDocumentListApi() {
        this.hasLoadedDataTabKeyArray = []
        this.handleTabChange(this.activeTabKey)
      },
      // 控制右键菜单关闭
      handleMenuClose() {
        this.$refs.tableContextMenuRef.menuVisible = false
        document.body.removeEventListener('click', this.handleMenuClose)
      },
      triggerCorrespondingMethod({ methodName, modalTitle }) {
        if (this[methodName]) this[methodName](modalTitle)
      }
    }
  },
  created() {
    this.$bus.$on('reloadDocumentListData', this.reloadDocumentListData)
    this.$bus.$on('tableMenuItemMethodTrigger', this.triggerCorrespondingMethod)
  },
  beforeDestroy() {
    this.$bus.$off('reloadDocumentListData', this.reloadDocumentListData)
    this.$bus.$off('tableMenuItemMethodTrigger', this.triggerCorrespondingMethod)
  },
  methods: {
    /**
     * 控制右键菜单开启
     * @param record 当前表格行信息
     */
    handleTableContextMenuOpen(record) {
      this.currentRightClickedTableRowInfo = Object.assign({}, record)
      this.$refs.tableContextMenuRef.currentMenuLevel = record.param
      this.$refs.tableContextMenuRef.menuStyle.top = event.clientY + 'px'
      this.$refs.tableContextMenuRef.menuStyle.left = event.clientX + 'px'
      this.$refs.tableContextMenuRef.menuVisible = true
      document.body.addEventListener('click', this.handleMenuClose)
    },
    /**
     * 当树组件选中设备层级节点时触发获取已发送文档列表
     * @param treeNodeInfo 树节点信息
     */
    loadHasSentDocumentListData(treeNodeInfo) {
      this.$nextTick(() => {
        if (this.$refs.hasSentDocumentTableListRef) {
          this.$refs.hasSentDocumentTableListRef.loadData(1)
          this.hasLoadedDataTabKeyArray.push(this.activeTabKey)
        }
      })
    },
    /**
     * tab标签切换时触发
     * @param activeTabKey 当前已激活tab的key
     */
    handleTabChange(activeTabKey) {
      this.$bus.$emit('handleSwitchDeviceDocClassCode', activeTabKey)
      if (activeTabKey && !this.hasLoadedDataTabKeyArray.includes(activeTabKey)) {
        if (activeTabKey === 1) {
          this.$nextTick(() => {
            if (this.$refs.hasSentDocumentTableListRef) this.$refs.hasSentDocumentTableListRef.loadData(1)
          })
        } else {
          this.$nextTick(() => {
            if (this.$refs.hasReceivedDocumentTableListRef) this.$refs.hasReceivedDocumentTableListRef.loadData(1)
          })
        }
        this.hasLoadedDataTabKeyArray.push(activeTabKey)
      }
    },
    /**
     * 文档以及NC程序导入/出库/入库/删除成功后触发重新加载文档列表
     * @param docClassCode 文档类别
     * @param attributionId 节点Id
     */
    reloadDocumentListData({ docClassCode, attributionId }) {
      // 如果上传的文档不是所属于当前所展示节点的文档则不重新获取文档列表
      if (this.currentTreeNodeInfo.key !== attributionId) return
      if (docClassCode === 'SEND') {
        if (this.$refs.hasSentDocumentTableListRef) this.$refs.hasSentDocumentTableListRef.loadData(1)
      } else {
        if (this.$refs.hasReceivedDocumentTableListRef) this.$refs.hasReceivedDocumentTableListRef.loadData(1)
      }
    },
    // 下载当前右键选中文档
    handleDownload() {
      const that = this
      const { docId, docName } = this.currentRightClickedTableRowInfo
      dncApi.downloadDocumentApi({ docId, docName })
        .then(res => {
          if (res && !res.success) {
            that.$notification.error({
              message: '消息',
              description: res.message
            })
          }
        })
        .catch(err => {
          that.$notification.error({
            message: '消息',
            description: err.message
          })
        })
    },
    // 删除当前右键选中文档
    handleDelete() {
      const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
      const that = this
      that.$confirm({
        title: '提示',
        content: `删除后不可取消,确认删除吗?`,
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          dncApi.deleteDeviceRelativeDocumentApi({ docId, attributionId })
            .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
      that.$confirm({
        title: '提示',
        content: `确认${menuLabel}吗?`,
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          dncApi.documentOutboundApi({ docId, docName })
            .then(res => {
              console.log('res------------------', res)
              if (res.success) {
                this.reloadDocumentListData({ docClassCode: param, attributionId })
                that.$notification.success({
                  message: '消息',
                  description: `${menuLabel}成功`
                })
              } else {
                that.$notification.error({
                  message: '消息',
                  description: res.message
                })
              }
            })
            .catch(err => {
              that.$notification.error({
                message: '消息',
                description: err.message
              })
            })
            .finally(() => {
              that.$destroyAll()
            })
        },
        onCancel: () => {
          that.$destroyAll()
        }
      })
    },
    /**
     * 发布当前右键选中文档
     * @param menuLabel
     */
    handleCancelPull(menuLabel) {
      const that = this
      const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
      that.$confirm({
        title: '提示',
        content: `确认${menuLabel}吗?`,
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          dncApi.documentCancelOutboundApi(docId)
            .then(res => {
              if (res.success) {
                this.reloadDocumentListData({ docClassCode: param, attributionId })
                that.$notification.success({
                  message: '消息',
                  description: res.message
                })
              } else {
                that.$notification.error({
                  message: '消息',
                  description: res.message
                })
              }
            })
            .catch(err => {
              that.$notification.error({
                message: '消息',
                description: err.message
              })
            })
            .finally(() => {
              that.$destroyAll()
            })
        },
        onCancel: () => {
          that.$destroyAll()
        }
      })
    },
    /**
     * 点击发布时触发当前文档发布
     * @param menuLabel
     */
    handlePublish(menuLabel) {
      const that = this
      const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
      that.$confirm({
        title: '提示',
        content: `确认${menuLabel}吗?`,
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          dncApi.documentPublishApi(docId)
            .then(res => {
              if (res.success) {
                this.reloadDocumentListData({ docClassCode: param, attributionId })
                this.$bus.$emit('reloadMainBottomTableData', 'documentVersion')
                that.$notification.success({
                  message: '消息',
                  description: res.message
                })
              } else {
                that.$notification.error({
                  message: '消息',
                  description: res.message
                })
              }
            })
            .catch(err => {
              that.$notification.error({
                message: '消息',
                description: err.message
              })
            })
            .finally(() => {
              that.$destroyAll()
            })
        },
        onCancel: () => {
          that.$destroyAll()
        }
      })
    },
    /**
     * 重新发布当前右键选中文档并重新发布退回上一文档版本
     * @param menuLabel
     */
    handleRepublish(menuLabel) {
      const that = this
      const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
      that.$confirm({
        title: '提示',
        content: `确认${menuLabel}吗?`,
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          dncApi.documentRepublishApi(docId)
            .then(res => {
              if (res.success) {
                this.reloadDocumentListData({ docClassCode: param, attributionId })
                that.$notification.success({
                  message: '消息',
                  description: res.message
                })
              } else {
                that.$notification.error({
                  message: '消息',
                  description: res.message
                })
              }
            })
            .catch(err => {
              that.$notification.error({
                message: '消息',
                description: err.message
              })
            })
            .finally(() => {
              that.$destroyAll()
            })
        },
        onCancel: () => {
          that.$destroyAll()
        }
      })
    },
    /**
     * 重归档当前右键选中文档且后续无法继续发布或归档
     * @param menuLabel
     */
    handlePigeonhole(menuLabel) {
      const that = this
      const { docId, param, attributionId } = this.currentRightClickedTableRowInfo
      that.$confirm({
        title: '提示',
        content: `${menuLabel}后不可取消,确认${menuLabel}吗?`,
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          dncApi.documentPigeonholeApi(docId)
            .then(res => {
              if (res.success) {
                this.reloadDocumentListData({ docClassCode: param, attributionId })
                that.$notification.success({
                  message: '消息',
                  description: res.message
                })
              } else {
                that.$notification.error({
                  message: '消息',
                  description: res.message
                })
              }
            })
            .catch(err => {
              that.$notification.error({
                message: '消息',
                description: err.message
              })
            })
            .finally(() => {
              that.$destroyAll()
            })
        },
        onCancel: () => {
          that.$destroyAll()
        }
      })
    },
    // 重置tabKey并且释放加载文档列表的接口
    releaseLoadDocumentListApi() {
      this.hasLoadedDataTabKeyArray = []
      this.handleTabChange(this.activeTabKey)
    },
    // 控制右键菜单关闭
    handleMenuClose() {
      this.$refs.tableContextMenuRef.menuVisible = false
      document.body.removeEventListener('click', this.handleMenuClose)
    },
    triggerCorrespondingMethod({ methodName, modalTitle }) {
      if (this[methodName]) this[methodName](modalTitle)
    }
  }
}
</script>
<style scoped>
  /deep/ .ant-table-tbody .ant-table-row {
    cursor: pointer;
  }
/deep/ .ant-table-tbody .ant-table-row {
  cursor: pointer;
}
</style>