Quellcode durchsuchen

app选择完权益后,返回权益页面,反显选中的权益

@dongkboy vor 2 Wochen
Ursprung
Commit
92661c2497
1 geänderte Dateien mit 15 neuen und 7 gelöschten Zeilen
  1. 15 7
      pages/reward/customerBenefit.vue

+ 15 - 7
pages/reward/customerBenefit.vue

@@ -280,11 +280,9 @@
 			}
 		},
 		onShow() {
-			// 从权益选择页返回时,重新计算剩余金额:剩余 = 可用 - 已使用(高精度)
+			// 从权益选择页返回或修改份数后,已使用/剩余金额按当前选中权益重新计算(高精度)
 			if (this.insFeeOrders && this.insFeeOrders.availableAmount !== undefined) {
-				const available = new Decimal(this.insFeeOrders.availableAmount || 0);
-				const used = new Decimal(this.insFeeOrders.usedAmount || 0);
-				this.$set(this.insFeeOrders, 'remainingAmount', available.minus(used).toString());
+				this.updateUsedAmount();
 			}
 		},
 		computed: {
@@ -293,7 +291,7 @@
 				const total = this.insOrderRightsPackageList.reduce(
 					(sum, item) => {
 						// 计算当前项的 packagePrice * quantity(高精度乘法)
-						const itemTotal = new Decimal(item.packagePrice).times(new Decimal(item.rightsCount));
+						const itemTotal = new Decimal(item.packagePrice).times(new Decimal(item.rightsCount || 0));
 						// 累加到总和
 						return sum.plus(itemTotal);
 					},
@@ -307,7 +305,7 @@
 				const total = this.insOrderRightsList.reduce(
 					(sum, item) => {
 						// 计算当前项的 packagePrice * quantity(高精度乘法)
-						const itemTotal = new Decimal(item.contractRate).times(new Decimal(item.rightsCount));
+						const itemTotal = new Decimal(item.contractRate).times(new Decimal(item.rightsCount || 0));
 						// 累加到总和
 						return sum.plus(itemTotal);
 					},
@@ -354,7 +352,9 @@
 			// 权益数量变化监听
 			onRightsCountChange(e, index, name, field, type) {
 				if (e.value == 0) {
-					return this[name].splice(index, 1);
+					this[name].splice(index, 1);
+					this.updateUsedAmount(); //份数减为0移除后,同步已使用/剩余金额
+					return;
 				}
 				// 获取当前项
 				const item = this[name][index];
@@ -381,8 +381,16 @@
 				} else {
 					// 无论是减少数量还是增加数量且未超过限制,都允许更新
 					item.rightsCount = newCount;
+					this.updateUsedAmount(); //份数变化后,同步已使用/剩余金额
 				}
 			},
+			// 按当前选中权益重新计算已使用/剩余金额(高精度)
+			updateUsedAmount() {
+				const used = new Decimal(this.totalPriceCount || 0).plus(new Decimal(this.totalPriceCount1 || 0));
+				const available = new Decimal(this.insFeeOrders.availableAmount || 0);
+				this.$set(this.insFeeOrders, 'usedAmount', used.toString());
+				this.$set(this.insFeeOrders, 'remainingAmount', available.minus(used).toString());
+			},
 
 			// 获取权益明细
 			async rightsDetails(item, index) {