|
@@ -2,7 +2,7 @@
|
|
|
<view class="pay-container">
|
|
<view class="pay-container">
|
|
|
<!-- 顶部导航栏 -->
|
|
<!-- 顶部导航栏 -->
|
|
|
<view class="nav-bar">
|
|
<view class="nav-bar">
|
|
|
- <view class="nav-title">扫码付款</view>
|
|
|
|
|
|
|
+ <view class="nav-title">付款</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
<!-- 支付金额区域 -->
|
|
<!-- 支付金额区域 -->
|
|
@@ -12,7 +12,7 @@
|
|
|
<text class="currency">¥</text>
|
|
<text class="currency">¥</text>
|
|
|
<text class="amount">{{ displayAmount }}</text>
|
|
<text class="amount">{{ displayAmount }}</text>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="amount-tip">请输入支付金额</view>
|
|
|
|
|
|
|
+ <view class="amount-tip">请输入金额</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
<!-- 支付方式展示 -->
|
|
<!-- 支付方式展示 -->
|
|
@@ -72,14 +72,13 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
-import { createPaymentOrder, requestPayment } from '@/api/payment';
|
|
|
|
|
-
|
|
|
|
|
|
|
+import { } from '@/api/payment';
|
|
|
export default {
|
|
export default {
|
|
|
- name: 'PayPage',
|
|
|
|
|
|
|
+ name: 'pay',
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
- currentAmount: '0.00',
|
|
|
|
|
- displayAmount: '0.00',
|
|
|
|
|
|
|
+ currentAmount: '0',
|
|
|
|
|
+ displayAmount: '0',
|
|
|
keyboardKeys: [
|
|
keyboardKeys: [
|
|
|
[
|
|
[
|
|
|
{ type: 'number', value: '1' },
|
|
{ type: 'number', value: '1' },
|
|
@@ -133,12 +132,12 @@ export default {
|
|
|
this.addDecimal();
|
|
this.addDecimal();
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 添加数字
|
|
// 添加数字
|
|
|
addNumber(num) {
|
|
addNumber(num) {
|
|
|
- if (this.currentAmount === '0.00') {
|
|
|
|
|
|
|
+ if (this.currentAmount === '0' || this.currentAmount === '0.00') {
|
|
|
this.currentAmount = num;
|
|
this.currentAmount = num;
|
|
|
- this.displayAmount = num;
|
|
|
|
|
|
|
+ this.hasDecimal = false;
|
|
|
|
|
+ this.decimalPlaces = 0;
|
|
|
} else {
|
|
} else {
|
|
|
if (this.hasDecimal) {
|
|
if (this.hasDecimal) {
|
|
|
if (this.decimalPlaces < 2) {
|
|
if (this.decimalPlaces < 2) {
|
|
@@ -153,7 +152,6 @@ export default {
|
|
|
}
|
|
}
|
|
|
this.updateDisplay();
|
|
this.updateDisplay();
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 添加小数点
|
|
// 添加小数点
|
|
|
addDecimal() {
|
|
addDecimal() {
|
|
|
if (!this.hasDecimal) {
|
|
if (!this.hasDecimal) {
|
|
@@ -162,7 +160,6 @@ export default {
|
|
|
this.updateDisplay();
|
|
this.updateDisplay();
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 删除数字
|
|
// 删除数字
|
|
|
deleteNumber() {
|
|
deleteNumber() {
|
|
|
if (this.currentAmount.length > 1) {
|
|
if (this.currentAmount.length > 1) {
|
|
@@ -174,6 +171,10 @@ export default {
|
|
|
// 删除普通数字
|
|
// 删除普通数字
|
|
|
if (this.hasDecimal && this.currentAmount.split('.')[1]) {
|
|
if (this.hasDecimal && this.currentAmount.split('.')[1]) {
|
|
|
this.decimalPlaces--;
|
|
this.decimalPlaces--;
|
|
|
|
|
+ // 如果删除后没有小数位了,重置状态
|
|
|
|
|
+ if (this.decimalPlaces === 0) {
|
|
|
|
|
+ this.hasDecimal = false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
this.currentAmount = this.currentAmount.slice(0, -1);
|
|
this.currentAmount = this.currentAmount.slice(0, -1);
|
|
|
}
|
|
}
|
|
@@ -184,13 +185,17 @@ export default {
|
|
|
}
|
|
}
|
|
|
this.updateDisplay();
|
|
this.updateDisplay();
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 更新显示金额
|
|
// 更新显示金额
|
|
|
updateDisplay() {
|
|
updateDisplay() {
|
|
|
let amount = parseFloat(this.currentAmount) || 0;
|
|
let amount = parseFloat(this.currentAmount) || 0;
|
|
|
- this.displayAmount = amount.toFixed(2);
|
|
|
|
|
|
|
+ // 如果没有输入小数点,不显示小数部分
|
|
|
|
|
+ if (!this.hasDecimal) {
|
|
|
|
|
+ this.displayAmount = Math.floor(amount).toString();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果有小数点,显示两位小数
|
|
|
|
|
+ this.displayAmount = amount.toFixed(2);
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 设置金额
|
|
// 设置金额
|
|
|
setAmount(amount) {
|
|
setAmount(amount) {
|
|
|
const numAmount = parseFloat(amount);
|
|
const numAmount = parseFloat(amount);
|
|
@@ -199,90 +204,27 @@ export default {
|
|
|
this.hasDecimal = this.currentAmount.includes('.');
|
|
this.hasDecimal = this.currentAmount.includes('.');
|
|
|
if (this.hasDecimal) {
|
|
if (this.hasDecimal) {
|
|
|
this.decimalPlaces = this.currentAmount.split('.')[1].length;
|
|
this.decimalPlaces = this.currentAmount.split('.')[1].length;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.decimalPlaces = 0;
|
|
|
}
|
|
}
|
|
|
this.updateDisplay();
|
|
this.updateDisplay();
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 处理支付
|
|
// 处理支付
|
|
|
async handlePay() {
|
|
async handlePay() {
|
|
|
if (!this.canPay) return;
|
|
if (!this.canPay) return;
|
|
|
-
|
|
|
|
|
const amount = parseFloat(this.currentAmount);
|
|
const amount = parseFloat(this.currentAmount);
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- uni.showLoading({
|
|
|
|
|
- title: '支付中...'
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 模拟支付请求
|
|
|
|
|
- const result = await this.requestPayment(amount);
|
|
|
|
|
-
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
-
|
|
|
|
|
- if (result.success) {
|
|
|
|
|
- // 支付成功,跳转到成功页面
|
|
|
|
|
- uni.navigateTo({
|
|
|
|
|
- url: `/admin/ghs/success?amount=${this.displayAmount}&orderId=${this.orderId || this.generateOrderId()}`
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- // 支付失败,显示弹框
|
|
|
|
|
- this.paymentResult = {
|
|
|
|
|
- success: false,
|
|
|
|
|
- amount: this.displayAmount,
|
|
|
|
|
- message: result.message
|
|
|
|
|
- };
|
|
|
|
|
- this.showPaymentModal = true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
- uni.showToast({
|
|
|
|
|
- title: '支付失败',
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 请求支付
|
|
// 请求支付
|
|
|
async requestPayment(amount) {
|
|
async requestPayment(amount) {
|
|
|
- try {
|
|
|
|
|
- // 创建支付订单
|
|
|
|
|
- const orderResult = await createPaymentOrder({
|
|
|
|
|
- amount: amount,
|
|
|
|
|
- paymentMethod: 'alipay',
|
|
|
|
|
- orderId: this.orderId || this.generateOrderId(),
|
|
|
|
|
- description: '扫码支付'
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if (!orderResult.success) {
|
|
|
|
|
- throw new Error(orderResult.message);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 发起支付
|
|
|
|
|
- const paymentResult = await requestPayment({
|
|
|
|
|
- orderId: orderResult.data.orderId,
|
|
|
|
|
- paymentMethod: 'alipay'
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- return paymentResult;
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error('支付请求失败:', error);
|
|
|
|
|
- return {
|
|
|
|
|
- success: false,
|
|
|
|
|
- message: error.message || '支付失败,请重试'
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
// 生成订单ID
|
|
// 生成订单ID
|
|
|
generateOrderId() {
|
|
generateOrderId() {
|
|
|
const timestamp = Date.now();
|
|
const timestamp = Date.now();
|
|
|
const random = Math.floor(Math.random() * 10000);
|
|
const random = Math.floor(Math.random() * 10000);
|
|
|
return `ORDER${timestamp}${random}`;
|
|
return `ORDER${timestamp}${random}`;
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|