Просмотр исходного кода

出具结论详情新增编辑完成

shiyanyu 1 месяц назад
Родитель
Сommit
474a4faf9c

+ 29 - 0
src/api/audit/conclusionMain.js

@@ -0,0 +1,29 @@
+import request from '@/utils/request'
+
+const url = window.context.form
+
+// 出具结论 - 获取记录
+export function getConclusionList(data) {
+  return request({
+    url: url + '/api/costProjectConclusion/v1/getByTaskId',
+    method: 'get',
+    params: data,
+  })
+}
+
+// 出具结论 - 新增
+export function addConclusion(data) {
+  return request({
+    url: url + '/api/costProjectConclusion/v1/',
+    method: 'post',
+    data: data,
+  })
+}
+// 出具结论 - 更新
+export function updateConclusion(data) {
+  return request({
+    url: url + '/api/costProjectConclusion/v1/',
+    method: 'put',
+    data: data,
+  })
+}

+ 131 - 30
src/views/costAudit/auditInfo/auditManage/conclusionMain.vue

@@ -2,10 +2,18 @@
   <div class="conclusion-container">
     <div class="conclusion-content">
       <!-- 保存按钮 -->
-      <div class="conclusion-actions">
+      <!-- <div class="conclusion-actions">
         <el-button type="primary" class="save-btn" @click="handleSave">
           保存
         </el-button>
+      </div> -->
+      <div class="collective-header">
+        <div class="collective-header-left">
+          <span>出具结论</span>
+        </div>
+        <div class="collective-header-right">
+          <el-button type="primary" @click="handleSave">保存</el-button>
+        </div>
       </div>
       <!-- 结论表单 -->
       <div class="conclusion-form">
@@ -84,6 +92,11 @@
 </template>
 
 <script>
+  import {
+    getConclusionList,
+    addConclusion,
+    updateConclusion,
+  } from '@/api/audit/conclusionMain'
   export default {
     name: 'ConclusionMain',
     components: {},
@@ -96,6 +109,14 @@
         type: [String, Number],
         default: null,
       },
