From 38b2a8369513ebcc34c6dd01a176593b825fe71e Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期日, 09 六月 2024 17:06:08 +0800
Subject: [PATCH] 工单管理更新

---
 src/views/tigerprojects/mes/prod/biz_mes_wo/index.vue |  130 +++++++++++++++++++--
 src/views/components/data.ts                          |   28 +++-
 src/views/components/bizMesWo.ts                      |  109 +++++++++++------
 src/api/tigerapi/system.ts                            |   29 ++++
 src/views/components/CustModal.vue                    |   49 +++++--
 5 files changed, 267 insertions(+), 78 deletions(-)

diff --git a/src/api/tigerapi/system.ts b/src/api/tigerapi/system.ts
index c961bb2..c5651ec 100644
--- a/src/api/tigerapi/system.ts
+++ b/src/api/tigerapi/system.ts
@@ -32,6 +32,7 @@
 } from './model/systemModel';
 import { defHttp } from '/@/utils/http/axios';
 import { isNullOrEmpty, isTimeType } from '/@/utils/is';
+import { MES_ROUTE_EDGE, MES_ROUTE_NODE } from './model/router';
 
 export enum Api {
   QueryUrl = '/Base/Query',
@@ -829,3 +830,31 @@
     },
   );
 };
+
+/*
+ * 杞崲宸ヨ壓璺嚎涓烘爲褰son
+ */
+function convertRouteToTreeData(
+  nodes: MES_ROUTE_NODE[],
+  edges: MES_ROUTE_EDGE[],
+  parentId: string,
+  id: string,
+  pid?: string,
+) {
+  const result: treeParamsListItem[] = [];
+  let temp: treeParamsListItem[] = [];
+  const _pid = pid == undefined ? '' : pid;
+  for (let i = 0; i < nodes.length; i++) {
+    const currPid = data[i][parentId] == null ? '' : data[i][parentId];
+    if (currPid === _pid) {
+      const obj: treeParamsListItem = data[i];
+      obj.PARAM_TYPE = _pid == '' ? '0' : '1'; //澧炲姞绫诲瀷
+      temp = convertToTreeData(data, parentId, id, data[i][id]);
+      if (temp.length > 0) {
+        obj.children = temp;
+      }
+      result.push(obj);
+    }
+  }
+  return result;
+}
diff --git a/src/views/components/CustModal.vue b/src/views/components/CustModal.vue
index a233bb4..ac65729 100644
--- a/src/views/components/CustModal.vue
+++ b/src/views/components/CustModal.vue
@@ -28,7 +28,11 @@
   import { custFunction } from './data';
   import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
   import { Layout, LayoutContent, Card } from 'ant-design-vue';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import { useI18n } from '/@/hooks/web/useI18n';
 
+  const { t } = useI18n();
+  const { notification, createErrorModal } = useMessage();
   const ALayout = Layout;
   const ACard = Card;
   const ALayoutContent = LayoutContent;
@@ -37,7 +41,8 @@
   const cType = ref('');
   const title = ref('');
   const width = ref('');
-  const FnName = ref('');
+  const FnName = ref({});
+  const initFnName = ref({});
   const dtlSlots = ref([] as any[]);
   const formSchema = ref([] as FormSchema[]);
   const formElName = ref([]);
@@ -59,12 +64,13 @@
     await nextTick();
     formSchema.value = [];
     setModalProps({ confirmLoading: false });
-    isUpdate.value = !!data?.isUpdate;
+    isUpdate.value = !!data?.isUpdate; //鏄惁鏇存柊
     cType.value = data?.ctype; //鏄摢涓〉闈�
     title.value = data?.title; //寮规鏍囬
     width.value = data?.width; //寮规瀹藉害
     formElName.value = data?.formElName; //寮规涓〃鍗曞悕瀛楁暟缁�
     useFormData.value = data?.formEl; //寮规涓〃鍗曞疄渚嬫暟缁�
+    FnName.value = data?.fnName; //淇濆瓨鏁版嵁鏂规硶
     //寰幆琛ㄥ崟鍚嶆暟缁勶紝鎿嶄綔鍚勮〃鍗曞瓧娈�
     formElName.value.forEach((name) => {
       if (!isNullOrUnDef(useFormData.value[name])) {
@@ -77,9 +83,9 @@
       }
     });
     //鍒濆鍖栨柟娉曡嚜瀹氫箟
-    if (!isNullOrEmpty(data?.FnName)) {
-      FnName.value = data?.FnName;
-      custFunction(unref(isUpdate.value), FnName.value, cType.value);
+    if (!isNullOrEmpty(data?.initFnName)) {
+      initFnName.value = data?.initFnName;
+      custFunction(unref(isUpdate.value), initFnName.value[cType.value], cType.value);
     }
   });
 
