| | |
| | | <script lang="ts" setup> |
| | | import type { MdmItemApi } from '#/api/mdm/item'; |
| | | import type { ErpPurchaseRequestApi } from '#/api/erp/purchase/request'; |
| | | |
| | | import { computed, nextTick, onMounted, ref, watch } from 'vue'; |
| | |
| | | erpCountInputFormatter, |
| | | erpPriceInputFormatter, |
| | | erpPriceMultiply, |
| | | } from '../../../../../packages/utils/src'; |
| | | } from '@vben/utils'; |
| | | |
| | | import { Input, InputNumber, Select, DatePicker } from 'ant-design-vue'; |
| | | import { Input, InputNumber, DatePicker, Switch } from 'ant-design-vue'; |
| | | |
| | | import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; |
| | | import { getItemPage } from '#/api/mdm/item'; |
| | | import { MdmItemSelect } from '#/views/basicData/mdm/components'; |
| | | |
| | | import { useFormItemColumns } from '../data'; |
| | | |
| | |
| | | const emit = defineEmits(['update:items']); |
| | | |
| | | const tableData = ref<ErpPurchaseRequestApi.PurchaseRequestItem[]>([]); |
| | | const productOptions = ref<MdmItemApi.Item[]>([]); |
| | | |
| | | /** 获取表格合计数据 */ |
| | | const summaries = computed(() => { |
| | | return { |
| | | count: tableData.value.reduce((sum, item) => sum + (item.requestCount || 0), 0), |
| | | count: tableData.value.reduce((sum, item) => sum + (item.count || 0), 0), |
| | | totalPrice: tableData.value.reduce( |
| | | (sum, item) => { |
| | | const price = erpPriceMultiply(item.estimatedPrice || 0, item.requestCount || 0) ?? 0; |
| | | const price = erpPriceMultiply(item.productPrice || 0, item.count || 0) ?? 0; |
| | | return sum + price; |
| | | }, |
| | | 0, |
| | |
| | | const newRow = { |
| | | id: undefined, |
| | | productId: undefined, |
| | | productUnitId: undefined, |
| | | productUnitName: undefined, |
| | | productBarCode: undefined, |
| | | requestCount: 1, |
| | | estimatedPrice: undefined, |
| | | requiredDate: undefined, |
| | | count: 1, |
| | | productPrice: undefined, |
| | | taxPercent: undefined, |
| | | demandTime: undefined, |
| | | remark: undefined, |
| | | totalPrice: 0, |
| | | qcCheckFlag: false, |
| | | }; |
| | | tableData.value.push(newRow); |
| | | emit('update:items', [...tableData.value]); |
| | |
| | | } |
| | | |
| | | /** 处理产品变更 */ |
| | | async function handleProductChange(productId: any, row: any) { |
| | | const product = productOptions.value.find((p) => p.id === productId); |
| | | function handleProductChange(product: any, row: any) { |
| | | if (!product) { |
| | | return; |
| | | } |
| | | row.productId = productId; |
| | | row.productId = product.id; |
| | | row.productBarCode = product.barCode; |
| | | row.productUnitId = product.unitMeasureId; |
| | | row.productUnitName = product.unitMeasureName; |
| | | row.productName = product.name; |
| | | row.estimatedPrice = product.purchasePrice || 0; |
| | | row.requestCount = row.requestCount || 1; |
| | | row.productPrice = product.purchasePrice || 0; |
| | | row.count = row.count || 1; |
| | | handleRowChange(row); |
| | | } |
| | | |
| | |
| | | tableData.value[index] = row; |
| | | } |
| | | // 计算预估金额 |
| | | if (row.estimatedPrice && row.requestCount) { |
| | | row.totalPrice = erpPriceMultiply(row.estimatedPrice, row.requestCount) ?? 0; |
| | | if (row.productPrice && row.count) { |
| | | row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0; |
| | | } |
| | | emit('update:items', [...tableData.value]); |
| | | } |
| | | |
| | | /** 初始化行数据 */ |
| | | function initRow(row: ErpPurchaseRequestApi.PurchaseRequestItem) { |
| | | if (row.estimatedPrice && row.requestCount) { |
| | | row.totalPrice = erpPriceMultiply(row.estimatedPrice, row.requestCount) ?? 0; |
| | | if (row.productPrice && row.count) { |
| | | row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0; |
| | | } |
| | | } |
| | | |
| | |
| | | if (!item.productId) { |
| | | throw new Error(`第 ${i + 1} 行:产品不能为空`); |
| | | } |
| | | if (!item.requestCount || item.requestCount <= 0) { |
| | | throw new Error(`第 ${i + 1} 行:申请数量不能为空`); |
| | | if (!item.count || item.count <= 0) { |
| | | throw new Error(`第 ${i + 1} 行:数量不能为空`); |
| | | } |
| | | } |
| | | } |
| | |
| | | }); |
| | | |
| | | /** 初始化 */ |
| | | onMounted(async () => { |
| | | const res = await getItemPage({ pageNo: 1, pageSize: 100, status: 0 }); |
| | | productOptions.value = res.list || []; |
| | | onMounted(() => { |
| | | if (tableData.value.length === 0) { |
| | | handleAdd(); |
| | | } |
| | |
| | | <template> |
| | | <Grid class="w-full"> |
| | | <template #productId="{ row }"> |
| | | <Select |
| | | <MdmItemSelect |
| | | v-if="!disabled" |
| | | v-model:value="row.productId" |
| | | :options="productOptions" |
| | | :field-names="{ label: 'name', value: 'id' }" |
| | | class="w-full" |
| | | :model-value="row.productId" |
| | | placeholder="请选择产品" |
| | | show-search |
| | | @update:model-value="row.productId = $event" |
| | | @change="handleProductChange($event, row)" |
| | | /> |
| | | <span v-else>{{ row.productName || '-' }}</span> |
| | | </template> |
| | | <template #requestCount="{ row }"> |
| | | <template #count="{ row }"> |
| | | <InputNumber |
| | | v-if="!disabled" |
| | | v-model:value="row.requestCount" |
| | | v-model:value="row.count" |
| | | :min="0" |
| | | :precision="3" |
| | | @change="handleRowChange(row)" |
| | | /> |
| | | <span v-else>{{ erpCountInputFormatter(row.requestCount) || '-' }}</span> |
| | | <span v-else>{{ erpCountInputFormatter(row.count) || '-' }}</span> |
| | | </template> |
| | | <template #estimatedPrice="{ row }"> |
| | | <template #productPrice="{ row }"> |
| | | <InputNumber |
| | | v-if="!disabled" |
| | | v-model:value="row.estimatedPrice" |
| | | v-model:value="row.productPrice" |
| | | :min="0" |
| | | :precision="2" |
| | | @change="handleRowChange(row)" |
| | | /> |
| | | <span v-else>{{ erpPriceInputFormatter(row.estimatedPrice) || '-' }}</span> |
| | | <span v-else>{{ erpPriceInputFormatter(row.productPrice) || '-' }}</span> |
| | | </template> |
| | | <template #requiredDate="{ row }"> |
| | | <template #taxPercent="{ row }"> |
| | | <InputNumber |
| | | v-if="!disabled" |
| | | v-model:value="row.taxPercent" |
| | | :min="0" |
| | | :max="100" |
| | | :precision="2" |
| | | @change="handleRowChange(row)" |
| | | /> |
| | | <span v-else>{{ row.taxPercent ? `${row.taxPercent}%` : '-' }}</span> |
| | | </template> |
| | | <template #demandTime="{ row }"> |
| | | <DatePicker |
| | | v-if="!disabled" |
| | | v-model:value="row.requiredDate" |
| | | v-model:value="row.demandTime" |
| | | valueFormat="YYYY-MM-DD" |
| | | class="w-full" |
| | | @change="handleRowChange(row)" |
| | | /> |
| | | <span v-else>{{ row.requiredDate || '-' }}</span> |
| | | <span v-else>{{ row.demandTime || '-' }}</span> |
| | | </template> |
| | | <template #remark="{ row }"> |
| | | <Input v-if="!disabled" v-model:value="row.remark" class="w-full" @change="handleRowChange(row)" /> |
| | | <span v-else>{{ row.remark || '-' }}</span> |
| | | </template> |
| | | <template #qcCheckFlag="{ row }"> |
| | | <Switch |
| | | v-if="!disabled" |
| | | v-model:checked="row.qcCheckFlag" |
| | | checked-children="是" |
| | | un-checked-children="否" |
| | | @change="handleRowChange(row)" |
| | | /> |
| | | <span v-else>{{ row.qcCheckFlag ? '是' : '否' }}</span> |
| | | </template> |
| | | <template #actions="{ row }"> |
| | | <TableAction |
| | |
| | | <div class="flex justify-between text-sm text-muted-foreground"> |
| | | <span class="font-medium text-foreground">合计:</span> |
| | | <div class="flex space-x-4"> |
| | | <span>申请数量:{{ erpCountInputFormatter(summaries.count) }}</span> |
| | | <span>数量:{{ erpCountInputFormatter(summaries.count) }}</span> |
| | | <span>预估金额:{{ erpPriceInputFormatter(summaries.totalPrice) }}</span> |
| | | </div> |
| | | </div> |
| | |
| | | /> |
| | | </template> |
| | | </Grid> |
| | | </template> |
| | | </template> |