Ver código fonte

feat: 工作底稿在线编辑保存

shiyanyu 1 mês atrás
pai
commit
b65e675ae0

+ 18 - 0
src/api/audit/taskDraft.js

@@ -24,3 +24,21 @@ export function deleteTaskDraft(data) {
     method: 'post',
   })
 }
+
+// 获取工作底稿在线编辑内容
+export function getTaskDraftOnlineEdit(data) {
+  return request({
+    url: url + '/api/enterprise/taskDraft/getByTaskId',
+    method: 'get',
+    params: data,
+  })
+}
+
+// 保存工作底稿在线编辑内容
+export function saveTaskDraftOnlineEdit(data) {
+  return request({
+    url: url + '/api/enterprise/taskDraft/save',
+    method: 'post',
+    data: data,
+  })
+}

+ 213 - 15
src/views/costAudit/auditInfo/auditManage/workDraft.vue

@@ -1,13 +1,21 @@
 <template>
   <div class="work-draft-container">
-    <ht-editor
-      v-model="workingPaperContent"
-      class="working-paper-editor"
-      height="500px"
-      width="100%"
-      :config="editorConfig"
-      @ready="onEditorReady"
-    />
+    <div class="editor-header">
+      <span class="editor-title">工作底稿在线编辑:</span>
+      <el-button type="primary" size="small" @click="handleOnlineEdit">
+        保存
+      </el-button>
+    </div>
+    <div class="editor-wrapper">
+      <ht-editor
+        v-model="workingPaperContent"
+        class="working-paper-editor"
+        height="500px"
+        width="100%"
+        :config="editorConfig"
+        @ready="onEditorReady"
+      />
+    </div>
     <!-- 工作底稿列表 -->
     <div>
       <el-button type="primary" size="small" @click="handleAddWorkingPaper">
@@ -125,6 +133,7 @@
               format="HH:mm"
               placeholder="开始时间"
               style="flex: 1"
+              @change="handleStartTimeChange"
             />
             <span>-</span>
             <el-time-picker
@@ -132,6 +141,7 @@
               format="HH:mm"
               placeholder="结束时间"
               style="flex: 1"
+              :picker-options="endTimePickerOptions"
             />
           </div>
         </el-form-item>
@@ -180,6 +190,8 @@
     getTaskDraftList,
     addTaskDraft,
     deleteTaskDraft,
+    getTaskDraftOnlineEdit,
+    saveTaskDraftOnlineEdit,
   } from '@/api/audit/taskDraft'
   import { uploadFile } from '@/api/file'
   export default {
@@ -200,7 +212,7 @@
           excludeMenus: ['image', 'video'],
         },
         // 工作底稿数据
-        workingPaperContent: '工作底稿内容将在这里展示。',
+        workingPaperContent: '',
         // 工作底稿记录列表
         workingPaperRecords: [],
         // 工作底稿弹窗
@@ -232,10 +244,97 @@
         },
       }
     },
