| | |
| | | <script lang="ts" setup> |
| | | import type { CrmBusinessApi } from '#/api/crm/business'; |
| | | import type { CrmContractApi } from '#/api/crm/contract'; |
| | | import type { CrmProductApi } from '#/api/crm/product'; |
| | | import type { MdmItemApi } from '#/api/mdm/item'; |
| | | |
| | | import { nextTick, onMounted, ref, watch } from 'vue'; |
| | | |
| | |
| | | |
| | | import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; |
| | | import { BizTypeEnum } from '#/api/crm/permission'; |
| | | import { getProductSimpleList } from '#/api/crm/product'; |
| | | import { getItemPage } from '#/api/mdm/item'; |
| | | import { $t } from '#/locales'; |
| | | |
| | | import { useProductEditTableColumns } from './data'; |
| | |
| | | } |
| | | |
| | | /** 切换产品时同步基础信息 */ |
| | | function handleProductChange(productId: any, row: any) { |
| | | const product = productOptions.value.find((p) => p.id === productId); |
| | | function handleProductChange(itemId: any, row: any) { |
| | | const product = productOptions.value.find((p) => p.id === itemId); |
| | | if (!product) { |
| | | return; |
| | | } |
| | | row.productUnit = product.unit; |
| | | row.productNo = product.no; |
| | | row.productPrice = product.price; |
| | | row.sellingPrice = product.price; |
| | | row.count = 0; |
| | | row.totalPrice = 0; |
| | | row.itemId = itemId; |
| | | row.itemName = product.name; |
| | | row.itemCode = product.code; |
| | | row.itemBarCode = product.barCode; |
| | | row.itemUnitName = product.unitMeasureName; |
| | | row.itemUnitName2 = product.unitMeasureName2; |
| | | row.itemUnitName3 = product.unitMeasureName3; |
| | | row.itemSpecification = product.specification; |
| | | row.itemPrice = product.salesPrice; |
| | | row.contractPrice = product.salesPrice; |
| | | row.count = row.count || 1; |
| | | row.totalPrice = erpPriceMultiply(row.contractPrice, row.count) ?? 0; |
| | | handleUpdateValue(row); |
| | | } |
| | | |
| | | /** 金额变动时重新计算合计 */ |
| | | function handlePriceChange(row: any) { |
| | | row.totalPrice = erpPriceMultiply(row.sellingPrice, row.count) ?? 0; |
| | | row.totalPrice = erpPriceMultiply(row.contractPrice, row.count) ?? 0; |
| | | handleUpdateValue(row); |
| | | } |
| | | |
| | | /** 将最新数据写回并通知父组件 */ |
| | | function handleUpdateValue(row: any) { |
| | | const index = tableData.value.findIndex((item) => item.id === row.id); |
| | | if (props.bizType === BizTypeEnum.CRM_BUSINESS) { |
| | | row.businessPrice = row.sellingPrice; |
| | | } else if (props.bizType === BizTypeEnum.CRM_CONTRACT) { |
| | | row.contractPrice = row.sellingPrice; |
| | | } |
| | | row.totalPrice = erpPriceMultiply(row.contractPrice, row.count) ?? 0; |
| | | if (index === -1) { |
| | | row.id = tableData.value.length + 1; |
| | | tableData.value.push(row); |
| | |
| | | } |
| | | await nextTick(); |
| | | tableData.value = products; |
| | | if (props.bizType === BizTypeEnum.CRM_BUSINESS) { |
| | | tableData.value.forEach((item) => { |
| | | item.sellingPrice = item.businessPrice; |
| | | }); |
| | | } else if (props.bizType === BizTypeEnum.CRM_CONTRACT) { |
| | | tableData.value.forEach((item) => { |
| | | item.sellingPrice = item.contractPrice; |
| | | }); |
| | | } |
| | | await gridApi.grid.reloadData(tableData.value); |
| | | }, |
| | | { |
| | |
| | | ); |
| | | |
| | | /** 初始化 */ |
| | | const productOptions = ref<CrmProductApi.Product[]>([]); // 产品下拉选项 |
| | | const productOptions = ref<MdmItemApi.Item[]>([]); // 物料下拉选项 |
| | | onMounted(async () => { |
| | | productOptions.value = await getProductSimpleList(); |
| | | const res = await getItemPage({ pageNo: 1, pageSize: 100, status: 0 }); |
| | | productOptions.value = res.list || []; |
| | | }); |
| | | </script> |
| | | |
| | | <template> |
| | | <Grid class="w-full"> |
| | | <template #productId="{ row }"> |
| | | <template #itemId="{ row }"> |
| | | <Select |
| | | v-model:value="row.productId" |
| | | v-model:value="row.itemId" |
| | | :options="productOptions" |
| | | :field-names="{ label: 'name', value: 'id' }" |
| | | class="w-full" |
| | | @change="handleProductChange($event, row)" |
| | | /> |
| | | </template> |
| | | <template #sellingPrice="{ row }"> |
| | | <template #contractPrice="{ row }"> |
| | | <InputNumber |
| | | v-model:value="row.sellingPrice" |
| | | v-model:value="row.contractPrice" |
| | | :min="0.001" |
| | | :precision="2" |
| | | @change="handlePriceChange(row)" |
| | |
| | | type: 'link', |
| | | danger: true, |
| | | popConfirm: { |
| | | title: $t('ui.actionMessage.deleteConfirm', [row.name]), |
| | | title: $t('ui.actionMessage.deleteConfirm', [row.itemName]), |
| | | confirm: handleDelete.bind(null, row), |
| | | }, |
| | | }, |