index.js
14 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/**
* Created by shipfi on 2016/6/2.
*/
import apiResource from './resource';
import weiIndex from './jsons/weiIndex';
import personData from './jsons/personData';
import orderNum from './jsons/orderNum';
import browseRecordList from './jsons/browseRecordList';
import myCollectionList from './jsons/myCollectionList';
import couponCenterList from './jsons/couponCenterList';
import couponCenterDetail from './jsons/couponCenterDetail';
import matchNetList from './jsons/matchNetList';
import couponTab from './jsons/couponTab';
import myCouponList from './jsons/myCouponList';
import myCouponDetail from './jsons/myCouponDetail';
import groupNav from './jsons/groupNav';
import myAddressList from './jsons/myAddressList';
import selectAddress from './jsons/selectAddress';
import checkOrder from './jsons/checkOrder';
import confirmOrder from './jsons/confirmOrder';
import pushOrder from './jsons/pushOrder';
import matchCouponList from './jsons/matchCouponList';
import orderList from './jsons/orderList';
import count from './jsons/count';
import {cacheType, cacheManager} from '../utils/cacheManager';
export default {
apiAddCache: function (promiseFun, cacheType, expiresInSeconds = 3600) {
return new Promise(function (resolve, reject) {
var apiCache = cacheManager.get(cacheType);
if (apiCache) {
console.log('Get ' + cacheType + ' from Cache===========================>');
console.log(apiCache);
resolve(apiCache);
} else {
promiseFun.then(function (res) {
console.log('Get ' + cacheType + ' from API===========================>');
apiCache = {
data: res.data
};
console.log(apiCache);
cacheManager.set(cacheType, apiCache, expiresInSeconds);
resolve(res);
}, function (err) {
reject(err);
});
}
});
},
/*获取首页结构*/
getweiIndext: function (pageId) {
//return apiResource.getweiIndext.get({pageId:pageId});
return new Promise(function (resolve, reject) {
if (true) {
resolve(weiIndex);
} else {
reject(error);
}
});
},
/*获取个人中心信息*/
getpersonData: function () {
// return apiResource.getpersonData.get();
return new Promise(function (resolve, reject) {
if (true) {
resolve(personData);
} else {
reject(error);
}
});
},
/*获取个人中心订单数*/
getorderNum: function () {
// return apiResource.getOrderNum.get();
return new Promise(function (resolve, reject) {
if (true) {
resolve(orderNum);
} else {
reject(error);
}
});
},
/*获取浏览记录*/
getbrowseRecordList: function (page, pageNum) {
// return apiResource.getbrowseRecordList.get({page:page,pageNum:pageNum});
return new Promise(function (resolve, reject) {
if (1 == 1) {
var newdata = [];
var isend = browseRecordList.content.list.length - page * pageNum;
if (isend >= pageNum) {
for (var i = page * pageNum; i < page * pageNum + pageNum; i++) {
newdata = newdata.concat(browseRecordList.content.list[i]);
}
} else if (0 < isend < pageNum) {
for (var i = page * pageNum; i < browseRecordList.content.list.length; i++) {
newdata = newdata.concat(browseRecordList.content.list[i]);
}
}
var data = {count: browseRecordList.content.count, content: newdata};
console.log("接口" + data.count);
resolve(data);
} else {
reject(1);
}
});
},
/*获取我的收藏列表*/
getmyCollectionList: function (page, pageNum) {
// return apiResource.getmyAddressList.get({page:page,pageNum:pageNum});
return new Promise(function (resolve, reject) {
if (1 == 1) {
var newdata = [];
var isend = myCollectionList.content.list.length - page * pageNum;
if (isend >= pageNum) {
for (var i = page * pageNum; i < page * pageNum + pageNum; i++) {
newdata = newdata.concat(myCollectionList.content.list[i]);
}
} else if (0 < isend < pageNum) {
for (var i = page * pageNum; i < myCollectionList.content.list.length; i++) {
newdata = newdata.concat(myCollectionList.content.list[i]);
}
}
var data = {count: myCollectionList.content.count, content: newdata};
console.log("接口" + data.count);
resolve(data);
} else {
reject(1);
}
});
},
/*添加/取消收藏*/
addCancelCollection: function (id, type) {
//return apiResource.addCancelCollection.save({favoriateId:id,type:type});
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve({code: 20000});
} else {
reject(1);
}
});
},
/*获取我的优惠券列表*/
getmyCouponList: function (page, pageNum) {
// return apiResource.getmyCouponList.get({page:page,pageNum:pageNum});
return new Promise(function (resolve, reject) {
if (1 == 1) {
var newdata = [];
var isend = myCouponList.content.list.length - page * pageNum;
if (isend >= pageNum) {
for (var i = page * pageNum; i < page * pageNum + pageNum; i++) {
newdata = newdata.concat(myCouponList.content.list[i]);
}
} else if (0 < isend < pageNum) {
for (var i = page * pageNum; i < myCouponList.content.list.length; i++) {
newdata = newdata.concat(myCouponList.content.list[i]);
}
}
var data = {count: myCouponList.content.count, content: newdata};
console.log("接口" + data.count);
resolve(data);
} else {
reject(1);
}
});
},
/*获取我的优惠券详情*/
getmyCouponDetail: function () {
// return apiResource.getmyCouponDetail.get();
return new Promise(function (resolve, reject) {
if (true) {
resolve(myCouponDetail);
} else {
reject(error);
}
});
},
/*获取优惠券中心列表*/
getcouponCenterList: function (cplType, page, pageNum) {
// return apiResource.getcouponCenterList.get({cplType:{cplType},page:page,pageNum:pageNum});
return new Promise(function (resolve, reject) {
if (1 == 1) {
var newdata = [];
var isend = couponCenterList.content.list.length - page * pageNum;
if (isend >= pageNum) {
for (var i = page * pageNum; i < page * pageNum + pageNum; i++) {
newdata = newdata.concat(couponCenterList.content.list[i]);
}
} else if (0 < isend < pageNum) {
for (var i = page * pageNum; i < couponCenterList.content.list.length; i++) {
newdata = newdata.concat(couponCenterList.content.list[i]);
}
}
var data = {count: couponCenterList.content.count, content: newdata};
console.log("接口" + data.count);
resolve(data);
} else {
reject(1);
}
});
},
//获取优惠券中心标题背景
getcouponTab: function () {
// return apiResource.getcouponTab.get();
return new Promise(function (resolve, reject) {
if (true) {
resolve(orderNum);
} else {
reject(error);
}
});
},
/*获取底部导航*/
getgroupNav: function () {
// return apiResource.getgroupNav.get();
return new Promise(function (resolve, reject) {
if (true) {
resolve(groupNav);
} else {
reject(error);
}
});
},
/*获取我的地址列表*/
getmyAddressList: function (page, pageNum) {
// return apiResource.getmyAddressList.get({page:page,pageNum:pageNum});
return new Promise(function (resolve, reject) {
if (1 == 1) {
var newdata = [];
var isend = myAddressList.content.list.length - page * pageNum;
if (isend >= pageNum) {
for (var i = page * pageNum; i < page * pageNum + pageNum; i++) {
newdata = newdata.concat(myAddressList.content.list[i]);
}
} else if (0 < isend < pageNum) {
for (var i = page * pageNum; i < myAddressList.content.list.length; i++) {
newdata = newdata.concat(myAddressList.content.list[i]);
}
}
var data = {content: {count: myAddressList.content.count, list: newdata}};
console.log("接口" + data.content);
resolve(data);
} else {
reject(1);
}
});
},
/*设置默认地址*/
setDefaultAddress: function (id) {
//return apiResource.setDefaultAddress.save({buyerAddressId:id});
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve({code: 20000});
} else {
reject(1);
}
});
},
/*删除地址*/
deleteAddress: function (id) {
//return apiResource.deleteAddress.delete({buyerAddressId:id});
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve({code: 20000});
} else {
reject(1);
}
});
},
/*获取指定地址信息*/
selectAddress: function (id) {
//return apiResource.selectAddress.get({buyerAddressId: id});
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve(selectAddress);
} else {
reject(1);
}
});
},
/*保存编辑地址信息*/
posteditAddress: function (data) {
return apiResource.posteditAddress.save(data);
},
/*保存新增地址信息*/
postaddAddress: function (data) {
return apiResource.postaddAddress.save(data);
},
/*确认订单(结算)*/
postcheckOrder: function (data) {
//return apiResource.postcheckOrder.save(data);
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve(checkOrder);
} else {
reject(1);
}
});
},
/*获取符合需求的优惠券列表*/
postmatchCouponList: function (data) {
//return apiResource.postmatchCouponList.save(data);
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve(matchCouponList);
} else {
reject(1);
}
});
},
/*确认下单*/
postconfirmOrder: function (data) {
//return apiResource.postconfirmOrder.save(data);
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve(confirmOrder);
} else {
reject(1);
}
});
},
/*支付页面*/
getpushOrder: function (orderId) {
//return apiResource.getpushOrder.get({orderId:orderId});
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve(pushOrder);
} else {
reject(1);
}
});
},
/*支付订单*/
postpayOrder: function (data) {
return apiResource.postpayOrder.save(data);
//return new Promise(function (resolve, reject) {
// if (1 == 1) {
// resolve(pushOrder);
// } else {
// reject(1);
// }
//});
},
/*订单列表*/
getOrderList: function (orderState, evaluationState, page, pageNum) {
// return apiResource.getOrderList.get({orderState:orderState,evaluationState:evaluationState,page:page,pageNum:pageNum});
return new Promise(function (resolve, reject) {
if (1 == 1) {
var newdata = [];
var isend = orderList.content.list.length - page * pageNum;
if (isend >= pageNum) {
for (let i = page * pageNum; i < page * pageNum + pageNum; i++) {
newdata = newdata.concat(orderList.content.list[i]);
}
} else if (0 < isend < pageNum) {
for (let i = page * pageNum; i < orderList.content.list.length; i++) {
newdata = newdata.concat(orderList.content.list[i]);
}
}
var data = {content: {count: orderList.content.count, list: newdata}}
//console.log(data.content)
resolve(data);
} else {
reject(1);
}
});
},
/*订单列表总数*/
getOrderCount: function () {
return new Promise(function (resolve, reject) {
if (1 == 1) {
resolve(count);
} else {
reject(1);
}
});
},
};