Browse Source

Merge branch 'master' of http://116.204.116.5:3000/zzw/cbjsxt-front-master

shiyanyu 1 tháng trước cách đây
mục cha
commit
4b0220842a

+ 9 - 1
src/api/auditReviewDocManage.js

@@ -60,7 +60,7 @@ export function getDocumentTemplateById(id) {
     method: 'get',
   })
 }
-// 根据ID查询数据项
+// 根据文书id查询数据项
 export function queryByDocumentId(params) {
   return request({
     url: url + `/costDocumentTemplateFile/v1/queryByDocumentId`,
@@ -68,3 +68,11 @@ export function queryByDocumentId(params) {
     params,
   })
 }
+// 根据文书id查询和whereValue查询
+export function queryByDocumentIdandWhereValue(params) {
+  return request({
+    url: url + `/costDocumentTemplateFile/v1/queryByDocumentIdandWhereValue`,
+    method: 'get',
+    params,
+  })
+}

+ 16 - 0
src/api/taskCustomizedRelease.js

@@ -233,6 +233,22 @@ export function deleteCostProjectDocument(id) {
     method: 'delete',
   })
 }
+// 更新扫描文件
+export function updateScan(data) {
+  return request({
+    url: `${url}/api/costProjectDocument/v1/updateScan`,
+    method: 'post',
+    data,
+  })
+}
+// 根据id生成文书并且下载
+export function downDocument(params) {
+  return request({
+    url: `${url}/api/costProjectDocument/v1/downDocument`,
+    method: 'get',
+    params,
+  })
+}
 /**
  * 根据流程节id获取节点模板数据
  */

+ 251 - 135
src/views/costAudit/projectInfo/auditTaskManage/taskCustomizedRelease/auditNoticeTab.vue

@@ -43,12 +43,12 @@
           <template #enterpriseId="{ row }">
             {{ getEnterpriseName(row) }}
           </template>
-          <template #scanDocumentUrl="scope">
+          <template #electronicDocumentUrl="scope">
             <el-button
               v-if="!isView"
               type="text"
               size="mini"
-              @click="handleUploadScan(scope.row, 'scanDocumentUrl')"
+              @click="handleUploadScan(scope.row, 'electronicDocumentUrl')"
             >
               上传附件
             </el-button>
@@ -56,7 +56,10 @@
               type="text"
               size="mini"
               @click="
-                handleViewScan(scope.row.scanDocumentUrl, 'scanDocumentUrl')
+                handleViewScan(
+                  scope.row.electronicDocumentUrl,
+                  'electronicDocumentUrl'
+                )
               "
             >
               查看附件
@@ -84,7 +87,7 @@
               查看附件
             </el-button>
           </template>
-          <template #electronicDocumentUrl="scope">
+          <template #action="scope">
             <el-button
               v-if="!isView"
               type="text"
@@ -138,6 +141,7 @@
         <div class="document-params">
           <h4>文书参数设置:</h4>
           <el-form
+            ref="documentForm"
             v-loading="loading.saveDocument"
             :model="document"
             label-width="170px"
@@ -175,21 +179,22 @@
                 选择文号
               </el-button>
             </el-form-item>
-            <el-form-item label="被监审单位:" prop="enterpriseId">
-              <el-select
-                v-model="document.enterpriseId"
-                placeholder="请选择被监审单位"
-                style="width: 100%"
-                clearable
-                multiple
-              >
-                <el-option
-                  v-for="item in allUnits"
-                  :key="item.unitId"
-                  :label="item.unitName"
-                  :value="item.unitId"
-                ></el-option>
-              </el-select>
+            <el-form-item label="被监审单位" prop="enterpriseId">
+              <div style="display: flex; align-items: center; gap: 15px">
+                <el-select
+                  v-model="document.enterpriseId"
+                  placeholder="请选择被监审单位"
+                  style="width: 100%"
+                  clearable
+                >
+                  <el-option
+                    v-for="item in allUnits"
+                    :key="item.unitId"
+                    :label="item.unitName"
+                    :value="item.unitId"
+                  ></el-option>
+                </el-select>
+              </div>
             </el-form-item>
             <el-form-item label="是否推送被监审单位:" prop="isPushed">
               <!-- 是否推送被监审单位 -->