@@ -97,19 +103,30 @@
       var values = {} as any;
       //寰幆琛ㄥ崟鍚嶆暟缁勶紝楠岃瘉鍚勮〃鍗曟暟鎹悎娉曟�э紝鍚堟硶鍒欒繑鍥炲悇琛ㄥ崟鏁版嵁锛岃繑鍥炲�煎彲浠ョ敤values['琛ㄥ崟鍚�']鑾峰彇琛ㄥ崟鏁版嵁
       for (let name of formElName.value) {
-        values[name] = await useFormData.value[name][1].validate();
+        if (!isNullOrEmpty(useFormData.value[name])) {
+          values[name] = await useFormData.value[name][1].validate();
+        }
       }
       setModalProps({ confirmLoading: true });
-
-      closeModal();
-      //鎴愬姛浜嬩欢锛屽皢鏁版嵁杩斿洖鍘熼〉闈�
-      emit('success', {
-        isUpdate: isUpdate.value,
-        fnName: 'handleSubmit',
-        cType: cType.value,
-        formElName: formElName.value,
-        values,
-      });
+      //璋冪敤鑷畾涔変繚瀛樻柟娉曚繚瀛樻暟鎹�
+      const action = await custFunction(values, FnName.value[cType.value], cType.value);
+      if (action as boolean) {
+        closeModal();
+        //鎴愬姛浜嬩欢锛屽皢鏁版嵁杩斿洖鍘熼〉闈�
+        emit('success', {
+          isUpdate: isUpdate.value,
+          fnName: 'handleSubmit',
+          cType: cType.value,
+          formElName: formElName.value,
+          values,
+        });
+      } else {
+        createErrorModal({
+          title: t('璀﹀憡'),
+          content: t('淇濆瓨鏁版嵁澶辫触'),
+          getContainer: () => document.body,
+        });
+      }
     } finally {
       setModalProps({ confirmLoading: false });
     }
diff --git a/src/views/components/bizMesWo.ts b/src/views/components/bizMesWo.ts
index 222e258..dc2c34a 100644
--- a/src/views/components/bizMesWo.ts
+++ b/src/views/components/bizMesWo.ts
@@ -1,3 +1,4 @@
+/* 宸ュ崟鐩稿叧鑷畾涔夋柟娉� */
 import { FunctionType } from '/@/api/tigerapi/model/systemModel';
 import { GetEnum, SaveEntity, getEntity } from '/@/api/tigerapi/system';
 import { FormSchema } from '/@/components/Table';
@@ -9,34 +10,70 @@
 
 const { t } = useI18n();
 const { getLocale } = useLocale();
