|
|
@@ -14,6 +14,7 @@ Page({
|
|
|
nozzleInfo: null,
|
|
|
quantify: '元',
|
|
|
fastInputs: [10, 20, 50, 100, 200, 500],
|
|
|
+ selectIndex:-1,
|
|
|
type: [{
|
|
|
name: '金额',
|
|
|
checked: true
|
|
|
@@ -23,7 +24,7 @@ Page({
|
|
|
checked: false
|
|
|
}
|
|
|
],
|
|
|
- inputValue: '',
|
|
|
+ inputValue: '0.00',
|
|
|
inputTip: '请输入金额',
|
|
|
amount: '',
|
|
|
latitude: 0, //用户当前经度
|
|
|
@@ -113,9 +114,24 @@ Page({
|
|
|
/** 输入框监听 */
|
|
|
onInputChange(event) {
|
|
|
console.log("输入框变化", event)
|
|
|
- this.setData({
|
|
|
- inputValue: event.detail.value
|
|
|
- })
|
|
|
+ let value = event.detail.value;
|
|
|
+
|
|
|
+ // 1. 过滤非法字符(只允许数字和小数点)
|
|
|
+ value = value.replace(/[^\d.]/g, "");
|
|
|
+
|
|
|
+ // 2. 限制小数点只能出现一次
|
|
|
+ const dotIndex = value.indexOf(".");
|
|
|
+ if (dotIndex !== -1) {
|
|
|
+ value = value.substring(0, dotIndex + 1) + value.substring(dotIndex).replace(/\./g, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 限制小数点后最多两位
|
|
|
+ if (dotIndex !== -1 && value.length > dotIndex + 3) {
|
|
|
+ value = value.substring(0, dotIndex + 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 更新输入框值
|
|
|
+ this.setData({ inputValue: value });
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -123,9 +139,11 @@ Page({
|
|
|
*/
|
|
|
onFastInputClick(event) {
|
|
|
console.log("点击", event)
|
|
|
- const amount = event.currentTarget.dataset.id;
|
|
|
+ const value = event.currentTarget.dataset.id;
|
|
|
+ const index = event.currentTarget.dataset.index;
|
|
|
this.setData({
|
|
|
- inputValue: amount
|
|
|
+ inputValue: value,
|
|
|
+ selectIndex:index
|
|
|
});
|
|
|
},
|
|
|
|
|
|
@@ -137,13 +155,13 @@ Page({
|
|
|
|
|
|
console.log('进入 toAuthorization 方法');
|
|
|
console.log(this.data)
|
|
|
- const distance = utils.haversine(this.data.stationLatitude,this.data.stationLongitude,this.data.latitude,this.data.longitude);
|
|
|
- if(distance > 500) {
|
|
|
- wx.showToast({
|
|
|
- title: '您不在油站范围内,请到油站时进行下单',
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
+ // const distance = utils.haversine(this.data.stationLatitude,this.data.stationLongitude,this.data.latitude,this.data.longitude);
|
|
|
+ // if(distance > 500) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '您不在油站范围内,请到油站时进行下单',
|
|
|
+ // })
|
|
|
+ // return
|
|
|
+ // }
|
|
|
this.createOrder();
|
|
|
},
|
|
|
|
|
|
@@ -159,11 +177,18 @@ Page({
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const value = this.data.inputValue;
|
|
|
- console.log("要授权的油枪信息", nozzle, value)
|
|
|
- if (value <= 0) {
|
|
|
+ const value = parseFloat(this.data.inputValue);
|
|
|
+ console.log("要授权的油枪信息", nozzle, value);
|
|
|
+ if (this.data.quantify == '元' && (value < 2.00 || value > 9900.00)) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '金额须在2~9900之间',
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const price = parseFloat(nozzle.productPrice);
|
|
|
+ if (this.data.quantify == '升' && (value < 1.00 || (value * price) > 9900.00)) {
|
|
|
wx.showToast({
|
|
|
- title: '定量值非法',
|
|
|
+ title: '升数不合法',
|
|
|
});
|
|
|
return;
|
|
|
}
|