Commit e393abdd by Lin

feat: 会员权益升级/权益提单-车架号动态校验

1 parent e92ccbeb
...@@ -4,6 +4,7 @@ const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-w ...@@ -4,6 +4,7 @@ const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-w
import fn from '../constant/ruleFn' import fn from '../constant/ruleFn'
const defaultLabelWidth = 'var(--fontSize140)' const defaultLabelWidth = 'var(--fontSize140)'
import api from '~/api/api' import api from '~/api/api'
import { validateVin, formatVinInput } from '~/utils/vinVaildate'
Component({ Component({
options: { options: {
styleIsolation: 'shared', // 自定义覆盖vant样式 styleIsolation: 'shared', // 自定义覆盖vant样式
...@@ -56,6 +57,7 @@ Component({ ...@@ -56,6 +57,7 @@ Component({
energyFormRule: constantData.energyFormRule, energyFormRule: constantData.energyFormRule,
oilFormRule: constantData.oilFormRule, oilFormRule: constantData.oilFormRule,
extendServiceFormRule: constantData.extendServiceFormRule, extendServiceFormRule: constantData.extendServiceFormRule,
vinValid: null, // VIN 车架号校验结果
isShowObj: { isShowObj: {
car: true, car: true,
customer: true, customer: true,
...@@ -130,6 +132,46 @@ Component({ ...@@ -130,6 +132,46 @@ Component({
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
// 表单输入事件处理
inputEvent(e) {
console.log(e, 'inputEvent')
let { attr } = e.detail
// 车架号输入处理:实时转大写 + 实时校验
if (attr == 'vin') {
const thisPage = wx.$router.getPageInstance()
const { dataAttrName } = this.data
// 从页面数据中获取刚刚更新的车架号值
const value = thisPage.data[dataAttrName]?.vin || ''
const upperVin = formatVinInput(value)
// 更新为大写
thisPage.setData({
[dataAttrName + '.vin']: upperVin
})
// 当输入满17位时,进行实时校验(防抖500ms)
if (upperVin.length === 17) {
validateVin(upperVin).then(res => {
let { valid } = res.data.data
console.log("upperVinRes", valid)
// 保存 valid 值到组件 data 中
this.setData({
vinValid: valid
})
}).catch(() => {
console.log("upperVinErr", upperVin)
// 校验失败时,设置为 false
this.setData({
vinValid: false
})
})
} else {
// 长度不足17位时,重置校验状态
this.setData({
vinValid: null
})
}
}
},
changeInclueType(e){ changeInclueType(e){
const {types} = e.target.dataset const {types} = e.target.dataset
let formData = this.getPageData() let formData = this.getPageData()
...@@ -260,8 +302,13 @@ Component({ ...@@ -260,8 +302,13 @@ Component({
}) })
}, },
handleConfirm(e) { handleConfirm(e) {
var { formRule, serviceInfo, imgObj, imgToInfo, energyFormRule, oilFormRule,retrofitInfo, extendServiceFormRule } = this.data var { formRule, serviceInfo, imgObj, imgToInfo, energyFormRule, oilFormRule, retrofitInfo, extendServiceFormRule, vinValid } = this.data
let formData = this.getPageData() let formData = this.getPageData()
// VIN 车架号校验检查
if (formData.vin && vinValid === false) {
wx.$util.showToast('车架号校验未通过,请重新输入')
return
}
let validObj = fn.checkRequired(formData, formRule) let validObj = fn.checkRequired(formData, formRule)
if (validObj) { if (validObj) {
wx.$util.showToast(validObj.message) wx.$util.showToast(validObj.message)
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
formData="{{ serviceInfo }}" formData="{{ serviceInfo }}"
dataAttrName="{{ dataAttrName }}" dataAttrName="{{ dataAttrName }}"
formDataList="{{ secondObj.carFormList }}" formDataList="{{ secondObj.carFormList }}"
bind:inputEvent="inputEvent"
></gl-form> ></gl-form>
</view> </view>
<view class="box"> <view class="box">
......
...@@ -57,7 +57,10 @@ const formRule = { ...@@ -57,7 +57,10 @@ const formRule = {
{ required: true, message: '车架号不能为空' }, { required: true, message: '车架号不能为空' },
{ {
validator: (rule, value) => { validator: (rule, value) => {
return /^[a-zA-Z0-9]{17}$/.test(value) ? null : { message: '车架号请输入17位数字和字母' } console.log("validatorVlue", value)
// VIN 车架号格式校验:17位字符,支持大写 A-H/J-N/P-Z、0-9(排除 I、O、Q)
const VALID_VIN_REG = /^[A-HJ-NPR-Z0-9]{17}$/i
return VALID_VIN_REG.test(value) ? null : { message: '请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)' }
} }
} }
], ],
......
...@@ -45,7 +45,7 @@ const formRule = { ...@@ -45,7 +45,7 @@ const formRule = {
validator: (rule, value) => { validator: (rule, value) => {
return value.length != 17 return value.length != 17
? { ? {
message: "请输入正确的17位车架号", message: "请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)",
} }
: null; : null;
}, },
...@@ -115,7 +115,7 @@ const formRuleSimple = { ...@@ -115,7 +115,7 @@ const formRuleSimple = {
return value return value
? value.length != 17 ? value.length != 17
? { ? {
message: "请输入正确的17位车架号", message: "请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)",
} }
: null : null
: null; : null;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!