Browse Source

feat: 添加支付页面退款和退款审核功能

- 在操作列中添加退款按钮和退款审核按钮
- 实现退款申请功能,支持退款金额输入和验证
- 实现退款审核功能,包含审核人、审核时间、审核意见
- 添加退款相关API接口:refundStorePayment、auditRefund等
- 按钮状态根据refundAuditStatus字段动态显示:待审核/审核通过/审核拒绝
- 优化按钮显示条件,排除特定状态的订单
xw 1 month ago
parent
commit
7899556d53
2 changed files with 317 additions and 1 deletions
  1. 28 0
      src/api/hisStore/storePayment.js
  2. 289 1
      src/views/hisStore/storePayment/index.vue

+ 28 - 0
src/api/hisStore/storePayment.js

@@ -69,3 +69,31 @@ export function exportStorePayment(query) {
     params: query
   })
 }
+
+// 退款
+export function refundStorePayment(data) {
+  return request({
+    url: '/store/store/storePayment/refundStorePayment',
+    method: 'post',
+    data: data
+  })
+}
+
+// 退款审核
+export function auditRefund(data) {
+  return request({
+    url: '/store/store/storePayment/refund/audit',
+    method: 'put',
+    data: data
+  })
+}
+
+// 获取退款审核详情
+export function getRefundAuditDetail(paymentId) {
+  return request({
+    url: '/store/store/storePayment/refund/audit/' + paymentId,
+    method: 'get'
+  })
+}
+
+

+ 289 - 1
src/views/hisStore/storePayment/index.vue

@@ -149,6 +149,25 @@
                 @click="handleUpdate(scope.row)"
                 v-hasPermi="['store:storePayment:edit']"
               >修改</el-button>
+              <el-button
+            v-if="scope.row.status==1&&scope.row.businessType==1"
+            size="mini"
+            type="text"
+            @click="handleRefund(scope.row)"
+            v-hasPermi="['store:storePayment:refund']"
+          >退款</el-button>
+              <el-button
+                v-if="scope.row.status != -1 && scope.row.status != 0"
+                size="mini"
+                type="text"
+                :icon="scope.row.refundAuditStatus == 0 || !scope.row.refundAuditStatus ? 'el-icon-check' : 'el-icon-success'"
+                @click="handleAudit(scope.row)"
+                :disabled="scope.row.refundAuditStatus == 1 || scope.row.refundAuditStatus == 2"
+              >
+                <span v-if="scope.row.refundAuditStatus == 0 || !scope.row.refundAuditStatus">退款审核</span>
+                <span v-else-if="scope.row.refundAuditStatus == 1">审核通过</span>
+                <span v-else-if="scope.row.refundAuditStatus == 2">审核拒绝</span>
+              </el-button>
             </template>
           </el-table-column>
         </el-table>
@@ -183,12 +202,86 @@
         <el-button type="primary" @click="submitForm">确 定</el-button>
         <el-button @click="cancel">取 消</el-button>
       </div>
