liu
3 天以前 ee7ac8df8bce38add1f75baf876b49de94b9e00a
src/views/wls/salesnotice/data.ts
@@ -5,21 +5,29 @@
import { h, markRaw } from 'vue';
import { DICT_TYPE, MesAutoCodeRuleCode } from '@vben/constants';
import {
  DICT_TYPE,
  MesAutoCodeRuleCode,
  MesWmWarehouseTypeEnum,
} from '@vben/constants';
import { Button } from 'ant-design-vue';
import { z } from '#/adapter/form';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { MdClientSelect } from '#/views/mes/md/client/components';
import { MdItemSelect } from '#/views/mes/md/item/components';
import CrmCustomerSelect from '#/components/crm-customer-select.vue';
import {
  getStockSummaryByBatch,
  getStockSummaryByItem,
  type MesWmMaterialStockApi,
} from '#/api/mes/wm/materialstock';
/** 表单类型 */
export type FormType = 'create' | 'detail' | 'finish' | 'update';
export type FormType = 'create' | 'detail' | 'update';
/** 表单头部是否只读(详情、执行出库态) */
/** 表单头部是否只读(详情态) */
function isHeaderReadonly(formType: FormType): boolean {
  return formType === 'detail' || formType === 'finish';
  return formType === 'detail';
}
/** 新增/修改的表单 */
@@ -79,17 +87,9 @@
      rules: 'required',
    },
    {
      fieldName: 'salesOrderCode',
      label: '销售订单编号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入销售订单编号',
      },
    },
    {
      fieldName: 'clientId',
      label: '客户',
      component: markRaw(MdClientSelect),
      component: markRaw(CrmCustomerSelect),
      componentProps: {
        placeholder: '请选择客户',
      },
@@ -103,7 +103,7 @@
        class: '!w-full',
        format: 'YYYY-MM-DD',
        placeholder: '请选择发货日期',
        valueFormat: 'x',
        valueFormat: 'YYYY-MM-DD',
      },
      rules: 'required',
    },
@@ -166,18 +166,9 @@
      },
    },
    {
      fieldName: 'salesOrderCode',
      label: '销售订单编号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入销售订单编号',
      },
    },
    {
      fieldName: 'clientId',
      label: '客户',
      component: markRaw(MdClientSelect),
      component: markRaw(CrmCustomerSelect),
      componentProps: {
        placeholder: '请选择客户',
      },
@@ -198,11 +189,6 @@
      field: 'name',
      title: '通知单名称',
      minWidth: 150,
    },
    {
      field: 'salesOrderCode',
      title: '销售订单编号',
      minWidth: 140,
    },
    {
      field: 'clientName',
@@ -238,6 +224,12 @@
        name: 'CellDict',
        props: { type: DICT_TYPE.MES_WM_SALES_NOTICE_STATUS },
      },
    },
    {
      field: 'outStatus',
      title: '出库状态',
      minWidth: 100,
      slots: { default: 'outStatus' },
    },
    {
      title: '操作',
@@ -279,6 +271,28 @@
      width: 100,
    },
    {
      field: 'outCount',
      title: '已出库数量',
      width: 100,
      formatter: ({ cellValue }: { cellValue: number }) => (cellValue || 0).toFixed(2),
    },
    {
      field: 'outProgress',
      title: '出库进度',
      width: 120,
      cellRender: {
        name: 'CellText',
        props: {
          formatter: ({ row }: { row: MesWmSalesNoticeLineApi.SalesNoticeLine }) => {
            const quantity = row.quantity || 0;
            const outCount = row.outCount || 0;
            const percent = quantity > 0 ? Math.round((outCount / quantity) * 100) : 0;
            return `${outCount.toFixed(2)} / ${quantity.toFixed(2)} (${percent}%)`;
          },
        },
      },
    },
    {
      field: 'batchCode',
      title: '批次号',
      minWidth: 120,
@@ -310,15 +324,98 @@
  ];
}
/** 通知单行新增/修改的表单 */
/** 正式库(合格库库存,stockState = 20)有库存的物料选项 */
export async function loadQualifiedStockItemOptions(): Promise<
  { label: string; value: number }[]
> {
  const list = await getStockSummaryByItem({
    stockState: 20,
    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
  });
  return list.map((item: MesWmMaterialStockApi.MaterialStockSummary) => ({
    label: [item.itemName, item.itemCode, `库存 ${item.totalQuantity}`]
      .filter(Boolean)
      .join(' '),
    value: item.itemId as number,
  }));
}
/** 指定物料的正式库存批次选项 */
export async function loadQualifiedStockBatchOptions(
  itemId: number,
): Promise<{ label: string; value: number }[]> {
  const list = await getStockSummaryByBatch({
    stockState: 20,
    itemId,
    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
  });
  return list.map((item: MesWmMaterialStockApi.MaterialStockSummary) => ({
    label: [item.batchCode, `库存 ${item.totalQuantity}`].filter(Boolean).join(' '),
    value: item.batchId as number,
  }));
}
/**
 * 可发货数量:所选物料/批次的正式库存(stockState = 20)汇总。
 *
 * 指定批次时精确到该批次,否则返回物料全部正式库存。
 */
export async function loadAvailableQuantity(
  itemId?: number,
  batchId?: number,
): Promise<number> {
  if (!itemId) {
    return 0;
  }
  if (batchId) {
    const list = await getStockSummaryByBatch({
    stockState: 20,
    itemId,
    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
  });
    return list.find((item) => item.batchId === batchId)?.totalQuantity ?? 0;
  }
  const list = await getStockSummaryByItem({
    stockState: 20,
    itemId,
    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
  });
  return list.find((item) => item.itemId === itemId)?.totalQuantity ?? 0;
}
/**
 * 通知单行新增/修改的表单。
 *
 * 物料、批次均从正式库库存(stockState = 20)中选择,
 * 批次选项随物料联动加载,可用库存不足由后端保存时校验。
 */
export function useLineFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'itemId',
      label: '物料',
      component: markRaw(MdItemSelect),
      component: 'Select',
      componentProps: {
        placeholder: '请选择物料',
        allowClear: true,
        filterOption: true,
        optionFilterProp: 'label',
        options: [],
        placeholder: '请选择物料(仅正式库库存)',
        showSearch: true,
      },
      rules: 'selectRequired',
    },
    {
      fieldName: 'batchId',
      label: '批次',
      component: 'Select',
      componentProps: {
        allowClear: true,
        filterOption: true,
        optionFilterProp: 'label',
        options: [],
        placeholder: '请选择批次(仅正式库库存)',
        showSearch: true,
      },
      rules: 'selectRequired',
    },
@@ -329,17 +426,18 @@
      componentProps: {
        class: '!w-full',
        min: 0.01,
        placeholder: '请输入发货数量',
        placeholder: '请输入发货数量(不可超过正式库存)',
        precision: 2,
      },
      rules: 'required',
    },
    {
      fieldName: 'batchCode',
      label: '批次号',
      fieldName: 'availableQuantity',
      label: '可发货数量',
      component: 'Input',
      componentProps: {
        placeholder: '请输入批次号',
        disabled: true,
        placeholder: '选择物料/批次后自动带出',
      },
    },
    {