| | |
| | | import type { CrmContractApi } from '#/api/crm/contract'; |
| | | import type { MdmItemApi } from '#/api/mdm/item'; |
| | | |
| | | import { nextTick, ref, watch } from 'vue'; |
| | | import { computed, nextTick, ref, watch } from 'vue'; |
| | | |
| | | import { erpPriceMultiply } from '@vben/utils'; |
| | | |
| | |
| | | }>(); |
| | | |
| | | const emit = defineEmits(['update:products']); |
| | | |
| | | /** 是否为商机类型 */ |
| | | const isBusiness = computed(() => props.bizType === BizTypeEnum.CRM_BUSINESS); |
| | | |
| | | /** 当前业务类型对应的价格字段名 */ |
| | | const priceField = computed(() => isBusiness.value ? 'businessPrice' : 'contractPrice'); |
| | | |
| | | /** 表格内部数据 */ |
| | | const tableData = ref<any[]>([]); |
| | |
| | | row.itemId = product.id; |
| | | row.itemName = product.name; |
| | | row.itemCode = product.code; |
| | | row.itemBarCode = product.barCode; |
| | | row.barCode = product.barCode; |
| | | row.itemUnitId = product.unitMeasureId; |
| | | 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[priceField.value] = product.salesPrice; |
| | | row.count = row.count || 1; |
| | | row.totalPrice = erpPriceMultiply(row.contractPrice, row.count) ?? 0; |
| | | row.totalPrice = erpPriceMultiply(row[priceField.value], row.count) ?? 0; |
| | | handleUpdateValue(row); |
| | | } |
| | | |
| | | /** 金额变动时重新计算合计 */ |
| | | function handlePriceChange(row: any) { |
| | | row.totalPrice = erpPriceMultiply(row.contractPrice, row.count) ?? 0; |
| | | row.totalPrice = erpPriceMultiply(row[priceField.value], row.count) ?? 0; |
| | | handleUpdateValue(row); |
| | | } |
| | | |
| | | /** 将最新数据写回并通知父组件 */ |
| | | function handleUpdateValue(row: any) { |
| | | const index = tableData.value.findIndex((item) => item.id === row.id); |
| | | row.totalPrice = erpPriceMultiply(row.contractPrice, row.count) ?? 0; |
| | | row.totalPrice = erpPriceMultiply(row[priceField.value], row.count) ?? 0; |
| | | if (index === -1) { |
| | | row.id = tableData.value.length + 1; |
| | | tableData.value.push(row); |
| | |
| | | trigger: 'click', |
| | | mode: 'cell', |
| | | }, |
| | | columns: useProductEditTableColumns(), |
| | | columns: useProductEditTableColumns(isBusiness.value), |
| | | data: tableData.value, |
| | | border: true, |
| | | showOverflow: true, |
| | |
| | | @change="handlePriceChange(row)" |
| | | /> |
| | | </template> |
| | | <template #businessPrice="{ row }"> |
| | | <InputNumber |
| | | v-model:value="row.businessPrice" |
| | | :min="0.001" |
| | | :precision="2" |
| | | @change="handlePriceChange(row)" |
| | | /> |
| | | </template> |
| | | <template #count="{ row }"> |
| | | <InputNumber |
| | | v-model:value="row.count" |