-
-export const getFns: Record<string, FunctionType> = {
+/* 鑷畾涔夋柟娉� */
+export const getWoFns: Record<string, FunctionType> = {
   handleSubmit: async (e, ...args) => {
-    try {
-      const values = await args[0][0].validate();
-      args[0][1]({ confirmLoading: true });
-      values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
-      //   const apiAction = SaveEntity(values, e, 'MES_LINE');
-      //   apiAction.then((action) => {
-      //     if (action.IsSuccessed) {
-      //       args[0][2]();
-      //       args[0][3]('success');
-      //     }
-      //   });
-      args[0][2]();
-      args[0][3]('success');
-    } finally {
-      args[0][1]({ confirmLoading: false });
-    }
+    const values = await args[0][0].validate();
+    return new Promise((resolve, reject) => {
+      try {
+        args[0][1]({ confirmLoading: true });
+        values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
+        //   const apiAction = SaveEntity(values, e, 'MES_LINE');
+        //   apiAction.then((action) => {
+        //     if (action.IsSuccessed) {
+        //       args[0][2]();
+        //       args[0][3]('success');
+        //     }
+        //   });
+        args[0][2]();
+        args[0][3]('success');
+        resolve(true);
+      } catch {
+        reject(false);
+      } finally {
+        args[0][1]({ confirmLoading: false });
+      }
+    });
   },
   rvSubmit: (e, ...args) => {
-    try {
-      args[0][0]({ confirmLoading: true });
-      args[0][1]();
-      args[0][2]('success');
-    } finally {
-      args[0][0]({ confirmLoading: false });
-    }
+    return new Promise((resolve, reject) => {
+      try {
+        args[0][0]({ confirmLoading: true });
+        args[0][1]();
+        args[0][2]('success');
+        resolve(true);
+      } catch {
+        reject(false);
+      } finally {
+        args[0][0]({ confirmLoading: false });
+      }
+    });
+  },
+  //宸ュ崟閰嶇疆淇濆瓨鏂规硶
+  SaveCofig: (e, ...args) => {
+    return new Promise((resolve, reject) => {
+      try {
+        const xx = e['prodinfo'];
+        resolve(true);
+      } catch {
+        reject(false);
+      } finally {
+        args[0][0]({ confirmLoading: false });
+      }
+    });
+  },
+  //宸ュ崟涓嬪彂淇濆瓨鏂规硶
+  SaveWoBatch: (e, ...args) => {
+    return new Promise((resolve, reject) => {
+      try {
+        const xx = e['forminfo'];
+        resolve(true);
+      } catch {
+        reject(false);
+      } finally {
+        args[0][0]({ confirmLoading: false });
+      }
+    });
   },
 };
 
@@ -96,7 +133,7 @@
     label: '鐗╂枡缂栫爜',
     required: true,
     colProps: {
-      span: 8,
+      span: 12,
     },
     componentProps: {
       placeholder: '璇疯緭鍏ョ墿鏂欑紪鐮�',
@@ -111,15 +148,7 @@
     component: 'Input',
     label: '鐗╂枡绫诲瀷',
     colProps: {
-      span: 8,
-    },
-  },
-  {
-    field: 'field6',
-    component: 'DatePicker',
-    label: '瀛楁3',
-    colProps: {
-      span: 8,
+      span: 12,
     },
   },
   {
@@ -152,12 +181,16 @@
     },
   },
   {
-    field: 'field8',
-    component: 'Input',
-    label: '瀛楁5',
+    field: 'fieldsc',
+    component: 'Upload',
+    label: '鎵撳嵃妯℃澘',
     colProps: {
       span: 10,
     },
+    rules: [{ required: true, message: '璇烽�夋嫨涓婁紶鏂囦欢' }],
+    componentProps: {
+      api: uploadApi,
+    },
   },
 ];
 
diff --git a/src/views/components/data.ts b/src/views/components/data.ts
index e6b981b..cbb4c0b 100644
--- a/src/views/components/data.ts
+++ b/src/views/components/data.ts
@@ -1,5 +1,5 @@
 import {
-  getFns,
+  getWoFns,
   woGetSelectSuccess,
   woCustFn,
   woformSchema,
@@ -12,17 +12,29 @@
 
 const { t } = useI18n();
 export const formSchema: FormSchema[] = [];
-export function custFunction(e: any, fnName: string, type: string, ...args) {
+export async function custFunction<T = any>(
+  e: any,
+  fnName: string,
+  type: string,
+  ...args
+): Promise<T> {
   switch (type) {
     case 'BIZ_MES_WO':
-      getFns[fnName](e, args);
-      break;
     case 'BIZ_MES_WO_Config':
-      getFns[fnName](e, args);
-      break;
+      return getWoFns[fnName](e, args);
+    // break;
     default:
-      break;
-      (e) => {};
+      return new Promise((resolve, reject) => {
+        try {
+          (e) => {};
+          resolve(true);
+        } catch {
+          reject(false);
+        } finally {
+          args[0][0]({ confirmLoading: false });
+        }
+      });
+    // break;
   }
 }
 
diff --git a/src/views/tigerprojects/mes/prod/biz_mes_wo/index.vue b/src/views/tigerprojects/mes/prod/biz_mes_wo/index.vue
index 56fe9bd..672314f 100644
--- a/src/views/tigerprojects/mes/prod/biz_mes_wo/index.vue
+++ b/src/views/tigerprojects/mes/prod/biz_mes_wo/index.vue
@@ -71,7 +71,7 @@
     >
       <!-- 鐢ㄦ彃妲借嚜瀹氫箟澶氳〃鍗� -->
       <template #[item.name] v-for="item in dtlSlots" :key="item.name">
-        <BasicForm @register="useFormData[item.name][0]">
+        <BasicForm @register="useFormData[item.name][0]" v-if="useFormData[item.name]">
           <!-- 鐢ㄦ彃妲借嚜瀹氫箟寮瑰嚭閫夋嫨妗� -->
           <template #[name]="{ field }" v-for="name in item.slots" :key="name">
             <a-button
@@ -86,13 +86,16 @@
             />
           </template>
         </BasicForm>
+        <!-- 鑷畾涔夊唴瀹� -->
+        <div style="height: 200px" id="lfContainer" v-if="isCustEl[item.name]"></div>
       </template>
     </CustModal>
     <RouteViewModal @register="registerRv" @success="RvItemSuccess" />
   </div>
 </template>
 <script lang="ts" setup>
-  import { reactive, unref, h, onMounted, ref, nextTick } from 'vue';
+  import { reactive, unref, h, onMounted, ref, nextTick, Ref } from 'vue';
+  import { Steps, Step, Layout, LayoutContent } from 'ant-design-vue';
   import { BasicTable, useTable, TableAction } from '/@/components/Table';
   import { BasicForm, FormSchema, FormActionType, useForm } from '/@/components/Form/index';
   import WoDrawer from './WoDrawer.vue';
@@ -109,8 +112,20 @@
   import { useModal } from '/@/components/Modal';
   import { getListByPage } from '/@/api/tigerapi/system';
   import { GetSelectSuccess, OpenSelectItem, getFormSchema } from '/@/views/components/data';
+  import LogicFlow from '@logicflow/core';
+  import { getRouteData } from '/@/api/tigerapi/mes/router';
+  import actionRect from '/@/components/FlowChart/src/actionRect';
+  import TestNode from '/@/components/FlowChart/src/TestNode';
+  import CollectNode from '/@/components/FlowChart/src/CollectNode';
+  import AssemblyNode from '/@/components/FlowChart/src/AssemblyNode';
+  import PackingNode from '/@/components/FlowChart/src/PackingNode';
+  import RepairNode from '/@/components/FlowChart/src/RepairNode';
+  import customEdge from '/@/components/FlowChart/src/customEdge';
+  import { Snapshot, BpmnElement, Menu, DndPanel, SelectionSelect } from '@logicflow/extension';
 
   const { t } = useI18n();
+  const ASteps = Steps;
+  const AStep = Step;
   const cType = ref('');
   const title = ref('宸ュ崟瀵煎叆');
   const mtitle = ref('宸ュ崟鍒楄〃');
@@ -123,6 +138,7 @@
     loading: false,
     tip: '鍔犺浇涓�...',
   });
