Ben Lin
2024-10-22 78999ce1626d2a786f3a705281eeba79c2f1d6dd
src/views/tigerprojects/system/lowcode/entityts/ProdRouteBinding.ts
@@ -4,7 +4,7 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-08-09 01:14:01
 * @LastEditTime: 2024-10-22 09:28:36
 */
import { Ref, h, ref, render, unref } from 'vue';
@@ -13,6 +13,7 @@
  GetRoutePTree,
  RouteToCust,
  RouteToProd,
  SetDefaultRoute,
} from '/@/api/tigerapi/mes/router';
import { GetEnum, SaveEntity, convertToTree, getEntity } from '/@/api/tigerapi/system';
import { useLocale } from '/@/locales/useLocale';
@@ -21,16 +22,22 @@
import { NavItem } from '/@/api/tigerapi/model/basModel';
import { useMessage } from '/@/hooks/web/useMessage';
import { useModal } from '/@/components/Modal';
import { BasicColumn, FormSchema, useTable } from '/@/components/Table';
import { ActionItem, BasicColumn, FormSchema, useTable } from '/@/components/Table';
import { CustModalParams } from '/@/api/tigerapi/model/systemModel';
import { useUserStore } from '/@/store/modules/user';
import { EventDataNode } from 'ant-design-vue/lib/tree';
import { ContextMenuItem } from '/@/components/TigerTree';
import { useForm } from '/@/components/Form';
import { mesApi } from '/@/api/tigerapi/mes/mesApi';
import { BAS_LABEL_VAR_WO, MesRotTree } from '/@/api/tigerapi/model/mesModel';
import { buildUUID } from '/@/utils/uuid';
import { AddOrEditLabelVarByWorkOrder } from '/@/api/tigerapi/mes/wo';
import { useProdRouteStore } from '/@/store/modules/prodRoute';
const { t } = useI18n();
const { createErrorModal } = useMessage();
const { getLocale } = useLocale();
const useProdRoute = useProdRouteStore();
function _default() {
  /* 定义变量 */
  const isNormal = (type: number) => type === 0;
@@ -75,8 +82,8 @@
     * @description: 高级表单和详情页面返回主页面的url
     * @return {*}
     */
    GetHomeUrl: () => {
      return `/V_BAS_PROD/LC/${encodeURI(JSON.stringify({ ID: 'V_BAS_PROD', colSlots: [], crudColSlots: [] }))}`;
    GetHomeUrl: (params) => {
      return `/V_BAS_PROD_R/LC/${encodeURI(JSON.stringify({ ID: 'V_BAS_PROD_R', colSlots: [], crudColSlots: [], sName: params['sName'] }))}`;
    },
    /**
     * @description: 获取树形数据
@@ -85,19 +92,40 @@
     */
    fetchTreeData: async (type: string, itemCode: string) => {
      let data = { title: '', treeData: [] as any[], fieldNames: {} };
      let prodTreeData = await GetRoutePTree({
      let prodTreeData = (await GetRoutePTree({
        prodCode: itemCode,
        orgCode: useUserStore().getUserInfo.orgCode,
      });
      // let uniqueArr = prodTreeData.reduce((acc, current) => {
      //   if (!acc.some((x) => x.pid == current.pid && x.id == current.id && x.seq == current.seq && x.type == current.type)) {
      //     acc.push(current);
      //   }
      //   return acc;
      // }, [] as V_MES_ROUTE_PTREE[]);
      data.treeData = convertToTree(prodTreeData, 'pid', 'tid', 'root');
      })) as unknown as MesRotTree[];
      let _treeData = convertToTree(prodTreeData, 'pid', 'tid', 'root');
      data.title = '工艺路线';
      data.fieldNames = { key: 'tid', title: 'name' };
      if (
        !useProdRoute.changeToCPPage ||
        !useProdRoute.curProdRotTree.some((q) => q.name == itemCode)
      ) {
        /* 保存工艺树形数据到状态管理 */
        useProdRoute.setCurProdRotTree({
          name: itemCode,
          treeInfo: _treeData as unknown as MesRotTree[],
        });
      }
      useProdRoute.setItemCode(itemCode);
      if (useProdRoute.curProdRotTree.some((q) => q.name == itemCode)) {
        data.treeData = useProdRoute.curProdRotTree.filter((q) => q.name == itemCode)[0].treeInfo;
      }
      return data;
    },
    /**
     * @description: 操作字段自定义按钮,必需要有的方法
     * @return {*}
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      data.push({
        icon: 'template|svg',
        tooltip: '模板维护',
        onClick: handleTemplate.bind(null, args, params),
        name: '模板维护',
      });
      return data;
    },
    /**
@@ -125,7 +153,15 @@
     * @return {*}
     */
    GetCrudColSlots: () => {
      return ['scanadd', 'assyadd', 'testadd', 'auditadd', 'printadd', 'pkgadd'];
      return [
        { name: 'scanadd', icon: 'search|svg' },
        { name: 'assyadd', icon: 'search|svg' },
        { name: 'testadd', icon: 'search|svg' },
        { name: 'auditadd', icon: 'search|svg' },
        { name: 'printadd', icon: 'search|svg' },
        { name: 'pkgadd', icon: 'search|svg' },
        { name: 'labeladd', icon: 'search|svg' },
      ];
    },
    /**
     * @description: 切换节点时事件方法
@@ -179,6 +215,7 @@
              ACT_TYPE: res.Data.Items[0].ACT_TYPE,
              CUST_CODE: params['selectedNodes'][0].cust,
              OPTION_1: res.Data.Items[0].OPTION_1,
              OPTION_2: res.Data.Items[0].OPTION_2,
            });
            /* 如果是包装规则 */
            if (res.Data.Items[0].ACT_TYPE == 6) {
@@ -247,6 +284,7 @@
              ItemCode: false,
            };
          }
          useProdRoute.setcurDtl(result);
          resolve(result);
        } catch (e) {
          reject(e);
@@ -269,6 +307,9 @@
        }
        values.AUTH_ORG = useUserStore().getUserInfo.orgCode;
        values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
        if (type == 'Action') {
          values.OPTION_1 = JSON.stringify(useProdRoute.getcurDtl['BAS_PKG_DTL']);
        }
        SaveEntity(values, true, entityName).then((action) => {
          if (action.IsSuccessed) {
            emit('success');
@@ -279,10 +320,14 @@
    /**
     * @description: 弹出选择框打开方法
     * @param {Fn} openItemModal
     * @param {array} args
     * @return {*}
     */
    OpenSelectItem: (openItemModal: Fn, ...args) => {
      let config = {};
      const openCrudModal = args[1];
      const record = args[2];
      const OrderNo = args[3];
      switch (args[0]) {
        case 'scanadd':
          config = ruleModalCfg;
@@ -300,12 +345,41 @@
          config = pkgModalCfg;
          break;
      }
      openItemModal(true, config);
      if (args[0] == 'labeladd') {
        openCrudModal(true, {
          isUpdate: true, //是否更新操作
          entityName: 'ProdRouteBinding', //是哪个页面
          ctype: 'BAS_LABEL_VAR_WO', //实体名称
          title: '模板维护', //标题
          width: '1024px', //弹出框宽度
          ItemColumns: TemplateBasColumn, //弹出框中表格字段结构
          schemas: [], //查询条件字段结构
          others: { WORK_ORDER: OrderNo }, //需要带到弹出窗口中的数据
          searchInfo: {
            TABLE_NAME: 'BAS_LABEL_VAR_WO', //实体名称
            LabelId: record.LABEL_CODE, //模板ID
            WorkOrder: OrderNo, //工单号
            apiUrl: mesApi.GetLabelVarByWorkOrder, //自定义获取数据分页的api,不用默认的基础方法
            // sqlcmd: ` (WORK_ORDER = '${OrderNo}' OR WORK_ORDER = '' OR WORK_ORDER IS NULL)`,
            // option:
            // {
            //   //根据据点查询,必需带这个参数
            //   UserId: useUserStore().getUserInfo.userId,
            //   ByOrg: true,
            //   CurOrg: useUserStore().getUserInfo.orgCode,
            // },
          },
          values: record, //表单记录
        });
      } else {
        openItemModal(true, config);
      }
    },
    /**
     * @description: 弹出选择框选择成功返回
     * @param {*} d
     * @param {*} u
     * @param {array} args
     * @return {*}
     */
    GetSelectSuccess: async (d, u, ...args) => {
@@ -415,6 +489,25 @@
        testadd: useModal(),
        auditadd: useModal(),
        printadd: useModal(),
        labeladd: useModal(),
        pkgadd: useModal(),
      };
    },
    /**
     * @description: 获取在增删改表单中的模态框应用列表
     * @return {*}
     */
    GetUseCrudModals: () => {
      return {
        addRoute: useModal(),
        addCustomer: useModal(),
        editRoute: useModal(),
        scanadd: useModal(),
        assyadd: useModal(),
        testadd: useModal(),
        auditadd: useModal(),
        printadd: useModal(),
        labeladd: useModal(),
        pkgadd: useModal(),
      };
    },
@@ -433,11 +526,13 @@
          // searchInfo: { TABLE_NAME: 'V_BAS_PKG_DTL' },
          dataSource: data.value['BAS_PKG_DTL'],
          columns: GetBaseColumns('BAS_PKG_DTL', args[0], data),
          maxHeight: 520,
          // maxHeight: 520,
          // scroll: { y: window.screen.width == 1366? 400: 450 },
          isCanResizeParent: true,
          useSearchForm: false,
          showTableSetting: false,
          bordered: true,
          canResize: true,
          // canResize: false,
          showIndexColumn: false,
          // rowSelection: {
          //   type: 'radio', //'checkbox'
@@ -475,6 +570,10 @@
        }),
      };
    },
    /**
     * @description: 获取行为或者节点的配置表单结构,使用useForm()
     * @return {*}
     */
    GetUseForm: () => {
      return {
        Action: useForm({
@@ -512,6 +611,7 @@
    /**
     * @description: 获取标题信息
     * @param {string} type
     * @param {*} item
     * @return {*}
     */
    GetTitle: (type: string, item) => {
@@ -526,7 +626,7 @@
     * @param {Ref} selectedNodes
     * @return {*}
     */
    SelectNode: (selectedNodes: Ref<any[]>) => {
    SelectNode: (selectedNodes: Ref<any[]>, code: string) => {
      let result = {
        showConfig: false,
        showNav: false,
@@ -545,16 +645,15 @@
      if (selectedNodes.value[0].type == 'Action' || selectedNodes.value[0].type == 'Node') {
        result.showNav = false;
        result.showConfig = true;
        if (selectedNodes.value[0].type == 'Action') {
          result.showOtherTable = { BAS_PKG_DTL: false, ItemCode: false };
        } else {
          result.showOtherTable = { BAS_PKG_DTL: false, ItemCode: false };
        }
        result.showOtherTable = { BAS_PKG_DTL: false, ItemCode: false };
      }
      /* 保存当前选择的节点数据到状态管理 */
      useProdRoute.setCurSelectedNodes({ name: code, SelectedNodes: selectedNodes.value });
      return result;
    },
    /**
     * @description: 获取导航项
     * @param {string} type
     * @return {*}
     */
    GetNavItems: (type: string) => {
@@ -569,6 +668,7 @@
              url: '/addRoute',
              action: 'addRoute',
              isStep: false,
              isCustEl: false,
            },
            {
              title: '添加客户工艺路线',
@@ -577,18 +677,29 @@
              url: '/addCustomer',
              action: 'addCustomer',
              isStep: true,
              isCustEl: false,
            },
          ];
          break;
        case 'Route':
          item = [
            {
              title: '编辑工艺路线',
              icon: 'clarity:note-edit-line',
              title: '编辑工艺路线', //标题
              icon: 'clarity:note-edit-line', //图标
              color: '#1fdaca', //字体颜色
              url: '/editRoute', //导航地址
              action: 'editRoute', //导航执行的方法,如果按这个action来执行,上面的url就无效
              isStep: false, //是否是步骤
              isCustEl: false, //是否是自定义html内容
            },
            {
              title: '设置默认工艺路线',
              icon: '',
              color: '#1fdaca',
              url: '/editRoute',
              action: 'editRoute',
              url: '',
              action: '',
              isStep: false,
              isCustEl: true,
            },
          ];
          break;
@@ -598,12 +709,15 @@
    /**
     * @description: 导航页面切换按钮时调用方法
     * @param {any} action
     * @param {array} args
     * @return {*}
     */
    navChangeItem: (action: any, ...args) => {
      const openRvModal = args[1];
      const openModal = args[0];
      switch (action) {
        case 'addRoute':
          args[0](true, {
          openModal(true, {
            title: '工艺路线列表',
            schemas: [
              {
@@ -639,12 +753,17 @@
          });
          break;
        case 'addCustomer':
          args[0](true, {
          openModal(true, {
            title: '请完成以下步骤',
          });
          break;
        case 'editRoute':
          args[1](true, { rotId: args[2][0].id, slotName: '' });
          openRvModal(true, {
            rotId: args[2][0].id,
            slotName: '',
            prodCode: args[3],
            custCode: args[2][0].cust,
          });
          break;
      }
    },
@@ -700,35 +819,55 @@
     * @return {*}
     */
    CustFunc: async (param: CustModalParams) => {
      switch (param['ctype']) {
        case 'BAS_PKG_DTL':
          // const ents = await getEntity({
          //   sqlcmd: `PKG_RULE_ID ='${param.values['PKG_RULE_ID']}'`,
          //   entityName: 'V_BAS_PKG_DTL',
          //   order: '',
          // });
          // param.data.value['Table'] = ents.Data.Items;
          param.data.value['BAS_PKG_DTL'].map((x) => {
            if (x.PKG_CODE == param.values['PKG_CODE']) {
              x.LABEL_CODE = param.values['LABEL_CODE'];
            }
          });
          param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
            param.data.value['BAS_PKG_DTL'],
          );
          break;
        case 'ItemCode':
          param.data.value['ItemCode'].map((x) => {
            if (x.ITEM_CODE == param.values['ITEM_CODE']) {
              x.IsBatchItem = param.values['IsBatchItem'];
              x.RULE_CODE = param.values['RULE_CODE'];
            }
          });
          param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
            param.data.value['ItemCode'],
          );
          break;
      }
      return new Promise<any>(async (resolve, reject) => {
        try {
          switch (param['ctype']) {
            case 'BAS_PKG_DTL':
              // const ents = await getEntity({
              //   sqlcmd: `PKG_RULE_ID ='${param.values['PKG_RULE_ID']}'`,
              //   entityName: 'V_BAS_PKG_DTL',
              //   order: '',
              // });
              // param.data.value['Table'] = ents.Data.Items;
              param.data.value['BAS_PKG_DTL'].map((x) => {
                if (x.PKG_CODE == param.values['PKG_CODE']) {
                  x.LABEL_CODE = param.values['LABEL_CODE'];
                  x.LABEL_ID = param.values['LABEL_CODE'];
                }
              });
              param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
                param.data.value['BAS_PKG_DTL'],
              );
              resolve('OK');
              break;
            case 'ItemCode':
              param.data.value['ItemCode'].map((x) => {
                if (x.ITEM_CODE == param.values['ITEM_CODE']) {
                  x.IsBatchItem = param.values['IsBatchItem'];
                  x.RULE_CODE = param.values['RULE_CODE'];
                }
              });
              param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
                param.data.value['ItemCode'],
              );
              resolve('OK');
              break;
            case 'BAS_LABEL_VAR_WO':
              param.values['WORK_ORDER'] = param.others['WORK_ORDER'];
              param.values['ID'] = buildUUID();
              var action = await AddOrEditLabelVarByWorkOrder(
                param.values as unknown as BAS_LABEL_VAR_WO,
              );
              resolve(action);
            case 'isDefault':
              /* 设置默认工艺路线 */
              var action = await useProdRoute.setDefaulRoute(param);
              resolve(action);
          }
        } catch (e) {
          reject(e);
        }
      });
    },
    /**
     * @description: 获取右键菜单列表
@@ -843,6 +982,12 @@
            //       },
            //   };
            // },
          },
          {
            dataIndex: 'LABEL_ID',
            title: '标签模板ID',
            ifShow: false,
            customRender: () => {},
          },
        ] as BasicColumn[];
        break;
@@ -1224,7 +1369,7 @@
    {
      field: 'LABEL_CODE',
      label: '标签打印',
      colProps: { span: 11 },
      colProps: { span: 9 },
      component: 'Input',
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
    },
@@ -1233,9 +1378,18 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: 1 },
      colProps: { span: 2 },
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
      colSlot: 'printadd',
    },
    {
      field: 'print1',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
      colSlot: 'labeladd',
    },
    {
      field: 'PKG_CODE',
@@ -1252,6 +1406,28 @@
      colProps: { span: 1, pull: 1 },
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
      colSlot: 'pkgadd',
    },
    {
      field: 'OPTION_2',
      label: '是否称重',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'REMARK',
@@ -1626,6 +1802,72 @@
    ] as FormSchema[],
  };
  /**
   * @description: 模板维护
   * @param {*} args
   * @param {Recordable} params
   * @return {*}
   */
  function handleTemplate(args, params: Recordable) {
    const openCrudModal = args[0];
    // const OrderNo = args[2];
    const ProdCode = args[2];
    openCrudModal(true, {
      isUpdate: true, //是否更新操作
      entityName: 'ProdRouteBinding', //是哪个页面
      ctype: 'BAS_LABEL_VAR_WO', //实体名称
      title: '模板维护', //标题
      width: '1024px', //弹出框宽度
      ItemColumns: TemplateBasColumn, //弹出框中表格字段结构
      schemas: [], //查询条件字段结构
      others: { WORK_ORDER: '', PROD_CODE: ProdCode }, //需要带到弹出窗口中的数据
      searchInfo: {
        TABLE_NAME: 'BAS_LABEL_VAR_WO', //实体名称
        LabelId: params['record'].LABEL_ID, //模板ID
        WorkOrder: '', //工单号
        ProdCode: ProdCode,
        CustCode: '',
        apiUrl: mesApi.GetLabelVarByWorkOrder, //自定义获取数据分页的api,不用默认的基础方法
      },
      values: params['record'], //表单记录
    });
  }
  /* 下发界面中的表单列表 */
  const TemplateBasColumn = [
    {
      dataIndex: 'LABEL_ID',
      title: '标签模板ID',
      ifShow: false,
      sorter: true,
      resizable: true,
    },
    {
      title: '工单号',
      dataIndex: 'WORK_ORDER',
      width: 280,
      editRow: true,
      // editable: true,
      ifShow: false,
    },
    {
      title: '变量名',
      dataIndex: 'VAR_NAME',
    },
    {
      title: '变量值',
      dataIndex: 'VAR_VALUE',
      editRow: true,
      editRule: true,
    },
    {
      title: '默认值',
      dataIndex: 'DEFAULT_VALUE',
      // editRow: true,
      // editRule: true,
    },
  ] as BasicColumn[];
  return [methods];
}