吴羡
7 天以前 37c7825ba84000caee76476cb734fec6e006569b
src/views/wls/packages/data.ts
@@ -13,6 +13,7 @@
import { Button } from 'ant-design-vue';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { getItem } from '#/api/mes/md/item';
import { getSimpleUserList } from '#/api/system/user';
import { ErpSaleOrderSelect } from '#/views/erp/sale/order/components';
import { MdClientSelect } from '#/views/mes/md/client/components';
@@ -429,8 +430,36 @@
  ];
}
/** 组装尾箱预览文案:整除时显示每箱数量并标记满装 */
function buildTailPreview(quantity?: number, boxQuantity?: number): string {
  if (!quantity || quantity <= 0 || !boxQuantity || boxQuantity <= 0) {
    return '输入装箱数量后自动计算';
  }
  const boxCount = Math.ceil(quantity / boxQuantity - 1e-9);
  const tail = Number((quantity - (boxCount - 1) * boxQuantity).toFixed(2));
  const full = Math.abs(tail - boxQuantity) < 1e-6;
  return `预计装 ${boxCount} 箱,尾箱 ${full ? boxQuantity : tail} 件${
    full ? '(满装)' : ''
  }`;
}
/** 刷新装箱预览(按表单中的装箱数量与每箱数量实时计算) */
export async function refreshTailPreview(formApi?: VbenFormApi) {
  if (!formApi) {
    return;
  }
  const values = (await formApi.getValues()) as {
    boxQuantity?: number;
    quantity?: number;
  };
  await formApi.setFieldValue(
    'tailPreview',
    buildTailPreview(values.quantity, values.boxQuantity),
  );
}
/** 装箱明细的表单 */
export function useLineFormSchema(): VbenFormSchema[] {
export function useLineFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
  return [
    {
      fieldName: 'workOrderId',
@@ -438,6 +467,16 @@
      component: markRaw(ProWorkOrderSelect),
      componentProps: {
        placeholder: '请选择生产订单',
        // 选择生产订单后,自动带出该订单的产品物料
        onChange: async (order?: { productId?: number }) => {
          await formApi?.setFieldValue('itemId', order?.productId);
          // 带出产品物料的每箱数量,用于计算尾箱
          const item = order?.productId
            ? await getItem(order.productId).catch(() => undefined)
            : undefined;
          await formApi?.setFieldValue('boxQuantity', item?.boxQuantity);
          await refreshTailPreview(formApi);
        },
      },
      rules: 'selectRequired',
    },
@@ -446,9 +485,19 @@
      label: '产品物料',
      component: markRaw(MdItemSelect),
      componentProps: {
        placeholder: '请选择产品物料',
        disabled: true,
        placeholder: '选择生产订单后自动带出',
      },
      rules: 'selectRequired',
      help: '自动取生产订单的产品,无需手动选择。',
    },
    {
      fieldName: 'boxQuantity',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'quantity',
@@ -459,8 +508,21 @@
        min: 0.01,
        placeholder: '请输入装箱数量',
        precision: 2,
        onChange: () => {
          refreshTailPreview(formApi);
        },
      },
      rules: 'required',
    },
    {
      fieldName: 'tailPreview',
      label: '装箱预览',
      component: 'Input',
      formItemClass: 'col-span-2',
      componentProps: {
        disabled: true,
        placeholder: '输入装箱数量后自动计算',
      },
    },
    {
      fieldName: 'expireDate',
@@ -514,6 +576,17 @@
      width: 100,
    },
    {
      field: 'boxCount',
      title: '箱数',
      width: 80,
    },
    {
      field: 'tailBoxQuantity',
      title: '尾箱数量',
      width: 110,
      slots: { default: 'tailBoxQuantity' },
    },
    {
      field: 'workOrderCode',
      title: '生产订单编号',
      minWidth: 140,