index.js
9.87 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import { getGoodsCategoryConfiguration } from "@/api/sys.base.js"
import { getAllGoodsList } from "@api/grounding"
import { getBaseSceneCodeBySceneType } from "@/common/sceneBaseSceneCode"
import { merchantSettleDistributeRuleLastRule } from "@api/shelfManage"
import { paymentChannelList } from "@api/merchant"
export default {
namespaced: true,
state: {
estimatedFlow: "",
estimatedUpgradeRate: "",
operationModeAsync: "",
shelfUpdateMerchant: {
merchantId: "",
merchantName: "",
scene: ""
},
shelfUpdateParMer: {},
shelfUpdateContractMer: {},
operationMode: "",
packageNoticeList: [], // 套餐数据
// 商品数据
goodsInfoData: {
id: "",
baseGoodsId: "",
sapCode: "",
supplierCode: "",
supplierName: "",
sceneName: "",
sceneType: "",
goodsName: "",
baseGoodsName: "",
goodsCode: "",
brandMerchantName: "",
specificationType: "1",
thumbUrl: [],
goodsTypeName: "",
goodsImgList: [],
goodsId: [],
specificationDetailList: [],
upgradeGoodsList: [],
distributionType: "0",
goodsSpecificationNameList: [],
status: "",
goodsSpecificationList: [],
goodsPositionList: [],
applicableModelNames: "",
positionNames: "",
shoppingMallFlag: "0",
goodsSpecificationSingleList: [],
specificationSingleDetailList: [],
selectedSceneCode: "",
goodsType: "",
baseGoodsNameEmpty: false,
scrmFlag: "N"
},
promiseGetGoodsCategoryConfiguration: null,
goodsCategoryConfigurationList: null,
isLoadingGoodsCategoryConfiguration: false, // 加载状态
promiseGetGoods: null,
goods: null,
isLoadingGoods: false, // 加载状态
merchantSettleDistributeRuleLastRule: null,
firstLineSunshineOnlinePointsFlag: null,
firstLineSunshine2OnlinePointsFlag: null,
paymentChannelList: [],
isLoadingPaymentChannelList: null,
promiseGetPaymentChannelList: null
},
mutations: {
/**
* @description 数据改变
* @param {Object} state state
*/
setUpdateGoodsInfo(state, data) {
state.goodsInfoData = Object.assign(state.goodsInfoData, data)
},
SET_DATA(state, { data, name }) {
state[name] = data
},
SET_LOADING(state, { isLoading, name }) {
state[name] = isLoading
},
SET_ERROR(state, error) {
state.error = error
},
SET_PROMISE(state, { promise, name }) {
state[name] = promise
}
},
actions: {
// ...原有fetchCategoryList
async refreshCategoryList({ commit, dispatch }) {
// 清空旧数据
commit("SET_DATA", {
data: null,
name: "goodsCategoryConfigurationList"
})
dispatch("getGoodsCategoryConfiguration") // 重新请求
// 清空旧数据
commit("SET_DATA", {
data: null,
name: "goods"
})
commit("SET_DATA", {
data: null,
name: "operationModeAsync"
})
commit("SET_DATA", {
data: null,
name: "firstLineSunshineOnlinePointsFlag"
})
commit("SET_DATA", {
data: null,
name: "firstLineSunshine2OnlinePointsFlag"
})
commit("SET_DATA", {
data: null,
name: "merchantSettleDistributeRuleLastRule"
})
dispatch("getGoods") // 重新请求
},
async getGoodsCategoryConfiguration({ commit, state }) {
if (state.goodsCategoryConfigurationList) {
return state.goodsCategoryConfigurationList
}
// 正在请求,返回现有Promise
if (state.promiseGetGoodsCategoryConfiguration) {
return state.promiseGetGoodsCategoryConfiguration
}
try {
commit("SET_LOADING", {
isLoading: true,
name: "isLoadingGoodsCategoryConfiguration"
})
const promise = getGoodsCategoryConfiguration({}) // 替换为你的API调用
commit("SET_PROMISE", {
promise,
name: "promiseGetGoodsCategoryConfiguration"
})
const response = await promise
commit("SET_DATA", {
data: response.list,
name: "goodsCategoryConfigurationList"
})
// 判断一下是商户多还是分账规则多, 去最大值做loading
const {
createBusinessApproveMerchantList,
merchantSettleDistributeRule
} = response
let timeNum = Math.max(
createBusinessApproveMerchantList?.length || 0,
merchantSettleDistributeRule?.goodsTypeGroupRules || 0,
15
)
console.log(timeNum, "timeNum")
timeNum = timeNum >= 15 ? timeNum : 0
console.log(timeNum, "timeNum")
setTimeout(() => {
commit("SET_LOADING", {
isLoading: false,
name: "isLoadingGoodsCategoryConfiguration"
})
}, timeNum * 1000)
return response.list
} finally {
// commit("SET_LOADING", {
// isLoading: false,
// name: "isLoadingGoodsCategoryConfiguration"
// })
commit("SET_PROMISE", {
promise: null,
name: "promiseGetGoodsCategoryConfiguration"
}) // 清除Promise
}
},
async getGoods({ commit, state }) {
if (state.goods) {
return state.goods
}
// 正在请求,返回现有Promise
if (state.promiseGetGoods) {
return state.promiseGetGoods
}
try {
commit("SET_LOADING", {
isLoading: true,
name: "isLoadingGoods"
})
const promise = getAllGoodsList({
currentPage: 1,
pageSize: 20,
baseSceneCode: getBaseSceneCodeBySceneType(0)
})
commit("SET_PROMISE", {
promise,
name: "promiseGetGoods"
})
const response = await promise
console.log(response, "getGoods")
commit("SET_DATA", {
data: response,
name: "goods"
})
return response
} finally {
commit("SET_LOADING", {
isLoading: false,
name: "isLoadingGoods"
})
commit("SET_PROMISE", {
promise: null,
name: "promiseGetGoods"
}) // 清除Promise
}
},
async getPaymentChannelList({ commit, state }) {
if (state.paymentChannelList && state.paymentChannelList.length) {
return state.paymentChannelList
}
// 正在请求,返回现有Promise
if (state.promiseGetPaymentChannelList) {
return state.promiseGetPaymentChannelList
}
try {
commit("SET_LOADING", {
isLoading: true,
name: "isLoadingPaymentChannelList"
})
const promise = paymentChannelList({}) // 替换为你的API调用
commit("SET_PROMISE", {
promise,
name: "promiseGetPaymentChannelList"
})
const response = await promise
console.log(response, "getGoods")
commit("SET_DATA", {
data: response,
name: "paymentChannelList"
})
return response
} finally {
commit("SET_LOADING", {
isLoading: false,
name: "isLoadingPaymentChannelList"
})
commit("SET_PROMISE", {
promise: null,
name: "promiseGetPaymentChannelList"
}) // 清除Promise
}
},
async getMerchantSettleDistributeRuleLastRule({ commit, state }, id) {
console.log(id, "getMerchantSettleDistributeRuleLastRule")
if (state.merchantSettleDistributeRuleLastRule) {
return state.merchantSettleDistributeRuleLastRule
}
// 正在请求,返回现有Promise
if (state.promiseMerchantSettleDistributeRuleLastRuleInfo) {
return state.promiseMerchantSettleDistributeRuleLastRuleInfo
}
try {
commit("SET_LOADING", {
isLoading: true,
name: "isLoadingRule"
})
const promise = merchantSettleDistributeRuleLastRule({
id
}) // 替换为你的API调用
commit("SET_PROMISE", {
promise,
name: "promiseMerchantSettleDistributeRuleLastRuleInfo"
})
const response = await promise
console.log(response, "getMerchantSettleDistributeRuleLastRule")
commit("SET_DATA", {
data: response,
name: "merchantSettleDistributeRuleLastRule"
})
return response
} finally {
commit("SET_LOADING", {
isLoading: false,
name: "isLoadingRule"
})
commit("SET_PROMISE", {
promise: null,
name: "promiseMerchantSettleDistributeRuleLastRuleInfo"
}) // 清除Promise
}
}
},
getters: {
getGoodsInfoData(state) {
return state.goodsInfoData
},
merchantSettleDistributeRuleLastRuleInfo(state) {
return state.merchantSettleDistributeRuleLastRule
},
packageNoticeList(state) {
return state.packageNoticeList
},
operationMode(state) {
return state.operationMode
},
shelfUpdateContractMer(state) {
return state.shelfUpdateContractMer
},
shelfUpdateMerchant(state) {
return state.shelfUpdateMerchant
},
shelfUpdateParMer(state) {
return state.shelfUpdateParMer
},
estimatedFlow(state) {
return state.estimatedFlow
},
estimatedUpgradeRate(state) {
return state.estimatedUpgradeRate
},
operationModeAsync(state) {
return state.operationModeAsync
},
firstLineSunshineOnlinePointsFlagAsync(state) {
return state.firstLineSunshineOnlinePointsFlag
},
firstLineSunshine2OnlinePointsFlagAsync(state) {
return state.firstLineSunshine2OnlinePointsFlag
},
isLoadingGoodsCategoryConfiguration(state) {
return state.isLoadingGoodsCategoryConfiguration
},
shelfType(state) {
// 多商户
return (
state.merchantSettleDistributeRuleLastRule?.basicInfo.shelfType == 2
)
}
}
}