Commit 61107157 by Lin

feat: VIN车架号动态校验/公共方法配置

1 parent d297548c
...@@ -554,4 +554,13 @@ module.exports = { ...@@ -554,4 +554,13 @@ module.exports = {
...data ...data
}) })
}, },
// VIN车架号校验
checkVinValidate(data={}) {
console.log("调用接口checkVinValidate",data);
return http.post({
method: 'dj.pad.api.vin.validate',
projectName: 'pad',
...data,
})
},
} }
const target = ['ip', 'dev', 'uat', 'prod', 'beta'] const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 2 const index = 1
/** /**
* *
0本地 0本地
......
...@@ -52,6 +52,7 @@ import Package from './Package.vue' ...@@ -52,6 +52,7 @@ import Package from './Package.vue'
import SkuGoods from './SkuGoods.vue' import SkuGoods from './SkuGoods.vue'
import { FORM_LIST, popupTypeEnum, payTypeList } from '../contant' import { FORM_LIST, popupTypeEnum, payTypeList } from '../contant'
import { interceptionMixin } from '@/mixin/index' import { interceptionMixin } from '@/mixin/index'
import { validateVin, formatVinInput } from '@/utils/vinVaildate'
export default { export default {
name: 'CreateOrder', name: 'CreateOrder',
mixins: [interceptionMixin], mixins: [interceptionMixin],
...@@ -216,6 +217,7 @@ export default { ...@@ -216,6 +217,7 @@ export default {
positionTypeList: [], positionTypeList: [],
valueKey: '', valueKey: '',
totalPrice: 0, totalPrice: 0,
validateState:null,
// 产品槽位配置,用于循环渲染产品组件 // 产品槽位配置,用于循环渲染产品组件
productSlots: { productSlots: {
frontGear: true, frontGear: true,
...@@ -382,6 +384,21 @@ export default { ...@@ -382,6 +384,21 @@ export default {
inputBlur(e, val) { inputBlur(e, val) {
console.log(e, val) console.log(e, val)
this.orderObj.customer[val.value] = this.orderObj[val.value] this.orderObj.customer[val.value] = this.orderObj[val.value]
// VIN车架号动态校验:车架号字段,动态转换为大写
let standNoVal = this.orderObj.standNo;
if (val.value === 'standNo' && standNoVal) {
this.orderObj.standNo = formatVinInput(standNoVal)
validateVin(this.orderObj.standNo).then(result => {
console.log("validateVin",result);
let { valid } = result.data;
this.validateState = valid
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
}).catch(err => {
console.log("validateVinErr",result);
})
}
}, },
// 校验必填等规则 // 校验必填等规则
checkRequired() { checkRequired() {
...@@ -430,9 +447,9 @@ export default { ...@@ -430,9 +447,9 @@ export default {
} }
} }
if (this.orderObj.standNo) { // if (this.orderObj.standNo) {
if (!utils.validateVIN(this.orderObj.standNo)) throw '车架号校验不匹配,请核对后重新输入' // if (!utils.validateVIN(this.orderObj.standNo)) throw '车架号校验不匹配,请核对后重新输入'
} // }
// 处理onlyLabel为true的特殊校验 // 处理onlyLabel为true的特殊校验
if (onlyLabelItem.length > 0) { if (onlyLabelItem.length > 0) {
...@@ -458,8 +475,22 @@ export default { ...@@ -458,8 +475,22 @@ export default {
// 提交 // 提交
async submit() { async submit() {
console.log(this.orderObj) // VIN车架号-动态校验
if (!this.checkRequired()) return const carVin = this.orderObj.standNo
console.log("validateState",this.validateState);
if (carVin) {
// 前置判断
if (carVin.length !== 17) {
uni.showToast({title:'请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)',icon:'none'})
return false
}
// 根据接口校验结果判断
if (carVin.length === 17 && !this.validateState) {
uni.showToast({title:'车架号校验不匹配,请核对后重新输入',icon:'none'})
return false
}
}
if (!(await this.checkDailyReport())) { if (!(await this.checkDailyReport())) {
const { orderCreateType } = this const { orderCreateType } = this
const obj = utils.deepClone(this.orderObj) const obj = utils.deepClone(this.orderObj)
......
...@@ -62,6 +62,7 @@ import SkuGoods from './SkuGoods.vue' ...@@ -62,6 +62,7 @@ import SkuGoods from './SkuGoods.vue'
import { checkDailyReport, showNextModal } from '@/utils/modalUtils' import { checkDailyReport, showNextModal } from '@/utils/modalUtils'
import { DEFEAT_FORM_LIST, popupTypeEnum, payTypeList } from '../contant' import { DEFEAT_FORM_LIST, popupTypeEnum, payTypeList } from '../contant'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import { validateVin, formatVinInput } from '@/utils/vinVaildate'
export default { export default {
name: 'DefeatOrder', name: 'DefeatOrder',
components: { components: {
...@@ -182,6 +183,7 @@ export default { ...@@ -182,6 +183,7 @@ export default {
positionTypeList: [], positionTypeList: [],
valueKey: '', valueKey: '',
totalPrice: 0, totalPrice: 0,
validateState:null,
// 产品槽位配置,用于循环渲染产品组件 // 产品槽位配置,用于循环渲染产品组件
productSlots: { productSlots: {
frontGear: true, frontGear: true,
...@@ -333,6 +335,20 @@ export default { ...@@ -333,6 +335,20 @@ export default {
console.log(e, val) console.log(e, val)
console.log(this.orderObj) console.log(this.orderObj)
this.orderObj.customer[val.value] = this.orderObj[val.value] this.orderObj.customer[val.value] = this.orderObj[val.value]
// VIN车架号动态校验:车架号字段,动态转换为大写
let standNoVal = this.orderObj.standNo;
if (val.value === 'standNo' && standNoVal) {
this.orderObj.standNo = formatVinInput(standNoVal)
validateVin(this.orderObj.standNo).then(result => {
console.log("validateVin",result);
let { valid } = result.data;
this.validateState = valid
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
}).catch(err => {
console.log("validateVinErr",result);
})
}
}, },
checkRequired() { checkRequired() {
const phoneRex = /^[1]([3-9])[0-9]{9}$/ const phoneRex = /^[1]([3-9])[0-9]{9}$/
...@@ -352,6 +368,21 @@ export default { ...@@ -352,6 +368,21 @@ export default {
}) })
}) })
// VIN车架号-动态校验
const carVin = this.orderObj.standNo
console.log("validateState",this.validateState);
if (carVin) {
// 前置判断
if (carVin.length !== 17) {
uni.showToast({title:'请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)',icon:'none'})
return false
}
// 根据接口校验结果判断
if (carVin.length === 17 && !this.validateState) {
uni.showToast({title:'车架号校验不匹配,请核对后重新输入',icon:'none'})
return false
}
}
// 遍历requiredArr,检查orderObj中是否有对应的值 // 遍历requiredArr,检查orderObj中是否有对应的值
for (let i = 0; i < requiredArr.length; i++) { for (let i = 0; i < requiredArr.length; i++) {
const item = requiredArr[i] const item = requiredArr[i]
...@@ -380,18 +411,17 @@ export default { ...@@ -380,18 +411,17 @@ export default {
} }
} }
if (this.orderObj.standNo) { // if (this.orderObj.standNo) {
const vinRex = /^(?=.*[A-Za-z])[A-Za-z0-9]{17}$/ // const vinRex = /^(?=.*[A-Za-z])[A-Za-z0-9]{17}$/
console.log(this.orderObj.standNo, vinRex.test(this.orderObj.standNo)) // console.log(this.orderObj.standNo, vinRex.test(this.orderObj.standNo))
if (!vinRex.test(this.orderObj.standNo)) { // if (!vinRex.test(this.orderObj.standNo)) {
uni.showToast({ // uni.showToast({
title: `请输入正确的VIN码`, // title: `请输入正确的VIN码`,
icon: 'none' // icon: 'none'
}) // })
return false // return false
} // }
} // }
// 处理onlyLabel为true的特殊校验 // 处理onlyLabel为true的特殊校验
if (onlyLabelItem.length > 0) { if (onlyLabelItem.length > 0) {
// 检查frontGear、frontWindow、rearGear、rearWindow、sunRoof和couponInfo字段中是否至少有一个不为空 // 检查frontGear、frontWindow、rearGear、rearWindow、sunRoof和couponInfo字段中是否至少有一个不为空
...@@ -419,6 +449,7 @@ export default { ...@@ -419,6 +449,7 @@ export default {
// 校验是否填写昨日日报 // 校验是否填写昨日日报
let staffCheck = await checkDailyReport() let staffCheck = await checkDailyReport()
if (staffCheck) return false if (staffCheck) return false
console.log("this.checkRequired()",this.checkRequired());
if (!this.checkRequired()) return if (!this.checkRequired()) return
const { orderCreateType } = this const { orderCreateType } = this
const obj = utils.deepClone(this.orderObj) const obj = utils.deepClone(this.orderObj)
......
...@@ -110,7 +110,7 @@ import UploadProofOfPayment from './UploadProofOfPayment.vue' ...@@ -110,7 +110,7 @@ import UploadProofOfPayment from './UploadProofOfPayment.vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import OrderPay from './OrderPay.vue' import OrderPay from './OrderPay.vue'
import NP from 'number-precision' import NP from 'number-precision'
import { validateVin, formatVinInput } from '@/utils/vinVaildate'
export default { export default {
name: 'CreateOrder', name: 'CreateOrder',
mixins: [interceptionMixin], mixins: [interceptionMixin],
...@@ -202,7 +202,8 @@ export default { ...@@ -202,7 +202,8 @@ export default {
valueKey: '', valueKey: '',
popupTitle: '', popupTitle: '',
pointsMultiRole: 'Y', pointsMultiRole: 'Y',
formKey: Date.now() formKey: Date.now(),
validateState:null
} }
...@@ -507,12 +508,27 @@ export default { ...@@ -507,12 +508,27 @@ export default {
}, },
// 输入框失去焦点事件 // 输入框失去焦点事件
inputBlur (e, val) { inputBlur (e, val) {
console.log("SSSSSS");
console.log(e, val) console.log(e, val)
if (val.value == 'price') { if (val.value == 'price') {
this.orderObj[val.value] = parseFloat(this.orderObj[val.value]) > 2000000 ? 2000000 : this.orderObj[val.value] this.orderObj[val.value] = parseFloat(this.orderObj[val.value]) > 2000000 ? 2000000 : this.orderObj[val.value]
return return
} }
this.orderObj[val.value] = this.orderObj[val.value] this.orderObj[val.value] = this.orderObj[val.value]
// VIN车架号动态校验:车架号字段,动态转换为大写
let carVinVal = this.orderObj.carVin;
if (val.value === 'carVin' && carVinVal) {
this.orderObj.carVin = formatVinInput(carVinVal)
validateVin(this.orderObj.carVin).then(result => {
console.log("validateVin",result);
let { valid } = result.data;
this.validateState = valid
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
}).catch(err => {
console.log("validateVinErr",result);
})
}
}, },
// 校验必填等规则 // 校验必填等规则
checkRequired () { checkRequired () {
...@@ -530,6 +546,21 @@ export default { ...@@ -530,6 +546,21 @@ export default {
} }
}) })
}) })
// VIN车架号-动态校验
const carVin = this.orderObj.carVin
console.log("validateState",this.validateState);
if (carVin) {
// 前置判断
if (carVin.length !== 17) {
uni.showToast({title:'请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)',icon:'none'})
return false
}
// 根据接口校验结果判断
if (carVin.length === 17 && !this.validateState) {
uni.showToast({title:'车架号校验不匹配,请核对后重新输入',icon:'none'})
return false
}
}
// 遍历requiredArr,检查orderObj中是否有对应的值 // 遍历requiredArr,检查orderObj中是否有对应的值
for (let i = 0; i < requiredArr.length; i++) { for (let i = 0; i < requiredArr.length; i++) {
const item = requiredArr[i] const item = requiredArr[i]
...@@ -539,9 +570,9 @@ export default { ...@@ -539,9 +570,9 @@ export default {
// 如果是customerPhone,添加phoneRex校验 // 如果是customerPhone,添加phoneRex校验
if (item.value === 'phone' && !phoneRex.test(value)) throw `请输入正确的${item.label}` if (item.value === 'phone' && !phoneRex.test(value)) throw `请输入正确的${item.label}`
} }
if (orderObj.carVin) { // if (orderObj.carVin) {
if (!utils.validateVIN(orderObj.carVin)) throw '车架号校验不匹配,请核对后重新输入' // if (!utils.validateVIN(orderObj.carVin)) throw '车架号校验不匹配,请核对后重新输入'
} // }
if (onlyLabelItem.length) { if (onlyLabelItem.length) {
const labelFields = ['skuGoods'] const labelFields = ['skuGoods']
......
...@@ -151,6 +151,7 @@ import dayjs from 'dayjs' ...@@ -151,6 +151,7 @@ import dayjs from 'dayjs'
import permision from '@/js_sdk/wa-permission/permission.js' import permision from '@/js_sdk/wa-permission/permission.js'
import { sign, md532, md516 } from 'utils/common' import { sign, md532, md516 } from 'utils/common'
import { signSecretKey } from '@/env.js' import { signSecretKey } from '@/env.js'
import { validateVin, formatVinInput } from '@/utils/vinVaildate'
export default { export default {
name: 'AddEvaluationFrom', name: 'AddEvaluationFrom',
components: { components: {
...@@ -548,7 +549,8 @@ export default { ...@@ -548,7 +549,8 @@ export default {
], ],
uploadOtherFields: [{ key: 41, label: '其他图片', required: false, accept: 'image', maxCount: 30, fullwidth: true }], uploadOtherFields: [{ key: 41, label: '其他图片', required: false, accept: 'image', maxCount: 30, fullwidth: true }],
currentField: null, currentField: null,
query: {} query: {},
validateVinState:null
} }
}, },
onLoad(options) { onLoad(options) {
...@@ -872,22 +874,38 @@ export default { ...@@ -872,22 +874,38 @@ export default {
} }
// 车架号验证 - 长度17且只能包含数字和大写字母 // 车架号验证 - 长度17且只能包含数字和大写字母
const vin = this.formData.carBaseReqDTO.vin // const vin = this.formData.carBaseReqDTO.vin
const vinRegex = /^[A-Z0-9]+$/ // const vinRegex = /^[A-Z0-9]+$/
if (!vinRegex.test(vin)) { // if (!vinRegex.test(vin)) {
uni.showToast({ // uni.showToast({
title: '车架号只能包含数字和大写字母', // title: '车架号只能包含数字和大写字母',
icon: 'none' // icon: 'none'
}) // })
return // return
// }
// if (vin.length != 17) {
// uni.showToast({
// title: '车架号必须为17位',
// icon: 'none'
// })
// return
// }
// VIN车架号-动态校验
const carVin = this.formData.carBaseReqDTO.vin
console.log("validateState",this.validateState);
if (carVin) {
// 前置判断
if (carVin.length !== 17) {
uni.showToast({title:'请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)',icon:'none'})
return false
}
// 根据接口校验结果判断
if (carVin.length === 17 && !this.validateState) {
uni.showToast({title:'车架号校验不匹配,请核对后重新输入',icon:'none'})
return false
} }
if (vin.length != 17) {
uni.showToast({
title: '车架号必须为17位',
icon: 'none'
})
return
} }
const engineNumber = this.formData.carBaseReqDTO.engineNumber const engineNumber = this.formData.carBaseReqDTO.engineNumber
const engineNumberRegex = /^[A-Za-z0-9]+$/ const engineNumberRegex = /^[A-Za-z0-9]+$/
...@@ -990,7 +1008,7 @@ export default { ...@@ -990,7 +1008,7 @@ export default {
}, },
handleCell(field) { handleCell(field) {
const that = this const that = this
console.log("handleCellAAAAA");
if (field.isCar) { if (field.isCar) {
this.openSelectCar() this.openSelectCar()
} else if (field.isCity) { } else if (field.isCity) {
...@@ -1110,6 +1128,17 @@ export default { ...@@ -1110,6 +1128,17 @@ export default {
if (upperValue !== value) { if (upperValue !== value) {
this.$set(this.formData.carBaseReqDTO, 'vin', upperValue) this.$set(this.formData.carBaseReqDTO, 'vin', upperValue)
} }
// VIN车架号动态校验:车架号字段,动态转换为大写
validateVin(upperValue).then(result => {
console.log("validateVin",result);
let { valid } = result.data;
this.validateState = valid
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
}).catch(err => {
console.log("validateVinErr",result);
})
} }
if (field.key === 'mileage') { if (field.key === 'mileage') {
let numValue = Number(value) let numValue = Number(value)
...@@ -1285,6 +1314,15 @@ export default { ...@@ -1285,6 +1314,15 @@ export default {
if (res.data.code == 0) { if (res.data.code == 0) {
if (res.data.data.status == 1) { if (res.data.data.status == 1) {
this.formData.carBaseReqDTO.vin = res.data.data.vin this.formData.carBaseReqDTO.vin = res.data.data.vin
validateVin(this.formData.carBaseReqDTO.vin).then(result => {
console.log("validateVin",result);
let { valid } = result.data;
this.validateState = valid
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
}).catch(err => {
console.log("validateVinErr",result);
})
uni.showToast({ title: '车架号识别完成并已自动填写到表单中', icon: 'none' }) uni.showToast({ title: '车架号识别完成并已自动填写到表单中', icon: 'none' })
uni.hideLoading() uni.hideLoading()
} else { } else {
......
import api from '@/api/index.js'
// 有效字符:大写 A-H/J-N/P-Z、0-9(排除 I、O、Q)
const VALID_VIN_REG = /^[A-HJ-NPR-Z0-9]{17}$/
const ERROR_MSG = '请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)'
// 防抖相关变量
let debounceTimer = null
let pendingResolve = null
let pendingReject = null
let pendingVin = null
const DEBOUNCE_DELAY = 500 // 防抖延迟时间(毫秒)
/**
* 车架号校验(统一处理版本)
* @param {string} vin - 车架号
* @returns {Promise<Object>} 返回校验结果 { success: boolean, message: string, data?: any, vin?: string }
*/
export function validateVin(vin) {
console.log("工具调用",vin);
return new Promise((resolve, reject) => {
const upperVin = vin ? vin.toUpperCase() : ''
// 格式校验失败
if (!upperVin || upperVin.length !== 17 || !VALID_VIN_REG.test(upperVin)) {
uni.showToast({
title: ERROR_MSG,
icon: 'none'
})
reject({
success: false,
message: ERROR_MSG
})
return
}
// 保存当前调用的 resolve 和 reject
pendingResolve = resolve
pendingReject = reject
pendingVin = upperVin
// 清除之前的定时器
if (debounceTimer) {
clearTimeout(debounceTimer)
}
// 设置防抖定时器
debounceTimer = setTimeout(() => {
// 执行接口调用
const currentVin = pendingVin
const currentResolve = pendingResolve
const currentReject = pendingReject
// 清空待处理变量
pendingVin = null
pendingResolve = null
pendingReject = null
debounceTimer = null
// 调用后端接口校验
api.commonApi.checkVinValidate({ vin: currentVin })
.then(res => {
console.log("checkVinValidate接口校验",res);
let { valid,message } = res
if (valid) {
// 校验成功但有提示信息
if (message) {
uni.showToast({
title: message,
icon: 'none'
})
}
currentResolve({
success: true,
message: message || '校验成功',
data: res,
vin: currentVin
})
} else {
// 接口返回失败
const errorMsg = message || '车架号校验失败'
uni.showToast({
title: errorMsg,
icon: 'none'
})
currentResolve({
success: false,
message: errorMsg,
data: res
})
}
})
.catch(err => {
const errorMsg = err.message || '车架号校验异常'
uni.showToast({
title: errorMsg,
icon: 'none'
})
currentReject({
success: false,
message: errorMsg
})
})
}, DEBOUNCE_DELAY)
})
}
/**
* 实时输入处理:自动转大写
*/
export function formatVinInput(value) {
return value ? value.toUpperCase() : ''
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!