|
|
@@ -432,8 +432,7 @@ function onSuccess(response: any) { |
|
|
|
return newarr |
|
|
|
}) |
|
|
|
addForm.value.detailList = newarr; |
|
|
|
//进行排序 |
|
|
|
startIdSort(); |
|
|
|
|
|
|
|
ElMessage.success(res.message) |
|
|
|
} else { |
|
|
|
ElMessage.error(res.message) |
|
|
@@ -442,19 +441,6 @@ function onSuccess(response: any) { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//号段排序,空格排到最后 |
|
|
|
function startIdSort() { |
|
|
|
addForm.value.detailList = addForm.value.detailList.sort((a, b) => { |
|
|
|
const isAEmpty = a.startId === "" || a.startId === undefined || a.startId === null; |
|
|
|
const isBEmpty = b.startId === "" || b.startId === undefined || b.startId === null; |
|
|
|
if (isAEmpty && !isBEmpty) return 1; // a是空,b不是,a排在后面 |
|
|
|
if (!isAEmpty && isBEmpty) return -1; // a不是空,b是空,a排在前面 |
|
|
|
if (isAEmpty && isBEmpty) return 0; |
|
|
|
// 使用字符串比较避免精度问题 |
|
|
|
return a.startId.localeCompare(b.startId); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 初始化还原数据 |
|
|
|
function clearData() { |
|
|
|
addForm.value = cloneDeep(initForm); |
|
|
@@ -562,27 +548,25 @@ function addMoreHandle(row: IObject) { |
|
|
|
} |
|
|
|
|
|
|
|
// 校验起始编号 |
|
|
|
function validateStartId( |
|
|
|
rule: any, |
|
|
|
value: string, |
|
|
|
callback: (e?: Error) => any |
|
|
|
) { |
|
|
|
let inventoryType = addForm.value.inventoryType; |
|
|
|
function validateStartId(rule: any, value: string, callback: (e?: Error) => any) { |
|
|
|
|
|
|
|
|
|
|
|
let indexArr = rule.field.split("-"); |
|
|
|
let index = indexArr[1]; |
|
|
|
let index = parseInt(indexArr[1]); |
|
|
|
let val = indexArr[2]; |
|
|
|
const detailList = addForm.value.detailList |
|
|
|
|
|
|
|
if (!isNumber(val)) { |
|
|
|
return callback(new Error("必须是数字!")); |
|
|
|
} |
|
|
|
let length = val.length; |
|
|
|
//长度校验 |
|
|
|
let inventoryType = addForm.value.inventoryType; |
|
|
|
if (inventoryType === "CARD" && length !== 20) { |
|
|
|
return callback(new Error("卡编号位数是20!")); |
|
|
|
} else if (inventoryType === "OBU" && length !== 16) { |
|
|
|
return callback(new Error("OBU编号位数是16!")); |
|
|
|
} |
|
|
|
//进行排序 |
|
|
|
startIdSort(); |
|
|
|
// 开始编号不能大于结束编号校验 |
|
|
|
if ( |
|
|
|
val && |
|
|
@@ -591,16 +575,47 @@ function validateStartId( |
|
|
|
) { |
|
|
|
return callback(new Error("开始编号不能大于结束编号")); |
|
|
|
} |
|
|
|
if ( |
|
|
|
val && index > 0 && |
|
|
|
addForm.value.detailList[index - 1].endId && |
|
|
|
BigInt(val) <= BigInt(addForm.value.detailList[index - 1].endId) |
|
|
|
) { |
|
|
|
return callback(new Error("开始编号要大于上一段的结束编号")); |
|
|
|
|
|
|
|
for (let i = 0; i < detailList.length; i++) { |
|
|
|
if (i === index) continue |
|
|
|
|
|
|
|
const otherRow = detailList[i] |
|
|
|
const otherStart = otherRow.startId |
|
|
|
const otherEnd = otherRow.endId |
|
|
|
|
|
|
|
if (otherStart && otherEnd) { |
|
|
|
if ( |
|
|
|
compareLargeNumbers(val, otherStart) >= 0 && |
|
|
|
compareLargeNumbers(val, otherEnd) <= 0 |
|
|
|
) { |
|
|
|
return callback(new Error(`号段范围与第 ${i + 1} 行重叠!`)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
callback(); |
|
|
|
} |
|
|
|
|
|
|
|
function compareLargeNumbers(a, b) { |
|
|
|
// 首先比较长度 |
|
|
|
if (a.length !== b.length) { |
|
|
|
return a.length > b.length ? 1 : -1; |
|
|
|
} |
|
|
|
|
|
|
|
// 长度相同,逐位比较 |
|
|
|
for (let i = 0; i < a.length; i++) { |
|
|
|
const digitA = parseInt(a[i], 10); |
|
|
|
const digitB = parseInt(b[i], 10); |
|
|
|
|
|
|
|
if (digitA > digitB) return 1; |
|
|
|
if (digitA < digitB) return -1; |
|
|
|
} |
|
|
|
|
|
|
|
// 完全相等 |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 校验结束编号 |
|
|
|
//编号规则。设备类型是卡的话,位数是20位 设备类型是OBU的话,位数的16位 |
|
|
|
function validateEndId(rule: any, value: string, callback: (e?: Error) => any) { |
|
|
@@ -621,7 +636,7 @@ function validateEndId(rule: any, value: string, callback: (e?: Error) => any) { |
|
|
|
if ( |
|
|
|
val && |
|
|
|
addForm.value.detailList[index].startId && |
|
|
|
BigInt(val) < (addForm.value.detailList[index].startId) |
|
|
|
val < (addForm.value.detailList[index].startId) |
|
|
|
) { |
|
|
|
return callback(new Error("结束编号不能小于开始编号")); |
|
|
|
} |