@@ -300,11 +305,9 @@
   import CostAuditDialog from '@/components/costAudit/CostAuditDialog.vue'
   import TemplatePreviewEdit from '@/components/costAudit/TemplatePreviewEdit.vue'
   import { getAllUnitList } from '@/api/auditEntityManage'
-  import {
-    getWhCateList,
-    queryByDocumentId,
-  } from '@/api/auditReviewDocManage.js'
+  import { queryByDocumentIdandWhereValue } from '@/api/auditReviewDocManage.js'
   import { getData } from '@/api/auditDocNoManage.js'
+  import { updateScan, downDocument } from '@/api/taskCustomizedRelease.js'
   import {
     addCostProjectDocument,
     updateCostProjectDocument,
@@ -332,17 +335,35 @@
     },
     data() {
       return {
+        isMultipleMode: false,
         dictData: {
           whGenerateType: [],
         },
         activeDocumentTypeId: '',
         document: {
+          createBy: '',
+          createTime: '',
+          documentAlias: '',
           documentId: '',
-          documentWhId: '',
+          documentName: '',
           documentNumber: '',
+          documentType: '',
+          documentWhId: '',
+          electronicDocumentUrl: '',
           enterpriseId: [],
-          dataList: [],
-          isPushed: '1',
+          feedbackDocumentUrl: '',
+          feedbackTime: '',
+          generateTime: '',
+          id: '',
+          isDeleted: '',
+          isPushed: '',
+          orderNum: 0,
+          pkVal: '',
+          projectId: '',
+          pushTime: '',
+          scanDocumentUrl: '',
+          updateBy: '',
+          updateTime: '',
         },
         loading: {
           saveDocument: false,
@@ -354,7 +375,7 @@
         dialogVisible: false,
         dialogTitle: '选择文号',
         documentDialogVisible: false,
-        documentDialogTitle: '编辑监审通知书',
+        documentDialogTitle: '添加监审通知书',
         dialogWidth: '70%',
         fileUrl: '',
         selectDocumentWhData: [],
@@ -495,17 +516,37 @@
 
       // 生成文书
       handleGenerateDocument() {
+        this.documentDialogTitle = '添加监审通知书'
         this.documentDialogVisible = true
         this.activeView = 'form'
         this.document = {
+          createBy: '',
+          createTime: '',
+          documentAlias: '',
           documentId: '',
-          documentWhId: '',
+          documentName: '',
           documentNumber: '',
-          enterpriseId: [],
-          isPushed: '1', // 默认设置为'1'(是)
+          documentType: '',
+          documentWhId: '',
+          electronicDocumentUrl: '',
+          enterpriseId: this.isMultipleMode ? [] : '',
+          feedbackDocumentUrl: '',
+          feedbackTime: '',
+          generateTime: '',
+          id: '',
+          isDeleted: '',
+          isPushed: '1',
+          orderNum: this.documentData.list.length + 1,
+          pkVal: '',
+          projectId: '',
+          pushTime: '',
+          scanDocumentUrl: '',
+          updateBy: '',
+          updateTime: '',
         }
         if (this.activeDocumentTypeId) {
           this.document.documentId = this.activeDocumentTypeId
+          this.handleTemplateChange()
         }
         this.costProjectDocumentFiles = []
       },
@@ -537,14 +578,19 @@
         }
       },
       handleTemplateChange() {
-        this.fileUrl = this.documentData.documentTypes.find(
+        let data = this.documentData.documentTypes.find(
           (item) => item.id === this.document.documentId
-        ).fileUrl
-        this.getDocumentData(this.document.documentId)
+        )
+        this.fileUrl = data.fileUrl
+        this.document.documentName = data.documentName
+        this.getDocumentData()
       },
-      getDocumentData(documentId) {
-        if (documentId) {
-          queryByDocumentId({ documentId }).then((res) => {
+      getDocumentData() {
+        if (this.document.documentId) {
+          queryByDocumentIdandWhereValue({
+            documentId: this.document.documentId,
+            whereValue: this.project.projectId,
+          }).then((res) => {
             this.costDocumentTemplateFiles = res.value || []
           })
         }
@@ -574,76 +620,55 @@
       },
       // 保存文档
       handleSaveDocument() {
-        // 验证是否选择了企业
-        if (
-          !this.document.enterpriseId ||
-          this.document.enterpriseId.length === 0
-        ) {
-          this.$message.error('请至少选择一个被监审单位!')
-          return
-        }
-
-        this.loading.saveDocument = true
-        if (this.document.id) {
-          updateCostProjectDocument({
-            id: this.document.id,
-            // documentAlias: this.document.documentAlias,
-            documentId: this.document.documentId,
-            documentNumber: this.document.documentNumber,
-            documentWhId: this.document.documentWhId,
-            costProjectDocumentFiles: this.costDocumentTemplateFiles,
-            isPushed: this.document.isPushed, // 添加isPushed字段
-            projectId: this.project.projectId,
-            // electronicDocumentUrl: '',
-            enterpriseId: this.document.enterpriseId.join(','), // 保存时转换为逗号分隔的字符串
-            // feedbackDocumentUrl: '',
-            // feedbackTime: '',
-            // generateTime: '',
-          })
-            .then((res) => {
-              this.loading.saveDocument = false
-              this.$message.success('保存成功!')
-              this.documentDialogVisible = false
-              this.activeView = ''
-              this.$emit('refresh', this.project.projectId)
-            })
-            .catch((err) => {
-              this.loading.saveDocument = false
+        // 校验表单
+        this.$refs.documentForm.validate((valid) => {
+          if (!valid) {
+            this.$message.error('请填写必填项!')
+            return false
+          }
+          this.loading.saveDocument = true
+          if (this.document.id) {
+            updateCostProjectDocument({
+              ...this.document,
+              costProjectDocumentFiles: this.costDocumentTemplateFiles,
+              projectId: this.project.projectId,
+              electronicDocumentUrl: this.fileUrl,
+              enterpriseId: this.isMultipleMode
+                ? this.document.enterpriseId.join(',')
+                : this.document.enterpriseId, // 保存时转换为逗号分隔的字符串
             })
-        } else {
-          // 处理多选逻辑,如果选择了多个单位,为每个单位创建一个文档记录
-          const promises = this.document.enterpriseId.map((enterpriseId) => {
-            return addCostProjectDocument({
-              // documentAlias: this.document.documentAlias,
+              .then((res) => {
+                this.loading.saveDocument = false
+                this.$message.success('保存成功!')
+                this.documentDialogVisible = false
+                this.activeView = ''
+                this.$emit('refresh', this.project.projectId)
+              })
+              .catch((err) => {
+                this.loading.saveDocument = false
+              })
+          } else {
+            addCostProjectDocument({
+              ...this.document,
               projectId: this.project.projectId,
-              documentId: this.document.documentId,
-              documentNumber: this.document.documentNumber,
-              documentWhId: this.document.documentWhId,
               costProjectDocumentFiles: this.costDocumentTemplateFiles || [],
-              enterpriseId: enterpriseId,
-              // electronicDocumentUrl: '',
-              // feedbackDocumentUrl: '',
-              // feedbackTime: '',
-              // generateTime: '',
-              isPushed: this.document.isPushed, // 使用isPushed,如果不存在则使用isPushed
-              // orderNum: 0,
-              // pushTime: '',
-              // scanDocumentUrl: '',
+              enterpriseId: this.isMultipleMode
+                ? this.document.enterpriseId.join(',')
+                : this.document.enterpriseId,
+              electronicDocumentUrl: this.fileUrl,
             })
-          })
-
-          Promise.all(promises)
-            .then(() => {
-              this.loading.saveDocument = false
-              this.$message.success('保存成功!')
-              this.documentDialogVisible = false
-              this.activeView = ''
-              this.$emit('refresh', this.project.projectId)
-            })
-            .catch((err) => {
-              this.loading.saveDocument = false
-            })
-        }
+              .then(() => {
+                this.loading.saveDocument = false
+                this.$message.success('保存成功!')
+                this.documentDialogVisible = false
+                this.activeView = ''
+                this.$emit('refresh', this.project.projectId)
+              })
+              .catch((err) => {
+                this.loading.saveDocument = false
+              })
+          }
+        })
       },
       // 处理取消
       handleCancel() {
@@ -716,12 +741,12 @@
             const fileInfo = uploadRes.value
             // 创建更新数据对象
             const updateData = {
-              ...row,
-              scanDocumentUrl: fileInfo?.savePath, // 更新扫描件URL
+              id: row.id,
+              electronicDocumentUrl: fileInfo?.savePath, // 更新扫描件URL
             }
 
             // 第六步:调用更新API
-            await updateCostProjectDocument(updateData)
+            await updateScan(updateData)
 
             // 第七步:更新成功,显示提示并刷新
             this.$message.success('文件上传成功并更新数据!')
@@ -755,20 +780,14 @@
       },
       // 编辑文档
       handleEditDocument(row) {
+        this.documentDialogTitle = '修改监审通知书'
         this.documentDialogVisible = true
         this.activeView = 'form'
         this.loadOpts()
         // 确保enterpriseId是数组格式,处理可能的逗号分隔字符串
-        const enterpriseId = row.enterpriseId
-          ? Array.isArray(row.enterpriseId)
-            ? row.enterpriseId
-            : typeof row.enterpriseId === 'string'
-            ? row.enterpriseId
-                .split(',')
-                .map((id) => id.trim())
-                .filter((id) => id) // 将逗号分隔字符串转换为数组
-            : [row.enterpriseId]
-          : []
+        const enterpriseId = this.isMultipleMode
+          ? row.enterpriseId.split(',')
+          : row.enterpriseId
         this.document = {
           ...row,
           documentId: Number(row.documentId),
@@ -776,10 +795,8 @@
           // 确保isPushed有值,如果row中没有,设置默认值'1'
           isPushed: row.isPushed !== undefined ? row.isPushed : '1',
         }
-        this.fileUrl = this.documentData.documentTypes.find(
-          (item) => item.id === this.document.documentId
-        ).fileUrl
-        this.getDocumentData(this.document.documentId)
+        this.fileUrl = this.document.electronicDocumentUrl
+        this.getDocumentData()
       },
 
       // 签章
@@ -799,27 +816,126 @@
         })
       },
 
+      handleDownloadDocument1(row) {
+        // 显示加载状态
+        this.$loading({
+          lock: true,
+          text: '文件下载中...',
+          spinner: 'el-icon-loading',
+          background: 'rgba(0, 0, 0, 0.7)',
+        })
+        let fileUrl = window.context.form + row.electronicDocumentUrl
+        let fileName = ''
+        // 从URL中提取文件名
+        const urlParts = fileUrl.split('/')
+        let urlFileName = urlParts[urlParts.length - 1]
+
+        // 处理URL可能包含查询参数的情况
+        if (urlFileName.includes('?')) {
+          urlFileName = urlFileName.split('?')[0]
+        }
+
+        // 检查从URL提取的文件名是否有效
+        if (urlFileName && /\.[a-zA-Z0-9]+$/.test(urlFileName)) {
+          fileName = urlFileName
+        } else {
+          // URL中无法提取有效文件名时,使用row.documentName作为备选
+          fileName = row.documentName || `监审通知书_${new Date().getTime()}`
+
+          // 确保备选文件名有扩展名
+          if (!/\.[a-zA-Z0-9]+$/.test(fileName)) {
+            fileName += '.pdf'
+          }
+        }
+        // 创建隐藏的a标签进行下载
+        const link = document.createElement('a')
+        link.style.display = 'none'
+        link.href = fileUrl
+        // 设置下载文件名
+        link.download = fileName
+        document.body.appendChild(link)
+        link.click()
+        document.body.removeChild(link)
+        // 关闭加载状态
+        this.$loading().close()
+      },
       // 下载文档
       handleDownloadDocument(row) {
-        if (!row.electronicDocumentUrl) {
-          this.$message.error('暂无电子文档可供下载!')
-          return
-        }
+        // 显示加载状态
+        this.$loading({
+          lock: true,
+          text: '文件下载中...',
+          spinner: 'el-icon-loading',
+          background: 'rgba(0, 0, 0, 0.7)',
+        })
 
-        try {
-          // 构建完整的文件URL
-          const fileUrl = row.electronicDocumentUrl.startsWith('http')
-            ? row.electronicDocumentUrl
-            : window.context.form + row.electronicDocumentUrl
+        // 从API中获取文件URL
+        downDocument({
+          id: row.id,
+        })
+          .then((res) => {
+            // 关闭加载状态
+            this.$loading().close()
 
-          // 直接在新窗口打开(浏览器会自动处理下载)
-          window.open(fileUrl, '_blank')
+            // 检查返回结果是否成功
+            if (!res || !res.state) {
+              this.$message.error(
+                `下载失败:${res?.message || '未获取到文件数据'}`
+              )
+              return
+            }
 
-          this.$message.success('文档下载开始!')
-        } catch (error) {
-          console.error('下载失败:', error)
-          this.$message.error('文档下载失败:' + (error.message || '未知错误'))
-        }
+            // 获取文件URL
+            const fileUrl = res.value
+            if (!fileUrl) {
+              this.$message.error('下载失败:未获取到文件URL')
+              return
+            }
+
+            // 优先从URL中提取文件名
+            let fileName = ''
+
+            // 从URL中提取文件名
+            const urlParts = fileUrl.split('/')
+            let urlFileName = urlParts[urlParts.length - 1]
+
+            // 处理URL可能包含查询参数的情况
+            if (urlFileName.includes('?')) {
+              urlFileName = urlFileName.split('?')[0]
+            }
+
+            // 检查从URL提取的文件名是否有效
+            if (urlFileName && /\.[a-zA-Z0-9]+$/.test(urlFileName)) {
+              fileName = urlFileName
+            } else {
+              // URL中无法提取有效文件名时,使用row.documentName作为备选
+              fileName =
+                row.documentName || `监审通知书_${new Date().getTime()}`
+
+              // 确保备选文件名有扩展名
+              if (!/\.[a-zA-Z0-9]+$/.test(fileName)) {
+                fileName += '.pdf'
+              }
+            }
+            // 创建隐藏的a标签进行下载
+            const link = document.createElement('a')
+            link.style.display = 'none'
+            link.href = fileUrl
+            // link.href = window.context.form + row.electronicDocumentUrl
+            // 设置下载文件名
+            link.download = fileName
+            document.body.appendChild(link)
+            link.click()
+            document.body.removeChild(link)
+          })
+          .catch((error) => {
+            // 关闭加载状态
+            this.$loading().close()
+            console.error('获取文件URL失败:', error)
+            this.$message.error(
+              `获取下载链接失败: ${error.message || '未知错误'}`
+            )
+          })
       },
     },
   }

+ 4 - 4
src/views/costAudit/projectInfo/auditTaskManage/taskCustomizedRelease/index.js

@@ -277,11 +277,11 @@ export const taskMixin = {
             slotName: 'generateTime',
           },
           {
-            prop: 'scanDocumentUrl',
+            prop: 'electronicDocumentUrl',
             label: '上传扫描件',
             width: 150,
             align: 'center',
-            slotName: 'scanDocumentUrl',
+            slotName: 'electronicDocumentUrl',
           },
           {
             prop: 'isPushed',
@@ -298,11 +298,11 @@ export const taskMixin = {
             slotName: 'feedbackDocumentUrl',
           },
           {
-            prop: 'electronicDocumentUrl',
+            prop: 'action',
             label: '电子文书',
             width: 200,
             align: 'center',
-            slotName: 'electronicDocumentUrl',
+            slotName: 'action',
           },
         ],
       },