+      projectId: {
+        type: [String, Number],
+        default: null,
+      },
+      active: {
+        type: Boolean,
+        default: false,
+      },
       currentNode: {
         type: String,
         default: '',
@@ -107,6 +128,8 @@
     },
     data() {
       return {
+        // 当前记录ID,用于判断是新增还是修改
+        currentRecordId: null,
         // 表单数据
         formData: {
           costComposition: '', // 定价成本构成
@@ -133,48 +156,121 @@
         return '出具结论'
       },
     },
+    watch: {
+      // 监听标签页激活状态,当切换到该标签页时加载数据
+      active(newVal, oldVal) {
+        if (newVal && !oldVal) {
+          // 从非激活变为激活时,加载数据
+          this.loadConclusionData()
+        }
+      },
+      projectId(newVal) {
+        // 监听projectId变化,如果当前标签页已激活,重新加载数据
+        if (newVal && this.active) {
+          this.loadConclusionData()
+        } else if (!newVal) {
+          // 如果projectId为空,重置表单
+          this.resetForm()
+        }
+      },
+    },
     mounted() {
-      // 组件挂载时,如果有id则加载数据
-      if (this.id) {
+      // 组件挂载时,如果标签页已激活且有projectId,则加载数据
+      if (this.active && (this.projectId || this.id)) {
         this.loadConclusionData()
       }
     },
     methods: {
       // 加载结论数据
       async loadConclusionData() {
+        const projectId = this.projectId || this.id
+        // if (!projectId) {
+        //   return
+        // }
         try {
-          // 这里应该调用实际的API获取数据
-          // const { data } = await getConclusionData(this.id)
-          // this.formData = data
+          const response = await getConclusionList({ taskId: projectId })
+
+          if (response && response.code === 200 && response.value) {
+            const data = response.value
+            // 保存当前记录ID,用于判断是新增还是修改
+            this.currentRecordId = data.id || null
 
-          // 模拟数据加载
-          console.log('加载结论数据,ID:', this.id)
+            // 回显数据,字段映射
+            this.formData = {
+              costComposition: data.pricingCostStructure || '', // 定价成本构成
+              auditContent: data.auditContentMethod || '', // 审核的内容和方法
+              costAdjustment: data.costDeductionReason || '', // 成本费用项目核增(减)情况及理由
+              auditConclusion: data.costAuditConclusion || '', // 成本监审结论
+              otherNotes: data.otherExplanations || '', // 其他需要说明的事项
+            }
+          } else {
+            // 没有数据,重置表单
+            this.resetForm()
+          }
         } catch (error) {
-          this.$message.error('加载结论数据失败')
           console.error('加载结论数据失败:', error)
+          this.$message.error('加载结论数据失败')
+          // 加载失败时重置表单
+          this.resetForm()
+        }
+      },
+
+      // 重置表单
+      resetForm() {
+        this.currentRecordId = null
+        this.formData = {
+          costComposition: '', // 定价成本构成
+          auditContent: '', // 审核的内容和方法
+          costAdjustment: '', // 成本费用项目核增(减)情况及理由
+          auditConclusion: '', // 成本监审结论
+          otherNotes: '', // 其他需要说明的事项
         }
       },
 
       // 保存结论
       async handleSave() {
+        const projectId = this.projectId || this.id
+        if (!projectId) {
+          this.$message.error('缺少项目ID')
+          return
+        }
+
         try {
-          // 这里应该调用实际的API保存数据
-          // const params = { ...this.formData }
-          // if (this.id) {
-          //   params.id = this.id
-          //   await updateConclusion(params)
-          // } else {
-          //   await createConclusion(params)
-          // }
-
-          this.$message.success('保存成功')
-          console.log('保存结论数据:', this.formData)
-
-          // 如果需要,保存成功后可以触发父组件的事件
-          this.$emit('saved', this.formData)
+          // 构建请求参数,字段映射
+          const params = {
+            taskId: projectId,
+            pricingCostStructure: this.formData.costComposition || '', // 定价成本构成
+            auditContentMethod: this.formData.auditContent || '', // 审核的内容和方法
+            costDeductionReason: this.formData.costAdjustment || '', // 成本费用项目核增(减)情况及理由
+            costAuditConclusion: this.formData.auditConclusion || '', // 成本监审结论
+            otherExplanations: this.formData.otherNotes || '', // 其他需要说明的事项
+          }
+
+          let response
+          // 如果有记录ID,调用修改接口;否则调用新增接口
+          if (this.currentRecordId) {
+            params.id = this.currentRecordId
+            response = await updateConclusion(params)
+          } else {
+            response = await addConclusion(params)
+          }
+
+          if (response && response.code === 200) {
+            this.$message.success('保存成功')
+
+            // 保存成功后,更新当前记录ID(如果是新增,接口会返回id)
+            if (response.value && response.value.id) {
+              this.currentRecordId = response.value.id
+            }
+
+            // 触发父组件的事件,通知保存成功(父组件会关闭弹窗并刷新列表)
+            this.$emit('saved', this.formData)
+          } else {
+            this.$message.error(response?.message || '保存失败')
+          }
         } catch (error) {
-          this.$message.error('保存失败')
           console.error('保存结论数据失败:', error)
+          this.$message.error('保存失败')
         }
       },
     },
@@ -185,18 +281,23 @@
   .conclusion-container {
     font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
       'Helvetica Neue', Arial, sans-serif;
-    padding: 20px;
+    /* padding: 20px; */
     background: #fff;
   }
 
-  .conclusion-header {
+  /* 页面头部样式 */
+  .collective-header {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
     margin-bottom: 20px;
+    padding: 5px 0;
   }
 
-  .conclusion-header-left {
-    font-size: 16px;
-    font-weight: 500;
-    color: #303133;
+  .collective-header-left span {
+    font-size: 18px;
+    font-weight: bold;
+    color: #333;
   }
 
   .conclusion-actions {

+ 12 - 0
src/views/costAudit/auditInfo/auditManage/index.vue

@@ -376,6 +376,18 @@
         this.loadAuditProjectList()
       },
 
+      // 主详情弹窗关闭处理
+      handleMainDetailsClose() {
+        this.selectedProject = null
+        this.mainDetailsVisible = false
+      },
+
+      // 主详情刷新处理
+      handleMainRefresh() {
+        // 刷新列表数据
+        this.loadAuditProjectList()
+      },
+
       // 查记录
       handleCheckRecord(project) {
         // memoManage

+ 9 - 0
src/views/costAudit/auditInfo/auditManage/mainDetails.vue

@@ -42,8 +42,10 @@
         >
           <conclusionMain
             :id="id"
+            :active="activeTab === 'costAudit'"
             :current-node="currentNode"
             :current-status="currentStatus"
+            @saved="handleConclusionSaved"
           />
         </el-tab-pane>
       </el-tabs>
@@ -213,6 +215,13 @@
         // 打开弹窗方法,供父组件通过ref调用
         this.$emit('update:visible', true)
       },
+      // 处理结论保存成功
+      handleConclusionSaved() {
+        // 关闭弹窗
+        this.handleClose()
+        // 触发父组件刷新列表
+        this.$emit('refresh')
+      },
       // 处理审核操作按钮点击
       handleAuditPass(item) {},