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
|
// vue的methods中
async dialogClick(){
let loading = this.$loading({
lock: true,
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.2)",
});
loading.$el.lastElementChild.style.fontSize = "40px";
try{
if(!this.submitOrderList.length){ // 只有其他物品
await this.addOtherGoods();
await this.applyOtherGoods();
}else if(!this.otherList.length){ // 只有常规物品
await this.applyOrdinaryGoods();
}else{ // 两者都有(进入此函数前已排除两者都无的情况)
await this.addOtherGoods();
await Promise.all([this.applyOtherGoods(), this.applyOrdinaryGoods()]);
}
loading.close();
this.$router.push({ path: "/ApplicationCompleted" });
} catch(error){
console.error(error);
loading.close();
this.$store.commit("comment/UP_ERRORINFO", {
type: "fail",
msg: error.message,
timestamp: new Date().getTime()
});
}
},
addOtherGoods(){
let otherGoods = this.otherList.map(item=>{
return {gNAME:item.name};
});
let params = {
token: this.$store.state.tab.token,
goods: JSON.stringify(otherGoods)
};
return this.$post(`goods/addApplyGoods`,params).then(res=>{
let requestData = this.$NodeRSA.decryptByPrivateKey(
res.requestData,
res.encrypted
);
this.otherList.forEach((item, index) => {
item.id = requestData.data[index].gID;
});
});
},
applyOtherGoods(){
let otherFinal = this.otherList.map(item => {
return {
gNAME: item.name,
gUSENUM: item.num,
gID: item.id
};
});
let params = {
token: this.$store.state.tab.token,
goods: JSON.stringify(otherFinal)
};
return this.$post(`goods/apply`, params).then(res=>{
let requestData = this.$NodeRSA.decryptByPrivateKey(
res.requestData,
res.encrypted
);
console.log(requestData, 'other goods submit order result');
if (requestData.code !== 0) {
throw new Error(requestData.message);
}
});
},
applyOrdinaryGoods() {
let params = {
token: this.$store.state.tab.token,
goods: JSON.stringify(this.submitOrderList)
};
return this.$post(`goods/apply`, params)
.then(res => {
let requestData = this.$NodeRSA.decryptByPrivateKey(
res.requestData,
res.encrypted
);
console.log(requestData, 'ordinary goods submit order result');
if (requestData.code !== 0) {
throw new Error(requestData.message);
}
});
},
|