Vintegral.js
12.1 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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
// 引入用来发送请求的方法。
import {
request
} from "../../request/index.js"
const a = getApp()
Page({
data: {
imagesUrl: a.globalData.baseUrl,
scrollLeft: 0,
// 轮播图数组
swiperList: [],
autoplay: true,
interval: 2000,
// 分类列表
cateList: [],
storeList: [], // 点赞列
recommendList: [], // 推荐列
title: '',
page: 1,
size: 3,
cate_id: '',
sott_time: '',
sort_price: '',
key_word: '',
cate_id: '',
nominate_switch: '',
click_num: '',
showDialog: false,
url: '',
more: true,
bannerImg: '',
pageNum: 1,
total: 0,
len: '',
red: false,
current_page: "",
last_page: '',
isshow: false
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onShow: function () {
this.getSwiperList()
this.getCateList()
this.getStoreList()
this.getRecommendList()
this.getBanner(),
this.setData({
more: true
})
},
onLoad: function (options) {
console.log(options);
// wx.startPullDownRefresh()
},
scroll(e) {
// console.log(e)
// console.log(e.detail.deltaX);
if (e.detail.deltaX > 0) {
this.setData({
len: '50%'
})
} else {
this.setData({
len: '100%'
})
}
},
upper(e) {
console.log("坐化", e);
// if (e.detail.direction == "left") {
// this.setData({
// len: '50%',
// // red: false
// })
// }
},
lower(e) {
console.log("右划", e)
if (e.detail.direction == "right") {
this.setData({
len: '100%',
// red: true
})
}
},
// 轮播列表
getSwiperList() {
let that = this;
request({
url: 'api/shop/roll'
})
.then(res => {
this.setData({
swiperList: res.data.data
})
// console.log(that.data.swiperList, "轮播")
})
},
getCateList() { // 获取分类列表
let that = this;
request({
url: 'api/shop/cate',
})
.then(res => {
that.setData({
cateList: res.data.data,
})
// console.log(res.data.data, that.data.cateList, "分类");
})
},
getBanner() { // 广告
let that = this;
request({
url: 'api/common/img',
})
.then(res => {
that.setData({
bannerImg: res.data.data,
})
})
},
// 获取点赞列表数据
getStoreList() {
let that = this;
request({
url: 'api/shop/shopZhong',
})
.then(res => {
that.setData({
storeList: res.data.data
})
// console.log(that.data.storeList, "点赞列表")
})
},
// 点赞商品详情
storeDetail(e) {
let id = e.currentTarget.dataset.id
let num = e.currentTarget.dataset.num
if (num == 1) {
wx.navigateTo({
url: '/pages/detail/detail?id=' + id,
})
} else {
// 无图详情
wx.navigateTo({
url: '/pages/detail/detail?id=' + id,
})
}
},
// 普通商品详情
Toproductdetails(e) {
let id = e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/productdetailsImg/productdetailsImg?id=' + id,
})
},
goToCates(e) { // 去分类
// console.log(e);
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: '/pages/category/category?id=' + id
})
},
// 查看更多
lookMoreTap() {
let that = this
that.setData({
more: false
})
request({
url: 'api/shop/zanGoodList',
})
.then(res => {
that.setData({
storeList: res.data.data
})
}).catch(err => {
console.log(err);
that.setData({
msg: err.msg
})
that.popTest()
})
},
lookMoreList() { // 更多
wx.navigateTo({
url: '/pages/searchList/searchList'
})
},
async onClickpopUp() { // 弹窗海报
this.setData({
showDialog: !this.data.showDialog
})
try {
const {
data: {
data
}
} = await request({
url: 'api/index/haiBao2'
})
this.setData({
url: data.img
})
} catch (err) {
console.log(err);
that.setData({
msg: err.msg
})
that.popTest()
}
},
keepPoster() {
var that = this;
wx.showLoading({
title: '加载中',
icon: 'none'
})
wx.downloadFile({
url: that.data.url,
success: function (res) {
wx.hideLoading()
// console.log('下载图片下载图片下载图片', res)
var tempFilePath = res.tempFilePath
//console.log('临时文件地址是:' + tempFilePath)
wx.saveFile({
tempFilePath: tempFilePath,
success: function (res) {
// console.log(res)
var saveFilePath = res.savedFilePath;
that.setData({
water_url: res.savedFilePath,
savepic: 1
})
wx.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() { //这里是用户同意授权后的回调
// console.log('111', that.data.water_url)
wx.saveImageToPhotosAlbum({
filePath: that.data.water_url,
success(res) {
wx.showModal({
content: '图片已保存到相册',
showCancel: false,
confirmText: '好的',
confirmColor: '#333',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
/* 该隐藏的隐藏 */
that.setData({
maskHidden: false
})
}
},
fail: function (res) {
}
})
}
})
},
fail() { //这里是用户拒绝授权后的回调
// wx.openSetting({
// success: function (data) {
// console.log(data)
// if (data.authSetting["scope.writePhotosAlbum"] === true) {
// console.log("是否授权成功")
// } else {
// applyApi.toast("授权失败");
// }
// }
// })
wx.showModal({
title: '提示',
content: '您取消授权,无法保存图片,点击确定打开权限',
success(res) {
if (res.confirm) {
console.log('用户点击确定')
wx.openSetting({
success(res) {
// console.log(res.authSetting)
// res.authSetting = {
// "scope.userInfo": true,
// "scope.userLocation": true
// }
}
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
})
} else { //用户已经授权过了
console.log('333', that.data.water_url)
// console.log(that.data.imagePath)
wx.saveImageToPhotosAlbum({
filePath: that.data.water_url,
success(res) {
console.log(res)
wx.showModal({
content: '图片已保存到相册',
showCancel: false,
confirmText: '好的',
confirmColor: '#333',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
/* 该隐藏的隐藏 */
that.setData({
maskHidden: false,
showDialog: !that.data.showDialog
})
}
},
fail: function (res) {
}
})
}
})
}
}
})
// console.log('123456855555555', that.data.water_url)
}, //可以将saveFilePath写入到页面数据中
fail: function (res) {
console.log('失败', res)
},
complete: function (res) {
console.log('complete后的res数据:')
},
}) //,
},
// fail: function (res) {
// wx.showModal({
// title: '下载失败',
// content: '请联系管理员',
// })
// },
complete: function (res) {},
})
},
// 推荐列
getRecommendList() {
let that = this;
wx.showLoading({
title: '加载中',
})
request({
url: 'api/shop/shopUnder',
data: {
page: that.data.pageNum
}
})
.then(res => {
console.log(res)
that.setData({
isshow: true,
recommendList: that.data.recommendList.concat(res.data.data.data),
total: res.data.data.total,
last_page: res.data.data.last_page,
current_page: res.data.data.current_page
})
wx.hideLoading()
}).catch(err => {
console.log(err);
that.setData({
msg: err.msg
})
that.popTest()
})
},
onReachBottom: function () {
let that = this
let newpageNum = this.data.pageNum;
console.log(newpageNum);
newpageNum++;
this.setData({
pageNum: newpageNum
})
if (that.data.isshow == true) {
if (that.data.last_page != that.data.current_page) {
that.getRecommendList();
} else {
that.setData({
msg: '已到底部了'
})
that.popTest()
}
}
},
popTest() {
wx.showToast({
title: this.data.msg,
icon: 'none', //如果要纯文本,不要icon,将值设为'none'
duration: 2000
})
},
onShareAppMessage(options) {
var that = this;
console.log(that.data.user_id)
// 设置菜单中的转发按钮触发转发事件时的转发内容
var shareObj = {
title: "车唛分享", // 默认是小程序的名称(可以写slogan等)
path: '/pages/stores/stores', // 默认是当前页面,必须是以‘/’开头的完整路径
imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
success: function (res) {
// 转发成功之后的回调
console.log(res);
that.setData({
msg: '易分享'
})
that.popMaskTest()
},
fail: function () {
// 转发失败之后的回调
if (res.errMsg == 'shareAppMessage:fail cancel') {
// 用户取消转发
} else if (res.errMsg == 'shareAppMessage:fail') {}
},
};
// 返回shareObj
return shareObj;
},
popMaskTest() {
wx.showToast({
title: this.data.msg,
icon: 'none',
duration: 2000,
mask: true //是否有透明蒙层,默认为false
//如果有透明蒙层,弹窗的期间不能点击文档内容
})
},
})