+    </el-dialog>
+        <el-dialog :title="refund.title" :visible.sync="refund.open" width="500px" append-to-body>
+      <el-form ref="refundForm" :model="refundForm" :rules="refundRules" label-width="100px">
+        <el-form-item label="支付订单号" prop="payCode">
+          <el-input v-model="refundForm.payCode" disabled placeholder="请输入支付订单号" />
+        </el-form-item>
+        <el-form-item label="支付类型" prop="payTypeCode">
+          <el-input v-model="refundForm.payTypeCode" disabled placeholder="请输入支付类型" />
+        </el-form-item>
+        <el-form-item label="支付金额" prop="payMoney">
+          <el-input v-model="refundForm.payMoney" disabled placeholder="请输入支付金额" />
+        </el-form-item>
+        <el-form-item label="退款金额" prop="refundMoney">
+          <el-input-number 
+            :min="0" 
+            :max="refundForm.payMoney"
+            :precision="2"
+            v-model="refundForm.refundMoney"  
+            placeholder="请输入退款金额"
+            style="width: 100%"
+          />
+          <div style="color: #909399; font-size: 12px; margin-top: 5px;">
+            支付金额:{{ refundForm.payMoney }} 元,最大可退款金额:{{ refundForm.payMoney }} 元
+          </div>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitRefundForm">确 定</el-button>
+        <el-button @click="cancelRefund">取 消</el-button>
+      </div>
+    </el-dialog>
+
+    <!-- 退款审核对话框 -->
+    <el-dialog :title="audit.title" :visible.sync="audit.open" width="500px" append-to-body>
+      <el-form ref="auditForm" :model="auditForm" :rules="auditRules" label-width="100px">
+        <el-form-item label="支付订单号" prop="payCode">
+          <el-input v-model="auditForm.payCode" disabled placeholder="支付订单号" />
+        </el-form-item>
+        <el-form-item label="支付类型" prop="payTypeCode">
+          <el-input v-model="auditForm.payTypeCode" disabled placeholder="支付类型" />
+        </el-form-item>
+        <el-form-item label="支付金额" prop="payMoney">
+          <el-input v-model="auditForm.payMoney" disabled placeholder="支付金额">
+            <template slot="append">元</template>
+          </el-input>
+        </el-form-item>
+        <el-form-item label="退款金额" prop="refundMoney">
+          <el-input v-model="auditForm.refundMoney" disabled placeholder="退款金额">
+            <template slot="append">元</template>
+          </el-input>
+        </el-form-item>
+        <el-form-item label="退款原因" prop="refundReason">
+          <el-input v-model="auditForm.refundReason" disabled type="textarea" :rows="2" placeholder="退款原因" />
+        </el-form-item>
+        <el-form-item label="审核结果" prop="auditStatus">
+          <el-radio-group v-model="auditForm.auditStatus">
+            <el-radio :label="1">同意退款</el-radio>
+            <el-radio :label="2">拒绝退款</el-radio>
+          </el-radio-group>
+        </el-form-item>
+        <el-form-item label="审核人" prop="auditUser">
+          <el-input v-model="auditForm.auditUser" disabled placeholder="审核人" />
+        </el-form-item>
+        <el-form-item label="审核时间" prop="auditTime">
+          <el-input v-model="auditForm.auditTime" disabled placeholder="审核时间" />
+        </el-form-item>
+        <el-form-item label="审核意见" prop="auditComment">
+          <el-input v-model="auditForm.auditComment" type="textarea" :rows="3" placeholder="请输入审核意见" />
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitAuditForm" :loading="auditLoading">确认审核</el-button>
+        <el-button @click="cancelAudit">取 消</el-button>
+      </div>
     </el-dialog>
   </div>
 </template>
 
 <script>
-import { listStorePayment, getStorePayment, delStorePayment, addStorePayment, updateStorePayment, exportStorePayment } from "@/api/hisStore/storePayment";
+import { refundStorePayment,listStorePayment, getStorePayment, delStorePayment, addStorePayment, updateStorePayment, exportStorePayment, auditRefund } from "@/api/hisStore/storePayment";
 import { treeselect } from "@/api/company/companyDept";
 import Treeselect from "@riophae/vue-treeselect";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
@@ -246,8 +339,40 @@ export default {
       },
       // 表单参数
       form: {},
+      // 退款相关
+      refund: {
+        title: "退款",
+        open: false
+      },
+      // 退款表单参数
+      refundForm: {},
+      // 审核相关
+      audit: {
+        title: "退款审核",
+        open: false
+      },
+      // 审核表单参数
+      auditForm: {},
+      // 审核加载状态
+      auditLoading: false,
       // 表单校验
       rules: {
+      },
+      // 退款表单校验
+      refundRules: {
+        refundMoney: [
+          { required: true, message: "退款金额不能为空", trigger: "blur" },
+          { type: "number", message: "退款金额必须为数字", trigger: "blur" }
+        ]
+      },
+      // 审核表单校验
+      auditRules: {
+        auditStatus: [
+          { required: true, message: "请选择审核结果", trigger: "change" }
+        ],
+        auditComment: [
+          { required: true, message: "请输入审核意见", trigger: "blur" }
+        ]
       }
     };
   },
@@ -403,6 +528,169 @@ export default {
         }).then(response => {
           this.download(response.msg);
         }).catch(function() {});