+  const lfInstance = ref(null) as Ref<LogicFlow | null>;
   const [registerRv, { openModal: openRvModal }] = useModal();
   const [registerWo, { openModal: openWoModal }] = useModal();
   const [registerItemAdd, { openModal: openItemModal }] = useModal();
@@ -148,10 +164,20 @@
     bordered: true,
     showIndexColumn: false,
   });
+  const routeData = ref({
+    nodes: [],
+    edges: [],
+  });
   const formSchema = ref([] as FormSchema[]);
   const woSchema = ref([] as FormSchema[]);
   const prodSchema = ref([] as FormSchema[]);
-  const xxSchema = ref([] as FormSchema[]);
+  const rotSchema = ref([] as FormSchema[]);
+  const isCustEl = ref({
+    forminfo: false,
+    woinfo: false,
+    prodinfo: false,
+    rotinfo: true,
+  });
   //琛ㄥ崟涓彃妲芥覆鏌撴寜閽墦寮�妯℃�佹useModal鏂规硶
   const useModalData = ref({
     add: useModal(),
@@ -185,17 +211,17 @@
       },
       showActionButtonGroup: false,
     }),
-    xxinfo: useForm({
-      labelWidth: 120,
-      schemas: xxSchema,
-      actionColOptions: {
-        span: 24,
-      },
-      showActionButtonGroup: false,
-    }),
+    // rotinfo: useForm({
+    //   labelWidth: 120,
+    //   schemas: rotSchema,
+    //   actionColOptions: {
+    //     span: 24,
+    //   },
+    //   showActionButtonGroup: false,
+    // }),
   });
 
-  onMounted(() => {});
+  onMounted(async () => {});
 
   //鏂板
   function addWo() {
@@ -231,19 +257,30 @@
         preIcons: { addRot: 'search|svg', setRot: 'config|svg' },
         title: '浜у搧淇℃伅',
       },
-      { name: 'xxinfo', slots: ['add'], preIcons: { add: 'search|svg' }, title: 'XXX' },
+      { name: 'rotinfo', slots: ['add'], preIcons: { add: 'search|svg' }, title: '宸ヨ壓淇℃伅' },
     ];
     woSchema.value = getFormSchema('woinfo');
     prodSchema.value = getFormSchema('prodinfo');
