| | |
| | | <script lang="ts" setup> |
| | | import type { ErpProductApi } from '#/api/erp/product/product'; |
| | | import type { MdmItemApi } from '#/api/mdm/item'; |
| | | import type { ErpStockCheckApi } from '#/api/erp/stock/check'; |
| | | |
| | | import { computed, nextTick, onMounted, ref, watch } from 'vue'; |
| | |
| | | import { Input, InputNumber, Select } from 'ant-design-vue'; |
| | | |
| | | import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; |
| | | import { getProductSimpleList } from '#/api/erp/product/product'; |
| | | import { getStockCount } from '#/api/erp/stock/stock'; |
| | | import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse'; |
| | | import { MdmItemSelect } from '#/views/basicData/mdm/components'; |
| | | |
| | | import { useFormItemColumns } from '../data'; |
| | | |
| | |
| | | const emit = defineEmits(['update:items']); |
| | | |
| | | const tableData = ref<ErpStockCheckApi.StockCheckItem[]>([]); // 表格数据 |
| | | const productOptions = ref<ErpProductApi.Product[]>([]); // 产品下拉选项 |
| | | const warehouseOptions = ref<any[]>([]); // 仓库下拉选项 |
| | | |
| | | /** 获取表格合计数据 */ |
| | |
| | | } |
| | | |
| | | /** 处理产品变更 */ |
| | | async function handleProductChange(productId: any, row: any) { |
| | | const product = productOptions.value.find((p) => p.id === productId); |
| | | if (!product) { |
| | | async function handleProductChange(item: MdmItemApi.Item | undefined, row: any) { |
| | | if (!item?.id) { |
| | | return; |
| | | } |
| | | row.productId = productId; |
| | | row.productUnitId = product.unitId; |
| | | row.productBarCode = product.barCode; |
| | | row.productUnitName = product.unitName; |
| | | row.productName = product.name; |
| | | row.productId = item.id; |
| | | row.productUnitId = item.unitMeasureId; |
| | | row.productBarCode = item.barCode; |
| | | row.productUnitName = item.unitMeasureName; |
| | | row.productName = item.name; |
| | | row.stockCount = row.warehouseId |
| | | ? (await getStockCount(productId, row.warehouseId)) || 0 |
| | | : (await getStockCount(productId)) || 0; |
| | | ? (await getStockCount(item.id, row.warehouseId)) || 0 |
| | | : (await getStockCount(item.id)) || 0; |
| | | row.actualCount = row.stockCount || 0; |
| | | row.productPrice = product.purchasePrice || 0; |
| | | row.productPrice = item.purchasePrice || 0; |
| | | row.count = row.actualCount - row.stockCount || 0; |
| | | handleRowChange(row); |
| | | } |
| | |
| | | |
| | | /** 初始化 */ |
| | | onMounted(async () => { |
| | | productOptions.value = await getProductSimpleList(); |
| | | warehouseOptions.value = await getWarehouseSimpleList(); |
| | | // 目的:新增时,默认添加一行 |
| | | if (tableData.value.length === 0) { |
| | |
| | | /> |
| | | </template> |
| | | <template #productId="{ row }"> |
| | | <Select |
| | | v-model:value="row.productId" |
| | | :options="productOptions" |
| | | :field-names="{ label: 'name', value: 'id' }" |
| | | class="w-full" |
| | | <MdmItemSelect |
| | | v-model:model-value="row.productId" |
| | | :label="row.productName" |
| | | placeholder="请选择产品" |
| | | show-search |
| | | :disabled="disabled" |
| | | @change="handleProductChange($event, row)" |
| | | @change="(item) => handleProductChange(item, row)" |
| | | /> |
| | | </template> |
| | | <template #actualCount="{ row }"> |