| | |
| | | import { Input, InputNumber, Select } from 'ant-design-vue'; |
| | | |
| | | import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; |
| | | import { getItemPage } from '#/api/mdm/item'; |
| | | import { getWarehouseStockCount } from '#/api/erp/stock/stock'; |
| | | import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse'; |
| | | import { MdmItemSelect } from '#/views/basicData/mdm/components'; |
| | | |
| | | import { useFormItemColumns } from '../data'; |
| | | |
| | |
| | | ]); |
| | | |
| | | const tableData = ref<ErpSaleReturnApi.SaleReturnItem[]>([]); // 表格数据 |
| | | const productOptions = ref<MdmItemApi.Item[]>([]); // 物料下拉选项 |
| | | const warehouseOptions = ref<any[]>([]); // 仓库下拉选项 |
| | | |
| | | /** 获取表格合计数据 */ |
| | |
| | | emit('update:items', [...tableData.value]); |
| | | } |
| | | |
| | | /** 处理产品变更:优先从关联订单物料中填充,兜底从全部物料中查找 */ |
| | | function handleProductChange(row: ErpSaleReturnApi.SaleReturnItem) { |
| | | /** 处理产品变更:优先从关联订单物料中填充,兜底使用弹框选中的物料 */ |
| | | function handleProductChange( |
| | | row: ErpSaleReturnApi.SaleReturnItem, |
| | | item?: MdmItemApi.Item, |
| | | ) { |
| | | // 优先从关联订单的物料中查找 |
| | | const orderItem = props.orderItems.find( |
| | | (item) => item.productId === row.productId, |
| | | (order) => order.productId === row.productId, |
| | | ); |
| | | if (orderItem) { |
| | | row.productName = orderItem.productName; |
| | |
| | | handleRowChange(row); |
| | | return; |
| | | } |
| | | // 兜底:从全部物料中查找 |
| | | const product = productOptions.value.find((item) => item.id === row.productId); |
| | | if (product) { |
| | | row.productName = product.name || ''; |
| | | row.productPrice = product.salesPrice ?? 0; |
| | | row.productUnitId = product.unitMeasureId; |
| | | row.productUnitName = product.unitMeasureName; |
| | | row.productBarCode = product.barCode; |
| | | if (item) { |
| | | row.productName = item.name || ''; |
| | | row.productPrice = item.salesPrice ?? 0; |
| | | row.productUnitId = item.unitMeasureId; |
| | | row.productUnitName = item.unitMeasureName; |
| | | row.productBarCode = item.barCode; |
| | | row.taxPercent = 0; |
| | | row.count = row.count || 1; |
| | | handleRowChange(row); |
| | |
| | | |
| | | /** 处理行数据变更 */ |
| | | function handleRowChange(row: any) { |
| | | recalcRow(row); |
| | | const index = tableData.value.findIndex((item) => item.seq === row.seq); |
| | | if (index === -1) { |
| | | tableData.value.push(row); |
| | |
| | | emit('update:items', [...tableData.value]); |
| | | } |
| | | |
| | | /** 初始化行数据 */ |
| | | function initRow(row: ErpSaleReturnApi.SaleReturnItem) { |
| | | /** |
| | | * 重算行金额(单价为**含税**单价) |
| | | * 含税金额 = 含税单价 × 数量;税额 = 含税金额 × 税率;不含税金额 = 含税金额 - 税额 |
| | | */ |
| | | function recalcRow(row: ErpSaleReturnApi.SaleReturnItem) { |
| | | if (row.productPrice && row.count) { |
| | | row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0; |
| | | const taxInclusivePrice = erpPriceMultiply(row.productPrice, row.count) ?? 0; |
| | | row.taxPrice = |
| | | erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0; |
| | | row.totalPrice = row.totalProductPrice + row.taxPrice; |
| | | erpPriceMultiply(taxInclusivePrice, (row.taxPercent || 0) / 100) ?? 0; |
| | | row.totalProductPrice = taxInclusivePrice - row.taxPrice; |
| | | row.totalPrice = taxInclusivePrice; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化行数据 |
| | | * 已有单据的明细行(带 id)沿用后端返回的金额,避免历史单据被新口径覆盖; |
| | | * 只有未保存的新增行才按新口径重算。 |
| | | */ |
| | | function initRow(row: ErpSaleReturnApi.SaleReturnItem) { |
| | | if (!row.id) { |
| | | recalcRow(row); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | /** 初始化 */ |
| | | onMounted(async () => { |
| | | const res = await getItemPage({ pageNo: 1, pageSize: 100, status: 0 }); |
| | | productOptions.value = res.list || []; |
| | | warehouseOptions.value = await getWarehouseSimpleList(); |
| | | }); |
| | | </script> |
| | |
| | | </template> |
| | | <template #productId="{ row }"> |
| | | <Select |
| | | v-if="orderItems?.length" |
| | | :disabled="disabled" |
| | | v-model:value="row.productId" |
| | | :options="orderItems?.length ? orderItems : productOptions" |
| | | :field-names="orderItems?.length ? { label: 'productName', value: 'productId' } : { label: 'name', value: 'id' }" |
| | | :options="orderItems" |
| | | :field-names="{ label: 'productName', value: 'productId' }" |
| | | class="w-full" |
| | | placeholder="请选择产品" |
| | | show-search |
| | | @change="handleProductChange(row)" |
| | | /> |
| | | <MdmItemSelect |
| | | v-else |
| | | v-model:model-value="row.productId" |
| | | :label="row.productName" |
| | | :disabled="disabled" |
| | | placeholder="请选择产品" |
| | | @change="(item) => handleProductChange(row, item)" |
| | | /> |
| | | </template> |
| | | <template #count="{ row }"> |
| | |
| | | <div class="flex space-x-4"> |
| | | <span>数量:{{ erpCountInputFormatter(summaries.count) }}</span> |
| | | <span> |
| | | 金额:{{ erpPriceInputFormatter(summaries.totalProductPrice) }} |
| | | 不含税金额:{{ erpPriceInputFormatter(summaries.totalProductPrice) }} |
| | | </span> |
| | | <span>税额:{{ erpPriceInputFormatter(summaries.taxPrice) }}</span> |
| | | <span> |
| | | 税额合计:{{ erpPriceInputFormatter(summaries.totalPrice) }} |
| | | 含税合计:{{ erpPriceInputFormatter(summaries.totalPrice) }} |
| | | </span> |
| | | </div> |
| | | </div> |