Ben Lin
2024-08-09 d7b0c15619e89d31c74f8db7a680b4c6a0009add
src/views/components/bizMesWo.ts
@@ -1,3 +1,11 @@
/*
 * @Description: 工单自定义方法ts
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-05 16:10:24
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-16 10:06:44
 */
/* 工单相关自定义方法 */
import { FunctionType } from '/@/api/tigerapi/model/systemModel';
import { GetEnum, SaveEntity, getEntity } from '/@/api/tigerapi/system';
@@ -6,11 +14,27 @@
import { useI18n } from '/@/hooks/web/useI18n';
import { uploadApi } from '/@/api/sys/upload';
import { useLocale } from '/@/locales/useLocale';
import { unref } from 'vue';
import { ref, unref } from 'vue';
import { BIZ_MES_WO_BATCH } from '/@/api/tigerapi/model/mesModel';
import { buildUUID } from '/@/utils/uuid';
import LogicFlow from '@logicflow/core';
import { BpmnElement } from '@logicflow/extension';
import { getRouteData } from '/@/api/tigerapi/mes/router';
import customEdge from '/@/components/FlowChart/src/customEdge';
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';
const { t } = useI18n();
const { getLocale } = useLocale();
/* 自定义方法 */
/**
 * @description: 自定义方法
 * @return {*}
 */
export const getWoFns: Record<string, FunctionType> = {
  handleSubmit: async (e, ...args) => {
    const values = await args[0][0].validate();
@@ -49,29 +73,149 @@
      }
    });
  },
  //工单配置保存方法
  /**
   * @description: 工单配置保存方法
   * @param {*} e
   * @param {array} args
   * @return {*}
   */
  SaveCofig: (e, ...args) => {
    return new Promise((resolve, reject) => {
      try {
        const xx = e['prodinfo'];
        resolve(true);
        const form = e['prodinfo'];
        const wo = e['mValues'];
        wo.ROUTE_STATUS = 1;
        SaveEntity(wo, true, 'BIZ_MES_WO').then((action) => {
          if (action.IsSuccessed) {
            resolve(true);
          } else {
            reject(false);
          }
        });
      } catch {
        reject(false);
      } finally {
        args[0][0]({ confirmLoading: false });
      }
    });
  },
  //工单下发保存方法
  /**
   * @description: 工单下发保存方法
   * @param {*} e
   * @param {array} args
   * @return {*}
   */
  SaveWoBatch: (e, ...args) => {
    return new Promise((resolve, reject) => {
      try {
        const xx = e['forminfo'];
        const form = e['forminfo'];
        const wo = e['mValues'];
        wo.ROUTE_CODE = form.ROUTE_CODE;
        wo.STATUS = 2;
        const woBatch: BIZ_MES_WO_BATCH = {
          ID: buildUUID(),
          CREATE_TIME: new Date(),
          CREATE_USER: useUserStore().getUserInfo.userId as string,
          UPDATE_TIME: new Date(),
          UPDATE_USER: useUserStore().getUserInfo.userId as string,
          GHOST_ROW: false,
          AUTH_ORG: '',
          AUTH_PROD: useUserStore().getUserInfo.prodCode as string,
          AUTH_WH: '',
          ORDER_NO: wo.ORDER_NO,
          STATUS: wo.STATUS,
          ITEM_CODE: wo.ITEM_CODE,
          CUST_CODE: wo.CUST_CODE,
          FACTORY: wo.FACTORY,
          WS_CODE: wo.WS_CODE,
          ACT_LINE: form.PLAN_LINE,
          STD_WORKER_QTY: wo.STD_WORKER_QTY,
          ACT_WORKER_QTY: wo.ACT_WORKER_QTY,
          RELEASE_TIME: new Date(),
          RELEASE_USER: useUserStore().getUserInfo.userId as string,
          PLAN_QTY: wo.PLAN_QTY,
          INPUT_QTY: wo.INPUT_QTY,
          OUTPUT_QTY: wo.OUTPUT_QTY,
          SCRAP_QTY: wo.SCRAP_QTY,
          STOCK_IN_QTY: wo.STOCK_IN_QTY,
          UPH: wo.UPH,
          UPPH: wo.UPPH,
          REMARK: wo.REMARK,
          ACT_START_TIME: wo.ACT_START_TIME,
          ACT_END_TIME: wo.ACT_END_TIME,
        };
        SaveEntity(woBatch, false, 'BIZ_MES_WO_BATCH').then((action) => {
          if (action.IsSuccessed) {
            SaveEntity(wo, true, 'BIZ_MES_WO').then((action) => {
              if (action.IsSuccessed) {
                resolve(true);
              } else {
                reject(false);
              }
            });
          } else {
            reject(false);
          }
        });
      } catch {
        reject(false);
      }
    });
  },
  initRoute: async (e, ...args) => {
    const _data = await getRouteData(args[0][0].ROUTE_CODE);
    args[0][1] = ref({
      nodes: [],
      edges: [],
    });
    return new Promise((resolve, reject) => {
      try {
        LogicFlow.use(BpmnElement);
        const lf = 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';
          },
        });
        lf.register(customEdge);
        lf.register(actionRect);
        lf.register(TestNode);
        lf.register(CollectNode);
        lf.register(AssemblyNode);
        lf.register(PackingNode);
        lf.register(RepairNode);
        lf.render({});
        //通过工艺路线ID获取图形数据,并渲染
        console.log('组件已挂载', _data);
        //工艺路线全信息,包括Node、Edge和Act
        // routeConfig.routeData = _data.Data;
        if (_data.Data != null) {
          //工艺路线主信息
          const currRoute = _data.Data.route;
          _data.Data.nodes.forEach((n) => {
            n.node.properties = JSON.parse(n.node.properties);
            args[0][1].value.nodes.push(n.node);
          });
          console.log('111', args[0][1]);
          _data.Data.edges.forEach((e) => {
            e.edge.properties = JSON.parse(e.edge.properties);
            args[0][1].value.edges.push(e.edge);
          });
          _data.Data.acts.forEach((act) => {
            act.node.properties = JSON.parse(act.node.properties);
            args[0][1].value.nodes.push(act.node);
          });
          console.log('init', unref(lf).getGraphData(), JSON.parse(JSON.stringify(args[0][1])));
          lf.render(args[0][1].value);
          // lf.graphModel.resize(500, 400);
          lf.graphModel.fitView();
          lf.graphModel.translateCenter();
        }
        resolve(true);
      } catch {
        reject(false);
      } finally {
        args[0][0]({ confirmLoading: false });
      }
    });
  },
