Ben Lin
2024-11-07 7c99be35803568d4743a8d134b0479bbf6f281fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * @Description: 产品工艺路线Store
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-18 15:09:47
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-10-22 08:37:57
 */
import { defineStore } from 'pinia';
import { store } from '@/store';
import { MesRotTree, PageRotTree } from '/@/api/tigerapi/model/mesModel';
import { SetDefaultRoute } from '/@/api/tigerapi/mes/router';
import { useUserStore } from './user';
import { findParent } from '/@/api/tigerapi/system';
 
interface ProdRouteState {
  curProdRotTree: PageRotTree[];
  curConfig: any;
  curSelectedNodes: any[];
  ItemCode: string;
  CustCode: string;
  name: string;
  curDtl: any;
  changeToCPPage: boolean;
}
 
export const useProdRouteStore = defineStore({
  id: 'app-prodrot',
  state: (): ProdRouteState => ({
    curProdRotTree: [],
    curConfig: {},
    curSelectedNodes: [],
    ItemCode: '',
    curDtl: {},
    changeToCPPage: false,
    name: '',
    CustCode: ''
  }),
  getters: {
    getCurProdRotTree(state): PageRotTree[] {
      return state.curProdRotTree;
    },
    getCurConfig(state): any {
      return state.curConfig;
    },
    getCurSelectedNodes(state): any[] {
      return state.curSelectedNodes;
    },
    getItemCodes(state): string {
      return state.ItemCode;
    },
    getCustCode(state): string {
      return state.CustCode;
    },
    getcurDtl(state): any {
      return state.curDtl;
    },
    getChangeToCPPage(state): boolean {
      return state.changeToCPPage;
    },
    getname(state): string {
      return state.name;
    },
  },
  actions: {
    setCurPkgConfig(val: any) {
      this.curConfig = val;
    },
    /**
     * @description: 当前工艺树数据
     * @param {any} val
     * @return {*}
     */
    setCurProdRotTree(val: any) {
      if (!this.curProdRotTree.some((q) => q.name == val.name)) {
        this.curProdRotTree.push(val);
      } else {
        if (val.length == 0) {
          this.curProdRotTree = [];
        } else {
          this.curProdRotTree.map((item) => {
            if (item.name == val.name) {
              item.treeInfo = val.treeInfo;
            }
          });
        }
      }
    },
    /**
     * @description: 当前选中节点
     * @param {any} val
     * @return {*}
     */
    setCurSelectedNodes(val: any) {
      if (!this.curSelectedNodes.some((q) => q.name == val.name)) {
        this.curSelectedNodes.push(val);
      } else {
        if (val.length == 0) {
          this.curSelectedNodes = [];
        } else {
          this.curSelectedNodes.map((item) => {
            if (item.name == val.name) {
              item.SelectedNodes = val.SelectedNodes;
            }
          });
        }
      }
    },
    setItemCode(val: string) {
      this.ItemCode = val;
    },
    setCustCode(val: string) {
      this.CustCode = val;
    },
    setcurDtl(val: any) {
      this.curDtl = val;
    },
    setChangeToCPPage(val: boolean) {
      this.changeToCPPage = val;
    },
    setname(val: string) {
      this.name = val;
    },
    resetState() {
      this.curProdRotTree = [];
      this.curConfig = {};
      this.curSelectedNodes = [];
      this.curDtl = {};
      this.name = '';
      this.ItemCode = '';
      this.CustCode = '';
    },
    /**
     * @description: 设置默认工艺路线
     * @return {*}
     */
    async setDefaulRoute(param) {
      /* 设置默认工艺路线 */
      var action = await SetDefaultRoute({
        rotCode: param.others['code'],
        prodCode: param.keyCode,
        custCode: '',
        rotId: '',
        options: {
          //根据据点查询,必需带这个参数
          UserId: useUserStore().getUserInfo.userId as string,
          ByOrg: true,
          CurOrg: useUserStore().getUserInfo.orgCode as string,
          ByProd: false,
          ByWh: false,
          OrgCode: useUserStore().getUserInfo.orgCode as string,
        },
        isDefault: param.others['isDefault'],
      });
      if (action.IsSuccessed) {
        const rotTree = this.curProdRotTree.filter((q) => q.name == this.getname);
        rotTree[0].treeInfo.children[0].children.map((item) => {
          if (item.code == param.others['code']) {
            item.isDefault = true;
          } else {
            item.isDefault = false;
          }
        });
      }
      return action;
    },
    /**
     * @description: 查找父项并返回
     * @param {string} tid
     * @return {*}
     */
    getParent(tid: string): MesRotTree {
      return findParent(this.getCurProdRotTree, tid) as unknown as MesRotTree;
    },
  },
});
 
// Need to be used outside the setup
export function useProdRouteWithOut() {
  return useProdRouteStore(store);
}