From 57bab40cc98e3432f7791caa64a598ac375f593d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A3=B7=E5=8F=B6?=
<14103883+leaf-phos@user.noreply.gitee.com>
Date: Fri, 28 Mar 2025 08:58:40 +0800
Subject: [PATCH] deubg
---
src/components/Business/Price/PriceSelect.vue | 2 +
src/utils/index.js | 6 ++-
.../edit-v2/components/ReportProductList.vue | 50 +++++++++++++++----
.../components/ReportProductOrderList.vue | 17 ++++++-
.../components/ReportProductUserList.vue | 18 +++++--
src/views/yh/reportProd/index.vue | 1 +
6 files changed, 79 insertions(+), 15 deletions(-)
diff --git a/src/components/Business/Price/PriceSelect.vue b/src/components/Business/Price/PriceSelect.vue
index c3c5ef5..822a333 100644
--- a/src/components/Business/Price/PriceSelect.vue
+++ b/src/components/Business/Price/PriceSelect.vue
@@ -132,6 +132,7 @@ export default {
...this.query
}
try {
+ console.log("queryParams", this.queryParams);
let res = await listPrice(this.queryParams);
this.options = res.rows;
this.total = res.total;
@@ -142,6 +143,7 @@ export default {
// 获取选项列表,并选中第一个
async getOptionsAndSelectFirst() {
await this.getOptions();
+ console.log(this.options);
if (this.options.length > 0) {
let value = this.options[0].priceId;
this.selectedValue = value;
diff --git a/src/utils/index.js b/src/utils/index.js
index 91ecb38..0cafd69 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -431,7 +431,11 @@ export function notNullDecimal(val) {
if (isEmpty(val)) {
return new Decimal(0);
}
- return new Decimal(val);
+ try {
+ return new Decimal(val);
+ } catch (e) {
+ return new Decimal(0);
+ }
}
/**
diff --git a/src/views/yh/report/edit-v2/components/ReportProductList.vue b/src/views/yh/report/edit-v2/components/ReportProductList.vue
index 8cf8d40..eab92f0 100644
--- a/src/views/yh/report/edit-v2/components/ReportProductList.vue
+++ b/src/views/yh/report/edit-v2/components/ReportProductList.vue
@@ -70,7 +70,7 @@
-
+ handleChangeNum(d.row, val)">
{{d.row.priceUnit | dv}}
@@ -256,6 +256,8 @@ export default {
computed: {
priceQuery() {
return (row) => {
+ // 每次调用该方法时都会使用最新的row数据来构建查询参数
+ console.log("priceQuery with updated row data:", row);
return {
deptId: this.form.deptId,
statusList: PriceStatus.canUse(),
@@ -282,6 +284,22 @@ export default {
this.showPattern = localStorage.getItem("report_show_pattern") === "true";
},
methods: {
+ // 判断良品是公式则计算出结果
+ handleChangeNum(row, val) {
+ if (val != null) {
+ if (typeof val === 'string' && /[+\-*/]/.test(val)) {
+ try {
+ // 使用eval计算公式
+ row.num = eval(val);
+ } catch (e) {
+ console.error('公式计算错误:', e);
+ row.num = notNullDecimal(val).toNumber();
+ }
+ } else {
+ row.num = notNullDecimal(val).toNumber();
+ }
+ }
+ },
getList() {
if (this.loadLoading) {
return;
@@ -358,7 +376,14 @@ export default {
},
// 选择工序
selectPrice(index) {
- this.$refs[`priceSelect${index}`].getOptionsAndSelectFirst();
+ // 获取当前行对象
+ const row = this.form.productList[index];
+ // 确保PriceSelect组件能获取到最新的参数
+ this.$nextTick(() => {
+ if (this.$refs[`priceSelect${index}`]) {
+ this.$refs[`priceSelect${index}`].getOptionsAndSelectFirst();
+ }
+ });
},
// 优化展开行处理
handleDetail(row) {
@@ -511,20 +536,25 @@ export default {
inputPlaceholder: `请输入【${fieldName}】`,
}).then(({ value }) => {
let isEditPrice = ['priceCategory', 'priceSize', 'pricePattern', 'priceName'].includes(prop);
- this.$nextTick(() => {
- for (let i = 0; i < this.rows.length; i++) {
- let row = this.rows[i];
- row[prop] = value;
- }
- if (isEditPrice) {
+
+ // 先批量设置属性值
+ for (let i = 0; i < this.rows.length; i++) {
+ let row = this.rows[i];
+ row[prop] = value;
+ }
+
+ // 如果是修改价格相关字段,需要重新查询单价
+ if (isEditPrice) {
+ // 使用nextTick确保UI更新后再查询价格
+ this.$nextTick(() => {
for (let i = 0; i < this.rows.length; i++) {
let index = this.form.productList.indexOf(this.rows[i]);
if (index != -1) {
this.selectPrice(index);
}
}
- }
- })
+ });
+ }
this.$message.success(`批量编辑成功,一共修改了${this.rows.length}行数据`);
})
},
diff --git a/src/views/yh/report/edit-v2/components/ReportProductOrderList.vue b/src/views/yh/report/edit-v2/components/ReportProductOrderList.vue
index 069409d..69bdf80 100644
--- a/src/views/yh/report/edit-v2/components/ReportProductOrderList.vue
+++ b/src/views/yh/report/edit-v2/components/ReportProductOrderList.vue
@@ -27,7 +27,7 @@
-
+ handleChangeNum(d.row, val)">
{{prod.priceUnit | dv}}
@@ -111,6 +111,21 @@ export default {
}
},
methods: {
+ handleChangeNum(row, val) {
+ if (val != null) {
+ if (typeof val === 'string' && /[+\-*/]/.test(val)) {
+ try {
+ // 使用eval计算公式
+ row.num = eval(val);
+ } catch (e) {
+ console.error('公式计算错误:', e);
+ row.num = notNullDecimal(val).toNumber();
+ }
+ } else {
+ row.num = notNullDecimal(val).toNumber();
+ }
+ }
+ },
getSummary({ columns, data }) {
const sums = [];
columns.forEach((column, index) => {
diff --git a/src/views/yh/report/edit-v2/components/ReportProductUserList.vue b/src/views/yh/report/edit-v2/components/ReportProductUserList.vue
index c0f0db9..305d8cb 100644
--- a/src/views/yh/report/edit-v2/components/ReportProductUserList.vue
+++ b/src/views/yh/report/edit-v2/components/ReportProductUserList.vue
@@ -17,7 +17,7 @@
-
+ handleChangeNum(d.row, val)">
{{prod.priceUnit | dv}}
@@ -137,11 +137,23 @@ export default {
return sums;
},
listUserWithShift,
- handleChangeNum() {
+ handleChangeNum(row, val) {
+ if (val != null) {
+ if (typeof val === 'string' && /[+\-*/]/.test(val)) {
+ try {
+ // 使用eval计算公式
+ row.num = eval(val);
+ } catch (e) {
+ console.error('公式计算错误:', e);
+ row.num = notNullDecimal(val).toNumber();
+ }
+ } else {
+ row.num = notNullDecimal(val).toNumber();
+ }
+ }
this.emitChangeNum();
},
emitChangeNum() {
- console.log('emitChangeNum');
this.$emit('change-num');
},
handleSelectionChange(selection) {
diff --git a/src/views/yh/reportProd/index.vue b/src/views/yh/reportProd/index.vue
index 9bd82b1..7f58c02 100644
--- a/src/views/yh/reportProd/index.vue
+++ b/src/views/yh/reportProd/index.vue
@@ -264,6 +264,7 @@ export default {
{key: 'defectNum', visible: false, label: '不良品', minWidth: null, sortable: true, overflow: false, align: 'center', width: "100"},
{key: 'pricePrice', visible: true, label: '单价', minWidth: null, sortable: true, overflow: false, align: 'right', width: null},
{key: 'totalAmount', visible: true, label: '总价', minWidth: null, sortable: true, overflow: false, align: 'right', width: null},
+ {key: 'remark', visible: true, label: '备注', minWidth: null, sortable: true, overflow: true, align: 'center', width: null},
{key: 'priceSpec', visible: false, label: '规格', minWidth: null, sortable: true, overflow: false, align: 'center', width: null},
{key: 'priceClassify', visible: false, label: '分类', minWidth: null, sortable: true, overflow: false, align: 'center', width: null},
{key: 'priceQuantity', visible: false, label: '倍数', minWidth: null, sortable: true, overflow: false, align: 'center', width: null},