app.js
11.3 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
App({
onLaunch: function () {
if (wx.getStorageSync('token')) {
this.getmessagelist()
}
this.getToken();
//自动更新版本
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '更新提示',
content: '新版本下载失败',
showCancel: false
})
})
},
post: function (url, data, showLoad) {
wx.showNavigationBarLoading()
var promise = new Promise((resolve, reject) => {
//init
let that = this;
let postData = data, baseUrl;
// let baseUrl = 'https://binhai.w.broing.cn/api';
// let baseUrl ='http://binhaitest.w.brotop.cn/api'
// 现在用的
// let baseUrl = 'https://binhai.w.broing.cn/api'
// let baseUrl = 'http://binhaitest.w.brotop.cn/api'
// 滨海
var entrance_type = wx.getStorageSync("entrance_type");
console.log(entrance_type);
if (entrance_type == '1' || entrance_type == '0' || url == '/getopenid/get' || url.indexOf('/wb/wb')>-1) {
//劳保商城入口
console.log('11111111111111111')
baseUrl = 'https://binhai.w.broing.cn/api';
// baseUrl = 'http://binhai.shs.broing.cn/api'
} else if (entrance_type == '2') {
//工会商城入口
console.log('@@@@@@@@@@@@@@@@@@@@@@')
baseUrl = 'https://binhaigh.w.broing.cn/api';
// baseUrl = 'http://gonghui.shs.broing.cn/api'
} else if (entrance_type == '3') {
//办公入口
baseUrl = 'https://bgcb.w.broing.cn/api';
}
// 天远甄选
// if (entrance_type == '1' || url == '/getopenid/get' || url.indexOf('address') > -1) {
// //劳保商城入口
// baseUrl = 'https://binhai2.w.broing.cn/api';
// } else if (entrance_type == '2') {
// //工会商城入口
// baseUrl = 'https://binhaigh2.w.broing.cn/api';
// } else if (entrance_type == '3') {
// //工会商城入口
// baseUrl = 'https://bgcb2.w.broing.cn/api';
// }
console.log(baseUrl);
//网络请求
wx.request({
url: baseUrl + url,
data: postData,
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded',
'token': wx.getStorageSync('token') || ''
},
success: function (res) { //返回取得的数据
console.log('ssssssssssssssssssssssssssssssssssss', res)
if (res.data.code == '200') {
resolve(res.data)
} else if (res.data.code == '5000') {
wx.hideLoading();
reject(res.data)
wx.removeStorageSync('login');
wx.showModal({
title: '提示',
content: res.data.msg,
showCancel: false
})
wx.removeStorageSync('token');
setTimeout(() => {
wx.navigateTo({
url: '/pages/register/register?type=1',
})
}, 1200)
} else {
wx.showModal({
title: '提示',
content: res.data.msg,
showCancel: false
})
reject(res.data)
}
setTimeout(function () {
wx.hideNavigationBarLoading()
}, 600)
},
fail: function (e) {
reject('网络出错');
wx.hideNavigationBarLoading()
}
})
});
return promise;
},
getToken() {
let that = this;
let u = that.interface.getToken;
wx.login({
success: (result) => {
that.postk(u, {
code: result.code
}).then((r) => {
console.log(r)
wx.setStorageSync('token', r.data.token)
wx.setStorageSync('login', r.data.login_new1)
wx.setStorageSync('gh_login', r.data.login_new2)
wx.setStorageSync('cb_login', r.data.login_new3)
wx.setStorageSync('sq', r.data.sq1)
wx.setStorageSync('gh_sq', r.data.sq2)
wx.setStorageSync('cb_sq', r.data.sq3)
})
},
fail: (res) => { },
complete: (res) => { },
})
},
// 开放商城公共接口
postk: function (url, data, showLoad) {
wx.showNavigationBarLoading()
var promise = new Promise((resolve, reject) => {
//init
let that = this;
let postData = data
// 滨海
let baseUrl = 'https://binhaidispark.w.broing.cn/api'
// 天远甄选
// let baseUrl = 'https://binhaidispark2.w.broing.cn/api'
//网络请求
wx.request({
url: baseUrl + url,
data: postData,
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded',
'token': wx.getStorageSync('token') || ''
// 'token': '' || ''
},
success: function (res) { //返回取得的数据
if (res.data.code == '1') {
resolve(res.data)
} else if (res.data.code == '5000') {
wx.hideLoading();
reject(res.data)
wx.removeStorageSync('token');
wx.removeStorageSync('login');
// wx.navigateTo({
// url: '/pages/register/register?type=1',
// })
} else {
wx.showToast({
title: res.data.msg,
icon: 'none',
})
reject(res.data)
}
setTimeout(function () {
wx.hideNavigationBarLoading()
}, 600)
},
fail: function (e) {
reject('网络出错');
wx.hideNavigationBarLoading()
}
})
});
return promise;
},
upload(filetype, file) {
var promise = new Promise((resolve, reject) => {
wx.showNavigationBarLoading()
wx.showLoading({
title: '上传中',
})
let url = 'https://binhaidispark.w.broing.cn/api/common/upload';
let head = {
'token': wx.getStorageSync('token'),
'XX-Device-Type': ''
}
let typename = {
filetype: filetype
}
wx.uploadFile({
url: url, //仅为示例,非真实的接口地址
filePath: file,
name: 'file',
header: head,
formData: typename,
success: function (res) {
console.log('上传文件后', res)
let temdata = JSON.parse(res.data);
console.log(temdata)
let urlobj = {
url: temdata.data.url
}
resolve(urlobj);
},
fail: function (res) {
reject('网络出错');
wx.hideNavigationBarLoading()
wx.hideLoading()
},
complete: () => {
wx.hideNavigationBarLoading()
wx.hideLoading()
},
})
});
return promise;
},
// 获取个人信息
getInfoFun() {
let that = this;
let u = that.interface.readteacher;
that.post(u, {}).then((r) => {
console.log('3489523498', r)
if (r.code == 200) {
wx.setStorageSync('login', r.msg.login_new)
// that.globalData.login_new=r.msg.login_new;
// console.log( that.globalData.login_new)
// t.setData({
// obj: r.msg
// })
}
})
},
getmessagelist() {
let that = this
let url = '/information/get_all';
let data = {
page: 1,
pageNum: 10,
}
this.post(url, data, "POST").then((r) => {
// console.log(r)
// that.setData({
// messagelist: that.data.messagelist.concat(r.msg)
// })
let newlist = [];
r.msg.forEach(function (value, index, array) {
console.log(newlist)
if (value.status == 1) {
newlist.push(value)
}
})
console.log('77889944556', newlist)
if (newlist.length != 0) {
wx.showTabBarRedDot({
index: 1,
success: function (red) {
wx.setTabBarBadge({
index: 1,
text: newlist.length.toString(),
})
}
})
}
}).catch((err) => { })
},
onShow: function () {
console.log('hahahahhahahahhhahh')
},
//接口管理
interface: {
openid: '/getopenid/get', // 获取openid
getcode: '/getopenid/getcode', // 获取验证码,
getToken: '/user/getToken',
readteacher: '/getopenid/readteacher', // 获取个人信息
login: '/getopenid/smslogin', // 登录
jifenlist: '/order/jifenlist', // 积分列表
address: '/address/index', // 地址列表
addaddress: '/address/add', // 添加地址
editaddress: '/address/edit', // 修改地址
deladdress: '/address/delete', // 删除地址
mraddress: '/address/mo', // 修改默认地址
adshow: '/address/editshow', //地址详情(数据回显)
about: '/wb/wb', // 关于我们
order: '/order/orderlist', // 获取订单列表
payorder: '/order/payorder', // 订单页点击支付
disorder: '/order/disorder', // 订单列表取消订单
orderrefund: '/order/orderrefund', // 退换货详情
// upload: 'https://binhai.w.broing.cn/api/common/upload', // 上传图片
upload: 'https://binhai.w.brotop.cn/api',
refund: '/order/refund', // 退货提交
delorder: '/order/delorder', // 删除订单
okorder: '/order/okorder', // 确认订单
orderInfo: '/order/orderInfo', // 订单详情
kuaidi: '/kuaidi/kuaidi', //物流信息
collectdel: '/product/collectdel', //收藏删除
collectList: '/getopenid/collectlist', //收藏列表
deleteseach: '/product/deleteseach', //删除搜索历史
order_pay: '/order/pay', //订单支付
now_add: '/order/now_add', //点击结算
hotsreach: '/product/hotsreach', // 热门搜索
searchhis: '/product/searchhis', // 商品搜索历史
search: '/product/search', // 商品搜索结果列表
getPid: '/cap/getpid', // 分类页面
prev_pay: '/shop/prev_pay', // 购物车点击结算
gwcshop: '/shop/gwcshop', //购物车数量修改保存
deletes: '/shop/deletes', //购物车删除
shopcar: '/shop/shopcar', // 购物车页面
now_prev_pay: '/shop/now_prev_pay', // 直接购买
addshop: '/shop/addshop', // 添加购物车
collect: '/product/collect', // 收藏
getInfo: '/product/getInfo', //商品详情
good_list: '/product/get', // 商品
index: '/cap/get', // 首页大小分类
banner: '/banner/index', // 轮播图
notice: '/cap/notice', // 公告
youfei: '/shop/youfei1', // 单算邮费
youfei1: '/shop/youfei', // 購物車邮费
shopcarNum: '/shop/shopcarnum', // 购物车数量
orderlist: '/shop/orderlist', // 订单各状态数量
order_read: '/shop/read', // 订单数
orderMixed: '/order/zhifu',
},
globalData: {
login_new: "",
// 滨海
baseUrlimg: 'https://binhaidispark.w.broing.cn/',
// 天远
// baseUrlimg: 'https://binhaidispark2.w.broing.cn/api',
}
})
// 滨海wx73497072e7340d61
// 天远wx2980402f625c4f80