| | |
| | | <script lang="ts" setup> |
| | | import type { MdmItemApi } from '#/api/mdm/item'; |
| | | import type { ErpSaleOrderApi } from '#/api/erp/sale/order'; |
| | | import type { ErpSaleReturnApi } from '#/api/erp/sale/return'; |
| | | |
| | | import { computed, nextTick, onMounted, ref, watch } from 'vue'; |
| | |
| | | erpCountInputFormatter, |
| | | erpPriceInputFormatter, |
| | | erpPriceMultiply, |
| | | } from '../../../../../packages/utils/src'; |
| | | } from '@vben/utils'; |
| | | |
| | | import { Input, InputNumber, Select } from 'ant-design-vue'; |
| | | |
| | | import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; |
| | | import { getProductSimpleList } from '#/api/erp/product/product'; |
| | | import { getItemPage } from '#/api/mdm/item'; |
| | | import { getWarehouseStockCount } from '#/api/erp/stock/stock'; |
| | | import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse'; |
| | | |
| | |
| | | disabled?: boolean; |
| | | discountPercent?: number; |
| | | otherPrice?: number; |
| | | orderItems?: ErpSaleOrderApi.SaleOrderItem[]; |
| | | } |
| | | |
| | | const props = withDefaults(defineProps<Props>(), { |
| | |
| | | disabled: false, |
| | | discountPercent: 0, |
| | | otherPrice: 0, |
| | | orderItems: () => [], |
| | | }); |
| | | |
| | | const emit = defineEmits([ |
| | |
| | | ]); |
| | | |
| | | const tableData = ref<ErpSaleReturnApi.SaleReturnItem[]>([]); // 表格数据 |
| | | const productOptions = ref<any[]>([]); // 产品下拉选项 |
| | | const productOptions = ref<MdmItemApi.Item[]>([]); // 物料下拉选项 |
| | | const warehouseOptions = ref<any[]>([]); // 仓库下拉选项 |
| | | |
| | | /** 获取表格合计数据 */ |
| | |
| | | emit('update:items', [...tableData.value]); |
| | | } |
| | | |
| | | /** 处理新增物料行 */ |
| | | function handleAdd() { |
| | | const newRow: ErpSaleReturnApi.SaleReturnItem = { |
| | | seq: Date.now(), |
| | | productId: undefined, |
| | | productName: '', |
| | | productPrice: 0, |
| | | productUnitId: undefined, |
| | | productUnitName: '', |
| | | count: 0, |
| | | totalProductPrice: 0, |
| | | taxPercent: 0, |
| | | taxPrice: 0, |
| | | totalPrice: 0, |
| | | remark: '', |
| | | }; |
| | | tableData.value.push(newRow); |
| | | emit('update:items', [...tableData.value]); |
| | | } |
| | | |
| | | /** 处理产品变更:优先从关联订单物料中填充,兜底从全部物料中查找 */ |
| | | function handleProductChange(row: ErpSaleReturnApi.SaleReturnItem) { |
| | | // 优先从关联订单的物料中查找 |
| | | const orderItem = props.orderItems.find( |
| | | (item) => item.productId === row.productId, |
| | | ); |
| | | if (orderItem) { |
| | | row.productName = orderItem.productName; |
| | | row.productPrice = orderItem.productPrice ?? 0; |
| | | row.productUnitId = orderItem.productUnitId; |
| | | row.productUnitName = orderItem.productUnitName; |
| | | row.productBarCode = orderItem.productBarCode; |
| | | row.taxPercent = orderItem.taxPercent ?? 0; |
| | | row.count = row.count || 1; |
| | | 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; |
| | | row.taxPercent = 0; |
| | | row.count = row.count || 1; |
| | | handleRowChange(row); |
| | | } |
| | | } |
| | | |
| | | /** 处理仓库变更 */ |
| | | async function handleWarehouseChange(row: ErpSaleReturnApi.SaleReturnItem) { |
| | | const stockCount = await getWarehouseStockCount({ |
| | |
| | | for (let i = 0; i < tableData.value.length; i++) { |
| | | const item = tableData.value[i]; |
| | | if (item) { |
| | | if (!item.productId) { |
| | | throw new Error(`第 ${i + 1} 行:产品不能为空`); |
| | | } |
| | | if (!item.warehouseId) { |
| | | throw new Error(`第 ${i + 1} 行:仓库不能为空`); |
| | | } |
| | |
| | | |
| | | /** 初始化 */ |
| | | onMounted(async () => { |
| | | productOptions.value = await getProductSimpleList(); |
| | | const res = await getItemPage({ pageNo: 1, pageSize: 100, status: 0 }); |
| | | productOptions.value = res.list || []; |
| | | warehouseOptions.value = await getWarehouseSimpleList(); |
| | | }); |
| | | </script> |
| | |
| | | </template> |
| | | <template #productId="{ row }"> |
| | | <Select |
| | | disabled |
| | | :disabled="disabled" |
| | | v-model:value="row.productId" |
| | | :options="productOptions" |
| | | :field-names="{ label: 'name', value: 'id' }" |
| | | :options="orderItems?.length ? orderItems : productOptions" |
| | | :field-names="orderItems?.length ? { label: 'productName', value: 'productId' } : { label: 'name', value: 'id' }" |
| | | class="w-full" |
| | | placeholder="请选择产品" |
| | | show-search |
| | | @change="handleProductChange(row)" |
| | | /> |
| | | </template> |
| | | <template #count="{ row }"> |
| | |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <TableAction |
| | | v-if="!disabled" |
| | | class="mt-2 flex justify-center" |
| | | :actions="[ |
| | | { |
| | | label: '添加退货产品', |
| | | type: 'default', |
| | | onClick: handleAdd, |
| | | }, |
| | | ]" |
| | | /> |
| | | </template> |
| | | </Grid> |
| | | </template> |