Browse Source

refactor(forecast-audit): 简化审批流程,移除审批弹窗表单

yz 2 weeks ago
parent
commit
ec27c15d4f
2 changed files with 60 additions and 96 deletions
  1. 56 55
      src/views/forecast-audit/auditIndex.js
  2. 4 41
      src/views/forecast-audit/index.vue

+ 56 - 55
src/views/forecast-audit/auditIndex.js

@@ -101,15 +101,10 @@ export default {
       data: [],
       /** @type {ForecastItem} 详情表单数据 */
       detailForm: {},
-      /** @type {ApprovalFormData} 审批表单数据 */
-      approvalForm: {
-        /** @type {string} 审批意见 */
-        approvalComment: '',
-        /** @type {boolean} 是否为通过审批 */
-        isApprove: true,
-        /** @type {ForecastItem|null} 当前审批的记录 */
-        currentRecord: null
-      },
+      /** @type {Object} 当前要审批的记录 */
+      currentApprovalRecord: null,
+      /** @type {boolean} 当前审批操作是否为通过 */
+      isCurrentApprovalApprove: true,
       /** @type {Object} avue表格配置 */
       option: {
         height: 'auto',
@@ -383,14 +378,17 @@ export default {
      * @returns {void}
      */
     approveRecord(row, index) {
-      this.approvalForm = {
-        approvalComment: '',
-        isApprove: true,
-        currentRecord: { ...row }
-      }
-      this.approvalDialogVisible = true
+      this.$confirm('确认通过此预测申报吗?', '审批确认', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'success'
+      }).then(() => {
+        this.performApproval(row, true)
+      }).catch(() => {
+        // 用户取消操作
+      })
     },
-
+    
     /**
      * 审批拒绝记录
      * @param {ForecastItem} row - 数据行对象
@@ -398,80 +396,83 @@ export default {
      * @returns {void}
      */
     rejectRecord(row, index) {
-      this.approvalForm = {
-        approvalComment: '',
-        isApprove: false,
-        currentRecord: { ...row }
-      }
-      this.approvalDialogVisible = true
+      this.$confirm('确认拒绝此预测申报吗?', '审批确认', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        this.performApproval(row, false)
+      }).catch(() => {
+        // 用户取消操作
+      })
     },
-
+    
     /**
      * 从详情页面审批通过
      * @returns {void}
      */
     approveFromDetail() {
-      this.approvalForm = {
-        approvalComment: '',
-        isApprove: true,
-        currentRecord: { ...this.detailForm }
-      }
-      this.detailDialogVisible = false
-      this.approvalDialogVisible = true
+      this.$confirm('确认通过此预测申报吗?', '审批确认', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'success'
+      }).then(() => {
+        this.detailDialogVisible = false
+        this.performApproval(this.detailForm, true)
+      }).catch(() => {
+        // 用户取消操作
+      })
     },
-
+    
     /**
      * 从详情页面审批拒绝
      * @returns {void}
      */
     rejectFromDetail() {
-      this.approvalForm = {
-        approvalComment: '',
-        isApprove: false,
-        currentRecord: { ...this.detailForm }
-      }
-      this.detailDialogVisible = false
-      this.approvalDialogVisible = true
+      this.$confirm('确认拒绝此预测申报吗?', '审批确认', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        this.detailDialogVisible = false
+        this.performApproval(this.detailForm, false)
+      }).catch(() => {
+        // 用户取消操作
+      })
     },
-
+    
     /**
-     * 确认审批操作
+     * 执行审批操作
+     * @param {ForecastItem} record - 要审批的记录
+     * @param {boolean} isApprove - 是否为通过审批
      * @returns {Promise<void>}
      * @throws {Error} 当审批操作失败时抛出错误
      */
-    async confirmApproval() {
+    async performApproval(record, isApprove) {
       try {
-        // 验证表单
-        await this.$refs.approvalForm.validate()
-
         this.submitting = true
-
-        const { currentRecord, isApprove, approvalComment } = this.approvalForm
-
+    
         // 构建更新数据
         const updateData = {
-          ...currentRecord,
+          ...record,
           approvalStatus: isApprove ? APPROVAL_STATUS.APPROVED : APPROVAL_STATUS.REJECTED,
-          approvalComment: approvalComment || null,
+          approvalComment: null, // 不再需要审批备注
           approvedBy: this.$store.getters.userInfo.user_id,
           approvedName: this.$store.getters.userInfo.real_name,
           approvedTime: new Date().toISOString().replace('T', ' ').substring(0, 19)
         }
-
+    
         const res = await updateForecast(updateData)
-
+    
         if (res.data && res.data.success) {
           this.$message.success(`审批${isApprove ? '通过' : '拒绝'}成功`)
-          this.approvalDialogVisible = false
           this.onLoad(this.page) // 重新加载数据
         } else {
           throw new Error(res.data?.msg || '审批操作失败')
         }
       } catch (error) {
         console.error('审批操作失败:', error)
-        if (error.message && error.message !== 'validation failed') {
-          this.$message.error(error.message)
-        }
+        this.$message.error(error.message || '审批操作失败')
       } finally {
         this.submitting = false
       }

+ 4 - 41
src/views/forecast-audit/index.vue

@@ -42,6 +42,7 @@
           size="small"
           icon="el-icon-check"
           @click="approveRecord(row, index)"
+          :loading="submitting"
         >
           通过
         </el-button>
@@ -51,6 +52,7 @@
           size="small"
           icon="el-icon-close"
           @click="rejectRecord(row, index)"
+          :loading="submitting"
         >
           拒绝
         </el-button>
@@ -196,7 +198,7 @@
           v-if="canApprove(detailForm)"
           type="success"
           @click="approveFromDetail"
-          :loading="approving"
+          :loading="submitting"
         >
           通过审批
         </el-button>
@@ -204,48 +206,9 @@
           v-if="canReject(detailForm)"
           type="danger"
           @click="rejectFromDetail"
-          :loading="rejecting"
-        >
-          拒绝审批
-        </el-button>
-      </span>
-    </el-dialog>
-
-    <!-- 审批确认弹窗 -->
-    <el-dialog
-      :title="approvalDialogTitle"
-      :visible.sync="approvalDialogVisible"
-      width="500px"
-      :close-on-click-modal="false"
-      append-to-body
-    >
-      <el-form
-        ref="approvalForm"
-        :model="approvalForm"
-        :rules="approvalFormRules"
-        label-width="100px"
-      >
-        <el-form-item label="审批意见" prop="approvalComment">
-          <el-input
-            v-model="approvalForm.approvalComment"
-            type="textarea"
-            :rows="4"
-            :placeholder="approvalForm.isApprove ? '请输入通过意见(可选)' : '请输入拒绝原因'"
-            maxlength="500"
-            show-word-limit
-          >
-          </el-input>
-        </el-form-item>
-      </el-form>
-
-      <span slot="footer" class="dialog-footer">
-        <el-button @click="approvalDialogVisible = false">取 消</el-button>
-        <el-button
-          :type="approvalForm.isApprove ? 'success' : 'danger'"
-          @click="confirmApproval"
           :loading="submitting"
         >
-          确认{{ approvalForm.isApprove ? '通过' : '拒绝' }}
+          拒绝审批
         </el-button>
       </span>
     </el-dialog>