| | |
| | | } from '@vben/constants'; |
| | | import { getDictOptions } from '@vben/hooks'; |
| | | |
| | | import { Button } from 'ant-design-vue'; |
| | | import { Button, message } from 'ant-design-vue'; |
| | | |
| | | import { generateAutoCode } from '#/api/mes/md/autocode/record'; |
| | | import { getItemByMdmItemId } from '#/api/mes/md/item'; |
| | | import { getSaleOrderItemListByOrderId } from '#/api/erp/sale/order'; |
| | | import CrmCustomerSelect from '#/components/crm-customer-select.vue'; |
| | | import { getRangePickerDefaultProps } from '#/utils'; |
| | | import { |
| | |
| | | } from '#/views/mes/md/item/components'; |
| | | import { SrmSupplierSelect } from '#/views/srm/supplier/components'; |
| | | import { ErpSaleOrderSelect } from '#/views/erp/sale/order/components'; |
| | | |
| | | import { summarizeProductionProduct } from './sale-order-fill'; |
| | | |
| | | /** 表单类型 */ |
| | | export type FormType = 'confirm' | 'create' | 'detail' | 'finish' | 'update'; |
| | |
| | | componentProps: { |
| | | disabled: headerReadonly, |
| | | placeholder: '请选择营销订单(ERP销售订单)', |
| | | // 选中营销订单后自动带入客户 |
| | | // 选中营销订单后自动带入客户、来源单号、产品和数量 |
| | | onChange: async (item?: ErpSaleOrderApi.SaleOrder) => { |
| | | if (!item) { |
| | | return; |
| | | } |
| | | const values = (await formApi?.getValues()) ?? {}; |
| | | if (values.clientId == null && item.customerId) { |
| | | await formApi?.setFieldValue('clientId', item.customerId); |
| | | await formApi?.setValues({ |
| | | clientId: item.customerId, |
| | | orderSourceCode: item.no, |
| | | productId: undefined, |
| | | quantity: undefined, |
| | | }); |
| | | if (!item.id) { |
| | | return; |
| | | } |
| | | const orderItems = await getSaleOrderItemListByOrderId(item.id); |
| | | const products = summarizeProductionProduct(orderItems ?? []); |
| | | if (products.length === 0) { |
| | | message.warning('该销售订单没有需要生产的产品明细'); |
| | | return; |
| | | } |
| | | if (products.length > 1) { |
| | | message.warning('该销售订单包含多个生产产品,请选择具体产品并填写数量'); |
| | | return; |
| | | } |
| | | const [product] = products; |
| | | const mesItem = await getItemByMdmItemId(product!.mdmProductId); |
| | | if (!mesItem?.id) { |
| | | message.warning('销售订单产品尚未同步到生产物料,请先同步产品主数据'); |
| | | return; |
| | | } |
| | | await formApi?.setValues({ |
| | | productId: mesItem.id, |
| | | quantity: product!.quantity, |
| | | }); |
| | | }, |
| | | }, |
| | | dependencies: { |