-    xxSchema.value = getFormSchema('xxinfo');
+    // rotSchema.value = getFormSchema('rotinfo');
+    if (lfInstance.value != null) {
+      routeData.value = {
+        nodes: [],
+        edges: [],
+      };
+      const lf = unref(lfInstance)!;
+      lf.render({});
+    }
     openCustModal(true, {
       isUpdate: true,
       ctype: cType,
       title: '宸ヨ壓閰嶇疆',
       width: '1000px',
       formEl: useFormData.value, //濡傛灉鏄涓〃鍗曪紝澧炲姞澶氫釜鎻掓Ы
-      formElName: ['woinfo', 'prodinfo', 'xxinfo'],
+      formElName: ['woinfo', 'prodinfo', 'rotinfo'], //琛ㄥ崟鎻掓Ы鍚嶇О锛屾敮鎸佸涓〃鍗�
       RowKey: '',
+      fnName: { BIZ_MES_WO_Config: 'SaveCofig' }, //淇濆瓨鏂规硶鍚�
+      initFnName: {}, //鍒濆鍖栨柟娉曞悕
+      isCustEl: isCustEl.value,
       ...record,
     });
   }
@@ -265,8 +302,11 @@
       title: '宸ュ崟涓嬪彂', //鏍囬
       width: '900px', //寮瑰嚭妗嗗搴�
       formEl: useFormData.value,
-      formElName: ['forminfo'],
+      formElName: ['forminfo'], //琛ㄥ崟鎻掓Ы鍚嶇О
       RowKeys: { add: 'ROUTE_CODE', set: 'ROUTE_CODE' }, //鎻掓Ы鐨勫脊鍑烘閫夋嫨鐨刢ode
+      fnName: { BIZ_MES_WO: 'SaveWoBatch' }, //淇濆瓨鏂规硶鍚�
+      initFnName: {}, //鍒濆鍖栨柟娉曞悕
+      isCustEl: isCustEl.value,
       ...record,
     });
   }
@@ -336,6 +376,13 @@
     let _val = {};
     _val[d.returnFieldName] = values[d.returnFieldName];
     useFormData.value[item][1].setFieldsValue(_val);
+    if (d.returnFieldName == 'ROUTE_CODE') {
+      routeData.value = {
+        nodes: [],
+        edges: [],
+      };
+      init(selectVals.value['ID']);
+    }
   }
 
   /* 寮瑰嚭閫夋嫨妗� */
@@ -350,4 +397,55 @@
     ); //[openRvModal], selectVals.value['ID']杩欐槸鑷畾涔夊弬鏁帮紝鎸夊疄闄呴渶姹�
   }
   function RvItemSuccess(d, u) {}
+
+  async function init(rotId) {
+    LogicFlow.use(BpmnElement);
+    lfInstance.value = new LogicFlow({
+      container: document.querySelector('#lfContainer'),
+      edgeGenerator: (sourceNode) => {
+        // console.log('a');
+        // 璧峰鑺傜偣绫诲瀷 rect 鏃朵娇鐢� 鑷畾涔夌殑杈� custom-edge
+        if (sourceNode.properties.isReturn) return 'custom-edge';
+        // if (sourceNode.type === 'rect') return 'custom-edge';
+        // return 'custom-edge';
+      },
+    });
+    const lf = unref(lfInstance)!;
+    // lf?.setDefaultEdgeType('line');
+    lf.register(customEdge);
+    lf.register(actionRect);
+    lf.register(TestNode);
+    lf.register(CollectNode);
+    lf.register(AssemblyNode);
+    lf.register(PackingNode);
+    lf.register(RepairNode);
+    lf.render({});
+    //閫氳繃宸ヨ壓璺嚎ID鑾峰彇鍥惧舰鏁版嵁锛屽苟娓叉煋
+    var _data = await getRouteData(rotId);
+    console.log('缁勪欢宸叉寕杞�', _data);
+    //宸ヨ壓璺嚎鍏ㄤ俊鎭紝鍖呮嫭Node銆丒dge鍜孉ct
+    // routeConfig.routeData = _data.Data;
+    if (_data.Data != null) {
+      //宸ヨ壓璺嚎涓讳俊鎭�
+      var currRoute = _data.Data.route;
+      _data.Data.nodes.forEach((n) => {
+        n.node.properties = JSON.parse(n.node.properties);
+        routeData.value.nodes.push(n.node);
+      });
+      console.log('111', routeData.value);
+      _data.Data.edges.forEach((e) => {
+        e.edge.properties = JSON.parse(e.edge.properties);
+        routeData.value.edges.push(e.edge);
+      });
+      _data.Data.acts.forEach((act) => {
+        act.node.properties = JSON.parse(act.node.properties);
+        routeData.value.nodes.push(act.node);
+      });
+      console.log('init', unref(lf).getGraphData(), JSON.parse(JSON.stringify(routeData.value)));
+      lf.render(routeData.value);
+      // lf.graphModel.resize(500, 400);
+      lf.graphModel.fitView();
+      lf.graphModel.translateCenter();
+    }
+  }
 </script>

--
Gitblit v1.9.3