优化商品的条码的自增逻辑,解决长条码的问题

This commit is contained in:
jishenghua
2025-12-25 22:30:03 +08:00
parent 1d5f0aefa8
commit 0a1a599a9d
3 changed files with 48 additions and 13 deletions

View File

@@ -564,6 +564,36 @@ export function getPrevMonthFormatDate(monthNum) {
return prevMonth.getFullYear() + seperator1 + month + seperator1 + strDate
}
/**
* 自定义大数加法函数,两个数字相加
* @param a
* @param b
* @returns {string}
*/
export function addBigNumbers(a, b) {
a = a.toString();
b = b.toString();
// 反转字符串,从个位开始计算
let aRev = a.split('').reverse();
let bRev = b.split('').reverse();
const maxLength = Math.max(aRev.length, bRev.length);
let result = [];
let carry = 0;
for (let i = 0; i < maxLength; i++) {
const digitA = i < aRev.length ? parseInt(aRev[i]) : 0;
const digitB = i < bRev.length ? parseInt(bRev[i]) : 0;
const sum = digitA + digitB + carry;
result.push(sum % 10);
carry = Math.floor(sum / 10);
}
// 处理最后的进位
if (carry > 0) {
result.push(carry);
}
// 反转回来得到正确的结果
return result.reverse().join('');
}
/**
* JS中根据指定值删除数组中的元素
* @param arrylist

View File

@@ -294,7 +294,7 @@
import JEditableTable from '@/components/jeecg/JEditableTable'
import { FormTypes, getRefPromise, VALIDATE_NO_PASSED, validateFormAndTables } from '@/utils/JEditableTableUtil'
import { changeNameToPinYin, checkMaterial, checkMaterialBarCode, getMaterialAttributeNameList, getMaterialAttributeValueListById, getMaxBarCode, queryMaterialCategoryTreeList } from '@/api/api'
import { autoJumpNextInput, handleIntroJs, removeByVal } from '@/utils/util'
import { autoJumpNextInput, handleIntroJs, removeByVal, addBigNumbers } from '@/utils/util'
import { getAction, httpAction } from '@/api/manage'
import JImageUpload from '@/components/jeecg/JImageUpload'
import JDate from '@/components/jeecg/JDate'
@@ -578,11 +578,14 @@
if(this.action === 'copyAdd') {
getMaxBarCode({}).then((res)=> {
if (res && res.code === 200) {
let maxBarCode = res.data.barCode - 0
let maxBarCode = res.data.barCode
let meTableData = []
for (let i = 0; i < tab.dataSource.length; i++) {
let meInfo = tab.dataSource[i]
meInfo.barCode = maxBarCode + i + 1
console.log(maxBarCode)
console.log(addBigNumbers(maxBarCode, i+1))
meInfo.barCode = addBigNumbers(maxBarCode, i+1)
console.log(meInfo.barCode)
meTableData.push(meInfo)
}
tab.dataSource = meTableData
@@ -1025,7 +1028,7 @@
getMaxBarCode({}).then((res)=>{
if(res && res.code===200) {
let k = 0
let maxBarCode = res.data.barCode-0
let maxBarCode = res.data.barCode
for (let i = 0; i < barCodeSku.length; i++) {
let currentBarCode = ''
let currentId = ''
@@ -1050,7 +1053,7 @@
wholesaleDecimal: wholesaleDecimal, lowDecimal: lowDecimal})
} else {
k = k+1
currentBarCode = maxBarCode + k
currentBarCode = addBigNumbers(maxBarCode, k)
meTableData.push({barCode: currentBarCode, commodityUnit: unit, sku: barCodeSku[i]})
}
}
@@ -1080,13 +1083,13 @@
if(this.maxBarCodeInfo === '') {
getMaxBarCode({}).then((res)=> {
if (res && res.code === 200) {
this.maxBarCodeInfo = res.data.barCode - 0
this.maxBarCodeInfo = this.maxBarCodeInfo + 1
this.maxBarCodeInfo = res.data.barCode
this.maxBarCodeInfo = addBigNumbers(this.maxBarCodeInfo, 1)
target.setValues([{rowKey: row.id, values: {barCode: this.maxBarCodeInfo, commodityUnit: unit?unit:''}}])
}
})
} else {
this.maxBarCodeInfo = this.maxBarCodeInfo + 1
this.maxBarCodeInfo = addBigNumbers(this.maxBarCodeInfo, 1)
target.setValues([{rowKey: row.id, values: {barCode: this.maxBarCodeInfo, commodityUnit: unit?unit:''}}])
}
},