oa二期内容更新bug修复,存在问题物料品牌规格的多字段查询需要重新确立独立接口

This commit is contained in:
2024-12-17 11:33:00 +08:00
parent 5cbeeee3a1
commit d72af5d3e6
2 changed files with 110 additions and 52 deletions

View File

@@ -1,58 +1,108 @@
// currencyFormatter.js
export function numberToCNY(money) {
if (!money) {
return '';
}
if (typeof money == 'number') {
money = money + '';
}
money = money.replace(/,/g, ''); // 替换originalVal中的“,”
money = money.replace(/\\s/g, ''); // 替换originalVal中的“,”
export function numberToCNY(amount) {
if (amount === 0) return '零元整';
const CN_NUMS = ['', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
const CN_INT_UNITS = ['', '拾', '佰', '仟'];
const CN_INT_BASE = ['元', '萬', '億', '兆'];
const CN_DEC_UNITS = ['角', '分'];
const INT_MAX = Math.pow(10, 16) - 1;
if (amount >= INT_MAX || amount <= -INT_MAX) {
throw new Error('超出支持的金额范围');
money = money.replace("¥", "")//替换掉可能出现的¥字符
if (isNaN(money)) { //验证输入的字符是否为数字
return money;
}
let parts = amount.toString().split('.');
let integerPart = parts[0];
let decimalPart = parts[1] || '';
// 处理整数部分
function convertInteger(numStr) {
let result = '';
let zeros = 0;
let unitPos = 0;
for (let i = numStr.length - 1; i >= 0; i--) {
let num = parseInt(numStr.charAt(i));
if (num === 0) {
zeros++;
//汉字的数字
var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
//基本单位
var cnIntRadice = new Array('', '拾', '佰', '仟');
//对应整数部分扩展单位
var cnIntUnits = new Array('', '万', '亿', '兆');
//对应小数部分单位
var cnDecUnits = new Array('角', '分', '毫', '厘');
//整数金额时后面跟的字符
var cnInteger = '整';
//整型完以后的单位
var cnIntLast = '元';
//最大处理的数字
var maxNum = 999999999999999.9999;
//金额整数部分
var integerNum;
//金额小数部分
var decimalNum;
//输出的中文金额字符串
var chineseStr = '';
//分离金额后用的数组,预定义
var parts;
if (money == '') {
return '';
}
money = parseFloat(money);
if (money >= maxNum) {
//超出最大处理数字
return '';
}
if (money == 0) {
chineseStr = cnNums[0] + cnIntLast + cnInteger;
return chineseStr;
}
//转换为字符串
money = money.toString();
if (money.indexOf('.') == -1) {
integerNum = money;
decimalNum = '';
} else {
parts = money.split('.');
integerNum = parts[0];
decimalNum = parts[1].substr(0, 4);
}
//获取整型部分转换
if (parseInt(integerNum, 10) > 0) {
var zeroCount = 0;
var IntLen = integerNum.length;
for (var i = 0; i < IntLen; i++) {
var n = integerNum.substr(i, 1);
var p = IntLen - i - 1;
var q = p / 4;
var m = p % 4;
if (n == '0') {
zeroCount++;
} else {
if (zeros > 0) {
result = '零' + result;
if (zeroCount > 0) {
chineseStr += cnNums[0];
}
zeros = 0;
result = CN_NUMS[num] + CN_INT_UNITS[unitPos % 4] + result;
//归零
zeroCount = 0;
chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
}
unitPos++;
if (unitPos % 4 === 0 && i > 0) {
result = CN_INT_BASE[Math.floor(unitPos / 4) - 1] + result;
if (m == 0 && zeroCount < 4) {
chineseStr += cnIntUnits[q];
}
}
return result.trim();
chineseStr += cnIntLast;
}
// 处理小数部分
function convertDecimal(numStr) {
return numStr.split('').map((digit, index) => {
return digit !== '0' ? CN_NUMS[digit] + CN_DEC_UNITS[index] : '';
}).join('');
//小数部分
if (decimalNum != '') {
var decLen = decimalNum.length;
for (var i = 0; i < decLen; i++) {
var n = decimalNum.substr(i, 1);
if (i != 0) {
if (n != '0') {
chineseStr += cnNums[Number(n)] + cnDecUnits[i];
}
} else {
chineseStr += cnNums[Number(n)];
if (n != '0') {
chineseStr += cnDecUnits[i];
}
}
}
}
let integerResult = convertInteger(integerPart);
let decimalResult = decimalPart.length > 0 ? convertDecimal(decimalPart) : '';
// 连接整数和小数部分,并确保格式正确
let finalResult = integerResult.replace(/零+$/, '') + '元' + decimalResult;
finalResult = finalResult.replace(/零+/g, '零');
return finalResult;
if (chineseStr == '') {
chineseStr += cnNums[0] + cnIntLast + cnInteger;
} else if (decimalNum == '') {
chineseStr += cnInteger;
}
return chineseStr;
}

View File

@@ -273,6 +273,9 @@
:key="item.id"
:label="item.name"
:value="item.id">
<span style="">{{ item.name }}</span>
<span style="color: #8492a6; font-size: 13px" v-if="item.model!==undefined">-{{ item.model }}</span>
<span style="color: #8492a6; font-size: 13px" v-if="item.brand!==undefined">-{{ item.brand }}</span>
</el-option>
</el-select>
</el-col>
@@ -280,7 +283,7 @@
<el-tag type="info" v-if="item.inventory===undefined">请选择物料</el-tag>
<el-tag type="info" v-else>{{ item.inventory }}</el-tag>
</el-col>
<el-col :span="8">
<el-col :span="6">
<el-input-number v-model="item.amount" :min="1" :max="item.inventory"></el-input-number>
</el-col>
<el-col :span="4">
@@ -574,9 +577,12 @@ export default {
}
},
// 获取对应的库存 后续添加品牌型号
handleGetInventory(e, index) {
this.form.outWareHouseList[index].inventory = this.oaWarehouseList[this.oaWarehouseList.findIndex(item => item.id === e)].inventory
console.log(this.form.outWareHouseList[index])
let obj = this.oaWarehouseList[this.oaWarehouseList.findIndex(item => item.id === e)]
this.form.outWareHouseList[index].inventory = obj.inventory
this.form.outWareHouseList[index].model = obj.model
this.form.outWareHouseList[index].brand = obj.brand
},
@@ -607,8 +613,10 @@ export default {
this.selectLoading = true;
listOaWarehouse(this.warehouseParams).then(res => {
this.oaWarehouseList = res.rows.filter(item => {
return item.name.toLowerCase()
.indexOf(query.toLowerCase()) > -1;
const queryLower = query.toLowerCase();
return item.name.toLowerCase().indexOf(queryLower) > -1 ||
item.model.toLowerCase().indexOf(queryLower) > -1 ||
item.brand.toLowerCase().indexOf(queryLower) > -1;
});
this.selectLoading = false;
})