From dc1d067c566bbde1c7170186960a8bd27f210a47 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 09 九月 2026 13:45:58 +0800
Subject: [PATCH] feat(bi): 新增决策总览仪表盘并优化预测分析功能

---
 src/views/wls/equipmentreceipt/data.ts |  342 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 342 insertions(+), 0 deletions(-)

diff --git a/src/views/wls/equipmentreceipt/data.ts b/src/views/wls/equipmentreceipt/data.ts
new file mode 100644
index 0000000..d2db989
--- /dev/null
+++ b/src/views/wls/equipmentreceipt/data.ts
@@ -0,0 +1,342 @@
+import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+import type { MesWmEquipmentReceiptApi } from '#/api/mes/wm/equipmentreceipt';
+import type { MesWmEquipmentReceiptLineApi } from '#/api/mes/wm/equipmentreceipt/line';
+
+import { h, markRaw } from 'vue';
+
+import { MesAutoCodeRuleCode, MesWmEquipmentReceiptStatusEnum } from '@vben/constants';
+
+import { Button } from 'ant-design-vue';
+
+import { generateAutoCode } from '#/api/mes/md/autocode/record';
+import { getRangePickerDefaultProps } from '#/utils';
+import { DvMachinerySelect } from '#/views/mes/dv/machinery/components';
+
+/** 琛ㄥ崟绫诲瀷 */
+export type FormType = 'create' | 'detail' | 'finish' | 'update';
+
+/** 琛ㄥ崟澶撮儴鏄惁鍙锛堣鎯呫�佹墽琛屽叆搴撴�侊級 */
+function isHeaderReadonly(formType: FormType): boolean {
+  return formType === 'detail' || formType === 'finish';
+}
+
+/** 璁惧鍏ュ簱鍗曠姸鎬佸睍绀烘槧灏� */
+export const EQUIPMENT_RECEIPT_STATUS_MAP: Record<
+  number,
+  { text: string; color: string }
+> = {
+  [MesWmEquipmentReceiptStatusEnum.PREPARE]: {
+    text: '鑽夌',
+    color: 'default',
+  },
+  [MesWmEquipmentReceiptStatusEnum.APPROVING]: {
+    text: '瀹℃壒涓�',
+    color: 'processing',
+  },
+  [MesWmEquipmentReceiptStatusEnum.APPROVED]: {
+    text: '宸插鎵�',
+    color: 'success',
+  },
+  [MesWmEquipmentReceiptStatusEnum.FINISHED]: {
+    text: '宸插畬鎴�',
+    color: 'cyan',
+  },
+  [MesWmEquipmentReceiptStatusEnum.CANCELED]: {
+    text: '宸插彇娑�',
+    color: 'warning',
+  },
+};
+
+/** 鏂板/淇敼鐨勮〃鍗� */
+export function useFormSchema(
+  formType: FormType,
+  formApi?: VbenFormApi,
+): VbenFormSchema[] {
+  const headerReadonly = isHeaderReadonly(formType);
+  return [
+    {
+      fieldName: 'id',
+      component: 'Input',
+      dependencies: {
+        triggerFields: [''],
+        show: () => false,
+      },
+    },
+    {
+      fieldName: 'status',
+      component: 'Input',
+      dependencies: {
+        triggerFields: [''],
+        show: () => false,
+      },
+    },
+    {
+      fieldName: 'code',
+      label: '鍗曟嵁缂栫爜',
+      component: 'Input',
+      componentProps: {
+        placeholder: '璇疯緭鍏ュ崟鎹紪鐮�',
+      },
+      rules: 'required',
+      suffix: headerReadonly
+        ? undefined
+        : () =>
+            h(
+              Button,
+              {
+                type: 'default',
+                onClick: async () => {
+                  const code = await generateAutoCode(
+                    MesAutoCodeRuleCode.WM_EQUIP_RECEIPT_CODE,
+                  );
+                  await formApi?.setFieldValue('code', code);
+                },
+              },
+              { default: () => '鐢熸垚' },
+            ),
+    },
+    {
+      fieldName: 'name',
+      label: '鍗曟嵁鍚嶇О',
+      component: 'Input',
+      componentProps: {
+        placeholder: '璇疯緭鍏ュ崟鎹悕绉�',
+      },
+      rules: 'required',
+    },
+    {
+      fieldName: 'receiptDate',
+      label: '鍏ュ簱鏃ユ湡',
+      component: 'DatePicker',
+      componentProps: {
+        format: 'YYYY-MM-DD',
+        placeholder: '璇烽�夋嫨鍏ュ簱鏃ユ湡',
+        valueFormat: 'YYYY-MM-DD',
+      },
+      rules: 'required',
+    },
+    {
+      fieldName: 'source',
+      label: '鍏ュ簱鏉ユ簮',
+      component: 'Input',
+      componentProps: {
+        placeholder: '璇疯緭鍏ュ叆搴撴潵婧�',
+      },
+    },
+    {
+      fieldName: 'remark',
+      label: '澶囨敞',
+      component: 'Textarea',
+      formItemClass: 'col-span-3',
+      componentProps: {
+        placeholder: '璇疯緭鍏ュ娉�',
+        rows: 3,
+      },
+    },
+  ];
+}
+
+/** 鍒楄〃鐨勬悳绱㈣〃鍗� */
+export function useGridFormSchema(): VbenFormSchema[] {
+  return [
+    {
+      fieldName: 'code',
+      label: '鍗曟嵁缂栫爜',
+      component: 'Input',
+      componentProps: {
+        allowClear: true,
+        placeholder: '璇疯緭鍏ュ崟鎹紪鐮�',
+      },
+    },
+    {
+      fieldName: 'name',
+      label: '鍗曟嵁鍚嶇О',
+      component: 'Input',
+      componentProps: {
+        allowClear: true,
+        placeholder: '璇疯緭鍏ュ崟鎹悕绉�',
+      },
+    },
+    {
+      fieldName: 'source',
+      label: '鍏ュ簱鏉ユ簮',
+      component: 'Input',
+      componentProps: {
+        allowClear: true,
+        placeholder: '璇疯緭鍏ュ叆搴撴潵婧�',
+      },
+    },
+    {
+      fieldName: 'receiptDate',
+      label: '鍏ュ簱鏃ユ湡',
+      component: 'RangePicker',
+      componentProps: {
+        ...getRangePickerDefaultProps(),
+        allowClear: true,
+      },
+    },
+    {
+      fieldName: 'status',
+      label: '鍗曟嵁鐘舵��',
+      component: 'Select',
+      componentProps: {
+        allowClear: true,
+        options: Object.entries(EQUIPMENT_RECEIPT_STATUS_MAP).map(
+          ([value, item]) => ({
+            label: item.text,
+            value: Number(value),
+          }),
+        ),
+        placeholder: '璇烽�夋嫨鍗曟嵁鐘舵��',
+      },
+    },
+  ];
+}
+
+/** 鍒楄〃鐨勫瓧娈� */
+export function useGridColumns(): VxeTableGridOptions<MesWmEquipmentReceiptApi.EquipmentReceipt>['columns'] {
+  return [
+    {
+      field: 'code',
+      title: '鍗曟嵁缂栫爜',
+      minWidth: 160,
+      slots: { default: 'code' },
+    },
+    {
+      field: 'name',
+      title: '鍗曟嵁鍚嶇О',
+      minWidth: 150,
+    },
+    {
+      field: 'source',
+      title: '鍏ュ簱鏉ユ簮',
+      minWidth: 120,
+    },
+    {
+      field: 'receiptDate',
+      title: '鍏ュ簱鏃ユ湡',
+      width: 180,
+      formatter: 'formatDate',
+    },
+    {
+      field: 'status',
+      title: '鍗曟嵁鐘舵��',
+      minWidth: 100,
+      slots: { default: 'status' },
+    },
+    {
+      title: '鎿嶄綔',
+      width: 240,
+      fixed: 'right',
+      slots: { default: 'actions' },
+    },
+  ];
+}
+
+/** 璁惧鍏ュ簱鍗曡瀛愯〃鐨勫瓧娈� */
+export function useLineGridColumns(
+  editable = true,
+): VxeTableGridOptions<MesWmEquipmentReceiptLineApi.EquipmentReceiptLine>['columns'] {
+  return [
+    {
+      field: 'machineryCode',
+      title: '璁惧缂栫爜',
+      minWidth: 120,
+    },
+    {
+      field: 'machineryName',
+      title: '璁惧鍚嶇О',
+      minWidth: 140,
+    },
+    {
+      field: 'itemCode',
+      title: '鐗╂枡缂栫爜',
+      minWidth: 120,
+    },
+    {
+      field: 'itemName',
+      title: '鐗╂枡鍚嶇О',
+      minWidth: 140,
+    },
+    {
+      field: 'specification',
+      title: '瑙勬牸鍨嬪彿',
+      minWidth: 120,
+    },
+    {
+      field: 'unitMeasureName',
+      title: '鍗曚綅',
+      width: 80,
+    },
+    {
+      field: 'quantity',
+      title: '鍏ュ簱鏁伴噺',
+      width: 100,
+    },
+    {
+      field: 'remark',
+      title: '澶囨敞',
+      minWidth: 120,
+    },
+    ...(editable
+      ? [
+          {
+            title: '鎿嶄綔',
+            width: 160,
+            fixed: 'right',
+            slots: { default: 'actions' },
+          } as const,
+        ]
+      : []),
+  ];
+}
+
+/** 璁惧鍏ュ簱鍗曡鏂板/淇敼鐨勮〃鍗� */
+export function useLineFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
+  return [
+    {
+      fieldName: 'itemId',
+      component: 'Input',
+      dependencies: {
+        triggerFields: [''],
+        show: () => false,
+      },
+    },
+    {
+      fieldName: 'machineryId',
+      label: '璁惧',
+      component: markRaw(DvMachinerySelect),
+      componentProps: {
+        placeholder: '璇烽�夋嫨璁惧',
+        onChange: async (machinery?: { itemId?: number }) => {
+          await formApi?.setFieldValue('itemId', machinery?.itemId);
+        },
+      },
+      rules: 'selectRequired',
+    },
+    {
+      fieldName: 'quantity',
+      label: '鍏ュ簱鏁伴噺',
+      component: 'InputNumber',
+      componentProps: {
+        class: '!w-full',
+        min: 0.01,
+        defaultValue: 1,
+        placeholder: '璇疯緭鍏ュ叆搴撴暟閲�',
+        precision: 2,
+      },
+      rules: 'required',
+    },
+    {
+      fieldName: 'remark',
+      label: '澶囨敞',
+      component: 'Textarea',
+      formItemClass: 'col-span-3',
+      componentProps: {
+        placeholder: '璇疯緭鍏ュ娉�',
+        rows: 3,
+      },
+    },
+  ];
+}
\ No newline at end of file

--
Gitblit v1.9.3