@@ -190,6 +334,7 @@
    rules: [{ required: true, message: '请选择上传文件' }],
    componentProps: {
      api: uploadApi,
      multiple: false,
    },
  },
];
@@ -244,7 +389,16 @@
    component: 'Input',
    required: true,
    colProps: {
      span: 12,
      span: 24,
    },
  },
  {
    field: 'RELEASE_QTY',
    label: '工单下发数量',
    component: 'Input',
    required: true,
    colProps: {
      span: 24,
    },
  },
  {
@@ -253,11 +407,11 @@
    component: 'ApiSelect',
    required: true,
    colProps: {
      span: 12,
      span: 24,
    },
    componentProps: {
      api: getEntity,
      params: { entityName: 'MES_LINE', sqlcmd: ' 1=1 ' },
      params: { entityName: 'MES_LINE', sqlcmd: ' 1=1 ', order: '' },
      resultField: 'Data.Items',
      labelField: 'LINE_NAME',
      valueField: 'LINE_CODE',
@@ -269,7 +423,7 @@
    component: 'Input',
    required: true,
    colProps: {
      span: 12,
      span: 22,
    },
  },
  {
@@ -292,21 +446,26 @@
      span: 1,
    },
  },
  {
    field: 'fieldsc',
    component: 'Upload',
    label: '打印模板',
    colProps: {
      span: 10,
    },
    rules: [{ required: true, message: '请选择上传文件' }],
    componentProps: {
      api: uploadApi,
    },
  },
  // {
  //   field: 'fieldsc',
  //   component: 'Upload',
  //   label: '打印模板',
  //   colProps: {
  //     span: 10,
  //   },
  //   rules: [{ required: true, message: '请选择上传文件' }],
  //   componentProps: {
  //     api: uploadApi,
  //   },
  // },
];
//工艺路线弹框返回
/**
 * @description: 工艺路线弹框返回
 * @param {*} d
 * @param {*} u
 * @return {*}
 */
export function woGetSelectSuccess(d, u) {
  return {
    ROUTE_CODE: d.values['val'],
@@ -314,7 +473,14 @@
  };
}
/* 自定义模态框打开方法 */
/**
 * @description: 自定义模态框打开方法
 * @param {Fn} openModal
 * @param {string} slotName
 * @param {Fn} others
 * @param {array} args
 * @return {*}
 */
export function woCustFn(openModal: Fn, slotName: string, others: Fn[], ...args) {
  switch (slotName) {
    case 'add':
@@ -350,6 +516,7 @@
        tableName: 'MES_ROUTE',
        rowKey: 'ROT_CODE',
        returnFieldName: 'ROUTE_CODE', //返回值要赋值的字段名称
        searchInfo: { TABLE_NAME: 'MES_ROUTE' },
      });
      break;
    case 'set':