Ben Lin
2024-06-18 c3e294ff76aff4654c7218645c7a13b539f66a36
src/views/components/bizMesWo.ts
@@ -1,136 +1,342 @@
/*
 * @Description: 工单自定义方法ts
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-05 16:10:24
 * @LastEditors: your name
 * @LastEditTime: 2024-06-15 22:43:55
 */
/* 工单相关自定义方法 */
import { FunctionType } from '/@/api/tigerapi/model/systemModel';
import { SaveEntity, getEntity } from '/@/api/tigerapi/system';
import { GetEnum, SaveEntity, getEntity } from '/@/api/tigerapi/system';
import { FormSchema } from '/@/components/Table';
import { useUserStore } from '/@/store/modules/user';
import { useI18n } from '/@/hooks/web/useI18n';
import { uploadApi } from '/@/api/sys/upload';
import { notification } from 'ant-design-vue';
import { useLocale } from '/@/locales/useLocale';
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';
import { multiply } from 'lodash-es';
const { t } = useI18n();
const { getLocale } = useLocale();
export const getFns: Record<string, FunctionType> = {
/**
 * @description: 自定义方法
 * @return {*}
 */
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 });
      }
    });
  },
  /**
   * @description: 工单配置保存方法
   * @param {*} e
   * @param {array} args
   * @return {*}
   */
  SaveCofig: (e, ...args) => {
    return new Promise((resolve, reject) => {
      try {
        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);
      }
    });
  },
  /**
   * @description: 工单下发保存方法
   * @param {*} e
   * @param {array} args
   * @return {*}
   */
  SaveWoBatch: (e, ...args) => {
    return new Promise((resolve, reject) => {
      try {
        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);
      }
    });
  },
};
export const woCfgformSchema: FormSchema[] = [
  {
    field: 'field1',
    field: 'ORDER_NO',
    component: 'Input',
    label: '字段1',
    label: '工单号',
    colProps: {
      span: 8,
    },
    componentProps: {
      placeholder: '自定义placeholder',
      placeholder: '请输入工单号',
      onChange: (e: any) => {
        console.log(e);
      },
    },
    dynamicDisabled: true,
  },
  {
    field: 'field2',
    field: 'ORDER_TYPE',
    component: 'Select',
    label: '工单类型',
    colProps: {
      span: 8,
    },
    defaultValue: 'Normal',
    componentProps: {
      options: [
        {
          label: '正常',
          value: 'Normal',
        },
        {
          label: '返工',
          value: 'Rework',
        },
      ],
    },
    dynamicDisabled: true,
  },
  {
    field: 'PLAN_QTY',
    component: 'Input',
    label: '字段2',
    label: '计划数量',
    colProps: {
      span: 8,
    },
  },
  {
    field: 'field3',
    component: 'DatePicker',
    label: '字段3',
    colProps: {
      span: 8,
    },
    dynamicDisabled: true,
  },
];
export const prodCfgformSchema: FormSchema[] = [
  {
    field: 'field4',
    field: 'ITEM_CODE',
    component: 'Input',
    label: '字段1',
    label: '物料编码',
    required: true,
    colProps: {
      span: 8,
      span: 12,
    },
    componentProps: {
      placeholder: '自定义placeholder',
      placeholder: '请输入物料编码',
      onChange: (e: any) => {
        console.log(e);
      },
    },
    dynamicDisabled: true,
  },
  {
    field: 'field5',
    field: 'ITEM_TYPE',
    component: 'Input',
    label: '字段2',
    label: '物料类型',
    colProps: {
      span: 8,
      span: 12,
    },
  },
  {
    field: 'field6',
    component: 'DatePicker',
    label: '字段3',
    colProps: {
      span: 8,
    },
  },
  {
    field: 'field7',
    label: '工艺路线',
    field: 'ROUTE_CODE',
    component: 'Input',
    label: '字段4',
    required: true,
    colProps: {
      span: 8,
      span: 12,
    },
  },
  {
    field: 'addRot',
    component: 'Input',
    label: '1',
    colSlot: 'addRot',
    defaultValue: 'MES_ROUTE',
    colProps: {
      span: 1,
    },
  },
  {
    field: 'setRot',
    component: 'Input',
    label: '1',
    colSlot: 'setRot',
    defaultValue: 'MES_ROUTE',
    colProps: {
      span: 1,
    },
  },
  {
    field: 'fieldsc',
    component: 'Upload',
    label: '打印模板',
    colProps: {
      span: 10,
    },
    rules: [{ required: true, message: '请选择上传文件' }],
    componentProps: {
      placeholder: '自定义placeholder',
      onChange: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'field8',
    component: 'Input',
    label: '字段5',
    colProps: {
      span: 8,
    },
  },
  {
    field: 'field9',
    component: 'DatePicker',
    label: '字段6',
    colProps: {
      span: 8,
      api: uploadApi,
      multiple: false,
    },
  },
];
@@ -151,11 +357,21 @@
    },
  },
  {
    field: 'field11',
    field: 'ROUTE_CODE',
    component: 'Input',
    label: '字段2',
    colProps: {
      span: 8,
    },
  },
  {
    field: 'add',
    component: 'Input',
    label: '1',
    colSlot: 'add',
    defaultValue: 'MES_ROUTE',
    colProps: {
      span: 1,
    },
  },
  {
@@ -237,7 +453,12 @@
  },
];
//工艺路线弹框返回
/**
 * @description: 工艺路线弹框返回
 * @param {*} d
 * @param {*} u
 * @return {*}
 */
export function woGetSelectSuccess(d, u) {
  return {
    ROUTE_CODE: d.values['val'],
@@ -245,10 +466,19 @@
  };
}
export function woCustFn(openItemModal: Fn, slotName: string, others: Fn[], ...args) {
/**
 * @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':
      openItemModal(true, {
    case 'addRot':
      openModal(true, {
        title: '工艺路线列表',
        schemas: [
          {
@@ -279,15 +509,17 @@
        tableName: 'MES_ROUTE',
        rowKey: 'ROT_CODE',
        returnFieldName: 'ROUTE_CODE', //返回值要赋值的字段名称
        searchInfo: {TABLE_NAME: 'MES_ROUTE' }
      });
      break;
    case 'set':
    case 'setRot':
      //   notification.success({
      //     message: '点击了设置按钮',
      //     description: `OK`,
      //     duration: 3,
      //   });
      others[0](true, { rotId: args[0][0], slotName: 'set' });
      others[0](true, { rotId: args[0][0], slotName: slotName });
      break;
    default:
      () => {};