feat:【antd】【erp 系统】sale/order 部分代码优化(form 修复 init 问题)
This commit is contained in:
@@ -227,7 +227,7 @@ export function useFormItemColumns(): VxeTableGridOptions['columns'] {
|
|||||||
{
|
{
|
||||||
field: 'taxPercent',
|
field: 'taxPercent',
|
||||||
title: '税率(%)',
|
title: '税率(%)',
|
||||||
minWidth: 100,
|
minWidth: 105,
|
||||||
slots: { default: 'taxPercent' },
|
slots: { default: 'taxPercent' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,22 +61,16 @@ const handleUpdateItems = (items: ErpSaleOrderApi.SaleOrderItem[]) => {
|
|||||||
|
|
||||||
/** 更新优惠金额 */
|
/** 更新优惠金额 */
|
||||||
const handleUpdateDiscountPrice = (discountPrice: number) => {
|
const handleUpdateDiscountPrice = (discountPrice: number) => {
|
||||||
if (formData.value) {
|
|
||||||
formData.value.discountPrice = discountPrice;
|
|
||||||
formApi.setValues({
|
formApi.setValues({
|
||||||
discountPrice: formData.value.discountPrice,
|
discountPrice,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 更新总金额 */
|
/** 更新总金额 */
|
||||||
const handleUpdateTotalPrice = (totalPrice: number) => {
|
const handleUpdateTotalPrice = (totalPrice: number) => {
|
||||||
if (formData.value) {
|
|
||||||
formData.value.totalPrice = totalPrice;
|
|
||||||
formApi.setValues({
|
formApi.setValues({
|
||||||
totalPrice: formData.value.totalPrice,
|
totalPrice,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 创建或更新销售订单 */
|
/** 创建或更新销售订单 */
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ watch(
|
|||||||
if (!items) {
|
if (!items) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
items.forEach((item) => initRow(item));
|
||||||
tableData.value = [...items];
|
tableData.value = [...items];
|
||||||
await gridApi.grid.reloadData(tableData.value);
|
await gridApi.grid.reloadData(tableData.value);
|
||||||
},
|
},
|
||||||
@@ -100,27 +101,21 @@ watch(
|
|||||||
{ deep: true },
|
{ deep: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
/** 初始化 */
|
|
||||||
onMounted(async () => {
|
|
||||||
productOptions.value = await getProductSimpleList();
|
|
||||||
});
|
|
||||||
|
|
||||||
/** 处理新增 */
|
/** 处理新增 */
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
const newRow = {
|
const newRow = {
|
||||||
|
id: undefined,
|
||||||
productId: undefined,
|
productId: undefined,
|
||||||
productName: '',
|
productUnitName: undefined, // 产品单位
|
||||||
productUnitId: undefined,
|
productBarCode: undefined, // 产品条码
|
||||||
productUnitName: '',
|
productPrice: undefined,
|
||||||
productBarCode: '',
|
stockCount: undefined,
|
||||||
count: 1,
|
count: 1,
|
||||||
productPrice: 0,
|
totalProductPrice: undefined,
|
||||||
totalProductPrice: 0,
|
|
||||||
taxPercent: 0,
|
taxPercent: 0,
|
||||||
taxPrice: 0,
|
taxPrice: undefined,
|
||||||
totalPrice: 0,
|
totalPrice: undefined,
|
||||||
stockCount: 0,
|
remark: undefined,
|
||||||
remark: '',
|
|
||||||
};
|
};
|
||||||
tableData.value.push(newRow);
|
tableData.value.push(newRow);
|
||||||
gridApi.grid.insertAt(newRow, -1);
|
gridApi.grid.insertAt(newRow, -1);
|
||||||
@@ -153,22 +148,11 @@ async function handleProductChange(productId: any, row: any) {
|
|||||||
row.stockCount = (await getStockCount(productId)) || 0;
|
row.stockCount = (await getStockCount(productId)) || 0;
|
||||||
row.productPrice = product.salePrice || 0;
|
row.productPrice = product.salePrice || 0;
|
||||||
row.count = row.count || 1;
|
row.count = row.count || 1;
|
||||||
handlePriceChange(row);
|
handleRowChange(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 处理价格变更 */
|
/** 处理行数据变更 */
|
||||||
function handlePriceChange(row: any) {
|
function handleRowChange(row: any) {
|
||||||
if (row.productPrice && row.count) {
|
|
||||||
row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
|
||||||
row.taxPrice =
|
|
||||||
erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
|
|
||||||
row.totalPrice = row.totalProductPrice + row.taxPrice;
|
|
||||||
}
|
|
||||||
handleUpdateValue(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 更新行数据 */
|
|
||||||
function handleUpdateValue(row: any) {
|
|
||||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
tableData.value.push(row);
|
tableData.value.push(row);
|
||||||
@@ -178,6 +162,16 @@ function handleUpdateValue(row: any) {
|
|||||||
emit('update:items', [...tableData.value]);
|
emit('update:items', [...tableData.value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 初始化行数据 */
|
||||||
|
const initRow = (row: ErpSaleOrderApi.SaleOrderItem): void => {
|
||||||
|
if (row.productPrice && row.count) {
|
||||||
|
row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||||
|
row.taxPrice =
|
||||||
|
erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
|
||||||
|
row.totalPrice = row.totalProductPrice + row.taxPrice;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** 获取表格合计数据 */
|
/** 获取表格合计数据 */
|
||||||
function getSummaries(): {
|
function getSummaries(): {
|
||||||
count: number;
|
count: number;
|
||||||
@@ -225,6 +219,15 @@ function validate() {
|
|||||||
defineExpose({
|
defineExpose({
|
||||||
validate,
|
validate,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
onMounted(async () => {
|
||||||
|
productOptions.value = await getProductSimpleList();
|
||||||
|
// 目的:新增时,默认添加一行
|
||||||
|
if (tableData.value.length === 0) {
|
||||||
|
handleAdd();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -248,7 +251,7 @@ defineExpose({
|
|||||||
v-model:value="row.count"
|
v-model:value="row.count"
|
||||||
:min="0"
|
:min="0"
|
||||||
:precision="2"
|
:precision="2"
|
||||||
@change="handlePriceChange(row)"
|
@change="handleRowChange(row)"
|
||||||
/>
|
/>
|
||||||
<span v-else>{{ row.count || '-' }}</span>
|
<span v-else>{{ row.count || '-' }}</span>
|
||||||
</template>
|
</template>
|
||||||
@@ -259,7 +262,7 @@ defineExpose({
|
|||||||
v-model:value="row.productPrice"
|
v-model:value="row.productPrice"
|
||||||
:min="0"
|
:min="0"
|
||||||
:precision="2"
|
:precision="2"
|
||||||
@change="handlePriceChange(row)"
|
@change="handleRowChange(row)"
|
||||||
/>
|
/>
|
||||||
<span v-else>{{ row.productPrice || '-' }}</span>
|
<span v-else>{{ row.productPrice || '-' }}</span>
|
||||||
</template>
|
</template>
|
||||||
@@ -271,7 +274,7 @@ defineExpose({
|
|||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
:precision="2"
|
:precision="2"
|
||||||
@change="handlePriceChange(row)"
|
@change="handleRowChange(row)"
|
||||||
/>
|
/>
|
||||||
<span v-else>{{ row.taxPercent || '-' }}</span>
|
<span v-else>{{ row.taxPercent || '-' }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user