dabeng 3 nedēļas atpakaļ
vecāks
revīzija
7d34c2522c
2 mainītis faili ar 24 papildinājumiem un 9 dzēšanām
  1. 8 0
      api/merchantDish.js
  2. 16 9
      pages/merchantDish/orders/order-details.vue

+ 8 - 0
api/merchantDish.js

@@ -203,6 +203,14 @@ const api = {
 		})
 	},
 
+	/** 商户端预约单批量直接退款(一次请求,后端逐用户订单处理) */
+	packageOrderReservationDirectRefundBatch(hostOrderId, userOrderIds) {
+		return http.post('/groupmeal/merchantPackageOrder/reservation/directRefundBatch', {
+			hostOrderId,
+			userOrderIds
+		})
+	},
+
 	/** 商户团餐订单出餐 */
 	packageOrderReady(orderId) {
 		return http.get('/groupmeal/merchantPackageOrder/orderReady', {

+ 16 - 9
pages/merchantDish/orders/order-details.vue

@@ -86,7 +86,7 @@
 		<view v-if="refundVisible" class="refund-mask" @click.self="closeRefundModal">
 			<view class="refund-dialog" @click.stop>
 				<text class="refund-title">提示</text>
-				<text class="refund-message">是否要发起退款</text>
+				<text class="refund-message">确认对{{ refundTargets.length }}个用户订单发起退款吗</text>
 				<view class="refund-actions">
 					<view class="refund-action cancel" @click="closeRefundModal">取消</view>
 					<view class="refund-action confirm" @click="confirmRefund">确定</view>
@@ -151,7 +151,8 @@ export default {
 			})
 		},
 		getItemKey(item, index) {
-			return item.merchantOrderPackageId || item.userOrderId || item.packageId || `item-${index}`
+			// 预约单退款的业务粒度是用户子订单;同一用户有多个套餐时必须一起选中。
+			return item.userOrderId || item.merchantOrderPackageId || item.packageId || `item-${index}`
 		},
 		isSelected(item, index) {
 			return this.selectedKeys.includes(this.getItemKey(item, index))
@@ -167,19 +168,19 @@ export default {
 				this.selectedKeys = []
 				return
 			}
-			this.selectedKeys = this.items.map((item, index) => this.getItemKey(item, index))
+			this.selectedKeys = [...new Set(this.items.map((item, index) => this.getItemKey(item, index)))]
 		},
 		handleRefund() {
 			const selected = this.items.filter((item, index) => this.isSelected(item, index))
 			if (!selected.length) {
-				uni.showToast({ title: '请选择要退款的套餐', icon: 'none' })
+				uni.showToast({ title: '请选择要退款的用户订单', icon: 'none' })
 				return
 			}
-			if (selected.some(item => !item.userOrderId)) {
+			if (selected.some((item) => !item.userOrderId)) {
 				uni.showToast({ title: '退款缺少用户子订单号', icon: 'none' })
 				return
 			}
-			this.refundTargets = selected
+			this.refundTargets = [...new Set(selected.map((item) => item.userOrderId))]
 			this.refundVisible = true
 		},
 		closeRefundModal() {
@@ -190,16 +191,22 @@ export default {
 		confirmRefund() {
 			if (!this.refundTargets.length || this.refundSubmitting) return
 			this.refundSubmitting = true
-			const userOrderIds = this.refundTargets.map(item => item.userOrderId)
-			merchantDishApi.packageOrderDirectRefund(userOrderIds).then((res) => {
+			merchantDishApi.packageOrderReservationDirectRefundBatch(
+				this.hostOrderId,
+				this.refundTargets
+			).then((res) => {
 				if (res.data.code !== 200) {
 					uni.showToast({ title: res.data.message || '退款失败', icon: 'none' })
 					return
 				}
+				const result = res.data.result || {}
 				this.refundVisible = false
 				this.refundTargets = []
 				this.selectedKeys = []
-				uni.showToast({ title: res.data.message || '退款成功', icon: 'success' })
+				uni.showToast({
+					title: res.data.message || '退款已受理',
+					icon: Number(result.rejectedCount || 0) > 0 ? 'none' : 'success'
+				})
 				this.loadDetail()
 			}).catch(() => {
 				uni.showToast({ title: '退款失败', icon: 'none' })