/*
|
* @Description: 产品工艺路线Store
|
* @Author: Ben Lin
|
* @version:
|
* @Date: 2024-06-18 15:09:47
|
* @LastEditors: Ben Lin
|
* @LastEditTime: 2024-10-16 00:41:53
|
*/
|
import { defineStore } from 'pinia';
|
import { store } from '@/store';
|
import { MesRotTree } 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: MesRotTree[];
|
curPkgConfig: any;
|
curSelectedNodes: any;
|
ItemCode: string;
|
}
|
|
export const useProdRouteStore = defineStore({
|
id: 'app-prodrot',
|
state: (): ProdRouteState => ({
|
curProdRotTree: [],
|
curPkgConfig: {},
|
curSelectedNodes: {},
|
ItemCode: ''
|
}),
|
getters: {
|
getCurProdRotTree(state): MesRotTree[] {
|
return state.curProdRotTree;
|
},
|
getCurPkgConfig(state): any {
|
return state.curPkgConfig;
|
},
|
getCurSelectedNodes(state): any {
|
return state.curSelectedNodes;
|
},
|
getItemCodes(state): string {
|
return state.ItemCode;
|
},
|
},
|
actions: {
|
setCurPkgConfig(val: any) {
|
this.curPkgConfig = val;
|
},
|
setCurProdRotTree(info: MesRotTree[]) {
|
this.curProdRotTree = info;
|
},
|
setCurSelectedNodes(val: any) {
|
this.curSelectedNodes = val;
|
},
|
setItemCode(val: string) {
|
this.ItemCode = val;
|
},
|
resetState() {
|
this.curProdRotTree = [];
|
this.curPkgConfig = {};
|
this.curSelectedNodes = {};
|
},
|
/**
|
* @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){
|
this.curProdRotTree[0].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);
|
}
|