+    computed: {
+      // 结束时间选择器的配置,限制结束时间不能小于开始时间
+      endTimePickerOptions() {
+        return {
+          selectableRange: this.getEndTimeSelectableRange(),
+        }
+      },
+    },
+    watch: {
+      id: {
+        handler(newVal) {
+          if (newVal) {
+            this.getWorkingPaperRecords()
+            this.getWorkingPaperContent()
+          }
+        },
+        immediate: true,
+      },
+    },
     mounted() {
-      this.getWorkingPaperRecords()
+      if (this.id) {
+        this.getWorkingPaperRecords()
+        this.getWorkingPaperContent()
+      }
     },
     methods: {
+      // 获取结束时间可选择的范围
+      getEndTimeSelectableRange() {
+        if (!this.workingPaperForm.startTime) {
+          // 如果没有开始时间,可以选择所有时间
+          return '00:00:00 - 23:59:59'
+        }
+        // 获取开始时间的小时和分钟
+        let startHour = 0
+        let startMinute = 0
+        if (this.workingPaperForm.startTime instanceof Date) {
+          startHour = this.workingPaperForm.startTime.getHours()
+          startMinute = this.workingPaperForm.startTime.getMinutes()
+        } else if (typeof this.workingPaperForm.startTime === 'string') {
+          const parts = this.workingPaperForm.startTime.split(':')
+          if (parts.length >= 2) {
+            startHour = parseInt(parts[0]) || 0
+            startMinute = parseInt(parts[1]) || 0
+          }
+        }
+        // 开始时间加1分钟,作为最小可选时间
+        let minHour = startHour
+        let minMinute = startMinute + 1
+        if (minMinute >= 60) {
+          minMinute = 0
+          minHour += 1
+        }
+        if (minHour >= 24) {
+          minHour = 23
+          minMinute = 59
+        }
+        // 格式化为 HH:mm:ss 格式
+        const minTime = `${String(minHour).padStart(2, '0')}:${String(
+          minMinute
+        ).padStart(2, '0')}:00`
+        return `${minTime} - 23:59:59`
+      },
+      // 开始时间变化时的处理
+      handleStartTimeChange() {
+        // 如果结束时间存在且小于开始时间,则清空结束时间或提示
+        if (this.workingPaperForm.endTime && this.workingPaperForm.startTime) {
+          const startTime = this.getTimeMinutes(this.workingPaperForm.startTime)
+          const endTime = this.getTimeMinutes(this.workingPaperForm.endTime)
+          if (endTime <= startTime) {
+            this.$message.warning('结束时间不能小于或等于开始时间,请重新选择')
+            this.workingPaperForm.endTime = null
+          }
+        }
+      },
+      // 获取时间的总分钟数(用于比较)
+      getTimeMinutes(time) {
+        if (!time) return 0
+        let hours = 0
+        let minutes = 0
+        if (time instanceof Date) {
+          hours = time.getHours()
+          minutes = time.getMinutes()
+        } else if (typeof time === 'string') {
+          const parts = time.split(':')
+          if (parts.length >= 2) {
+            hours = parseInt(parts[0]) || 0
+            minutes = parseInt(parts[1]) || 0
+          }
+        }
+        return hours * 60 + minutes
+      },
       // 获取工作底稿列表
       async getWorkingPaperRecords() {
         if (!this.id) {
@@ -287,6 +386,59 @@
         console.log('编辑器已就绪', editor)
         // 可以在这里获取编辑器实例,进行更多操作
       },
+      // 获取工作底稿在线编辑内容
+      async getWorkingPaperContent() {
+        if (!this.id) {
+          return
+        }
+        try {
+          const res = await getTaskDraftOnlineEdit({ taskId: this.id })
+          if (res && res.code === 200 && res.value) {
+            // 回显内容到编辑器
+            this.workingPaperContent = res.value.content || ''
+          } else {
+            // 如果没有数据,初始化为空
+            this.workingPaperContent = ''
+          }
+        } catch (error) {
+          console.error('获取工作底稿在线编辑内容失败:', error)
+          this.workingPaperContent = ''
+        }
+      },
+      // 保存工作底稿在线编辑内容
+      async handleOnlineEdit() {
+        if (!this.id) {
+          this.$message.warning('缺少任务ID')
+          return
+        }
+        try {
+          // 获取当前时间,格式化为 yyyy-MM-dd HH:mm:ss
+          const now = new Date()
+          const year = now.getFullYear()
+          const month = String(now.getMonth() + 1).padStart(2, '0')
+          const day = String(now.getDate()).padStart(2, '0')
+          const hours = String(now.getHours()).padStart(2, '0')
+          const minutes = String(now.getMinutes()).padStart(2, '0')
+          const seconds = String(now.getSeconds()).padStart(2, '0')
+          const updateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
+
+          const params = {
+            taskId: this.id,
+            content: this.workingPaperContent || '',
+            updateTime: updateTime,
+          }
+
+          const res = await saveTaskDraftOnlineEdit(params)
+          if (res && res.code === 200) {
+            this.$message.success(res.message || '保存成功')
+          } else {
+            this.$message.error(res.message || '保存失败')
+          }
+        } catch (error) {
+          console.error('保存工作底稿在线编辑内容失败:', error)
+          this.$message.error('保存失败')
+        }
+      },
       // 工作底稿操作
       handleAddWorkingPaper() {
         this.isEditWorkingPaper = false
@@ -423,6 +575,23 @@
         try {
           await this.$refs.workingPaperForm.validate()
 
+          // 验证时间范围
+          if (
+            this.workingPaperForm.startTime &&
+            this.workingPaperForm.endTime
+          ) {
+            const startMinutes = this.getTimeMinutes(
+              this.workingPaperForm.startTime
+            )
+            const endMinutes = this.getTimeMinutes(
+              this.workingPaperForm.endTime
+            )
+            if (endMinutes <= startMinutes) {
+              this.$message.error('结束时间不能小于或等于开始时间')
+              return
+            }
+          }
+
           // 格式化日期
           const auditDate = new Date(this.workingPaperForm.auditDate)
           const formattedDate = `${auditDate.getFullYear()}-${String(
@@ -672,12 +841,41 @@
   }
 </script>
 
-<style scoped>
-  /* .work-draft-container {
-    padding: 20px;
-  } */
+<style scoped lang="scss">
+  .work-draft-container {
+    width: 100%;
+  }
 
-  .working-paper-editor {
+  .editor-header {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
     margin-bottom: 20px;
   }
+
+  .editor-title {
+    font-size: 16px;
+    font-weight: bold;
+  }
+
+  .editor-wrapper {
+    width: 100%;
+    margin-bottom: 20px;
+  }
+
+  .working-paper-editor {
+    width: 100% !important;
+  }
+
+  :deep(.inputs.ht-form-inputs__inline) {
+    width: 100%;
+  }
+
+  :deep(.ht-editor) {
+    width: 100% !important;
+  }
+
+  :deep(.ht-container) {
+    width: 100% !important;
+  }
 </style>