gaoluyang
3 天以前 e4994fccfb49ebfb108ba62cbd82aea4e004f6d8
src/views/wls/productissue/data.ts
@@ -1,5 +1,7 @@
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MdmItemApi } from '#/api/mdm/item';
import type { MesProTaskApi } from '#/api/mes/pro/task';
import type { MesWmMaterialStockApi } from '#/api/mes/wm/materialstock';
import type { MesWmProductIssueApi } from '#/api/mes/wm/productissue';
import type { MesWmProductIssueDetailApi } from '#/api/mes/wm/productissue/detail';
@@ -18,10 +20,15 @@
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { getRangePickerDefaultProps } from '#/utils';
import { MdItemSelect } from '#/views/mes/md/item/components';
import { MdmItemSelect } from '#/views/basicData/mdm/components';
import { MdWorkstationSelect } from '#/views/mes/md/workstation/components';
import { ProTaskSelect } from '#/views/mes/pro/task/components';
import { ProWorkOrderSelect } from '#/views/mes/pro/workorder/components';
import { WmMaterialStockSelect } from '#/views/wls/materialstock/components';
import {
  buildItemUnitSchema,
  useLineUnitHandlers,
} from '#/views/wls/utils/item-unit-convert';
import {
  WmWarehouseAreaSelect,
  WmWarehouseLocationSelect,
@@ -101,7 +108,7 @@
        format: 'YYYY-MM-DD HH:mm:ss',
        placeholder: '请选择需求时间',
        showTime: true,
        valueFormat: 'x',
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
      },
      rules: 'required',
    },
@@ -110,9 +117,33 @@
      label: '生产订单',
      component: markRaw(ProWorkOrderSelect),
      componentProps: {
        placeholder: '请选择生产订单',
        status: MesProWorkOrderStatusEnum.CONFIRMED,
        // 订单变更:清空已选生产任务,避免任务与订单不一致
        onChange: async () => {
          await formApi?.setFieldValue('taskId', undefined);
        },
      },
      rules: 'selectRequired',
    },
    {
      fieldName: 'taskId',
      label: '生产任务',
      component: markRaw(ProTaskSelect),
      componentProps: {
        placeholder: '请选择生产任务',
        // 选中任务后自动带出其工作站
        onChange: async (task?: MesProTaskApi.Task) => {
          await formApi?.setFieldValue('workstationId', task?.workstationId);
        },
      },
      dependencies: {
        triggerFields: ['workOrderId'],
        componentProps: (values) => ({
          disabled: !values.workOrderId,
          placeholder: values.workOrderId ? '请选择生产任务' : '请先选择生产订单',
          workOrderId: values.workOrderId,
        }),
      },
    },
    {
      fieldName: 'workstationId',
@@ -201,6 +232,11 @@
      minWidth: 140,
    },
    {
      field: 'taskCode',
      title: '生产任务',
      minWidth: 140,
    },
    {
      field: 'workstationName',
      title: '工作站',
      minWidth: 120,
@@ -256,9 +292,24 @@
      minWidth: 120,
    },
    {
      field: 'itemModel',
      title: '物料型号',
      minWidth: 120,
    },
    {
      field: 'unitMeasureName',
      title: '单位',
      width: 80,
      title: '主计量单位',
      width: 100,
    },
    {
      field: 'enterUnitMeasureName',
      title: '录入单位',
      width: 90,
    },
    {
      field: 'enterQuantity',
      title: '录入数量',
      width: 100,
    },
    {
      field: 'quantity',
@@ -279,29 +330,24 @@
}
/** 领料单行新增/修改的表单 */
export function useLineFormSchema(): VbenFormSchema[] {
export function useLineFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
  const unitHandlers = useLineUnitHandlers(formApi);
  return [
    {
      fieldName: 'itemId',
      label: '产品物料',
      component: markRaw(MdItemSelect),
      component: markRaw(MdmItemSelect),
      componentProps: {
        placeholder: '请选择产品物料',
        // 切换物料后,重新记录物料主单位并清空型号、录入单位口径
        onChange: async (item?: MdmItemApi.Item) => {
          await unitHandlers.handleItemChange(item?.id);
        },
      },
      rules: 'selectRequired',
    },
    {
      fieldName: 'quantity',
      label: '领料数量',
      component: 'InputNumber',
      componentProps: {
        class: '!w-full',
        min: 0,
        placeholder: '请输入领料数量',
        precision: 2,
      },
      rules: 'required',
    },
    // 物料型号 / 录入单位 / 录入数量 / 领料数量(物料主单位口径)
    ...buildItemUnitSchema(formApi, { quantityLabel: '领料数量' }),
    {
      fieldName: 'remark',
      label: '备注',
@@ -370,9 +416,17 @@
      },
    },
    {
      fieldName: 'batchId',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'itemId',
      label: '物料',
      component: markRaw(MdItemSelect),
      component: markRaw(MdmItemSelect),
      componentProps: {
        disabled: true,
      },
@@ -382,12 +436,13 @@
      label: '库存记录',
      component: markRaw(WmMaterialStockSelect),
      componentProps: {
        // 选择库存记录后,自动回填仓库/库区/库位/批次/数量
        // 选择库存记录后,自动回填物料/仓库/库区/库位/批次/数量,全部以库存记录为准
        onChange: async (stock?: MesWmMaterialStockApi.MaterialStock) => {
          await formApi?.setValues({
            areaId: stock?.areaId,
            batchCode: stock?.batchCode,
            batchId: stock?.batchId,
            itemId: stock?.itemId,
            locationId: stock?.locationId,
            quantity: stock?.quantity,
            quantityMax: stock?.quantity,
@@ -399,7 +454,8 @@
      dependencies: {
        triggerFields: ['itemId'],
        componentProps: (values) => ({
          itemId: values.itemId,
          // 库存选择弹窗只识别 mdmItemId 入参,并用它作为 itemId 过滤条件
          mdmItemId: values.itemId,
        }),
      },
    },