// pages/detail/detail.js
|
var listData = require('../../data/test-data.js');
|
// var WxParse = require('../../src/wxParse/wxParse.js');
|
// var Quantity = require('../template/cart-input/cart-input-template.js');
|
var utils = require("../../utils/util.js")
|
var app = getApp();
|
let isLogin = false;
|
let matcode = "";
|
let imgDownloadSum = 0;
|
let imgDownloadObj = {
|
isComplete:false
|
};
|
import {Http} from "../../utils/http-p.js";
|
const Request = new Http();
|
// Object.assign({}, Quantity,
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
navTitle: [{
|
text: "商品描述",
|
id: 0
|
},
|
{
|
text: "商品属性",
|
id: 1
|
},
|
{
|
text: "售后服务",
|
id: 2
|
}
|
],
|
isShow: false,
|
isPanicCanBuy:true,
|
isGroupCanBuy:true,
|
isSelectedAllSku:true,
|
actionType: "payOrder",
|
Quantity: {
|
quantity: 1,
|
min: 1,
|
max: 999999
|
},
|
clientHeight: "100%",
|
overflow: "auto",
|
list: [],
|
isPullTelephone: false,
|
cltcode: '',
|
isShowBuyingButton:true,
|
attrList:[
|
{
|
title: '颜色',
|
list: [
|
{
|
name:'红',
|
checked: true
|
},
|
{
|
name:'黄',
|
checked: false
|
},
|
|
]
|
},
|
{
|
title: '尺寸',
|
list: [
|
{
|
name:'大',
|
checked: false
|
},
|
{
|
name:'小',
|
checked: true
|
},
|
|
]
|
}
|
]
|
},
|
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function(options) {
|
// homeLayoutStyle = options.homeLayoutStyle;
|
imgDownloadSum = 0;
|
|
// this.setData({
|
// homeLayoutStyle: homeLayoutStyle
|
// })
|
|
// if (homeLayoutStyle) {
|
// return false;
|
// }
|
|
// const query = wx.createSelectorQuery()
|
// console.log('query.select(#myCanvas)',query.select('#myCanvas'))
|
// query.select('#myCanvas')
|
// .fields({ node: true, size: true })
|
// .exec((res) => {
|
// const canvas = res[0].node
|
// const ctx = canvas.getContext('2d')
|
// console.log(canvas,ctx)
|
// this.setData({
|
// canvas,
|
// context:ctx
|
// })
|
// })
|
|
this.setData({
|
cltcode: app.globalData.Cltcode
|
})
|
console.log('cltcode', this.data.cltcode);
|
// this.getSetting()
|
matcode = options.matcode;
|
wx.showLoading({
|
mask: false,
|
title: '加载中',
|
})
|
if (!app.globalData.openID || !app.globalData.FromUserId) {
|
app.globalData.indexCallback = (res) => {
|
// console.log('没有。。。。')
|
this.getSetting();
|
this.getDetailData();
|
}
|
} else{
|
this.getSetting();
|
this.getDetailData();
|
}
|
|
|
},
|
onCountDownFinish(){
|
console.log('倒计时结束了。。。')
|
this.getDetailData ();
|
},
|
getDetailData () {
|
var that = this;
|
// option接收其他页面传递过来的值,?后面的变量名id
|
wx.request({
|
url: utils.getUrl('/shopping/getMatCode.do?matcode=' + matcode),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
method: "GET",
|
success: (res)=> {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
that.setData({
|
goodsItem: res.data.list,
|
CouponList:res.data.CouponList,
|
groupBuyingList:res.data.groupBuyingList,
|
SkuParameterList:res.data.SkuParameterList,
|
SkuMatCodeList:res.data.SkuMatCodeList,
|
title: res.data.list.MatName,
|
num: 0,
|
description: res.data.list.Description,
|
Mininum: res.data.list.Mininum||1,
|
['Quantity.quantity']: res.data.list.Mininum||1
|
// price: goodsItem.Price
|
})
|
this.handleNoticeText(res.data.list);
|
|
// WxParse.wxParse('article', 'html', res.data.list.Description, that, 5);
|
this.getPosterQrCode();
|
this.handleCurrentGoods();
|
wx.setNavigationBarTitle({
|
title: res.data.list.MatName,
|
})
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/getMatCode.do');
|
}
|
|
});
|
|
/**
|
* WxParse.wxParse(bindName , type, data, target,imagePadding)
|
* 1.bindName绑定的数据名(必填)
|
* 2.type可以为html或者md(必填)
|
* 3.data为传入的具体数据(必填)
|
* 4.target为Page对象,一般为this(必填)
|
* 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
|
*/
|
},
|
|
handleNoticeText(res){
|
this.setData({
|
isPanicCanBuy:true,
|
isGroupCanBuy:true
|
})
|
let {
|
Quantity,
|
isRestrictQuantity,
|
isStartupPanicBuying,
|
PanicBuyingStartTimeBalance,
|
PanicBuyingEndTimeBalance,
|
PanicBuyingStartTime,
|
PanicBuyingEndTime,
|
isStartupGroupBuying,
|
GroupBuyingMembers,
|
GroupBuyingPrice,
|
GroupBuyingStartTime,
|
GroupBuyingEndTime,
|
GroupBuyingStartTimeBalance,
|
GroupBuyingEndTimeBalance
|
} = res;
|
if (isStartupPanicBuying&&PanicBuyingStartTimeBalance>0) {
|
this.setData({
|
noticeText:`未开抢,开抢时间${PanicBuyingStartTime}至${PanicBuyingEndTime}`,
|
isPanicCanBuy:false
|
})
|
}
|
else if (isStartupPanicBuying&&PanicBuyingStartTimeBalance<=0&&PanicBuyingEndTimeBalance>0) {
|
this.setData({
|
noticeText:`商品抢购中,结束时间为${PanicBuyingEndTime}`,
|
isPanicCanBuy:true
|
})
|
}
|
else if (isStartupPanicBuying&&PanicBuyingEndTimeBalance<=0) {
|
this.setData({
|
noticeText:`本次商品抢购已结束`,
|
isPanicCanBuy:false
|
})
|
}
|
|
if (isStartupGroupBuying&&GroupBuyingStartTimeBalance>0) {
|
this.setData({
|
noticeText:`未开抢,开抢时间${GroupBuyingStartTime}至${GroupBuyingEndTime}`,
|
isGroupCanBuy:false
|
})
|
}
|
else if (isStartupGroupBuying&&GroupBuyingStartTimeBalance<=0&&GroupBuyingEndTimeBalance>0) {
|
this.setData({
|
noticeText:`商品拼团抢购中,结束时间为${GroupBuyingEndTime}`,
|
isGroupCanBuy:true
|
})
|
}
|
else if (isStartupGroupBuying&&GroupBuyingEndTimeBalance<=0) {
|
this.setData({
|
noticeText:`本次商品限时团购已结束`,
|
isGroupCanBuy:false
|
})
|
}
|
|
if (isRestrictQuantity&&Quantity<=0) {
|
this.setData({
|
noticeText:`该商品已售罄`,
|
isPanicCanBuy:false
|
})
|
}
|
|
console.log('isPanicCanBuy',this.data.isPanicCanBuy);
|
console.log('isGroupCanBuy',this.data.isGroupCanBuy);
|
},
|
|
btnTap: async function (e) {
|
// var that = this;
|
// var isGet = this.data.isGet;
|
// isGet = !isGet;
|
// wx.showLoading({
|
// title: '',
|
// });
|
// setTimeout(function () {
|
// wx.hideLoading();
|
// that.setData({
|
// isGet: isGet
|
// })
|
// }, 800);
|
// await utils.isAuthorize(this);
|
// if(!this.data.isAuthorize){
|
// if (!await utils.authorize(e, this)){
|
// return;
|
// }
|
// }
|
var id = e.target.dataset.couponid;
|
var index = e.target.dataset.index;
|
console.log('领取index',index)
|
// couponStatus : //0 正常:可以抢 ; 1 已经抢完 ; 2 未开抢 ; 3 已经抢过了,不能重复抢 ; 4 已经提醒(微信模板消息提醒)
|
wx.showLoading()
|
wx.request({
|
url: utils.getUrl('/shopping/coupon.do?m=savePersonalCouponCode&couponcode=' + id),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
// this.getDetailData();
|
if(res.data.state=='success'){
|
wx.showToast({
|
icon:'none',
|
title: res.data.success,
|
})
|
this.setData({
|
[`CouponList[${index}].Status`]:3
|
})
|
console.log(this.data.CouponList[index].Status)
|
} else{
|
wx.showToast({
|
title: '领取失败',
|
})
|
}
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/coupon.do');
|
}
|
})
|
|
|
},
|
|
getPosterQrCode(){
|
|
wx.request({
|
url: utils.getUrl('/shopping/poster/getQrCodeForPoster.do'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
data:{
|
QrCodeType:30,
|
matcode:matcode
|
},
|
success: res => {
|
if(!utils.requestError(res)){
|
return false;
|
}
|
// this.getDetailData();
|
console.log(res.data);
|
this.setData({
|
QrCode:res.data.QrCode
|
})
|
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/poster/getQrCodeForPoster.do');
|
}
|
})
|
},
|
|
getSetting() {
|
// 获取设置
|
|
let isPullTelephone1 = false;
|
let getSetting = Request.request({
|
url: '/shopping/getSettingEntity.do'
|
}).then((res) => {
|
console.log('设置数据',res)
|
isPullTelephone1 = res.isPullTelephoneWhenViewProductDetail
|
console.log('isPullTelephone设置', isPullTelephone1)
|
this.setData({
|
generateOrderProcess: res.generateOrderProcess||0
|
})
|
this.setData({
|
isPullTelephone: isPullTelephone1,
|
isShowBuyingButton: res.isShowBuyingButton || false
|
})
|
console.log('isPullTelephone:', isPullTelephone1);
|
});
|
|
|
},
|
|
getPhoneNumber(e) {
|
console.log('getPhoneNumber', e);
|
|
if (e.detail.phoneNumber.errMsg == 'getPhoneNumber:ok') {
|
Request.request({
|
url: '/shopping/account.do',
|
data: {
|
m: 'telRegByAutoReg',
|
// ReferralsCode: this.data.UserId,
|
// ReferralsName: this.data.Name,
|
ReferralsCode: app.globalData.cardUserData.UserId,
|
ReferralsName: app.globalData.cardUserData.Name,
|
encryptedData: e.detail.phoneNumber.encryptedData,
|
iv: e.detail.phoneNumber.iv,
|
// SessionKey: app.globalData.SessionKey
|
}
|
}).then((res) => {
|
console.log('/shopping/account.do', res);
|
if (res.cltcode) {
|
app.globalData.Cltcode = res.cltcode;
|
this.setData({
|
isPullTelephone: false,
|
cltcode: res.cltcode
|
})
|
}
|
});
|
} else{
|
console.log('取消授权');
|
// wx.switchTab({
|
// url: url
|
// });
|
}
|
|
},
|
|
/*查看图片*/
|
viewImg: function(e) {
|
var src = e.currentTarget.dataset.src;
|
// console.log(src)
|
wx.previewImage({
|
current: src, // 当前显示图片的http链接
|
urls: this.data.goodsItem.images // 需要预览的图片http链接列表
|
})
|
},
|
|
// 导航条点击
|
navTap: function(e) {
|
this.setData({
|
num: e.currentTarget.dataset.num
|
})
|
},
|
|
// 隐藏层滑入
|
showLayer: function() {
|
var that = this;
|
utils.showLayer(that, "translateY", 300, 0);
|
},
|
|
// 隐藏层滑出
|
hideLayer: function() {
|
var that = this;
|
utils.hideLayer(that, "translateY", 500);
|
this.setData({
|
['Quantity.quantity']: this.data.Mininum||1,
|
isSelectedSku: false
|
|
})
|
},
|
|
|
// downloadFile(){
|
// console.log(app.globalData.cardUserData)
|
// console.log('头像',app.globalData.cardUserData.Avatar)
|
// console.log('logo',app.globalData.logoUrl)
|
// console.log('二维码',this.data.QrCode)
|
// console.log('商品',this.data.goodsItem.PhotoPath)
|
// let avatarUrl = wx.pro.downloadFile({
|
// url: app.globalData.cardUserData.Avatar
|
// }).then((res)=>{
|
// if (res.statusCode === 200) {
|
// imgDownloadSum++;
|
// console.log('......头像',res.tempFilePath)
|
// this.setData({
|
// avatarUrl: res.tempFilePath
|
// })
|
// }
|
// })
|
// let goodsImg = wx.pro.downloadFile({
|
// url: this.data.goodsItem.PhotoPath
|
// }).then((res)=>{
|
// if (res.statusCode === 200) {
|
// imgDownloadSum++;
|
// console.log('......商品',res.tempFilePath)
|
// this.setData({
|
// goodsImg: res.tempFilePath
|
// })
|
// }
|
// })
|
// let qrCodeImg = wx.pro.downloadFile({
|
// url: this.data.QrCode
|
// }).then((res)=>{
|
// if (res.statusCode === 200) {
|
// console.log('......二维码',res.tempFilePath)
|
// imgDownloadSum++;
|
// this.setData({
|
// qrCodeImg: res.tempFilePath
|
// })
|
// }
|
// })
|
|
// Promise.all([avatarUrl,goodsImg,qrCodeImg]).then((res)=>{
|
|
// imgDownloadObj.isComplete = true;
|
|
// // imgDownloadObj.isComplete = true;
|
// }).catch((err)=>{
|
// // this.getPosterQrCode();
|
// console.log('请检查名片头像、公司logo等图片是否已经配置',err)
|
// // \n 点击确定重试,点击取消关闭弹窗。
|
// wx.hideToast();
|
// wx.showModal({
|
// title:'提示',
|
// content:`${err.errMsg}`,
|
// showCancel:false,
|
// success:(res)=>{
|
// // if (res.confirm) {
|
// // console.log('用户点击确定')
|
// // wx.showLoading()
|
// // this.downloadFile()
|
// // } else if (res.cancel) {
|
// // console.log('用户点击取消')
|
// // }
|
|
// }
|
// })
|
|
// })
|
|
// },
|
|
// createCanvas(e){
|
|
// wx.showToast({
|
// title: '生成中...',
|
// icon: 'loading',
|
// mask:true,
|
// duration: 10000
|
// });
|
|
// if (imgDownloadObj.isComplete) {
|
// // wx.hideToast()
|
// // let posterCreate = this.selectComponent('#posterCreate');
|
// // posterCreate.formSubmit(e);
|
// this.sendCommand(e);
|
// } else {
|
// // 下载图片到本地
|
// this.downloadFile();
|
// // utils.watchObj(imgDownloadObj,(prop,val)=>{
|
// // console.log(JSON.stringify(imgDownloadObj)+prop+'值变化!!!','新值为'+val)
|
// utils.watchObj(imgDownloadObj,'isComplete',(val)=>{
|
// console.log(JSON.stringify(imgDownloadObj)+'isComplete值变化!!!','新值为'+val)
|
// if (imgDownloadObj.isComplete) {
|
// this.sendCommand(e);
|
// }
|
// // wx.hideToast()
|
// // let posterCreate = this.selectComponent('#posterCreate');
|
// // posterCreate.formSubmit(e);
|
|
// })
|
|
// }
|
|
// },
|
|
// sendCommand(e){
|
// wx.hideToast()
|
// let posterCreate = this.selectComponent('#posterCreate');
|
// posterCreate.formSubmit(e);
|
// },
|
|
|
// // 加载函数
|
// loadImage(src) {
|
// return new Promise((resolve,reject) => {
|
// const img = this.data.canvas.createImage();
|
// img.onload = () => {
|
// resolve(img);
|
// };
|
// img.onerror = (e) => {
|
// reject(e);
|
// };
|
// img.src = src;
|
// });
|
// },
|
|
|
|
//将canvas转换为图片保存到本地,然后将图片路径传给image图片的src
|
// createPoster (e) {
|
// let posterCreate = this.selectComponent('#posterCreate');
|
// let canvas = e.detail.canvas;
|
// console.log(e)
|
// // let context = canvas.getContext('2d');
|
// let context = e.detail.context;
|
// // let context = wx.createCanvasContext('mycanvas');
|
|
// // let path = "../../imgs/gobg.png";
|
// // //不知道是什么原因,手机环境能正常显示
|
// // context.drawImage(path, 0, 0, 375, 183);
|
// let avatarImg = this.data.avatarUrl;
|
// console.log(avatarImg,"avatarImg")
|
// // let path2 = "../../imgs/chengzhong.png";
|
// let goodsImg = this.data.goodsImg;
|
// let qrCodeImg = this.data.qrCodeImg;
|
// // let path5 = "../../imgs/computer.png";
|
// // context.drawImage(path2, 126, 186, 120, 120);
|
// // context.save(); // 保存当前context的状态
|
// console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
|
// // let name = that.data.name;
|
// // //绘制名字
|
// // context.setFontSize(30);
|
// // context.setFillStyle('#333333');
|
// // context.setTextAlign('center');
|
// // context.fillText(name, 185, 160);
|
// // context.stroke();
|
// context.beginPath()
|
// context.fillStyle="#fff";
|
// context.fillRect(0, 0, 375, 667);
|
// context.closePath()
|
// //绘制文字
|
// context.beginPath()
|
// context.setFontSize(16);
|
// context.fillStyle='#333333';
|
// context.textAlign='left';
|
// context.fillText("我看上了这款商品", 140, 50);
|
// context.stroke();
|
|
// context.setFontSize(16);
|
// context.fillStyle='#333333';
|
// context.textAlign='left';
|
// context.fillText("帮我看看咋样啊~~", 140, 85);
|
// context.stroke();
|
// context.closePath();
|
// //绘制商品
|
// context.beginPath();
|
// context.drawImage(goodsImg, 48, 125, 280, 280);
|
// // 商品文字
|
|
// context.setFontSize(16);
|
// context.fillStyle='#333333';
|
// context.textAlign='left';
|
// var result = this.breakLinesForCanvas(context,
|
// this.data.goodsItem.MatName.slice(0,50),
|
// 170, '14px 微软雅黑');
|
// var lineHeight = 25;
|
// result.forEach(function(line, index) {
|
// context.fillText(line, 50, lineHeight * index + 435);
|
// // context.fillText("商品描述", 50, 445);
|
// });
|
|
// context.stroke();
|
// context.setFontSize(32);
|
// context.fillStyle='#f23232';
|
// context.textAlign='left';
|
// context.fillText("¥1999.00", 45, 505);
|
// context.stroke();
|
// context.closePath();
|
|
// // 绘制分割线
|
// context.beginPath()
|
// context.strokeStyle='#ddd'
|
// context.moveTo(10, 520)
|
// context.lineTo(365, 520)
|
// context.stroke()
|
// context.closePath();
|
// //绘制code码
|
// // context.setFontSize(40);
|
// // context.setFillStyle('#ffe200');
|
// // context.setTextAlign('center');
|
// // context.fillText(that.data.code, 185, 435);
|
// // context.stroke();
|
// //绘制左下角文字背景图
|
// context.beginPath();
|
// context.drawImage(qrCodeImg, 20, 530, 120, 120);
|
|
// //绘制右下角扫码提示语
|
// // context.drawImage(path5, 248, 578, 90, 25);
|
// context.setFontSize(16);
|
// context.fillStyle='#333';
|
// context.textAlign='left';
|
// context.fillText("长按识别小程序码 即可查看~",150, 600);
|
// context.stroke();
|
// //绘制头像
|
// context.arc(80, 60, 40, 0, 2 * Math.PI) //画出圆
|
// context.strokeStyle = "#ffe200";
|
// context.clip(); //裁剪上面的圆形
|
// context.drawImage(avatarImg, 40, 20, 80, 80); // 在刚刚裁剪的园上画图
|
// context.closePath();
|
// // context.draw();
|
// // let posterCreate = this.selectComponent('#posterCreate');
|
// // posterCreate.createPoster();
|
// // console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
|
// //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
|
// setTimeout( ()=> {
|
|
|
// posterCreate.createPoster(canvas);
|
// console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
|
// }, 500);
|
// },
|
// authorizeInfo(e){
|
// console.log('authorizeInfo',e)
|
// },
|
// createNewImg (e) {
|
// console.log('createNewImg',e)
|
// let posterCreate = this.selectComponent('#posterCreate');
|
// let goodsItem = this.data.goodsItem;
|
// let context = e.detail.context;
|
// // let childComp = e.detail.childComp;
|
// // let context = wx.createCanvasContext('mycanvas');
|
// context.clearRect(0, 0, 375, 667);
|
// context.setFillStyle("#fff");
|
// context.fillRect(0, 0, 375, 667)
|
// // let path = "../../imgs/gobg.png";
|
// // //不知道是什么原因,手机环境能正常显示
|
// // context.drawImage(path, 0, 0, 375, 183);
|
// let avatarImg = this.data.avatarUrl;
|
// console.log(avatarImg,"avatarImg")
|
// // let path2 = "../../imgs/chengzhong.png";
|
// let goodsImg = this.data.goodsImg;
|
// let qrCodeImg = this.data.qrCodeImg;
|
// console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
|
// // let path5 = "../../imgs/computer.png";
|
// // context.drawImage(path2, 126, 186, 120, 120);
|
// // context.save(); // 保存当前context的状态
|
|
// //绘制文字
|
// context.beginPath()
|
// context.setFontSize(16);
|
// context.setFillStyle('#333333');
|
// context.setTextAlign('left');
|
// context.fillText("我看上了这款商品", 140, 50);
|
// context.stroke();
|
// context.setFontSize(16);
|
// context.setFillStyle('#333333');
|
// context.setTextAlign('left');
|
// context.fillText("帮我看看咋样啊~~", 140, 85);
|
// context.stroke();
|
// context.closePath();
|
// //绘制商品
|
// context.drawImage(goodsImg, 48, 125, 280, 280);
|
// // 商品文字
|
// context.beginPath();
|
// context.setFontSize(16);
|
// context.setFillStyle('#333333');
|
// context.setTextAlign('left');
|
// var result = posterCreate.breakLinesForCanvas(context,
|
// goodsItem.MatName.slice(0,40),
|
// 220, 14);
|
// var lineHeight = 25;
|
// result.forEach(function(line, index) {
|
// context.fillText(line, 50, lineHeight * index + 435);
|
// // context.fillText("商品描述", 50, 445);
|
// });
|
|
// context.stroke();
|
// context.setFontSize(32);
|
// context.setFillStyle('#f23232');
|
// context.setTextAlign('left');
|
// context.fillText(goodsItem.CurrencySign+goodsItem.Price, 45, 495);
|
// context.stroke();
|
// context.closePath();
|
|
// // 绘制分割线
|
// context.beginPath()
|
// context.strokeStyle='#ddd'
|
// context.moveTo(10, 520)
|
// context.lineTo(365, 520)
|
// context.stroke()
|
// context.closePath();
|
// //绘制code码
|
// // context.setFontSize(40);
|
// // context.setFillStyle('#ffe200');
|
// // context.setTextAlign('center');
|
// // context.fillText(that.data.code, 185, 435);
|
// // context.stroke();
|
// //绘制左下角二维码
|
// context.drawImage(qrCodeImg, 20, 530, 120, 120);
|
|
// //绘制右下角扫码提示语
|
// // context.drawImage(path5, 248, 578, 90, 25);
|
// context.setFontSize(16);
|
// context.setFillStyle('#333');
|
// context.setTextAlign('left');
|
// context.fillText("长按识别小程序码 即可查看~",150, 600);
|
// context.stroke();
|
// //绘制头像
|
// context.arc(80, 60, 40, 0, 2 * Math.PI) //画出圆
|
// context.strokeStyle = "#ffe200";
|
// context.clip(); //裁剪上面的圆形
|
// context.drawImage(avatarImg, 40, 20, 80, 80); // 在刚刚裁剪的园上画图
|
// context.draw();
|
// //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
|
// setTimeout(()=> {
|
// posterCreate.createPoster();
|
// // console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
|
// }, 300);
|
// },
|
|
buyTap: function(event) {
|
// 根据按钮不同区分“下一步”触发的事件
|
let name = event.target.dataset.name || event.detail.name;
|
console.log(event);
|
this.setData({
|
groupCode:event.detail.groupCode||'',
|
});
|
if (name === "order") {
|
this.setData({
|
actionType: 'payOrder'
|
})
|
// utils.subscribeMessage({
|
// callback:()=>{
|
// if (this.data.isShow) {
|
// this.hideLayer();
|
// } else {
|
// this.showLayer();
|
// }
|
// }
|
// })
|
} else if (name === "cart") {
|
this.setData({
|
actionType: 'addCart'
|
})
|
|
}
|
else if (name === "group") {
|
this.setData({
|
actionType: 'groupBuying'
|
})
|
|
}
|
if (this.data.isShow) {
|
this.hideLayer();
|
} else {
|
this.showLayer();
|
}
|
},
|
|
selectedSku(){
|
// console.log(888);
|
// if (!this.data.isPanicCanBuy) return;
|
this.setData({
|
isSelectedSku: true
|
})
|
if (this.data.isShow) {
|
this.hideLayer();
|
} else {
|
this.showLayer();
|
}
|
},
|
|
handleCurrentGoods(){
|
/*
|
*
|
* 首先拿到当前商品的所有skuid [],同时也是选中的id
|
* 处理所有商品的skuid为字符串
|
* 用户点击sku[i],拼接为字符串与上面的对比
|
* */
|
let SkuParameterList = this.data.SkuParameterList;
|
let SkuMatCodeList = this.data.SkuMatCodeList;
|
let MatCode = this.data.goodsItem.MatCode;
|
let selectedSkuId = [];
|
let selectedSkuName = [];
|
let goodsSkuIdStrings = [];
|
let goodsSkuIdList = [];
|
let skuIdList = [];
|
let skuSetName = [];
|
SkuParameterList.forEach((item) => {
|
let arr = [];
|
item.skuList.forEach((item) => {
|
arr.push(item.skuId)
|
})
|
skuIdList.push(arr);
|
skuSetName.push(item.skuSetName);
|
})
|
SkuMatCodeList.forEach((item,index)=>{
|
let skuIdString = '';
|
let skuIdArr = [];
|
for (let i = 1; i < 11; i++) {
|
if (item.MatCode === MatCode && item[`skuId${i}`]){
|
selectedSkuId.push(item[`skuId${i}`])
|
selectedSkuName.push(item[`skuName${i}`])
|
}
|
if (item[`skuId${i}`]){
|
skuIdString+=item[`skuId${i}`]
|
skuIdArr.push(item[`skuId${i}`])
|
}
|
}
|
goodsSkuIdStrings.push(skuIdString)
|
goodsSkuIdList.push(skuIdArr)
|
})
|
this.setData({
|
selectedSkuId,
|
selectedSkuName,
|
selectedSkuNameStr: selectedSkuName.join(' '),
|
goodsSkuIdStrings,
|
skuIdList,
|
goodsSkuIdList,
|
skuSetName,
|
skuSetNameStr:skuSetName.join(','),
|
})
|
console.log('selectedSkuId',selectedSkuId);
|
console.log('selectedSkuName',selectedSkuName);
|
console.log('goodsSkuIdStrings',goodsSkuIdStrings);
|
console.log('skuIdList',skuIdList);
|
console.log('goodsSkuIdList',goodsSkuIdList);
|
console.log('skuSetName',skuSetName);
|
this.handleSkuIds();
|
},
|
async selectGoodsAttr(e){
|
|
|
let attrIndex = e.currentTarget.dataset.i;
|
let listIndex = e.currentTarget.dataset.index;
|
let skuId = e.currentTarget.dataset.skuId;
|
let skuName = e.currentTarget.dataset.skuName;
|
let isEnabled = e.currentTarget.dataset.isEnabled;
|
let selectedSkuId = this.data.selectedSkuId;
|
let selectedSkuName = this.data.selectedSkuName;
|
let length = selectedSkuId.length;
|
console.log(e,selectedSkuId);
|
// if (!isEnabled) return;
|
|
selectedSkuId[attrIndex] = skuId;
|
selectedSkuName[attrIndex] = skuName;
|
selectedSkuId.forEach((item,index)=>{
|
if (index>attrIndex){
|
selectedSkuId[index] = ''
|
selectedSkuName[index] = ''
|
}
|
})
|
selectedSkuId.forEach((item)=>{
|
if (item==="") length--;
|
})
|
this.setData({
|
// [`selectedSkuId[${attrIndex}]`]:skuId,
|
selectedSkuId:selectedSkuId,
|
// [`selectedskuName[${attrIndex}]`]:skuName,
|
// [`selectedskuName[${attrIndex}]`]:skuName,
|
selectedSkuNameStr: selectedSkuName.join(' '),
|
selectedSkuIdLength: length
|
})
|
console.log(selectedSkuId,selectedSkuName,this.data.selectedSkuIdLength);
|
// console.log(await this.getSkuParameterByMatCode());
|
let [errMsg,spRes] = await this.getSkuParameterByMatCode();
|
if (errMsg) {
|
return;
|
}
|
console.log(spRes);
|
if (length<selectedSkuId.length) {
|
this.setData({
|
SkuParameterList:spRes.SkuParameterList,
|
isSelectedAllSku:false,
|
})
|
} else {
|
this.setData({
|
SkuParameterList:spRes.SkuParameterList,
|
CouponList:spRes.CouponList,
|
goodsItem:spRes.list,
|
groupBuyingList:spRes.groupBuyingList,
|
isSelectedAllSku:true,
|
})
|
matcode = spRes.list.MatCode
|
this.handleNoticeText(spRes.list);
|
}
|
if (spRes.list.MatName) {
|
wx.setNavigationBarTitle({
|
title: spRes.list.MatName,
|
})
|
}
|
// selectedSkuId[attrIndex] = skuId;
|
// let goodsSkuIdStrings = this.data.goodsSkuIdStrings;
|
// let hasSkuId = goodsSkuIdStrings.includes(selectedSkuId.join(''));
|
// console.log(goodsSkuIdStrings,selectedSkuId.join(''));
|
// if (goodsSkuIdStrings.includes(selectedSkuId.join(''))){
|
// this.setData({
|
// [`selectedSkuId[${attrIndex}]`]:skuId
|
// })
|
// } else{
|
//
|
// }
|
// this.handleDisabledSkuId();
|
/*
|
* 遍历第一列,把没有的标记
|
* 点击第一列可选的项后,遍历剩下所有列,把没有的标记
|
* */
|
// let list = this.data.attrList[attrIndex].list;
|
// list.forEach((item,index)=>{
|
// item.checked = index === listIndex;
|
// })
|
// this.setData({
|
// [`attrList[${attrIndex}].list`]:list
|
// })
|
|
},
|
async getSkuParameterByMatCode(){
|
this.handleSkuIds();
|
let data = this.data.skuIds;
|
let [errMsg,res] = await utils.to(
|
wx.$http.request({
|
url:'/shopping/getSkuParameterByMatCode.do',
|
data
|
})
|
)
|
return [errMsg,res];
|
|
},
|
handleSkuIds(){
|
let data = {};
|
let selectedSkuId = this.data.selectedSkuId;
|
let selectedSkuIdLength = this.data.selectedSkuIdLength;
|
for (let i = 1; i < 11; i++) {
|
if (selectedSkuId[i-1]){
|
data[`skuId${i}`] = selectedSkuId[i-1]
|
} else {
|
data[`skuId${i}`] = ''
|
}
|
}
|
if (selectedSkuIdLength<selectedSkuId.length) {
|
data.matcode = this.data.goodsItem.MatCode;
|
}
|
console.log(selectedSkuIdLength,selectedSkuId.length);
|
console.log(data);
|
this.setData({
|
skuIds:data
|
});
|
},
|
|
handleDisabledSkuId(){
|
let SkuMatCodeList = this.data.SkuMatCodeList;
|
let skuIdList = this.data.skuIdList;
|
let goodsSkuIdList = this.data.goodsSkuIdList.flat(2);
|
// console.log(goodsSkuIdList);
|
let disabledSkuId = [];
|
let selectedSkuId = this.data.selectedSkuId;
|
// SkuMatCodeList.forEach((item,index)=>{
|
// let disabledArr = [];
|
// if (skuIdList[0].includes(item.skuId1)) {
|
// disabledArr.push()
|
// }
|
// })
|
let disabledArr = [];
|
skuIdList.forEach((list,index)=>{
|
if (index === 0){
|
list.forEach((item,i)=>{
|
if (goodsSkuIdList.includes(item)){
|
disabledArr.push(true)
|
} else{
|
disabledArr.push(false)
|
}
|
})
|
disabledSkuId.push(disabledArr);
|
}
|
|
})
|
|
|
|
|
},
|
|
quantityEdit(e){
|
// console.log(e)
|
this.setData({
|
['Quantity.quantity']:parseFloat(e.detail.quantity)
|
})
|
// console.log(this.data.Quantity)
|
},
|
groupBuying(e){
|
console.log('准备团购');
|
if (!this.data.isGroupCanBuy) return;
|
if (!this.data.isSelectedAllSku) {
|
wx.showToast({
|
title: '请选择正确的分类',
|
icon:'none'
|
})
|
return
|
};
|
let quantity = this.data.Quantity.quantity;
|
let matCode = this.data.goodsItem.MatCode;
|
let groupCode = this.data.groupCode;
|
let goodsItem = this.data.goodsItem;
|
let skuIds = this.data.skuIds;
|
// let eventChannel = this.getOpenerEventChannel();
|
//?quantity=${quantity}&matcode=${matcode}&groupCode=${groupCode}
|
wx.navigateTo({
|
url: `../order/order`,
|
success(res){
|
res.eventChannel.emit('getSelectedGoods', {
|
quantity,
|
matCode,
|
groupCode,
|
goodsItem,
|
skuIds
|
});
|
}
|
})
|
},
|
// 加入购物车触发事件
|
addCart: function(e) {
|
if (!this.data.isPanicCanBuy) return;
|
if (!this.data.isSelectedAllSku) {
|
wx.showToast({
|
title: '请选择正确的分类',
|
icon:'none'
|
})
|
return
|
};
|
|
//获取数量,价格,商品名称,id,封面图
|
var num = this.data.Quantity.quantity;
|
var price = this.data.goodsItem.Price;
|
var id = this.data.goodsItem.MatCode;
|
var title = this.data.goodsItem.MatCode;
|
var img = this.data.goodsItem.images[0];
|
console.log(this.data.Quantity)
|
let skuIds = this.data.skuIds;
|
|
|
wx.request({
|
url: utils.getUrl('/shopping/cart.do?m=add'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
data: {
|
matcode: title,
|
quantity: num,
|
...skuIds
|
},
|
success: function(res) {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
utils.showTip("添加成功!");
|
},
|
fail: function(errmsg) {
|
utils.requestFail(errmsg,'/shopping/cart.do');
|
}
|
})
|
|
|
|
|
this.hideLayer();
|
wx.showLoading({
|
title: '加载中',
|
})
|
|
// setTimeout(function () {
|
// wx.hideLoading();
|
// utils.showTip("添加成功!");
|
// }, 1000)
|
|
},
|
// 立即购买触发事件
|
payOrder: function(e) {
|
if (!this.data.isPanicCanBuy) return;
|
if (!this.data.isSelectedAllSku) {
|
wx.showToast({
|
title: '请选择正确的分类',
|
icon:'none'
|
})
|
return
|
};
|
// utils.subscribeMessage({
|
// callback:()=>{
|
|
// }
|
// })
|
//获取数量,价格,商品名称,id,封面图
|
var num = this.data.Quantity.quantity;
|
var id = this.data.goodsItem.MatCode;
|
console.log(this.data.Quantity)
|
wx.showLoading({
|
title: '加载中',
|
})
|
let skuIds = this.data.skuIds;
|
wx.request({
|
url: utils.getUrl('/shopping/cart.do?m=add&action=goshop'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
data: {
|
matcode: id,
|
quantity: num,
|
...skuIds
|
},
|
success: res=> {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
|
wx.navigateTo({
|
url: '../order/order?selectedCartIds='+res.data.CartId
|
})
|
// if(isLogin){
|
// wx.navigateTo({
|
// url: '../order/order'
|
// })
|
// } else {
|
// wx.navigateTo({
|
// url: '../authorize/authorize?fromPage=cart'
|
// })
|
// }
|
|
// wx.switchTab({
|
// url: '../cart/cart'
|
// });
|
},
|
fail: function(errmsg) {
|
utils.requestFail(errmsg,'/shopping/cart.do');
|
|
}
|
})
|
|
|
|
|
this.hideLayer();
|
|
},
|
|
|
goCart: function() {
|
let tabBarList = app.globalData.tabBarList;
|
let goCart = tabBarList.filter((item)=>{
|
// console.log(item);
|
return item.includes('/cart')
|
})
|
// console.log(tabBarList,goCart);
|
if (goCart.length>0) {
|
wx.reLaunch({
|
url: '../cart/cart'
|
});
|
} else {
|
wx.reLaunch({
|
url: '../classify2/classify2'
|
});
|
}
|
|
},
|
|
goIndex: function() {
|
wx.switchTab({
|
url: '../index/index'
|
});
|
},
|
goCollect: function() {
|
wx.showLoading();
|
wx.request({
|
url: utils.getUrl('/shopping/wishlist.do?m=add&matcode=' + matcode),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
wx.showToast({
|
title: '收藏成功!'
|
})
|
|
},
|
fail: function(errmsg) {
|
utils.requestFail(errmsg,'/shopping/wishlist.do');
|
}
|
})
|
},
|
// 提交fromid
|
formIdSubmit: function (e) {
|
// utils.formIdSubmit(e, this);
|
wx.navigateTo({
|
url: '../message/message',
|
})
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function() {
|
// 发送行为信息
|
if (app.globalData.FromUserId) {
|
utils.userBehavior('ViewProductDetail', {matcode:matcode});
|
}
|
|
// var that = this;
|
// // 显示对方发来的最新消息
|
// app.globalData.newMsgCallback = onMessage => {
|
// console.log('购物车页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
|
// utils.msgTimer(that);
|
// }
|
// // 页面显示时更新未读消息的值
|
// utils.refreshUnreadMsgNum(this);
|
},
|
onUnload(){
|
imgDownloadSum=0;
|
imgDownloadObj = {
|
isComplete:false
|
};
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage: function () {
|
// if (ops.from === 'button') {
|
// // 来自页面内转发按钮
|
// console.log(ops.target)
|
// }
|
|
// console.log('title',utils.getShareTitle())
|
return {
|
// title: '我在' + app.globalData.titleName +'发现' + this.data.title + ',赶快来看看吧',
|
title: utils.getShareTitle(),
|
path: 'pages/detail/detail?FromUserId=' + app.globalData.FromUserId + '&FromOpenId=' + app.globalData.openID + '&OpenFrom=fromShare&matcode=' + matcode,
|
success: function (res) {
|
// 转发成功
|
console.log("转发成功:" + JSON.stringify(res));
|
// 发送行为信息
|
// utils.userBehavior('ForwardMyCard');
|
// utils.showModal(res)
|
},
|
fail: function (res) {
|
// 转发失败
|
console.log("转发失败:" + JSON.stringify(res));
|
}
|
}
|
}
|
|
|
|
|
})
|