Ben Lin
2024-08-22 ec0d91353b767f089fa72f3cd1eb62568852710b
src/views/tigerprojects/mes/eng/route/index.vue
@@ -47,7 +47,12 @@
<script lang="ts" setup>
  import { FlowChart } from '/@/components/FlowChart';
  import { PageWrapper } from '/@/components/Page';
  import { SaveRouteData, getRouteData } from '/@/api/tigerapi/mes/router';
  import {
    SaveRouteData,
    SaveWoRouteData,
    getRouteData,
    getWoRouteData,
  } from '/@/api/tigerapi/mes/router';
  import { useModal } from '/@/components/Modal';
  import RouteModal from './RouteModal.vue';
  import { onMounted, ref, unref, Ref, provide, reactive, nextTick, watch } from 'vue';
@@ -94,6 +99,7 @@
    currentAct: {} as MES_ROUTE_NODE_ACT,
    routeData: {} as RouteData,
    activeKey: 1,
    isWorkOrder: false,
  });
  const currRoute = ref({} as MES_ROUTE);
  const routeData = ref({
@@ -104,11 +110,16 @@
  provide<Ref<MES_ROUTE>>('mesRoute', currRoute);
  const selectnode = ref({} as node);
  const currRotId = ref(route.params?.id);
  const prodCode = ref('');
  const custCode = ref('');
  const colSlots = ref<any>([]);
  const crudColSlots = ref<any>([]);
  const entityName = ref<any>('MES_POSITION');
  const props = defineProps({
    rotId: { type: String, default: '' },
    rotType: { type: String, default: 'Route' },
    prodCode: { type: String, default: '' },
    custCode: { type: String, default: '' },
  });
  const IsOperation = ref(false);
  const title = ref('');
@@ -116,10 +127,10 @@
  let _num = 1;
  let _numEdge = 1;
  watch(
    () => props.rotId,
    [() => props.rotId,()=> props.prodCode, () => props.custCode],
    (v) => {
      if (v !== currRotId.value) {
        currRotId.value = v;
      if (!isNullOrEmpty(v[0]) && v[0] !== currRotId.value) {
        currRotId.value = v[0];
        if (!isNullOrUnDef(unref(currlf))) {
          unref(currlf).render({});
          routeData.value = {
@@ -128,6 +139,12 @@
          };
          init(currlf);
        }
      }
      if (!isNullOrEmpty(v[1]) && v[1] !== prodCode.value) {
        prodCode.value = v[1];
      }
      if (!isNullOrEmpty(v[2]) && v[2] !== custCode.value) {
        custCode.value = v[2];
      }
    },
    { deep: true },
@@ -145,7 +162,11 @@
  async function init(lf) {
    currlf.value = unref(lf);
    //通过工艺路线ID获取图形数据,并渲染
    var _data = await getRouteData(currRotId.value);
    routeConfig.isWorkOrder = props.rotType == 'Wo';
    var _data =
      props.rotType == 'Route'
        ? await getRouteData(currRotId.value)
        : await getWoRouteData(currRotId.value);
    console.log('组件已挂载', _data);
    //工艺路线全信息,包括Node、Edge和Act
    routeConfig.routeData = _data.Data;
@@ -154,6 +175,12 @@
      currRoute.value = _data.Data.route;
      if (!isNullOrEmpty(currRotId.value) && isNullOrEmpty(props.rotId)) {
        setTitle('设计:工艺路线-' + currRoute.value.ROT_CODE);
      }
      if(!isNullOrEmpty(prodCode.value)){
        currRoute.value.PROD_CODE = !isNullOrEmpty(currRoute.value.PROD_CODE)?currRoute.value.PROD_CODE: prodCode.value;
      }
      if(!isNullOrEmpty(custCode.value)){
        currRoute.value.CUST_CODE = !isNullOrEmpty(currRoute.value.CUST_CODE)?currRoute.value.CUST_CODE: custCode.value;
      }
      _data.Data.nodes.forEach((n) => {
        n.node.properties = JSON.parse(n.node.properties);
@@ -174,6 +201,11 @@
    }
  }
  /**
   * @description: 获取工艺路线图数据
   * @param {*} lf
   * @return {*}
   */
  const GetRotData = (lf) => {
    var currRotData: RouteData = {
      route: {
@@ -192,6 +224,9 @@
        AUTH_ORG: useUserStore().getUserInfo.orgCode,
        AUTH_PROD: '',
        AUTH_WH: '',
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
      },
      nodes: [],
      edges: [],
@@ -244,6 +279,9 @@
              // DO_IF_FAIL: a.DO_IF_FAIL,
              node: {} as node,
              IS_ACTIVE: a.IS_ACTIVE,
              WORK_ORDER: a.WORK_ORDER,
              PROD_CODE: a.PROD_CODE,
              CUST_CODE: a.CUST_CODE,
            };
            var pnode = [n];
            while (pnode[0].properties.operType == 'Action') {
@@ -294,6 +332,9 @@
              OPTION_4: '',
              OPTION_5: '',
              node: {} as node,
              WORK_ORDER: nd.WORK_ORDER,
              PROD_CODE: nd.PROD_CODE,
              CUST_CODE: nd.CUST_CODE,
            };
            nd.GPH_TYPE = n.type;
            nd.GPH_PROP = JSON.stringify(n.properties);
@@ -342,6 +383,9 @@
        OPTION_4: '',
        OPTION_5: '',
        edge: {} as edge,
        WORK_ORDER: routeConfig.routeData.route.WORK_ORDER,
        PROD_CODE: routeConfig.routeData.route.PROD_CODE,
        CUST_CODE: routeConfig.routeData.route.CUST_CODE,
      };
      routeConfig.routeData.edges.push(edge);
      currRotData.edges.push(edge);
@@ -355,7 +399,10 @@
   */
  async function handleSave(lf) {
    console.log('handleSave', unref(lf).getGraphData().nodes[0]);
    if (isNullOrEmpty(currRoute.value.ROT_CODE)) {
    if (
      isNullOrEmpty(currRoute.value.ROT_CODE) ||
      (props.rotType == 'Wo' && isNullOrEmpty(currRoute.value.WORK_ORDER))
    ) {
      createErrorModal({
        title: t('未选择'),
        content: t('未选择工艺路线或者新增工艺路线'),
@@ -380,7 +427,10 @@
          getContainer: () => document.body,
        });
      } else {
        var action = await SaveRouteData(GetRotData(lf));
        var action =
          props.rotType == 'Wo'
            ? await SaveWoRouteData(GetRotData(lf))
            : await SaveRouteData(GetRotData(lf));
        if (action.IsSuccessed) {
          await refreshPage();
        }
@@ -455,6 +505,9 @@
        OPTION_4: '',
        OPTION_5: '',
        node: {} as node,
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
      };
      routeConfig.routeData.nodes.push(_node);
      _num++;
@@ -504,6 +557,9 @@
          OPTION_5: '',
          REMARK: '',
          node: {} as node,
          WORK_ORDER: currRoute.value.WORK_ORDER,
          PROD_CODE: currRoute.value.PROD_CODE,
          CUST_CODE: currRoute.value.CUST_CODE,
        };
        routeConfig.routeData.acts.push(_act);
        _numEdge++;
@@ -542,6 +598,9 @@
        OPTION_5: '',
        REMARK: '',
        node: {} as node,
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
      };
      const actModel = lf.getNodeModelById(selectnode.value.id);
      actModel.updateText(routeConfig.currentAct?.ACT_NAME);
@@ -574,6 +633,10 @@
        ALLOW_DFT_IN: _node.ALLOW_DFT_IN,
        IS_OUTPUT: _node.IS_OUTPUT,
        REMARK: _node.REMARK,
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
        node: {} as node,
      };
      const nodeModel = lf.getNodeModelById(selectnode.value.id);
      nodeModel.updateText(_node.NODE_NAME);