From 3f0856494e2265305b33a06d41796237c6eeda9f Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 29 七月 2026 17:45:33 +0800
Subject: [PATCH] 银川 1.生产任务 - 选工作站自动计算生产时长 2.生产流程 - 查看产品设计归档及附件
---
src/views/mes/pro/task/data.ts | 57 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/src/views/mes/pro/task/data.ts b/src/views/mes/pro/task/data.ts
index 605cd9c..a24e576 100644
--- a/src/views/mes/pro/task/data.ts
+++ b/src/views/mes/pro/task/data.ts
@@ -3,12 +3,17 @@
import type { MesProTaskApi } from '#/api/mes/pro/task';
import type { MesProWorkOrderApi } from '#/api/mes/pro/workorder';
+import type { Ref } from 'vue';
+
import { markRaw } from 'vue';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
+import { message } from 'ant-design-vue';
+
import CrmCustomerSelect from '#/components/crm-customer-select.vue';
+import { calculateTaskDuration } from '#/api/mes/pro/task';
import { getRangePickerDefaultProps } from '#/utils';
import { MdItemSelect } from '#/views/mes/md/item/components';
import { MdWorkstationSelect } from '#/views/mes/md/workstation/components';
@@ -166,7 +171,7 @@
},
{
title: '鎿嶄綔',
- width: 100,
+ width: 160,
fixed: 'right',
slots: { default: 'actions' },
},
@@ -279,7 +284,7 @@
class: '!w-full',
disabled: true,
format: 'YYYY-MM-DD',
- valueFormat: 'x',
+ valueFormat: 'YYYY-MM-DD',
},
},
{
@@ -376,7 +381,7 @@
}
/** 鐢熶骇浠诲姟鏂板/淇敼鐨勮〃鍗� */
-export function useTaskFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
+export function useTaskFormSchema(formApi?: VbenFormApi, workOrderQuantity?: Ref<number | undefined>): VbenFormSchema[] {
return [
{
fieldName: 'workstationId',
@@ -384,6 +389,7 @@
component: markRaw(MdWorkstationSelect),
componentProps: {
placeholder: '璇烽�夋嫨宸ヤ綔绔�',
+ onChange: () => recalcDuration(formApi),
},
rules: 'selectRequired',
},
@@ -391,11 +397,13 @@
fieldName: 'quantity',
label: '鎺掍骇鏁伴噺',
component: 'InputNumber',
+ description: () => workOrderQuantity?.value != null ? `璁㈠崟鏁伴噺锛�${workOrderQuantity.value}` : '',
componentProps: {
class: '!w-full',
min: 0.01,
placeholder: '璇疯緭鍏ユ帓浜ф暟閲�',
precision: 2,
+ onChange: () => recalcDuration(formApi),
},
rules: 'required',
},
@@ -410,11 +418,17 @@
component: 'DatePicker',
componentProps: {
class: '!w-full',
- placeholder: '璇烽�夋嫨寮�濮嬫椂闂�',
+ placeholder: '璇峰厛閫夋嫨宸ヤ綔绔�',
showTime: true,
- valueFormat: 'x',
- // 寮�濮嬫椂闂村彉鏇达細閲嶆柊璁$畻缁撴潫鏃堕棿
+ valueFormat: 'YYYY-MM-DD HH:mm:ss',
onChange: () => recalcEndTime(formApi),
+ },
+ dependencies: {
+ triggerFields: ['workstationId'],
+ componentProps: (values) => ({
+ disabled: !values.workstationId,
+ placeholder: values.workstationId ? '璇烽�夋嫨寮�濮嬫椂闂�' : '璇峰厛閫夋嫨宸ヤ綔绔�',
+ }),
},
rules: 'required',
},
@@ -440,7 +454,7 @@
class: '!w-full',
disabled: true,
showTime: true,
- valueFormat: 'x',
+ valueFormat: 'YYYY-MM-DD HH:mm:ss',
},
},
{
@@ -456,6 +470,24 @@
];
}
+/** 閫夋嫨宸ヤ綔绔欐垨淇敼鏁伴噺鍚庯紝鑷姩璁$畻鐢熶骇鏃堕暱 */
+async function recalcDuration(formApi?: VbenFormApi) {
+ if (!formApi) return;
+ const values = await formApi.getValues();
+ if (!values.workstationId || !values.quantity) return;
+ try {
+ const res = await calculateTaskDuration(values.workstationId, values.quantity);
+ await formApi.setFieldValue('duration', res.duration);
+ if (res.duration === 0) {
+ message.warning('璇ュ伐浣滅珯鏈粦瀹氳澶囷紝鎴栫粦瀹氳澶囨湭閰嶇疆鐢熶骇鏁堢巼');
+ }
+ // 閲嶆柊璁$畻缁撴潫鏃堕棿
+ await recalcEndTime(formApi);
+ } catch {
+ // 璁$畻澶辫触涓嶉樆濉炵敤鎴锋搷浣�
+ }
+}
+
/** 璁$畻缁撴潫鏃堕棿锛氬紑濮嬫椂闂� + 鐢熶骇鏃堕暱锛堝皬鏃讹級 */
async function recalcEndTime(formApi?: VbenFormApi) {
if (!formApi) {
@@ -463,11 +495,12 @@
}
const values = await formApi.getValues();
if (values.startTime && values.duration) {
- const start = Number(values.startTime);
- await formApi.setFieldValue(
- 'endTime',
- start + values.duration * 3600 * 1000,
- );
+ const start = new Date(values.startTime).getTime();
+ const endTime = start + values.duration * 3600 * 1000;
+ const pad = (n: number) => String(n).padStart(2, '0');
+ const d = new Date(endTime);
+ const formatted = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
+ await formApi.setFieldValue('endTime', formatted);
}
}
--
Gitblit v1.9.3