Commit 43fdc4f6 by Lin

feat: 会员权益-新增工单-车架号校验

1 parent c1db60f4
......@@ -147,11 +147,17 @@ Component({
thisPage.setData({
[dataAttrName + '.carVin']: upperVin
})
// 当输入满17位时,进行实时校验(防抖500ms)
if (upperVin.length === 17) {
validateVin(upperVin).catch(() => {
// 校验失败,validateVin 内部已经显示了错误提示
validateVin(upperVin).then(res => {
let { valid } = res.data.data;
console.log("upperVinRes",valid);
// 保存 valid 值到组件 data 中
this.setData({
vinValid: valid
});
}).catch(() => {
console.log("upperVinErr",upperVin);
})
}
}
......@@ -251,8 +257,10 @@ Component({
var {
dataAttrName,
formRule,
pointsMultiRole
pointsMultiRole,
vinValid
} = this.data
// let thisPage = this.$router.getCurrentPage()
let thisPage = wx.$router.getPageInstance()
// console.log(thisPage.data['orderInfo']['actualSalesPersonId'])
......@@ -270,7 +278,21 @@ Component({
return false
}
}
// 车架号校验
const carVin = thisPage.data[dataAttrName]?.carVin
if (carVin) {
const isCarVinRequired = formRule?.carVin?.some(rule => rule.required === true) // 再次判断一下车架号是否必填项
// 前置判断
if (carVin.length !== 17 && isCarVinRequired) {
wx.$util.showToast('请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)')
return false
}
// 根据接口校验结果判断
if (carVin.length === 17 && !vinValid) {
wx.$util.showToast('车架号校验不匹配,请核对后重新输入')
return false
}
}
let validObj = fn.checkRequired(thisPage.data[dataAttrName], formRule)
if (validObj) {
wx.$util.showToast(validObj.message)
......
......@@ -26,6 +26,7 @@ let toastList = {
payeeType: "收款方不能为空",
selectPayType: "支付方式不能为空"
};
import { validateVin, formatVinInput } from '~/utils/vinVaildate'
const phoneRex = /^[1]([3-9])[0-9]{9}$/;
// orderSource 订单来源(1后台录入,2移动端预录客户,3移动端升级下单,4再次下单)
......@@ -253,10 +254,16 @@ Page({
let {
orderObj
} = this.data;
orderObj.customer[type] = data;
this.setData({
orderObj,
});
// 车架号字段特殊处理
if (type === 'standNo') {
const prop = `orderObj.customer[${type}]`
this.handleVinInput(data, prop, true) // 扫描时立即校验
} else {
orderObj.customer[type] = data;
this.setData({
orderObj,
});
}
},
navOcr(e) {
let {
......@@ -321,6 +328,7 @@ Page({
let {
name
} = e.currentTarget.dataset;
let prop = `orderObj.${name}`
if (name == "customer.customerPhone" && phoneRex.test(value)) {
// 如果手机号有变动 需清订单的空礼券和商品
let deleteName = [
......@@ -343,6 +351,12 @@ Page({
});
this.setGoodsTotal(goodsList);
}
// 车架号字段特殊处理
if (name === 'customer.standNo') {
console.log("车架号校验",prop);
this.handleVinInput(value, prop) // 手动输入时需达到17位才校验
return;
}
this.setData({
[`orderObj.${name}`]: value.trim(),
});
......@@ -1589,6 +1603,24 @@ Page({
});
this.setGoodsTotal(chooseList);
},
handleVinInput(value, prop, autoValidate = false) {
const formattedValue = formatVinInput(value || '')
this.setData({
[prop]: formattedValue
})
// 扫描时立即校验,手动输入时需达到17位才校验
if (formattedValue && (autoValidate || formattedValue.length === 17)) {
validateVin(formattedValue)
.then(result => {
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
})
.catch(error => {
// 校验失败,所有提示已在公共方法中处理
console.log('车架号校验失败:', error)
})
}
},
handleSpecificationsEcho(item) {
let skuArr = [];
let {
......@@ -1658,7 +1690,6 @@ Page({
// app .
getYQorderInfo()
.then((merchantSettingInfo) => {
console.log(merchantSettingInfo, 'merchantSettingInfo');
let dictionaryObj = {
carTypeRequiredFlag: "carBrand",
standNoRequiredFlag: "standNo",
......@@ -1867,7 +1898,7 @@ Page({
}
// 是订单补录跳转进来的
if (res?.orderCreateType == "additionRecordOrder") {
let { supplementId, selectOutTradeNoArr } = res
let {supplementId, selectOutTradeNoArr} = res
if (supplementId) {
return this.checkShowOrderInfo()
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!