/*
|
* @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);
|
}
|