|
@@ -125,7 +125,7 @@
|
|
|
|
|
|
|
|
<el-table-column v-if="isCul" label="最终值" prop="result">
|
|
<el-table-column v-if="isCul" label="最终值" prop="result">
|
|
|
<template slot-scope="{ row }">
|
|
<template slot-scope="{ row }">
|
|
|
- <span>{{ row.result || '/' }}</span>
|
|
|
|
|
|
|
+ <span>{{ formatResult(row.result) }}</span>
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
|
|
|
|
@@ -175,9 +175,9 @@ export default {
|
|
|
isFirst: true,
|
|
isFirst: true,
|
|
|
forms: [],
|
|
forms: [],
|
|
|
multipleSelection: [],
|
|
multipleSelection: [],
|
|
|
- baoliuxiaoshu:true,
|
|
|
|
|
- config: 1,
|
|
|
|
|
- isUpdatingFromParent: false // 标记是否来自父组件的更新
|
|
|
|
|
|
|
+ baoliuxiaoshu: true,
|
|
|
|
|
+ config: 2,
|
|
|
|
|
+ isUpdatingFromParent: false // 标记是否来自父组件的更新
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
computed: {},
|
|
computed: {},
|
|
@@ -199,18 +199,17 @@ export default {
|
|
|
this.culXiuZheng()
|
|
this.culXiuZheng()
|
|
|
},
|
|
},
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
- handler(val) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ handler(val) {
|
|
|
if (val.lieBiaoShuJu) {
|
|
if (val.lieBiaoShuJu) {
|
|
|
// 标记开始内部更新,避免无限循环调用initData导致卡死(控制forms里的this.$emit的循环调用)
|
|
// 标记开始内部更新,避免无限循环调用initData导致卡死(控制forms里的this.$emit的循环调用)
|
|
|
- this.isUpdatingFromParent = true
|
|
|
|
|
|
|
+ this.isUpdatingFromParent = true
|
|
|
//现在每一次watch到数据变化,都会执行initData方法
|
|
//现在每一次watch到数据变化,都会执行initData方法
|
|
|
if (!this.isCul) {
|
|
if (!this.isCul) {
|
|
|
this.forms = this.initData(val.lieBiaoShuJu)
|
|
this.forms = this.initData(val.lieBiaoShuJu)
|
|
|
} else {
|
|
} else {
|
|
|
this.forms = this.initData(val.lieBiaoShuJu)
|
|
this.forms = this.initData(val.lieBiaoShuJu)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
this.culXiuZheng()
|
|
this.culXiuZheng()
|
|
|
},
|
|
},
|
|
@@ -226,13 +225,13 @@ export default {
|
|
|
this.$emit('change-data', 'lieBiaoShuJu', JSON.stringify(val))
|
|
this.$emit('change-data', 'lieBiaoShuJu', JSON.stringify(val))
|
|
|
},
|
|
},
|
|
|
*/
|
|
*/
|
|
|
- handler(val) {
|
|
|
|
|
|
|
+ handler(val) {
|
|
|
this.culXiuZheng()
|
|
this.culXiuZheng()
|
|
|
//只有非内部更新时才向父组件发送数据(避免无限循环的调用导致卡死,由formData里的方法对该变量控制)
|
|
//只有非内部更新时才向父组件发送数据(避免无限循环的调用导致卡死,由formData里的方法对该变量控制)
|
|
|
if (!this.isUpdatingFromParent) {
|
|
if (!this.isUpdatingFromParent) {
|
|
|
this.$emit('change-data', 'lieBiaoShuJu', JSON.stringify(val))
|
|
this.$emit('change-data', 'lieBiaoShuJu', JSON.stringify(val))
|
|
|
} else {
|
|
} else {
|
|
|
- this.isUpdatingFromParent = false // 重置标记
|
|
|
|
|
|
|
+ this.isUpdatingFromParent = false // 重置标记
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
deep: true
|
|
deep: true
|
|
@@ -319,7 +318,11 @@ export default {
|
|
|
}
|
|
}
|
|
|
// this.formData.jianCeShiJian = '2025-03-01' // 测试用
|
|
// this.formData.jianCeShiJian = '2025-03-01' // 测试用
|
|
|
if (
|
|
if (
|
|
|
- !item.result && item.rate && (this.formData.jianCeShiJian || this.formData.bianZhiShiJian || this.readonly)
|
|
|
|
|
|
|
+ !item.result &&
|
|
|
|
|
+ item.rate &&
|
|
|
|
|
+ (this.formData.jianCeShiJian ||
|
|
|
|
|
+ this.formData.bianZhiShiJian ||
|
|
|
|
|
+ this.readonly)
|
|
|
) {
|
|
) {
|
|
|
let jianCeShiJian = ''
|
|
let jianCeShiJian = ''
|
|
|
if (this.readonly || !this.formData.jianCeShiJian) {
|
|
if (this.readonly || !this.formData.jianCeShiJian) {
|
|
@@ -409,20 +412,22 @@ export default {
|
|
|
const self = this
|
|
const self = this
|
|
|
this.forms.forEach((item) => {
|
|
this.forms.forEach((item) => {
|
|
|
if (item.value) {
|
|
if (item.value) {
|
|
|
- if(!self.baoliuxiaoshu && self.formData.leiXing === '纯水机') { //绍兴环境,纯水机不需要保留小数
|
|
|
|
|
|
|
+ if (!self.baoliuxiaoshu && self.formData.leiXing === '纯水机') {
|
|
|
|
|
+ //绍兴环境,纯水机不需要保留小数
|
|
|
if (item.fixValue) {
|
|
if (item.fixValue) {
|
|
|
- item.result = self.addStringDecimals(item.fixValue,item.value)
|
|
|
|
|
|
|
+ item.result = self.addStringDecimals(item.fixValue, item.value)
|
|
|
} else {
|
|
} else {
|
|
|
- item.result = (+item.value)
|
|
|
|
|
|
|
+ item.result = +item.value
|
|
|
}
|
|
}
|
|
|
- }else{ //其他环境、其他页面
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //其他环境、其他页面
|
|
|
if (item.fixValue) {
|
|
if (item.fixValue) {
|
|
|
item.result = (+item.fixValue + +item.value).toFixed(this.config)
|
|
item.result = (+item.fixValue + +item.value).toFixed(this.config)
|
|
|
} else {
|
|
} else {
|
|
|
- item.result = (+item.value)//无修正值时不处理小数位
|
|
|
|
|
|
|
+ item.result = +item.value //无修正值时不处理小数位
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
item.status = this.getStatus(item.range, item.result)
|
|
item.status = this.getStatus(item.range, item.result)
|
|
|
} else {
|
|
} else {
|
|
|
item.result = ''
|
|
item.result = ''
|
|
@@ -430,6 +435,19 @@ export default {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+ // 展示用格式化:保留两位小数(向下取值),末尾可省略的0不展示
|
|
|
|
|
+ formatResult(val) {
|
|
|
|
|
+ if (val === '' || val === null || val === undefined) return '/'
|
|
|
|
|
+ const num = Number(val)
|
|
|
|
|
+ if (Number.isNaN(num)) return val
|
|
|
|
|
+ // 向下取值保留两位小数
|
|
|
|
|
+ const floored = Math.floor(num * 100) / 100
|
|
|
|
|
+ let str = String(floored)
|
|
|
|
|
+ if (str.includes('.')) {
|
|
|
|
|
+ str = str.replace(/0+$/, '').replace(/\.$/, '')
|
|
|
|
|
+ }
|
|
|
|
|
+ return str
|
|
|
|
|
+ },
|
|
|
formatData(val) {
|
|
formatData(val) {
|
|
|
return JSON.stringify(val)
|
|
return JSON.stringify(val)
|
|
|
},
|
|
},
|
|
@@ -453,55 +471,52 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
addStringDecimals(a, b) {
|
|
addStringDecimals(a, b) {
|
|
|
- // 分割整数和小数部分
|
|
|
|
|
- const [int1, dec1 = ''] = a.split('.');
|
|
|
|
|
- const [int2, dec2 = ''] = b.split('.');
|
|
|
|
|
-
|
|
|
|
|
- // 计算最大小数位数
|
|
|
|
|
- const maxDecimal = Math.max(dec1.length, dec2.length);
|
|
|
|
|
-
|
|
|
|
|
- // 小数部分补零对齐
|
|
|
|
|
- const paddedDec1 = dec1.padEnd(maxDecimal, '0');
|
|
|
|
|
- const paddedDec2 = dec2.padEnd(maxDecimal, '0');
|
|
|
|
|
-
|
|
|
|
|
- // 拼接完整整数(原值 × 10^maxDecimal)
|
|
|
|
|
- const fullInt1 = int1 + paddedDec1;
|
|
|
|
|
- const fullInt2 = int2 + paddedDec2;
|
|
|
|
|
-
|
|
|
|
|
- // 大整数相加
|
|
|
|
|
- let carry = 0;
|
|
|
|
|
- let result = '';
|
|
|
|
|
- let i = fullInt1.length - 1;
|
|
|
|
|
- let j = fullInt2.length - 1;
|
|
|
|
|
-
|
|
|
|
|
- while (i >= 0 || j >= 0 || carry) {
|
|
|
|
|
- const digit1 = i >= 0 ? parseInt(fullInt1[i--], 10) : 0;
|
|
|
|
|
- const digit2 = j >= 0 ? parseInt(fullInt2[j--], 10) : 0;
|
|
|
|
|
- const sum = digit1 + digit2 + carry;
|
|
|
|
|
- carry = Math.floor(sum / 10);
|
|
|
|
|
- result = (sum % 10) + result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 处理前导零
|
|
|
|
|
- result = result.replace(/^0+/, '') || '0';
|
|
|
|
|
-
|
|
|
|
|
- // 插入小数点
|
|
|
|
|
- if (maxDecimal > 0) {
|
|
|
|
|
- const pos = result.length - maxDecimal;
|
|
|
|
|
|
|
+ // 分割整数和小数部分
|
|
|
|
|
+ const [int1, dec1 = ''] = a.split('.')
|
|
|
|
|
+ const [int2, dec2 = ''] = b.split('.')
|
|
|
|
|
+
|
|
|
|
|
+ // 计算最大小数位数
|
|
|
|
|
+ const maxDecimal = Math.max(dec1.length, dec2.length)
|
|
|
|
|
+
|
|
|
|
|
+ // 小数部分补零对齐
|
|
|
|
|
+ const paddedDec1 = dec1.padEnd(maxDecimal, '0')
|
|
|
|
|
+ const paddedDec2 = dec2.padEnd(maxDecimal, '0')
|
|
|
|
|
+
|
|
|
|
|
+ // 拼接完整整数(原值 × 10^maxDecimal)
|
|
|
|
|
+ const fullInt1 = int1 + paddedDec1
|
|
|
|
|
+ const fullInt2 = int2 + paddedDec2
|
|
|
|
|
+
|
|
|
|
|
+ // 大整数相加
|
|
|
|
|
+ let carry = 0
|
|
|
|
|
+ let result = ''
|
|
|
|
|
+ let i = fullInt1.length - 1
|
|
|
|
|
+ let j = fullInt2.length - 1
|
|
|
|
|
+
|
|
|
|
|
+ while (i >= 0 || j >= 0 || carry) {
|
|
|
|
|
+ const digit1 = i >= 0 ? parseInt(fullInt1[i--], 10) : 0
|
|
|
|
|
+ const digit2 = j >= 0 ? parseInt(fullInt2[j--], 10) : 0
|
|
|
|
|
+ const sum = digit1 + digit2 + carry
|
|
|
|
|
+ carry = Math.floor(sum / 10)
|
|
|
|
|
+ result = (sum % 10) + result
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理前导零
|
|
|
|
|
+ result = result.replace(/^0+/, '') || '0'
|
|
|
|
|
+
|
|
|
|
|
+ // 插入小数点
|
|
|
|
|
+ if (maxDecimal > 0) {
|
|
|
|
|
+ const pos = result.length - maxDecimal
|
|
|
if (pos <= 0) {
|
|
if (pos <= 0) {
|
|
|
- // 整数部分为零的情况
|
|
|
|
|
- result = '0.' + result.padStart(maxDecimal, '0');
|
|
|
|
|
|
|
+ // 整数部分为零的情况
|
|
|
|
|
+ result = '0.' + result.padStart(maxDecimal, '0')
|
|
|
} else {
|
|
} else {
|
|
|
- // 正常插入小数点
|
|
|
|
|
- result =
|
|
|
|
|
- result.slice(0, pos) +
|
|
|
|
|
- '.' +
|
|
|
|
|
- result.slice(pos);
|
|
|
|
|
|
|
+ // 正常插入小数点
|
|
|
|
|
+ result = result.slice(0, pos) + '.' + result.slice(pos)
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
-},
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result
|
|
|
|
|
+ },
|
|
|
goRemove() {
|
|
goRemove() {
|
|
|
this.forms = this.forms.filter(
|
|
this.forms = this.forms.filter(
|
|
|
(item) => !this.multipleSelection.includes(item)
|
|
(item) => !this.multipleSelection.includes(item)
|