付晓文。 1 месяц назад
Родитель
Сommit
2cc9ee73a2
1 измененных файлов с 88 добавлено и 39 удалено
  1. 88 39
      pages/topUp/settings.vue

+ 88 - 39
pages/topUp/settings.vue

@@ -12,7 +12,7 @@
 		<view class="card min-card">
 			<view class="min-head">
 				<text class="label">自定义充值最低金额</text>
-				<text class="min-tip">默认最低金额为100</text>
+				<text class="min-tip">默认为固定档位中的最低金额</text>
 			</view>
 			<view class="min-input-wrap">
 				<text class="currency">¥</text>
@@ -20,7 +20,7 @@
 					class="min-input"
 					type="digit"
 					v-model="form.minAmount"
-					placeholder="100"
+					:placeholder="String(lowestTierAmount || '')"
 					placeholder-class="placeholder"
 					@input="onMinAmountInput"
 				/>
@@ -94,27 +94,29 @@
 						<text class="form-label">充值金额</text>
 						<input
 							class="form-input"
-							type="digit"
+							type="number"
 							v-model="tierForm.amount"
-							placeholder="请点击输入"
+							placeholder="请输入正整数"
 							placeholder-class="form-placeholder"
+							@input="onTierAmountInput('amount', $event)"
 						/>
 					</view>
 					<view class="form-row">
 						<text class="form-label">赠送金额</text>
 						<input
 							class="form-input"
-							type="digit"
+							type="number"
 							v-model="tierForm.giftAmount"
-							placeholder="请点击输入"
+							placeholder="选填,默认0"
 							placeholder-class="form-placeholder"
+							@input="onTierAmountInput('giftAmount', $event)"
 						/>
 					</view>
 					<view class="form-row link-row" @click="openCouponSelect">
 						<text class="form-label">赠送优惠券</text>
 						<view class="link-right">
 							<text class="link-text" :class="{ active: couponSelectedCount > 0 }">
-								{{ couponSelectedCount > 0 ? '已选择' : '请选择' }}
+								{{ couponSelectedCount > 0 ? `已选 ${couponSelectedCount} 张` : '去选择' }}
 							</text>
 							<u-icon name="arrow-right" color="#c0c4cc" size="14"></u-icon>
 						</view>
@@ -203,12 +205,8 @@
 				</scroll-view>
 
 				<view class="footer coupon-footer">
-					<view
-						class="save-btn"
-						:class="{ disabled: tempCouponCount <= 0 }"
-						@click="confirmCouponSelect"
-					>
-						{{ tempCouponCount > 0 ? `确定添加${tempCouponCount}张` : '确认添加' }}
+					<view class="save-btn" @click="confirmCouponSelect">
+						{{ tempCouponCount > 0 ? `确定选择(已选 ${tempCouponCount} 张)` : '确定选择' }}
 					</view>
 				</view>
 			</view>
@@ -239,7 +237,7 @@
 				configVersion: null,
 				form: {
 					acceptShare: true,
-					minAmount: '100',
+					minAmount: '',
 					tiers: []
 				},
 				tierVisible: false,
@@ -266,9 +264,17 @@
 					return gift > 0 || couponQty > 0;
 				});
 			},
