| | |
| | | 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); |
| | |
| | | |
| | | /** 初始化 */ |
| | | 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 }"> |
| | | <InputNumber |