+    },
+    /** 退款按钮操作 */
+    handleRefund(row) {
+      this.resetRefundForm();
+      this.refundForm = {
+        paymentId: row.paymentId,
+        payCode: row.payCode,
+        payTypeCode: row.payTypeCode,
+        payMoney: row.payMoney,
+        refundMoney: row.payMoney // 默认显示支付金额
+      };
+      this.refund.open = true;
+    },
+    /** 退款表单重置 */
+    resetRefundForm() {
+      this.refundForm = {
+        paymentId: null,
+        payCode: null,
+        payTypeCode: null,
+        payMoney: null,
+        refundMoney: null
+      };
+      if (this.$refs.refundForm) {
+        this.$refs.refundForm.clearValidate();
+      }
+    },
+    /** 取消退款 */
+    cancelRefund() {
+      this.refund.open = false;
+      this.resetRefundForm();
+    },
+    /** 提交退款表单 */
+    submitRefundForm() {
+      this.$refs["refundForm"].validate(valid => {
+        if (valid) {
+          // 验证退款金额是否合理
+          if (this.refundForm.refundMoney <= 0) {
+            this.msgError("退款金额必须大于0");
+            return;
+          }
+          
+          if (this.refundForm.refundMoney > this.refundForm.payMoney) {
+            this.msgError("退款金额不能超过支付金额");
+            return;
+          }
+          
+          this.$confirm('是否确认退款金额 ' + this.refundForm.refundMoney + ' 元?', '确认退款', {
+            confirmButtonText: '确认退款',
+            cancelButtonText: '取消',
+            type: 'warning'
+          }).then(() => {
+            // 调用退款 API
+            const refundData = {
+              paymentId: this.refundForm.paymentId,
+              refundMoney: this.refundForm.refundMoney,
+              refundReason: '用户申请退款' // 可以后续添加退款原因输入框
+            };
+            
+            refundStorePayment(refundData).then(response => {
+              if (response.code === 200) {
+                this.msgSuccess("退款申请提交成功");
+                this.refund.open = false;
+                this.getList(); // 刷新列表
+              } else {
+                this.msgError(response.msg || "退款申请失败");
+              }
+            }).catch(error => {
+              console.error('退款申请失败:', error);
+              this.msgError("退款申请失败,请稍后重试");
+            });
+          }).catch(() => {
+            // 取消退款
+          });
+        }
+      });
+    },
+    /** 退款审核按钮操作 */
+    handleAudit(row) {
+      this.resetAuditForm();
+      // 获取当前用户信息和时间
+      const currentUser = this.$store.state.user.name || '管理员';
+      const currentTime = this.parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}');
+      
+      this.auditForm = {
+        paymentId: row.paymentId,
+        payCode: row.payCode,
+        payTypeCode: row.payTypeCode,
+        payMoney: row.payMoney,
+        refundMoney: row.refundMoney,
+        refundReason: row.refundReason || '用户申请退款',
+        auditStatus: null,
+        auditUser: currentUser,
+        auditTime: currentTime,
+        auditComment: ''
+      };
+      this.audit.open = true;
+    },
+    /** 审核表单重置 */
+    resetAuditForm() {
+      this.auditForm = {
+        paymentId: null,
+        payCode: null,
+        payTypeCode: null,
+        payMoney: null,
+        refundMoney: null,
+        refundReason: null,
+        auditStatus: null,
+        auditUser: null,
+        auditTime: null,
+        auditComment: ''
+      };
+      if (this.$refs.auditForm) {
+        this.$refs.auditForm.clearValidate();
+      }
+    },
+    /** 取消审核 */
+    cancelAudit() {
+      this.audit.open = false;
+      this.resetAuditForm();
+    },
+    /** 提交退款审核表单 */
+    submitAuditForm() {
+      this.$refs["auditForm"].validate(valid => {
+        if (valid) {
+          const auditStatusText = this.auditForm.auditStatus === 1 ? '同意退款' : '拒绝退款';
+          
+          this.$confirm('是否确认审核结果为“' + auditStatusText + '”?', '确认退款审核', {
+            confirmButtonText: '确认审核',
+            cancelButtonText: '取消',
+            type: 'warning'
+          }).then(() => {
+            this.auditLoading = true;
+            
+            // 调用退款审核 API
+            const auditData = {
+              paymentId: this.auditForm.paymentId,
+              refundMoney: this.auditForm.refundMoney,
+              auditStatus: this.auditForm.auditStatus,
+              auditUser: this.auditForm.auditUser,
+              auditTime: this.auditForm.auditTime,
+              auditComment: this.auditForm.auditComment
+            };
+            
+            auditRefund(auditData).then(response => {
+              this.auditLoading = false;
+              if (response.code === 200) {
+                const statusText = this.auditForm.auditStatus === 1 ? '已审核通过' : '已审核拒绝';
+                this.msgSuccess("退款审核完成,状态更新为" + statusText);
+                this.audit.open = false;
+                this.getList(); // 刷新列表
+              } else {
+                this.msgError(response.msg || "退款审核失败");
+              }
+            }).catch(error => {
+              this.auditLoading = false;
+              console.error('退款审核失败:', error);
+              this.msgError("退款审核失败,请稍后重试");
+            });
+          }).catch(() => {
+            // 取消审核
+          });
+        }
+      });
     }
   }
 };