|
@@ -132,11 +132,10 @@
|
|
|
>
|
|
|
<el-input-number
|
|
|
onmousewheel="return false;"
|
|
|
- :value="formData.data.purchaseDetailList[$index].count"
|
|
|
- :precision="2"
|
|
|
+ v-model="formData.data.purchaseDetailList[$index].count"
|
|
|
:controls="false"
|
|
|
:min="0"
|
|
|
- @change="(e) => handleChangeAmount(e, $index,'count')"
|
|
|
+ @change="(e) => handleChangeMoney(e, $index, 'count')"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
</template>
|
|
@@ -150,11 +149,10 @@
|
|
|
>
|
|
|
<el-input-number
|
|
|
onmousewheel="return false;"
|
|
|
- :value="formData.data.purchaseDetailList[$index].price"
|
|
|
- :precision="2"
|
|
|
+ v-model="formData.data.purchaseDetailList[$index].price"
|
|
|
:controls="false"
|
|
|
:min="0"
|
|
|
- @change="(e) => handleChangeAmount(e, $index,'price')"
|
|
|
+ @change="(e) => handleChangeMoney(e, $index, 'price')"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
</template>
|
|
@@ -217,10 +215,10 @@
|
|
|
:inline-message="true"
|
|
|
>
|
|
|
<el-input-number
|
|
|
- v-model="row.price"
|
|
|
- :precision="2"
|
|
|
+ onmousewheel="return false;"
|
|
|
+ v-model="formData.data.otherFeeList[$index].price"
|
|
|
:controls="false"
|
|
|
- @change="handleChangeAmount"
|
|
|
+ @change="(e) => handleChangeOtherMoney(e, $index, 'price')"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
</template>
|
|
@@ -687,42 +685,48 @@ const handleChangeSupplier = (val) => {
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
-const handleChangeProductAmount = () => {
|
|
|
- let sum = 0;
|
|
|
- for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
|
|
|
- const e = formData.data.purchaseDetailList[i];
|
|
|
- e.amount = parseFloat(e.count * e.price).toFixed(2);
|
|
|
- sum += Number(e.amount);
|
|
|
- }
|
|
|
- formData.data.productAmount = parseFloat(sum).toFixed(2);
|
|
|
-};
|
|
|
|
|
|
-const handleChangeOtherAmount = () => {
|
|
|
- let sum = 0;
|
|
|
- for (let i = 0; i < formData.data.otherFeeList.length; i++) {
|
|
|
- const e = formData.data.otherFeeList[i];
|
|
|
- sum += Number(e.price);
|
|
|
+const formatNumber = (value) => {
|
|
|
+ if (value === null || value === undefined || value === "") {
|
|
|
+ return "";
|
|
|
}
|
|
|
- formData.data.otherAmount = parseFloat(sum).toFixed(2);
|
|
|
+ // 将输入值保留四位小数
|
|
|
+ const formattedValue = parseFloat(value).toFixed(4);
|
|
|
+ // 移除多余的0
|
|
|
+ return parseFloat(formattedValue).toString();
|
|
|
};
|
|
|
|
|
|
// 计算采购总金额
|
|
|
-const handleChangeAmount = (e,index,key) => {
|
|
|
- console.log(e,index,key)
|
|
|
- formData.data.purchaseDetailList[index][key] = e
|
|
|
- handleChangeProductAmount();
|
|
|
- handleChangeOtherAmount();
|
|
|
- let sum = 0;
|
|
|
+const handleChangeAmount = () => {
|
|
|
+ let productAmount = 0;
|
|
|
for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
|
|
|
const e = formData.data.purchaseDetailList[i];
|
|
|
- e.amount = parseFloat(e.count * e.price).toFixed(2);
|
|
|
- sum += Number(e.amount);
|
|
|
+ e.amount = formatNumber(parseFloat(e.count * e.price));
|
|
|
+ productAmount += Number(e.amount);
|
|
|
}
|
|
|
+ formData.data.productAmount = formatNumber(productAmount);
|
|
|
+ // 其他收费
|
|
|
+ let otherAmount = 0;
|
|
|
for (let i = 0; i < formData.data.otherFeeList.length; i++) {
|
|
|
const e = formData.data.otherFeeList[i];
|
|
|
- sum += Number(e.price);
|
|
|
+ otherAmount += Number(e.price);
|
|
|
}
|
|
|
- formData.data.amount = parseFloat(sum).toFixed(2);
|
|
|
+ formData.data.otherAmount = formatNumber(otherAmount);
|
|
|
+ formData.data.amount = formatNumber(
|
|
|
+ parseFloat(
|
|
|
+ Number(formData.data.productAmount) + Number(formData.data.otherAmount)
|
|
|
+ )
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+const handleChangeMoney = (val, index, key) => {
|
|
|
+ formData.data.purchaseDetailList[index][key] = formatNumber(val);
|
|
|
+ handleChangeAmount();
|
|
|
+};
|
|
|
+
|
|
|
+const handleChangeOtherMoney = (val, index, key) => {
|
|
|
+ formData.data.otherFeeList[index][key] = formatNumber(val);
|
|
|
+ handleChangeAmount();
|
|
|
};
|
|
|
|
|
|
const productUnit = ref([]);
|