提交 | 用户 | age
|
d98d05
|
1 |
// pages/detail/detail.js |
S |
2 |
var listData = require('../../data/test-data.js'); |
|
3 |
// var WxParse = require('../../src/wxParse/wxParse.js'); |
|
4 |
// var Quantity = require('../template/cart-input/cart-input-template.js'); |
|
5 |
var utils = require("../../utils/util.js") |
|
6 |
var app = getApp(); |
|
7 |
let isLogin = false; |
|
8 |
let matcode = ""; |
|
9 |
let imgDownloadSum = 0; |
|
10 |
let imgDownloadObj = { |
|
11 |
isComplete:false |
|
12 |
}; |
|
13 |
import {Http} from "../../utils/http-p.js"; |
|
14 |
const Request = new Http(); |
53cc6f
|
15 |
// Object.assign({}, Quantity, |
d98d05
|
16 |
Page({ |
S |
17 |
|
|
18 |
/** |
|
19 |
* 页面的初始数据 |
|
20 |
*/ |
|
21 |
data: { |
|
22 |
navTitle: [{ |
|
23 |
text: "商品描述", |
|
24 |
id: 0 |
|
25 |
}, |
|
26 |
{ |
|
27 |
text: "商品属性", |
|
28 |
id: 1 |
|
29 |
}, |
|
30 |
{ |
|
31 |
text: "售后服务", |
|
32 |
id: 2 |
|
33 |
} |
|
34 |
], |
|
35 |
isShow: false, |
|
36 |
isCanBuy:true, |
a50a5b
|
37 |
isCanBuy2:true, |
d98d05
|
38 |
actionType: "payOrder", |
S |
39 |
Quantity: { |
|
40 |
quantity: 1, |
|
41 |
min: 1, |
|
42 |
max: 999999 |
|
43 |
}, |
|
44 |
clientHeight: "100%", |
|
45 |
overflow: "auto", |
|
46 |
list: [], |
|
47 |
isPullTelephone: false, |
53cc6f
|
48 |
cltcode: '', |
S |
49 |
attrList:[ |
|
50 |
{ |
|
51 |
title: '颜色', |
|
52 |
list: [ |
|
53 |
{ |
|
54 |
name:'红', |
|
55 |
checked: true |
|
56 |
}, |
|
57 |
{ |
|
58 |
name:'黄', |
|
59 |
checked: false |
|
60 |
}, |
|
61 |
|
|
62 |
] |
|
63 |
}, |
|
64 |
{ |
|
65 |
title: '尺寸', |
|
66 |
list: [ |
|
67 |
{ |
|
68 |
name:'大', |
|
69 |
checked: false |
|
70 |
}, |
|
71 |
{ |
|
72 |
name:'小', |
|
73 |
checked: true |
|
74 |
}, |
|
75 |
|
|
76 |
] |
|
77 |
} |
|
78 |
] |
d98d05
|
79 |
}, |
S |
80 |
|
|
81 |
|
|
82 |
/** |
|
83 |
* 生命周期函数--监听页面加载 |
|
84 |
*/ |
|
85 |
onLoad: function(options) { |
|
86 |
// homeLayoutStyle = options.homeLayoutStyle; |
|
87 |
imgDownloadSum = 0; |
53cc6f
|
88 |
|
d98d05
|
89 |
// this.setData({ |
S |
90 |
// homeLayoutStyle: homeLayoutStyle |
|
91 |
// }) |
|
92 |
|
|
93 |
// if (homeLayoutStyle) { |
|
94 |
// return false; |
|
95 |
// } |
|
96 |
|
|
97 |
// const query = wx.createSelectorQuery() |
|
98 |
// console.log('query.select(#myCanvas)',query.select('#myCanvas')) |
|
99 |
// query.select('#myCanvas') |
|
100 |
// .fields({ node: true, size: true }) |
|
101 |
// .exec((res) => { |
|
102 |
// const canvas = res[0].node |
|
103 |
// const ctx = canvas.getContext('2d') |
|
104 |
// console.log(canvas,ctx) |
|
105 |
// this.setData({ |
|
106 |
// canvas, |
|
107 |
// context:ctx |
|
108 |
// }) |
|
109 |
// }) |
|
110 |
|
|
111 |
this.setData({ |
|
112 |
cltcode: app.globalData.Cltcode |
|
113 |
}) |
|
114 |
console.log('cltcode', this.data.cltcode); |
|
115 |
// this.getSetting() |
|
116 |
matcode = options.matcode; |
|
117 |
wx.showLoading({ |
|
118 |
mask: false, |
|
119 |
title: '加载中', |
|
120 |
}) |
|
121 |
if (!app.globalData.openID || !app.globalData.FromUserId) { |
|
122 |
app.globalData.indexCallback = (res) => { |
|
123 |
// console.log('没有。。。。') |
|
124 |
this.getSetting(); |
|
125 |
this.getDetailData(); |
|
126 |
} |
|
127 |
} else{ |
|
128 |
this.getSetting(); |
|
129 |
this.getDetailData(); |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
}, |
|
134 |
onCountDownFinish(){ |
|
135 |
console.log('倒计时结束了。。。') |
|
136 |
this.getDetailData (); |
|
137 |
}, |
|
138 |
getDetailData () { |
|
139 |
var that = this; |
|
140 |
// option接收其他页面传递过来的值,?后面的变量名id |
|
141 |
wx.request({ |
|
142 |
url: utils.getUrl('/shopping/getMatCode.do?matcode=' + matcode), |
|
143 |
header: { |
|
144 |
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') |
|
145 |
}, |
|
146 |
method: "GET", |
|
147 |
success: (res)=> { |
|
148 |
wx.hideLoading(); |
|
149 |
if(!utils.requestError(res)){ |
|
150 |
return false; |
|
151 |
} |
|
152 |
that.setData({ |
|
153 |
goodsItem: res.data.list, |
|
154 |
CouponList:res.data.CouponList, |
53cc6f
|
155 |
groupBuyingList:res.data.groupBuyingList, |
S |
156 |
SkuParameterList:res.data.SkuParameterList, |
|
157 |
SkuMatCodeList:res.data.SkuMatCodeList, |
d98d05
|
158 |
title: res.data.list.MatName, |
S |
159 |
num: 0, |
|
160 |
description: res.data.list.Description, |
|
161 |
Mininum: res.data.list.Mininum||1, |
|
162 |
['Quantity.quantity']: res.data.list.Mininum||1 |
|
163 |
// price: goodsItem.Price |
|
164 |
}) |
a50a5b
|
165 |
this.handleNoticeText(res.data.list); |
53cc6f
|
166 |
|
d98d05
|
167 |
// WxParse.wxParse('article', 'html', res.data.list.Description, that, 5); |
S |
168 |
this.getPosterQrCode(); |
53cc6f
|
169 |
this.handleCurrentGoods(); |
d98d05
|
170 |
wx.setNavigationBarTitle({ |
S |
171 |
title: res.data.list.MatName, |
|
172 |
}) |
|
173 |
}, |
|
174 |
fail: function (errmsg) { |
|
175 |
utils.requestFail(errmsg,'/shopping/getMatCode.do'); |
|
176 |
} |
|
177 |
|
|
178 |
}); |
|
179 |
|
|
180 |
/** |
|
181 |
* WxParse.wxParse(bindName , type, data, target,imagePadding) |
|
182 |
* 1.bindName绑定的数据名(必填) |
|
183 |
* 2.type可以为html或者md(必填) |
|
184 |
* 3.data为传入的具体数据(必填) |
|
185 |
* 4.target为Page对象,一般为this(必填) |
|
186 |
* 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选) |
|
187 |
*/ |
a50a5b
|
188 |
}, |
S |
189 |
|
|
190 |
handleNoticeText(res){ |
|
191 |
let { |
|
192 |
Quantity, |
|
193 |
isRestrictQuantity, |
|
194 |
isStartupPanicBuying, |
|
195 |
PanicBuyingStartTimeBalance, |
|
196 |
PanicBuyingEndTimeBalance, |
|
197 |
PanicBuyingStartTime, |
|
198 |
PanicBuyingEndTime, |
|
199 |
isStartupGroupBuying, |
|
200 |
GroupBuyingMembers, |
|
201 |
GroupBuyingPrice, |
|
202 |
GroupBuyingStartTime, |
|
203 |
GroupBuyingEndTime, |
|
204 |
GroupBuyingStartTimeBalance, |
|
205 |
GroupBuyingEndTimeBalance |
|
206 |
} = res; |
|
207 |
if (isStartupPanicBuying&&PanicBuyingStartTimeBalance>0) { |
|
208 |
this.setData({ |
|
209 |
noticeText:`未开抢,开抢时间${PanicBuyingStartTime}至${PanicBuyingEndTime}`, |
|
210 |
isCanBuy:false |
|
211 |
}) |
|
212 |
} |
|
213 |
else if (isStartupPanicBuying&&PanicBuyingStartTimeBalance<=0&&PanicBuyingEndTimeBalance>0) { |
|
214 |
this.setData({ |
|
215 |
noticeText:`商品抢购中,结束时间为${PanicBuyingEndTime}`, |
|
216 |
isCanBuy:true |
|
217 |
}) |
|
218 |
} |
|
219 |
else if (isStartupPanicBuying&&PanicBuyingEndTimeBalance<=0) { |
|
220 |
this.setData({ |
|
221 |
noticeText:`本次商品抢购已结束`, |
|
222 |
isCanBuy:false |
|
223 |
}) |
|
224 |
} |
|
225 |
|
|
226 |
if (isStartupGroupBuying&&GroupBuyingStartTimeBalance>0) { |
|
227 |
this.setData({ |
|
228 |
noticeText:`未开抢,开抢时间${GroupBuyingStartTime}至${GroupBuyingEndTime}`, |
|
229 |
isCanBuy:false |
|
230 |
}) |
|
231 |
} |
|
232 |
else if (isStartupGroupBuying&&GroupBuyingStartTimeBalance<=0&&GroupBuyingEndTimeBalance>0) { |
|
233 |
this.setData({ |
|
234 |
noticeText:`商品拼团抢购中,结束时间为${GroupBuyingEndTime}`, |
|
235 |
isCanBuy:true |
|
236 |
}) |
|
237 |
} |
|
238 |
else if (isStartupGroupBuying&&GroupBuyingEndTimeBalance<=0) { |
|
239 |
this.setData({ |
|
240 |
noticeText:`本次商品限时团购已结束`, |
|
241 |
isCanBuy:false |
|
242 |
}) |
|
243 |
} |
|
244 |
|
|
245 |
if (isRestrictQuantity&&Quantity<=0) { |
|
246 |
this.setData({ |
|
247 |
noticeText:`该商品已售罄`, |
|
248 |
isCanBuy:false |
|
249 |
}) |
|
250 |
} |
d98d05
|
251 |
}, |
S |
252 |
|
|
253 |
btnTap: function (e) { |
|
254 |
// var that = this; |
|
255 |
// var isGet = this.data.isGet; |
|
256 |
// isGet = !isGet; |
|
257 |
// wx.showLoading({ |
|
258 |
// title: '', |
|
259 |
// }); |
|
260 |
// setTimeout(function () { |
|
261 |
// wx.hideLoading(); |
|
262 |
// that.setData({ |
|
263 |
// isGet: isGet |
|
264 |
// }) |
|
265 |
// }, 800); |
|
266 |
utils.isAuthorize(this); |
|
267 |
if(!this.data.isAuthorize){ |
|
268 |
if (!utils.authorize(e, this)){ |
|
269 |
return; |
|
270 |
} |
|
271 |
} |
|
272 |
var id = e.target.dataset.couponid; |
|
273 |
var index = e.target.dataset.index; |
|
274 |
console.log('领取index',index) |
|
275 |
// couponStatus : //0 正常:可以抢 ; 1 已经抢完 ; 2 未开抢 ; 3 已经抢过了,不能重复抢 ; 4 已经提醒(微信模板消息提醒) |
|
276 |
wx.showLoading() |
|
277 |
wx.request({ |
|
278 |
url: utils.getUrl('/shopping/coupon.do?m=savePersonalCouponCode&couponcode=' + id), |
|
279 |
header: { |
|
280 |
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') |
|
281 |
}, |
|
282 |
success: res => { |
|
283 |
wx.hideLoading(); |
|
284 |
if(!utils.requestError(res)){ |
|
285 |
return false; |
|
286 |
} |
|
287 |
// this.getDetailData(); |
|
288 |
if(res.data.state=='success'){ |
|
289 |
wx.showToast({ |
|
290 |
icon:'none', |
|
291 |
title: res.data.success, |
|
292 |
}) |
|
293 |
this.setData({ |
|
294 |
[`CouponList[${index}].Status`]:3 |
|
295 |
}) |
|
296 |
console.log(this.data.CouponList[index].Status) |
|
297 |
} else{ |
|
298 |
wx.showToast({ |
|
299 |
title: '领取失败', |
|
300 |
}) |
|
301 |
} |
|
302 |
|
|
303 |
}, |
|
304 |
fail: function (errmsg) { |
|
305 |
utils.requestFail(errmsg,'/shopping/coupon.do'); |
|
306 |
} |
|
307 |
}) |
|
308 |
|
|
309 |
|
|
310 |
}, |
|
311 |
|
|
312 |
getPosterQrCode(){ |
53cc6f
|
313 |
|
d98d05
|
314 |
wx.request({ |
S |
315 |
url: utils.getUrl('/shopping/poster/getQrCodeForPoster.do'), |
|
316 |
header: { |
|
317 |
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') |
|
318 |
}, |
|
319 |
data:{ |
|
320 |
QrCodeType:30, |
|
321 |
matcode:matcode |
|
322 |
}, |
|
323 |
success: res => { |
|
324 |
if(!utils.requestError(res)){ |
|
325 |
return false; |
|
326 |
} |
|
327 |
// this.getDetailData(); |
|
328 |
console.log(res.data); |
|
329 |
this.setData({ |
|
330 |
QrCode:res.data.QrCode |
|
331 |
}) |
53cc6f
|
332 |
|
d98d05
|
333 |
|
S |
334 |
}, |
|
335 |
fail: function (errmsg) { |
|
336 |
utils.requestFail(errmsg,'/shopping/poster/getQrCodeForPoster.do'); |
|
337 |
} |
|
338 |
}) |
|
339 |
}, |
|
340 |
|
|
341 |
getSetting() { |
|
342 |
// 获取设置 |
|
343 |
|
|
344 |
let isPullTelephone1 = false; |
|
345 |
let getSetting = Request.request({ |
|
346 |
url: '/shopping/getSettingEntity.do' |
|
347 |
}).then((res) => { |
|
348 |
console.log('设置数据',res) |
|
349 |
isPullTelephone1 = res.isPullTelephoneWhenViewProductDetail |
|
350 |
console.log('isPullTelephone设置', isPullTelephone1) |
|
351 |
this.setData({ |
|
352 |
generateOrderProcess: res.generateOrderProcess||0 |
|
353 |
}) |
|
354 |
this.setData({ |
|
355 |
isPullTelephone: isPullTelephone1 |
|
356 |
}) |
|
357 |
console.log('isPullTelephone:', isPullTelephone1); |
|
358 |
}); |
|
359 |
// let getLogin = Request.request({ |
|
360 |
// url: '/shopping/confirm.do?m=isLogin' |
|
361 |
// }).then((res) => { |
|
362 |
// console.log('denglu',res) |
|
363 |
// isLogin = res.isLogin |
|
364 |
// // res.isLogin ? isLogin = false : isLogin = true |
|
365 |
// // console.log('isPullTelephone2', isPullTelephone2) |
|
366 |
// }); |
|
367 |
// Promise.all([getSetting, getLogin]).then(()=> { |
|
368 |
// let isPullTelephone = false; |
|
369 |
// if (isPullTelephone1 && !isLogin) { |
|
370 |
// isPullTelephone = true; |
|
371 |
// // if(!this.data.isAuthorize){ |
|
372 |
// // if (!utils.authorize(e, this)){ |
|
373 |
// // return; |
|
374 |
// // } |
|
375 |
// // } |
|
376 |
// } |
|
377 |
// this.setData({ |
|
378 |
// isPullTelephone: isPullTelephone |
|
379 |
// }) |
|
380 |
// console.log('isPullTelephone:', isPullTelephone); |
|
381 |
// }) |
|
382 |
// Request.request({ |
|
383 |
// url: '/wx/getCardUserInfo.do', |
|
384 |
// data: { |
|
385 |
// FromUserId: app.globalData.FromUserId |
|
386 |
// } |
|
387 |
// }).then((res) => { |
|
388 |
// console.log(res); |
|
389 |
// this.setData({ |
|
390 |
// UserId: res.UserId, |
|
391 |
// Name: res.Name |
|
392 |
// }); |
|
393 |
// }); |
|
394 |
|
|
395 |
}, |
|
396 |
|
|
397 |
getPhoneNumber(e) { |
|
398 |
console.log('getPhoneNumber', e); |
|
399 |
|
|
400 |
if (e.detail.phoneNumber.errMsg == 'getPhoneNumber:ok') { |
|
401 |
Request.request({ |
|
402 |
url: '/shopping/account.do', |
|
403 |
data: { |
|
404 |
m: 'telRegByAutoReg', |
|
405 |
// ReferralsCode: this.data.UserId, |
|
406 |
// ReferralsName: this.data.Name, |
|
407 |
ReferralsCode: app.globalData.cardUserData.UserId, |
|
408 |
ReferralsName: app.globalData.cardUserData.Name, |
|
409 |
encryptedData: e.detail.phoneNumber.encryptedData, |
|
410 |
iv: e.detail.phoneNumber.iv, |
|
411 |
SessionKey: app.globalData.SessionKey |
|
412 |
} |
|
413 |
}).then((res) => { |
|
414 |
console.log('/shopping/account.do', res); |
|
415 |
if (res.cltcode) { |
|
416 |
app.globalData.Cltcode = res.cltcode; |
|
417 |
this.setData({ |
|
418 |
isPullTelephone: false, |
|
419 |
cltcode: res.cltcode |
|
420 |
}) |
|
421 |
} |
|
422 |
}); |
|
423 |
} else{ |
|
424 |
console.log('取消授权'); |
|
425 |
// wx.switchTab({ |
|
426 |
// url: url |
|
427 |
// }); |
|
428 |
} |
|
429 |
|
|
430 |
}, |
|
431 |
|
|
432 |
/*查看图片*/ |
|
433 |
viewImg: function(e) { |
|
434 |
var src = e.currentTarget.dataset.src; |
|
435 |
// console.log(src) |
|
436 |
wx.previewImage({ |
|
437 |
current: src, // 当前显示图片的http链接 |
|
438 |
urls: this.data.goodsItem.images // 需要预览的图片http链接列表 |
|
439 |
}) |
|
440 |
}, |
|
441 |
|
|
442 |
// 导航条点击 |
|
443 |
navTap: function(e) { |
|
444 |
this.setData({ |
|
445 |
num: e.currentTarget.dataset.num |
|
446 |
}) |
|
447 |
}, |
|
448 |
|
|
449 |
// 隐藏层滑入 |
|
450 |
showLayer: function() { |
|
451 |
var that = this; |
|
452 |
utils.showLayer(that, "translateY", 300, 0); |
|
453 |
}, |
|
454 |
|
|
455 |
// 隐藏层滑出 |
|
456 |
hideLayer: function() { |
|
457 |
var that = this; |
|
458 |
utils.hideLayer(that, "translateY", 500); |
|
459 |
this.setData({ |
a50a5b
|
460 |
['Quantity.quantity']: this.data.Mininum||1, |
S |
461 |
isSelectedSku: false |
|
462 |
|
d98d05
|
463 |
}) |
S |
464 |
}, |
|
465 |
|
53cc6f
|
466 |
|
d98d05
|
467 |
// downloadFile(){ |
S |
468 |
// console.log(app.globalData.cardUserData) |
|
469 |
// console.log('头像',app.globalData.cardUserData.Avatar) |
|
470 |
// console.log('logo',app.globalData.logoUrl) |
|
471 |
// console.log('二维码',this.data.QrCode) |
|
472 |
// console.log('商品',this.data.goodsItem.PhotoPath) |
|
473 |
// let avatarUrl = wx.pro.downloadFile({ |
|
474 |
// url: app.globalData.cardUserData.Avatar |
|
475 |
// }).then((res)=>{ |
|
476 |
// if (res.statusCode === 200) { |
|
477 |
// imgDownloadSum++; |
|
478 |
// console.log('......头像',res.tempFilePath) |
|
479 |
// this.setData({ |
|
480 |
// avatarUrl: res.tempFilePath |
|
481 |
// }) |
|
482 |
// } |
|
483 |
// }) |
|
484 |
// let goodsImg = wx.pro.downloadFile({ |
|
485 |
// url: this.data.goodsItem.PhotoPath |
|
486 |
// }).then((res)=>{ |
|
487 |
// if (res.statusCode === 200) { |
|
488 |
// imgDownloadSum++; |
|
489 |
// console.log('......商品',res.tempFilePath) |
|
490 |
// this.setData({ |
|
491 |
// goodsImg: res.tempFilePath |
|
492 |
// }) |
|
493 |
// } |
|
494 |
// }) |
|
495 |
// let qrCodeImg = wx.pro.downloadFile({ |
|
496 |
// url: this.data.QrCode |
|
497 |
// }).then((res)=>{ |
|
498 |
// if (res.statusCode === 200) { |
|
499 |
// console.log('......二维码',res.tempFilePath) |
|
500 |
// imgDownloadSum++; |
|
501 |
// this.setData({ |
|
502 |
// qrCodeImg: res.tempFilePath |
|
503 |
// }) |
|
504 |
// } |
|
505 |
// }) |
|
506 |
|
|
507 |
// Promise.all([avatarUrl,goodsImg,qrCodeImg]).then((res)=>{ |
|
508 |
|
|
509 |
// imgDownloadObj.isComplete = true; |
|
510 |
|
|
511 |
// // imgDownloadObj.isComplete = true; |
|
512 |
// }).catch((err)=>{ |
|
513 |
// // this.getPosterQrCode(); |
|
514 |
// console.log('请检查名片头像、公司logo等图片是否已经配置',err) |
|
515 |
// // \n 点击确定重试,点击取消关闭弹窗。 |
|
516 |
// wx.hideToast(); |
|
517 |
// wx.showModal({ |
|
518 |
// title:'提示', |
|
519 |
// content:`${err.errMsg}`, |
|
520 |
// showCancel:false, |
|
521 |
// success:(res)=>{ |
|
522 |
// // if (res.confirm) { |
|
523 |
// // console.log('用户点击确定') |
|
524 |
// // wx.showLoading() |
|
525 |
// // this.downloadFile() |
|
526 |
// // } else if (res.cancel) { |
|
527 |
// // console.log('用户点击取消') |
|
528 |
// // } |
53cc6f
|
529 |
|
d98d05
|
530 |
// } |
S |
531 |
// }) |
|
532 |
|
|
533 |
// }) |
53cc6f
|
534 |
|
d98d05
|
535 |
// }, |
S |
536 |
|
|
537 |
// createCanvas(e){ |
53cc6f
|
538 |
|
d98d05
|
539 |
// wx.showToast({ |
S |
540 |
// title: '生成中...', |
|
541 |
// icon: 'loading', |
|
542 |
// mask:true, |
|
543 |
// duration: 10000 |
|
544 |
// }); |
53cc6f
|
545 |
|
d98d05
|
546 |
// if (imgDownloadObj.isComplete) { |
S |
547 |
// // wx.hideToast() |
|
548 |
// // let posterCreate = this.selectComponent('#posterCreate'); |
|
549 |
// // posterCreate.formSubmit(e); |
|
550 |
// this.sendCommand(e); |
|
551 |
// } else { |
|
552 |
// // 下载图片到本地 |
|
553 |
// this.downloadFile(); |
|
554 |
// // utils.watchObj(imgDownloadObj,(prop,val)=>{ |
|
555 |
// // console.log(JSON.stringify(imgDownloadObj)+prop+'值变化!!!','新值为'+val) |
|
556 |
// utils.watchObj(imgDownloadObj,'isComplete',(val)=>{ |
|
557 |
// console.log(JSON.stringify(imgDownloadObj)+'isComplete值变化!!!','新值为'+val) |
|
558 |
// if (imgDownloadObj.isComplete) { |
|
559 |
// this.sendCommand(e); |
|
560 |
// } |
|
561 |
// // wx.hideToast() |
|
562 |
// // let posterCreate = this.selectComponent('#posterCreate'); |
|
563 |
// // posterCreate.formSubmit(e); |
53cc6f
|
564 |
|
d98d05
|
565 |
// }) |
53cc6f
|
566 |
|
d98d05
|
567 |
// } |
53cc6f
|
568 |
|
d98d05
|
569 |
// }, |
S |
570 |
|
|
571 |
// sendCommand(e){ |
|
572 |
// wx.hideToast() |
|
573 |
// let posterCreate = this.selectComponent('#posterCreate'); |
|
574 |
// posterCreate.formSubmit(e); |
|
575 |
// }, |
|
576 |
|
|
577 |
|
|
578 |
// // 加载函数 |
|
579 |
// loadImage(src) { |
|
580 |
// return new Promise((resolve,reject) => { |
|
581 |
// const img = this.data.canvas.createImage(); |
|
582 |
// img.onload = () => { |
|
583 |
// resolve(img); |
|
584 |
// }; |
|
585 |
// img.onerror = (e) => { |
|
586 |
// reject(e); |
|
587 |
// }; |
|
588 |
// img.src = src; |
|
589 |
// }); |
|
590 |
// }, |
|
591 |
|
|
592 |
|
53cc6f
|
593 |
|
d98d05
|
594 |
//将canvas转换为图片保存到本地,然后将图片路径传给image图片的src |
S |
595 |
// createPoster (e) { |
|
596 |
// let posterCreate = this.selectComponent('#posterCreate'); |
|
597 |
// let canvas = e.detail.canvas; |
|
598 |
// console.log(e) |
|
599 |
// // let context = canvas.getContext('2d'); |
|
600 |
// let context = e.detail.context; |
|
601 |
// // let context = wx.createCanvasContext('mycanvas'); |
53cc6f
|
602 |
|
d98d05
|
603 |
// // let path = "../../imgs/gobg.png"; |
S |
604 |
// // //不知道是什么原因,手机环境能正常显示 |
|
605 |
// // context.drawImage(path, 0, 0, 375, 183); |
|
606 |
// let avatarImg = this.data.avatarUrl; |
|
607 |
// console.log(avatarImg,"avatarImg") |
|
608 |
// // let path2 = "../../imgs/chengzhong.png"; |
|
609 |
// let goodsImg = this.data.goodsImg; |
|
610 |
// let qrCodeImg = this.data.qrCodeImg; |
|
611 |
// // let path5 = "../../imgs/computer.png"; |
|
612 |
// // context.drawImage(path2, 126, 186, 120, 120); |
|
613 |
// // context.save(); // 保存当前context的状态 |
|
614 |
// console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg) |
|
615 |
// // let name = that.data.name; |
|
616 |
// // //绘制名字 |
|
617 |
// // context.setFontSize(30); |
|
618 |
// // context.setFillStyle('#333333'); |
|
619 |
// // context.setTextAlign('center'); |
|
620 |
// // context.fillText(name, 185, 160); |
|
621 |
// // context.stroke(); |
|
622 |
// context.beginPath() |
|
623 |
// context.fillStyle="#fff"; |
|
624 |
// context.fillRect(0, 0, 375, 667); |
|
625 |
// context.closePath() |
|
626 |
// //绘制文字 |
|
627 |
// context.beginPath() |
|
628 |
// context.setFontSize(16); |
|
629 |
// context.fillStyle='#333333'; |
|
630 |
// context.textAlign='left'; |
|
631 |
// context.fillText("我看上了这款商品", 140, 50); |
|
632 |
// context.stroke(); |
53cc6f
|
633 |
|
d98d05
|
634 |
// context.setFontSize(16); |
S |
635 |
// context.fillStyle='#333333'; |
|
636 |
// context.textAlign='left'; |
|
637 |
// context.fillText("帮我看看咋样啊~~", 140, 85); |
|
638 |
// context.stroke(); |
|
639 |
// context.closePath(); |
|
640 |
// //绘制商品 |
|
641 |
// context.beginPath(); |
|
642 |
// context.drawImage(goodsImg, 48, 125, 280, 280); |
|
643 |
// // 商品文字 |
53cc6f
|
644 |
|
d98d05
|
645 |
// context.setFontSize(16); |
S |
646 |
// context.fillStyle='#333333'; |
|
647 |
// context.textAlign='left'; |
|
648 |
// var result = this.breakLinesForCanvas(context, |
|
649 |
// this.data.goodsItem.MatName.slice(0,50), |
|
650 |
// 170, '14px 微软雅黑'); |
|
651 |
// var lineHeight = 25; |
|
652 |
// result.forEach(function(line, index) { |
|
653 |
// context.fillText(line, 50, lineHeight * index + 435); |
|
654 |
// // context.fillText("商品描述", 50, 445); |
|
655 |
// }); |
53cc6f
|
656 |
|
d98d05
|
657 |
// context.stroke(); |
S |
658 |
// context.setFontSize(32); |
|
659 |
// context.fillStyle='#f23232'; |
|
660 |
// context.textAlign='left'; |
|
661 |
// context.fillText("¥1999.00", 45, 505); |
|
662 |
// context.stroke(); |
|
663 |
// context.closePath(); |
53cc6f
|
664 |
|
d98d05
|
665 |
// // 绘制分割线 |
S |
666 |
// context.beginPath() |
|
667 |
// context.strokeStyle='#ddd' |
|
668 |
// context.moveTo(10, 520) |
|
669 |
// context.lineTo(365, 520) |
|
670 |
// context.stroke() |
|
671 |
// context.closePath(); |
|
672 |
// //绘制code码 |
|
673 |
// // context.setFontSize(40); |
|
674 |
// // context.setFillStyle('#ffe200'); |
|
675 |
// // context.setTextAlign('center'); |
|
676 |
// // context.fillText(that.data.code, 185, 435); |
|
677 |
// // context.stroke(); |
|
678 |
// //绘制左下角文字背景图 |
|
679 |
// context.beginPath(); |
|
680 |
// context.drawImage(qrCodeImg, 20, 530, 120, 120); |
53cc6f
|
681 |
|
d98d05
|
682 |
// //绘制右下角扫码提示语 |
S |
683 |
// // context.drawImage(path5, 248, 578, 90, 25); |
|
684 |
// context.setFontSize(16); |
|
685 |
// context.fillStyle='#333'; |
|
686 |
// context.textAlign='left'; |
|
687 |
// context.fillText("长按识别小程序码 即可查看~",150, 600); |
|
688 |
// context.stroke(); |
|
689 |
// //绘制头像 |
|
690 |
// context.arc(80, 60, 40, 0, 2 * Math.PI) //画出圆 |
|
691 |
// context.strokeStyle = "#ffe200"; |
|
692 |
// context.clip(); //裁剪上面的圆形 |
|
693 |
// context.drawImage(avatarImg, 40, 20, 80, 80); // 在刚刚裁剪的园上画图 |
|
694 |
// context.closePath(); |
|
695 |
// // context.draw(); |
|
696 |
// // let posterCreate = this.selectComponent('#posterCreate'); |
|
697 |
// // posterCreate.createPoster(); |
|
698 |
// // console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg) |
|
699 |
// //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时 |
|
700 |
// setTimeout( ()=> { |
|
701 |
|
53cc6f
|
702 |
|
d98d05
|
703 |
// posterCreate.createPoster(canvas); |
S |
704 |
// console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg) |
|
705 |
// }, 500); |
|
706 |
// }, |
|
707 |
// authorizeInfo(e){ |
|
708 |
// console.log('authorizeInfo',e) |
|
709 |
// }, |
|
710 |
// createNewImg (e) { |
|
711 |
// console.log('createNewImg',e) |
|
712 |
// let posterCreate = this.selectComponent('#posterCreate'); |
|
713 |
// let goodsItem = this.data.goodsItem; |
|
714 |
// let context = e.detail.context; |
|
715 |
// // let childComp = e.detail.childComp; |
|
716 |
// // let context = wx.createCanvasContext('mycanvas'); |
|
717 |
// context.clearRect(0, 0, 375, 667); |
|
718 |
// context.setFillStyle("#fff"); |
|
719 |
// context.fillRect(0, 0, 375, 667) |
|
720 |
// // let path = "../../imgs/gobg.png"; |
|
721 |
// // //不知道是什么原因,手机环境能正常显示 |
|
722 |
// // context.drawImage(path, 0, 0, 375, 183); |
|
723 |
// let avatarImg = this.data.avatarUrl; |
|
724 |
// console.log(avatarImg,"avatarImg") |
|
725 |
// // let path2 = "../../imgs/chengzhong.png"; |
|
726 |
// let goodsImg = this.data.goodsImg; |
|
727 |
// let qrCodeImg = this.data.qrCodeImg; |
|
728 |
// console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg) |
|
729 |
// // let path5 = "../../imgs/computer.png"; |
|
730 |
// // context.drawImage(path2, 126, 186, 120, 120); |
|
731 |
// // context.save(); // 保存当前context的状态 |
|
732 |
|
|
733 |
// //绘制文字 |
|
734 |
// context.beginPath() |
|
735 |
// context.setFontSize(16); |
|
736 |
// context.setFillStyle('#333333'); |
|
737 |
// context.setTextAlign('left'); |
|
738 |
// context.fillText("我看上了这款商品", 140, 50); |
|
739 |
// context.stroke(); |
|
740 |
// context.setFontSize(16); |
|
741 |
// context.setFillStyle('#333333'); |
|
742 |
// context.setTextAlign('left'); |
|
743 |
// context.fillText("帮我看看咋样啊~~", 140, 85); |
|
744 |
// context.stroke(); |
|
745 |
// context.closePath(); |
|
746 |
// //绘制商品 |
|
747 |
// context.drawImage(goodsImg, 48, 125, 280, 280); |
|
748 |
// // 商品文字 |
|
749 |
// context.beginPath(); |
|
750 |
// context.setFontSize(16); |
|
751 |
// context.setFillStyle('#333333'); |
|
752 |
// context.setTextAlign('left'); |
|
753 |
// var result = posterCreate.breakLinesForCanvas(context, |
|
754 |
// goodsItem.MatName.slice(0,40), |
|
755 |
// 220, 14); |
|
756 |
// var lineHeight = 25; |
|
757 |
// result.forEach(function(line, index) { |
|
758 |
// context.fillText(line, 50, lineHeight * index + 435); |
|
759 |
// // context.fillText("商品描述", 50, 445); |
|
760 |
// }); |
53cc6f
|
761 |
|
d98d05
|
762 |
// context.stroke(); |
S |
763 |
// context.setFontSize(32); |
|
764 |
// context.setFillStyle('#f23232'); |
|
765 |
// context.setTextAlign('left'); |
|
766 |
// context.fillText(goodsItem.CurrencySign+goodsItem.Price, 45, 495); |
|
767 |
// context.stroke(); |
|
768 |
// context.closePath(); |
53cc6f
|
769 |
|
d98d05
|
770 |
// // 绘制分割线 |
S |
771 |
// context.beginPath() |
|
772 |
// context.strokeStyle='#ddd' |
|
773 |
// context.moveTo(10, 520) |
|
774 |
// context.lineTo(365, 520) |
|
775 |
// context.stroke() |
|
776 |
// context.closePath(); |
|
777 |
// //绘制code码 |
|
778 |
// // context.setFontSize(40); |
|
779 |
// // context.setFillStyle('#ffe200'); |
|
780 |
// // context.setTextAlign('center'); |
|
781 |
// // context.fillText(that.data.code, 185, 435); |
|
782 |
// // context.stroke(); |
|
783 |
// //绘制左下角二维码 |
|
784 |
// context.drawImage(qrCodeImg, 20, 530, 120, 120); |
53cc6f
|
785 |
|
d98d05
|
786 |
// //绘制右下角扫码提示语 |
S |
787 |
// // context.drawImage(path5, 248, 578, 90, 25); |
|
788 |
// context.setFontSize(16); |
|
789 |
// context.setFillStyle('#333'); |
|
790 |
// context.setTextAlign('left'); |
|
791 |
// context.fillText("长按识别小程序码 即可查看~",150, 600); |
|
792 |
// context.stroke(); |
|
793 |
// //绘制头像 |
|
794 |
// context.arc(80, 60, 40, 0, 2 * Math.PI) //画出圆 |
|
795 |
// context.strokeStyle = "#ffe200"; |
|
796 |
// context.clip(); //裁剪上面的圆形 |
|
797 |
// context.drawImage(avatarImg, 40, 20, 80, 80); // 在刚刚裁剪的园上画图 |
|
798 |
// context.draw(); |
|
799 |
// //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时 |
|
800 |
// setTimeout(()=> { |
|
801 |
// posterCreate.createPoster(); |
|
802 |
// // console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg) |
|
803 |
// }, 300); |
|
804 |
// }, |
|
805 |
|
|
806 |
buyTap: function(event) { |
|
807 |
// 根据按钮不同区分“下一步”触发的事件 |
53cc6f
|
808 |
let name = event.target.dataset.name || event.detail.name; |
S |
809 |
console.log(event); |
|
810 |
this.setData({ |
|
811 |
groupCode:event.detail.groupCode||'', |
|
812 |
}); |
|
813 |
if (name === "order") { |
d98d05
|
814 |
this.setData({ |
S |
815 |
actionType: 'payOrder' |
|
816 |
}) |
|
817 |
// utils.subscribeMessage({ |
|
818 |
// callback:()=>{ |
|
819 |
// if (this.data.isShow) { |
|
820 |
// this.hideLayer(); |
|
821 |
// } else { |
|
822 |
// this.showLayer(); |
|
823 |
// } |
|
824 |
// } |
|
825 |
// }) |
53cc6f
|
826 |
} else if (name === "cart") { |
d98d05
|
827 |
this.setData({ |
S |
828 |
actionType: 'addCart' |
|
829 |
}) |
53cc6f
|
830 |
|
S |
831 |
} |
|
832 |
else if (name === "group") { |
|
833 |
this.setData({ |
|
834 |
actionType: 'groupBuying' |
|
835 |
}) |
|
836 |
|
d98d05
|
837 |
} |
S |
838 |
if (this.data.isShow) { |
|
839 |
this.hideLayer(); |
|
840 |
} else { |
|
841 |
this.showLayer(); |
|
842 |
} |
|
843 |
}, |
|
844 |
|
a50a5b
|
845 |
selectedSku(){ |
S |
846 |
// console.log(888); |
|
847 |
if (!this.data.isCanBuy) return; |
|
848 |
this.setData({ |
|
849 |
isSelectedSku: true |
|
850 |
}) |
|
851 |
if (this.data.isShow) { |
|
852 |
this.hideLayer(); |
|
853 |
} else { |
|
854 |
this.showLayer(); |
|
855 |
} |
|
856 |
}, |
|
857 |
|
53cc6f
|
858 |
handleCurrentGoods(){ |
S |
859 |
/* |
|
860 |
* |
|
861 |
* 首先拿到当前商品的所有skuid [],同时也是选中的id |
|
862 |
* 处理所有商品的skuid为字符串 |
|
863 |
* 用户点击sku[i],拼接为字符串与上面的对比 |
|
864 |
* */ |
|
865 |
let SkuParameterList = this.data.SkuParameterList; |
|
866 |
let SkuMatCodeList = this.data.SkuMatCodeList; |
|
867 |
let MatCode = this.data.goodsItem.MatCode; |
|
868 |
let selectedSkuId = []; |
|
869 |
let selectedSkuName = []; |
a50a5b
|
870 |
let goodsSkuIdStrings = []; |
S |
871 |
let goodsSkuIdList = []; |
|
872 |
let skuIdList = []; |
|
873 |
let skuSetName = []; |
|
874 |
SkuParameterList.forEach((item) => { |
|
875 |
let arr = []; |
|
876 |
item.skuList.forEach((item) => { |
|
877 |
arr.push(item.skuId) |
|
878 |
}) |
|
879 |
skuIdList.push(arr); |
|
880 |
skuSetName.push(item.skuSetName); |
|
881 |
}) |
53cc6f
|
882 |
SkuMatCodeList.forEach((item,index)=>{ |
S |
883 |
let skuIdString = ''; |
a50a5b
|
884 |
let skuIdArr = []; |
53cc6f
|
885 |
for (let i = 1; i < 11; i++) { |
S |
886 |
if (item.MatCode === MatCode && item[`skuId${i}`]){ |
|
887 |
selectedSkuId.push(item[`skuId${i}`]) |
|
888 |
selectedSkuName.push(item[`skuName${i}`]) |
|
889 |
} |
|
890 |
if (item[`skuId${i}`]){ |
|
891 |
skuIdString+=item[`skuId${i}`] |
a50a5b
|
892 |
skuIdArr.push(item[`skuId${i}`]) |
53cc6f
|
893 |
} |
S |
894 |
} |
a50a5b
|
895 |
goodsSkuIdStrings.push(skuIdString) |
S |
896 |
goodsSkuIdList.push(skuIdArr) |
53cc6f
|
897 |
}) |
S |
898 |
this.setData({ |
|
899 |
selectedSkuId, |
|
900 |
selectedSkuName, |
a50a5b
|
901 |
selectedSkuNameStr: selectedSkuName.join(' '), |
S |
902 |
goodsSkuIdStrings, |
|
903 |
skuIdList, |
|
904 |
goodsSkuIdList, |
|
905 |
skuSetName, |
|
906 |
skuSetNameStr:skuSetName.join(','), |
53cc6f
|
907 |
}) |
S |
908 |
console.log('selectedSkuId',selectedSkuId); |
|
909 |
console.log('selectedSkuName',selectedSkuName); |
a50a5b
|
910 |
console.log('goodsSkuIdStrings',goodsSkuIdStrings); |
S |
911 |
console.log('skuIdList',skuIdList); |
|
912 |
console.log('goodsSkuIdList',goodsSkuIdList); |
|
913 |
console.log('skuSetName',skuSetName); |
|
914 |
this.handleSkuIds(); |
53cc6f
|
915 |
}, |
a50a5b
|
916 |
async selectGoodsAttr(e){ |
53cc6f
|
917 |
|
a50a5b
|
918 |
|
53cc6f
|
919 |
let attrIndex = e.currentTarget.dataset.i; |
S |
920 |
let listIndex = e.currentTarget.dataset.index; |
|
921 |
let skuId = e.currentTarget.dataset.skuId; |
a50a5b
|
922 |
let skuName = e.currentTarget.dataset.skuName; |
S |
923 |
let isEnabled = e.currentTarget.dataset.isEnabled; |
53cc6f
|
924 |
let selectedSkuId = this.data.selectedSkuId; |
a50a5b
|
925 |
let selectedSkuName = this.data.selectedSkuName; |
S |
926 |
let length = selectedSkuId.length; |
|
927 |
console.log(e,selectedSkuId); |
|
928 |
if (!isEnabled) return; |
53cc6f
|
929 |
|
a50a5b
|
930 |
selectedSkuId[attrIndex] = skuId; |
S |
931 |
selectedSkuName[attrIndex] = skuName; |
|
932 |
selectedSkuId.forEach((item,index)=>{ |
|
933 |
if (index>attrIndex){ |
|
934 |
selectedSkuId[index] = '' |
|
935 |
selectedSkuName[index] = '' |
|
936 |
length--; |
|
937 |
} |
|
938 |
}) |
|
939 |
this.setData({ |
|
940 |
// [`selectedSkuId[${attrIndex}]`]:skuId, |
|
941 |
selectedSkuId:selectedSkuId, |
|
942 |
// [`selectedskuName[${attrIndex}]`]:skuName, |
|
943 |
// [`selectedskuName[${attrIndex}]`]:skuName, |
|
944 |
selectedSkuNameStr: selectedSkuName.join(' '), |
|
945 |
selectedSkuIdLength: length |
|
946 |
}) |
|
947 |
console.log(selectedSkuId,selectedSkuName,this.data.selectedSkuIdLength); |
|
948 |
// console.log(await this.getSkuParameterByMatCode()); |
|
949 |
let [errMsg,spRes] = await this.getSkuParameterByMatCode(); |
|
950 |
if (errMsg) { |
|
951 |
return; |
53cc6f
|
952 |
} |
a50a5b
|
953 |
console.log(spRes); |
S |
954 |
if (length<selectedSkuId.length) { |
|
955 |
this.setData({ |
|
956 |
SkuParameterList:spRes.SkuParameterList, |
|
957 |
isCanBuy2:false, |
|
958 |
}) |
|
959 |
} else { |
|
960 |
this.setData({ |
|
961 |
SkuParameterList:spRes.SkuParameterList, |
|
962 |
CouponList:spRes.CouponList, |
|
963 |
goodsItem:spRes.list, |
|
964 |
groupBuyingList:spRes.groupBuyingList, |
|
965 |
isCanBuy2:true, |
|
966 |
}) |
|
967 |
matcode = spRes.list.MatCode |
|
968 |
this.handleNoticeText(spRes.list); |
|
969 |
} |
|
970 |
|
|
971 |
// selectedSkuId[attrIndex] = skuId; |
|
972 |
// let goodsSkuIdStrings = this.data.goodsSkuIdStrings; |
|
973 |
// let hasSkuId = goodsSkuIdStrings.includes(selectedSkuId.join('')); |
|
974 |
// console.log(goodsSkuIdStrings,selectedSkuId.join('')); |
|
975 |
// if (goodsSkuIdStrings.includes(selectedSkuId.join(''))){ |
|
976 |
// this.setData({ |
|
977 |
// [`selectedSkuId[${attrIndex}]`]:skuId |
|
978 |
// }) |
|
979 |
// } else{ |
|
980 |
// |
|
981 |
// } |
|
982 |
// this.handleDisabledSkuId(); |
53cc6f
|
983 |
/* |
S |
984 |
* 遍历第一列,把没有的标记 |
|
985 |
* 点击第一列可选的项后,遍历剩下所有列,把没有的标记 |
|
986 |
* */ |
|
987 |
// let list = this.data.attrList[attrIndex].list; |
|
988 |
// list.forEach((item,index)=>{ |
|
989 |
// item.checked = index === listIndex; |
|
990 |
// }) |
|
991 |
// this.setData({ |
|
992 |
// [`attrList[${attrIndex}].list`]:list |
|
993 |
// }) |
|
994 |
|
|
995 |
}, |
a50a5b
|
996 |
async getSkuParameterByMatCode(){ |
S |
997 |
this.handleSkuIds(); |
|
998 |
let data = this.data.skuIds; |
|
999 |
let [errMsg,res] = await utils.to( |
|
1000 |
wx.$http.request({ |
|
1001 |
url:'/shopping/getSkuParameterByMatCode.do', |
|
1002 |
data |
|
1003 |
}) |
|
1004 |
) |
|
1005 |
return [errMsg,res]; |
|
1006 |
|
|
1007 |
}, |
|
1008 |
handleSkuIds(){ |
|
1009 |
let data = {}; |
|
1010 |
let selectedSkuId = this.data.selectedSkuId; |
|
1011 |
let selectedSkuIdLength = this.data.selectedSkuIdLength; |
|
1012 |
for (let i = 1; i < 11; i++) { |
|
1013 |
if (selectedSkuId[i-1]){ |
|
1014 |
data[`skuId${i}`] = selectedSkuId[i-1] |
|
1015 |
} else { |
|
1016 |
data[`skuId${i}`] = '' |
|
1017 |
} |
|
1018 |
} |
|
1019 |
if (selectedSkuIdLength<selectedSkuId.length) { |
|
1020 |
data.matcode = this.data.goodsItem.MatCode; |
|
1021 |
} |
|
1022 |
console.log(selectedSkuIdLength,selectedSkuId.length); |
|
1023 |
console.log(data); |
|
1024 |
this.setData({ |
|
1025 |
skuIds:data |
|
1026 |
}); |
|
1027 |
}, |
|
1028 |
|
|
1029 |
handleDisabledSkuId(){ |
|
1030 |
let SkuMatCodeList = this.data.SkuMatCodeList; |
|
1031 |
let skuIdList = this.data.skuIdList; |
|
1032 |
let goodsSkuIdList = this.data.goodsSkuIdList.flat(2); |
|
1033 |
// console.log(goodsSkuIdList); |
|
1034 |
let disabledSkuId = []; |
|
1035 |
let selectedSkuId = this.data.selectedSkuId; |
|
1036 |
// SkuMatCodeList.forEach((item,index)=>{ |
|
1037 |
// let disabledArr = []; |
|
1038 |
// if (skuIdList[0].includes(item.skuId1)) { |
|
1039 |
// disabledArr.push() |
|
1040 |
// } |
|
1041 |
// }) |
|
1042 |
let disabledArr = []; |
|
1043 |
skuIdList.forEach((list,index)=>{ |
|
1044 |
if (index === 0){ |
|
1045 |
list.forEach((item,i)=>{ |
|
1046 |
if (goodsSkuIdList.includes(item)){ |
|
1047 |
disabledArr.push(true) |
|
1048 |
} else{ |
|
1049 |
disabledArr.push(false) |
|
1050 |
} |
|
1051 |
}) |
|
1052 |
disabledSkuId.push(disabledArr); |
|
1053 |
} |
|
1054 |
|
|
1055 |
}) |
|
1056 |
|
|
1057 |
|
|
1058 |
|
|
1059 |
|
|
1060 |
}, |
53cc6f
|
1061 |
|
d98d05
|
1062 |
quantityEdit(e){ |
S |
1063 |
// console.log(e) |
|
1064 |
this.setData({ |
|
1065 |
['Quantity.quantity']:parseFloat(e.detail.quantity) |
|
1066 |
}) |
|
1067 |
// console.log(this.data.Quantity) |
53cc6f
|
1068 |
}, |
S |
1069 |
groupBuying(e){ |
|
1070 |
console.log('准备团购'); |
a50a5b
|
1071 |
if (!this.data.isCanBuy) return; |
S |
1072 |
if (!this.data.isCanBuy2) { |
|
1073 |
wx.showToast({ |
|
1074 |
title: '请选择正确的分类', |
|
1075 |
icon:'none' |
|
1076 |
}) |
|
1077 |
return |
|
1078 |
}; |
53cc6f
|
1079 |
let quantity = this.data.Quantity.quantity; |
S |
1080 |
let matCode = this.data.goodsItem.MatCode; |
|
1081 |
let groupCode = this.data.groupCode; |
|
1082 |
let goodsItem = this.data.goodsItem; |
a50a5b
|
1083 |
let skuIds = this.data.skuIds; |
53cc6f
|
1084 |
// let eventChannel = this.getOpenerEventChannel(); |
S |
1085 |
//?quantity=${quantity}&matcode=${matcode}&groupCode=${groupCode} |
|
1086 |
wx.navigateTo({ |
|
1087 |
url: `../order/order`, |
|
1088 |
success(res){ |
|
1089 |
res.eventChannel.emit('getSelectedGoods', { |
|
1090 |
quantity, |
|
1091 |
matCode, |
|
1092 |
groupCode, |
a50a5b
|
1093 |
goodsItem, |
S |
1094 |
skuIds |
53cc6f
|
1095 |
}); |
S |
1096 |
} |
|
1097 |
}) |
d98d05
|
1098 |
}, |
S |
1099 |
// 加入购物车触发事件 |
|
1100 |
addCart: function(e) { |
a50a5b
|
1101 |
if (!this.data.isCanBuy) return; |
d98d05
|
1102 |
// utils.isAuthorize(this); |
S |
1103 |
// console.log(this.data.isAuthorize,333) |
|
1104 |
// if(!this.data.isAuthorize){ |
|
1105 |
// if (!utils.authorize(e, this)){ |
|
1106 |
// return; |
|
1107 |
// } |
|
1108 |
// } |
|
1109 |
//获取数量,价格,商品名称,id,封面图 |
|
1110 |
var num = this.data.Quantity.quantity; |
|
1111 |
var price = this.data.goodsItem.Price; |
|
1112 |
var id = this.data.goodsItem.MatCode; |
|
1113 |
var title = this.data.goodsItem.MatCode; |
|
1114 |
var img = this.data.goodsItem.images[0]; |
|
1115 |
console.log(this.data.Quantity) |
a50a5b
|
1116 |
let skuIds = this.data.skuIds; |
53cc6f
|
1117 |
|
d98d05
|
1118 |
|
S |
1119 |
wx.request({ |
|
1120 |
url: utils.getUrl('/shopping/cart.do?m=add'), |
|
1121 |
header: { |
|
1122 |
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') |
|
1123 |
}, |
|
1124 |
data: { |
|
1125 |
matcode: title, |
a50a5b
|
1126 |
quantity: num, |
S |
1127 |
...skuIds |
d98d05
|
1128 |
}, |
S |
1129 |
success: function(res) { |
|
1130 |
wx.hideLoading(); |
|
1131 |
if(!utils.requestError(res)){ |
|
1132 |
return false; |
|
1133 |
} |
|
1134 |
|
|
1135 |
utils.showTip("添加成功!"); |
|
1136 |
}, |
|
1137 |
fail: function(errmsg) { |
|
1138 |
utils.requestFail(errmsg,'/shopping/cart.do'); |
|
1139 |
} |
|
1140 |
}) |
|
1141 |
|
|
1142 |
|
|
1143 |
|
|
1144 |
|
|
1145 |
this.hideLayer(); |
|
1146 |
wx.showLoading({ |
|
1147 |
title: '加载中', |
|
1148 |
}) |
|
1149 |
|
|
1150 |
// setTimeout(function () { |
|
1151 |
// wx.hideLoading(); |
|
1152 |
// utils.showTip("添加成功!"); |
|
1153 |
// }, 1000) |
|
1154 |
|
|
1155 |
}, |
|
1156 |
// 立即购买触发事件 |
|
1157 |
payOrder: function(e) { |
a50a5b
|
1158 |
if (!this.data.isCanBuy) return; |
S |
1159 |
if (!this.data.isCanBuy2) { |
|
1160 |
wx.showToast({ |
|
1161 |
title: '请选择正确的分类', |
|
1162 |
icon:'none' |
|
1163 |
}) |
|
1164 |
return |
|
1165 |
}; |
d98d05
|
1166 |
// utils.subscribeMessage({ |
S |
1167 |
// callback:()=>{ |
53cc6f
|
1168 |
|
d98d05
|
1169 |
// } |
S |
1170 |
// }) |
|
1171 |
//获取数量,价格,商品名称,id,封面图 |
|
1172 |
var num = this.data.Quantity.quantity; |
|
1173 |
var id = this.data.goodsItem.MatCode; |
|
1174 |
console.log(this.data.Quantity) |
|
1175 |
wx.showLoading({ |
|
1176 |
title: '加载中', |
|
1177 |
}) |
a50a5b
|
1178 |
let skuIds = this.data.skuIds; |
d98d05
|
1179 |
wx.request({ |
S |
1180 |
url: utils.getUrl('/shopping/cart.do?m=add&action=goshop'), |
|
1181 |
header: { |
|
1182 |
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') |
|
1183 |
}, |
|
1184 |
data: { |
|
1185 |
matcode: id, |
a50a5b
|
1186 |
quantity: num, |
S |
1187 |
...skuIds |
d98d05
|
1188 |
}, |
S |
1189 |
success: res=> { |
|
1190 |
wx.hideLoading(); |
|
1191 |
if(!utils.requestError(res)){ |
|
1192 |
return false; |
|
1193 |
} |
|
1194 |
// utils.isAuthorize(this); |
|
1195 |
// if(!this.data.isAuthorize){ |
|
1196 |
// if (!utils.authorize(e, this)){ |
|
1197 |
// return; |
|
1198 |
// } |
|
1199 |
// } |
|
1200 |
|
|
1201 |
wx.navigateTo({ |
0da8db
|
1202 |
url: '../order/order?selectedCartIds='+res.data.CartId |
d98d05
|
1203 |
}) |
S |
1204 |
// if(isLogin){ |
|
1205 |
// wx.navigateTo({ |
|
1206 |
// url: '../order/order' |
|
1207 |
// }) |
|
1208 |
// } else { |
|
1209 |
// wx.navigateTo({ |
|
1210 |
// url: '../authorize/authorize?fromPage=cart' |
|
1211 |
// }) |
|
1212 |
// } |
|
1213 |
|
|
1214 |
// wx.switchTab({ |
|
1215 |
// url: '../cart/cart' |
|
1216 |
// }); |
|
1217 |
}, |
|
1218 |
fail: function(errmsg) { |
|
1219 |
utils.requestFail(errmsg,'/shopping/cart.do'); |
|
1220 |
|
|
1221 |
} |
|
1222 |
}) |
|
1223 |
|
|
1224 |
|
|
1225 |
|
|
1226 |
|
|
1227 |
this.hideLayer(); |
|
1228 |
|
|
1229 |
}, |
|
1230 |
|
|
1231 |
|
|
1232 |
goCart: function() { |
|
1233 |
wx.reLaunch({ |
|
1234 |
url: '../cart/cart' |
|
1235 |
}); |
|
1236 |
}, |
|
1237 |
|
|
1238 |
goIndex: function() { |
|
1239 |
wx.switchTab({ |
|
1240 |
url: '../index/index' |
|
1241 |
}); |
|
1242 |
}, |
|
1243 |
goCollect: function() { |
|
1244 |
wx.showLoading(); |
|
1245 |
wx.request({ |
|
1246 |
url: utils.getUrl('/shopping/wishlist.do?m=add&matcode=' + matcode), |
|
1247 |
header: { |
|
1248 |
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') |
|
1249 |
}, |
|
1250 |
success: res => { |
|
1251 |
|
|
1252 |
wx.hideLoading(); |
|
1253 |
if(!utils.requestError(res)){ |
|
1254 |
return false; |
|
1255 |
} |
|
1256 |
|
|
1257 |
wx.showToast({ |
|
1258 |
title: '收藏成功!' |
|
1259 |
}) |
|
1260 |
|
|
1261 |
}, |
|
1262 |
fail: function(errmsg) { |
|
1263 |
utils.requestFail(errmsg,'/shopping/wishlist.do'); |
|
1264 |
} |
|
1265 |
}) |
|
1266 |
}, |
|
1267 |
// 提交fromid |
|
1268 |
formIdSubmit: function (e) { |
|
1269 |
// utils.formIdSubmit(e, this); |
|
1270 |
wx.navigateTo({ |
|
1271 |
url: '../message/message', |
|
1272 |
}) |
|
1273 |
}, |
|
1274 |
|
|
1275 |
/** |
|
1276 |
* 生命周期函数--监听页面初次渲染完成 |
|
1277 |
*/ |
|
1278 |
onReady: function() { |
|
1279 |
|
|
1280 |
}, |
|
1281 |
|
|
1282 |
/** |
|
1283 |
* 生命周期函数--监听页面显示 |
|
1284 |
*/ |
|
1285 |
onShow: function() { |
|
1286 |
// 发送行为信息 |
|
1287 |
if (app.globalData.FromUserId) { |
|
1288 |
utils.userBehavior('ViewProductDetail', {matcode:matcode}); |
|
1289 |
} |
|
1290 |
|
|
1291 |
// var that = this; |
|
1292 |
// // 显示对方发来的最新消息 |
|
1293 |
// app.globalData.newMsgCallback = onMessage => { |
|
1294 |
// console.log('购物车页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data)) |
|
1295 |
// utils.msgTimer(that); |
|
1296 |
// } |
|
1297 |
// // 页面显示时更新未读消息的值 |
|
1298 |
// utils.refreshUnreadMsgNum(this); |
|
1299 |
}, |
|
1300 |
onUnload(){ |
|
1301 |
imgDownloadSum=0; |
|
1302 |
imgDownloadObj = { |
|
1303 |
isComplete:false |
|
1304 |
}; |
|
1305 |
}, |
|
1306 |
|
|
1307 |
/** |
|
1308 |
* 用户点击右上角分享 |
|
1309 |
*/ |
|
1310 |
onShareAppMessage: function () { |
|
1311 |
// if (ops.from === 'button') { |
|
1312 |
// // 来自页面内转发按钮 |
|
1313 |
// console.log(ops.target) |
|
1314 |
// } |
53cc6f
|
1315 |
|
d98d05
|
1316 |
// console.log('title',utils.getShareTitle()) |
S |
1317 |
return { |
|
1318 |
// title: '我在' + app.globalData.titleName +'发现' + this.data.title + ',赶快来看看吧', |
|
1319 |
title: utils.getShareTitle(), |
|
1320 |
path: 'pages/detail/detail?FromUserId=' + app.globalData.FromUserId + '&FromOpenId=' + app.globalData.openID + '&OpenFrom=fromShare&matcode=' + matcode, |
|
1321 |
success: function (res) { |
|
1322 |
// 转发成功 |
|
1323 |
console.log("转发成功:" + JSON.stringify(res)); |
|
1324 |
// 发送行为信息 |
|
1325 |
// utils.userBehavior('ForwardMyCard'); |
|
1326 |
// utils.showModal(res) |
|
1327 |
}, |
|
1328 |
fail: function (res) { |
|
1329 |
// 转发失败 |
|
1330 |
console.log("转发失败:" + JSON.stringify(res)); |
|
1331 |
} |
|
1332 |
} |
|
1333 |
} |
|
1334 |
|
|
1335 |
|
|
1336 |
|
|
1337 |
|
|
1338 |
}) |