+			/** 固定档位中的最低充值金额,用作自定义最低金额默认值 */
+			lowestTierAmount() {
+				const amounts = (this.form.tiers || [])
+					.map((t) => Number(t.amount))
+					.filter((n) => !Number.isNaN(n) && n > 0);
+				if (!amounts.length) return 0;
+				return Math.min(...amounts);
+			},
 			canSubmitTier() {
 				const amount = String(this.tierForm.amount || '').trim();
-				return !!amount && Number(amount) > 0;
+				return !!amount && /^\d+$/.test(amount) && Number(amount) > 0;
 			},
 			tierFormTitle() {
 				if (this.tierEditIndex === -1) {
@@ -291,12 +297,24 @@
 		},
 		methods: {
 			onMinAmountInput(e) {
-				const val = String((e && e.detail && e.detail.value) || this.form.minAmount || '')
-					.replace(/[^\d]/g, '');
+				let val = String((e && e.detail && e.detail.value) || this.form.minAmount || '');
+				// 允许小数:只保留数字和第一个小数点,最多两位小数
+				val = val.replace(/[^\d.]/g, '');
+				const parts = val.split('.');
+				if (parts.length > 1) {
+					val = parts[0] + '.' + parts.slice(1).join('').slice(0, 2);
+				}
 				this.$nextTick(() => {
 					this.form.minAmount = val;
 				});
 			},
+			onTierAmountInput(field, e) {
+				const val = String((e && e.detail && e.detail.value) || this.tierForm[field] || '')
+					.replace(/[^\d]/g, '');
+				this.$nextTick(() => {
+					this.$set(this.tierForm, field, val);
+				});
+			},
 			loadSettings() {
 				this.loading = true;
 				prepaidApi
@@ -309,21 +327,30 @@
 						const data = res.data.result;
 						this.configVersion = data.version;
 						const tiers = Array.isArray(data.tiers) ? data.tiers : [];
+						const mappedTiers = tiers.map((tier) => ({
+							id: tier.tierId || createId(),
+							amount: Number(tier.rechargeAmount) || 0,
+							giftAmount: Number(tier.giftAmount) || 0,
+							coupons: (tier.coupons || []).map((c) => ({
+								id: c.couponId,
+								name: c.couponName || '',
+								type: String(c.couponType) === '2' ? 'discount' : 'reduce',
+								qty: Number(c.quantity) || 1
+							}))
+						}));
+						const lowest = mappedTiers
+							.map((t) => Number(t.amount))
+							.filter((n) => n > 0);
+						const defaultMin = lowest.length ? Math.min(...lowest) : '';
 						this.form = {
 							acceptShare: data.acceptSharedPrepaid !== false,
 							minAmount:
-								data.customMinAmount != null ? String(data.customMinAmount) : '100',
-							tiers: tiers.map((tier) => ({
-								id: tier.tierId || createId(),
-								amount: Number(tier.rechargeAmount) || 0,
-								giftAmount: Number(tier.giftAmount) || 0,
-								coupons: (tier.coupons || []).map((c) => ({
-									id: c.couponId,
-									name: c.couponName || '',
-									type: String(c.couponType) === '2' ? 'discount' : 'reduce',
-									qty: Number(c.quantity) || 1
-								}))
-							}))
+								data.customMinAmount != null && data.customMinAmount !== ''
+									? String(data.customMinAmount)
+									: defaultMin !== ''
+										? String(defaultMin)
+										: '',
+							tiers: mappedTiers
 						};
 					})
 					.catch(() => {
@@ -345,8 +372,9 @@
 				const item = this.form.tiers[index];
 				this.tierEditIndex = index;
 				this.tierForm = {
-					amount: item.amount != null ? String(item.amount) : '',
-					giftAmount: item.giftAmount != null ? String(item.giftAmount) : '',
+					amount: item.amount != null ? String(Math.floor(Number(item.amount)) || '') : '',
+					giftAmount:
+						item.giftAmount != null ? String(Math.floor(Number(item.giftAmount)) || 0) : '',
 					coupons: JSON.parse(JSON.stringify(item.coupons || []))
 				};
 				this.tierVisible = true;
@@ -355,6 +383,10 @@
 				this.tierVisible = false;
 			},
 			removeTier(index) {
+				if ((this.form.tiers || []).length <= 2) {
+					uni.showToast({ title: '至少保留2个固定充值档位', icon: 'none' });
+					return;
+				}
 				uni.showModal({
 					title: '提示',
 					content: '确认删除该充值档位吗?',
@@ -369,17 +401,17 @@
 			submitTier() {
 				if (!this.canSubmitTier) return;
 				const amountStr = String(this.tierForm.amount || '').trim();
-				if (!/^\d+(\.\d{1,2})?$/.test(amountStr) || Number(amountStr) <= 0) {
-					uni.showToast({ title: '充值金额须大于0', icon: 'none' });
+				if (!/^\d+$/.test(amountStr) || Number(amountStr) <= 0) {
+					uni.showToast({ title: '充值金额须为正整数', icon: 'none' });
 					return;
 				}
 				const amount = Number(amountStr);
 				const giftRaw = String(this.tierForm.giftAmount || '').trim();
-				const giftAmount = giftRaw === '' ? 0 : Number(giftRaw);
-				if (Number.isNaN(giftAmount) || giftAmount < 0) {
-					uni.showToast({ title: '赠送金额格式不正确', icon: 'none' });
+				if (giftRaw !== '' && !/^\d+$/.test(giftRaw)) {
+					uni.showToast({ title: '赠送金额须为非负整数', icon: 'none' });
 					return;
 				}
+				const giftAmount = giftRaw === '' ? 0 : Number(giftRaw);
 				const payload = {
 					id: this.tierEditIndex === -1 ? createId() : this.form.tiers[this.tierEditIndex].id,
 					amount,
@@ -510,6 +542,12 @@
 					return;
 				}
 				const amounts = this.form.tiers.map((t) => Number(t.amount) || 0);
+				for (let i = 0; i < amounts.length; i++) {
+					if (!Number.isInteger(amounts[i]) || amounts[i] <= 0) {
+						uni.showToast({ title: '档位充值金额须为正整数', icon: 'none' });
+						return;
+					}
+				}
 				for (let i = 1; i < amounts.length; i++) {
 					if (amounts[i] <= amounts[i - 1]) {
 						uni.showToast({ title: '档位充值金额须严格递增', icon: 'none' });
@@ -519,13 +557,24 @@
 				// 有赠送余额/优惠券时接口要求关闭自定义充值
 				const customAmountEnabled = !this.hasGiftConfig;
 				const minRaw = String(this.form.minAmount || '').trim();
-				let customMinAmount = 100;
+				const lowest = this.lowestTierAmount;
+				let customMinAmount = lowest || 0;
 				if (minRaw !== '') {
+					if (!/^\d+(\.\d{1,2})?$/.test(minRaw) || Number(minRaw) <= 0) {
+						uni.showToast({ title: '自定义最低金额须大于0,最多两位小数', icon: 'none' });
+						return;
+					}
 					customMinAmount = Number(minRaw);
-					if (!customMinAmount || customMinAmount < 100) {
-						uni.showToast({ title: '自定义最低金额不得低于100', icon: 'none' });
+					if (lowest && customMinAmount < lowest) {
+						uni.showToast({
+							title: `自定义最低金额不能低于最低档位(${lowest})`,
+							icon: 'none'
+						});
 						return;
 					}
+				} else if (!lowest) {
+					uni.showToast({ title: '请配置固定充值档位', icon: 'none' });
+					return;
 				}
 				const payload = {
 					acceptSharedPrepaid: !!this.form.acceptShare,