// 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();
|
|
var matcode = "";
|
var currentIndex = "";
|
|
Page(Object.assign({}, Quantity, {
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
isShow: false,
|
Quantity: {
|
quantity: 1,
|
min: 1,
|
max: 999999
|
},
|
clientHeight: "100%",
|
overflow: "visible",
|
list: [],
|
//所有详情图片的高度 (必须)
|
imgHeightsList:[],
|
//图片宽度
|
// imgwidth: 750,
|
// //默认 (必须)
|
current: 0, //当前所在滑块的 index
|
scrollLeft: 0, //滚动条的位置,一个选项卡宽度是90(自定义来自css),按比例90*n设置位置
|
navlist: [],
|
newMsg: '',
|
// conlist: [
|
// {
|
// images: ["https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1538123801132&di=5e568130a99adfe7a3c77a857ea93afd&imgtype=0&src=http%3A%2F%2Fimg.redocn.com%2Fsheji%2F20150512%2Ftaobaohuazhuangpinshangpinxiangqingyesheji_4321666.jpg",
|
// "https://upload-images.jianshu.io/upload_images/2464047-d97a7be761c51cf1.jpg"
|
// ]
|
// },
|
|
// {
|
// images: ["https://s1.ax2x.com/2018/09/27/5HcbnX.jpg", "https://upload-images.jianshu.io/upload_images/2464047-d97a7be761c51cf1.jpg",
|
// ]
|
// },
|
|
// {
|
// images: ["https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1538123801130&di=5e9bf568bd91ec4e0465c244f2ed50a7&imgtype=0&src=http%3A%2F%2Fa.vpimg3.com%2Fupload%2Fmerchandise%2F190729%2Fshk-4045787141382-110_2.jpg",
|
// "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1538123801132&di=92284712efd718621a825712d5f2cf04&imgtype=0&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F40%2F02%2F93bOOOPICb8_1024.jpg"
|
// ]
|
// },
|
// {
|
// images: ["https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1566978673,1265238851&fm=26&gp=0.jpg"
|
// ]
|
// },
|
// {
|
// images: [
|
// "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1193292794,3586818293&fm=26&gp=0.jpg"
|
// ]
|
// }
|
|
// ]
|
|
|
},
|
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function(options) {
|
console.log(options)
|
let id = options.id;
|
let index = options.index;
|
currentIndex = index;
|
|
this.setData({
|
current: index,
|
MatCode: id
|
})
|
|
|
|
wx.request({
|
url: utils.getUrl('/shopping/getMatCodeList.do?' + 'fromdata=7'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res=> {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
this.setData({
|
navlist: res.data.list,
|
scrollLeft: index * 90
|
})
|
|
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/getMatCodeList.do');
|
}
|
})
|
|
|
// matcode = options.id;
|
// var that = this;
|
wx.showLoading({
|
mask: false,
|
title: '加载中',
|
})
|
// option接收其他页面传递过来的值,?后面的变量名id
|
wx.request({
|
url: utils.getUrl('/shopping/getMatCode.do?matcode=' + options.id),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
method: "GET",
|
success: res=> {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
this.setData({
|
goodsItem: res.data.list,
|
})
|
WxParse.wxParse('article', 'html', res.data.list.Description, this, 5);
|
|
},
|
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,可选)
|
*/
|
|
|
|
// option接收其他页面传递过来的值,?后面的变量名id
|
},
|
/*查看图片*/
|
viewImg: function(e) {
|
var src = e.currentTarget.dataset.src;
|
// console.log(src)
|
wx.previewImage({
|
current: src, // 当前显示图片的http链接
|
urls: [src] // 需要预览的图片http链接列表
|
})
|
},
|
|
|
// 隐藏层滑入
|
showLayer: function() {
|
var that = this;
|
utils.showLayer(that, "translateY", 300, 0);
|
},
|
|
// 隐藏层滑出
|
hideLayer: function() {
|
var that = this;
|
utils.hideLayer(that, "translateY", 500);
|
},
|
|
buyTap: function (event) {
|
|
if (this.data.isShow) {
|
this.hideLayer();
|
} else {
|
this.showLayer();
|
}
|
},
|
handleZanQuantityChange(e) {
|
var componentId = e.componentId;
|
var quantity = e.quantity;
|
this.setData({
|
[`${componentId}.quantity`]: quantity,
|
price: (this.data.goodsItem.price * quantity).toFixed(2)
|
|
});
|
},
|
|
// 加入购物车触发事件
|
addCart: function() {
|
//获取数量,价格,商品名称,id,封面图
|
var num = this.data.Quantity.quantity;
|
var id = this.data.goodsItem.MatCode;
|
|
wx.showLoading({
|
title: '加载中',
|
})
|
|
wx.request({
|
url: utils.getUrl('/shopping/cart.do?m=add&action=goshop'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
data: {
|
matcode: id,
|
quantity: num
|
},
|
success: function (res) {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
wx.switchTab({
|
url: '../cart/cart'
|
});
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/cart.do');
|
}
|
})
|
|
|
|
|
this.hideLayer();
|
|
},
|
|
|
|
//tab切换
|
tab: function(event) {
|
this.setData({
|
current: event.target.dataset.current
|
})
|
//锚点处理
|
this.setData({
|
scrollLeft: event.target.dataset.current * 90
|
})
|
|
wx.showLoading({
|
mask: false,
|
title: '加载中',
|
})
|
// option接收其他页面传递过来的值,?后面的变量名id
|
wx.request({
|
url: utils.getUrl('/shopping/getMatCode.do?matcode=' + event.currentTarget.dataset.matcode),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
method: "GET",
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
this.setData({
|
goodsItem: res.data.list,
|
})
|
WxParse.wxParse('article', 'html', res.data.list.Description, this, 5);
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/getMatCode.do');
|
}
|
|
});
|
},
|
// //滑动事件
|
// eventchange: function(event) {
|
|
// this.setData({
|
// current: event.detail.current
|
// })
|
// //锚点处理
|
// this.setData({
|
// scrollLeft: event.detail.current * 90
|
// })
|
// },
|
|
//
|
imageLoad: function (e) {
|
// //获取图片真实宽度
|
// var imgwidth = e.detail.width,
|
// imgheight = e.detail.height,
|
// //宽高比
|
// ratio = imgwidth / imgheight;
|
// // console.log(imgwidth, imgheight)
|
// //计算的高度值
|
// var viewHeight = 750 / ratio;
|
// var imgheight = viewHeight;
|
// var imgheights = this.data.imgheights;
|
// //把每一张图片的对应的高度记录到数组里
|
// imgheights[e.target.dataset.id] = imgheight;
|
// this.setData({
|
// imgheights: imgheights
|
// })
|
|
// console.log(this.data.imgheights)
|
|
var query = wx.createSelectorQuery();
|
//选择id
|
var that = this;
|
var imgHeightsList = [];
|
query.selectAll('.cosmo-img').boundingClientRect(function (rect) {
|
|
for(let i = 0; i<rect.length;i++){
|
imgHeightsList.push(rect[i].height)
|
}
|
that.setData({
|
imgHeightsList: imgHeightsList
|
})
|
|
}).exec();
|
|
// query.select('.cosmo-img').boundingClientRect()
|
// query.exec(function (res) {
|
// //res就是 所有标签为mjltest的元素的信息 的数组
|
// console.log(res);
|
// //取高度
|
// // console.log(res[0].height);
|
// })
|
},
|
|
// 提交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:this.data.MatCode});
|
}
|
|
|
// var that = this;
|
// // 显示对方发来的最新消息
|
// app.globalData.newMsgCallback = onMessage => {
|
// console.log('消息页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
|
// utils.msgTimer(that);
|
// }
|
//
|
// // 页面显示时更新未读消息的值
|
// utils.refreshUnreadMsgNum(this);
|
|
},
|
|
/**
|
* 用户点击右上角分享(index.js)
|
*/
|
// onShareAppMessage: function (ops) {
|
// if (ops.from === 'button') {
|
// // 来自页面内转发按钮
|
// console.log(ops.target)
|
// }
|
// return {
|
// title: 'pages/idCard/idCard?FromOpenId=' + app.globalData.openID + '&FromUserId=' + app.globalData.FromUserId || '我的分享123',
|
// path: 'pages/idCard/idCard?FromOpenId=' + app.globalData.openID + '&FromUserId=' + app.globalData.FromUserId,
|
// success: function (res) {
|
// // 转发成功
|
// console.log("转发成功:" + JSON.stringify(res));
|
// // utils.showModal(res)
|
// },
|
// fail: function (res) {
|
// // 转发失败
|
// console.log("转发失败:" + JSON.stringify(res));
|
// }
|
// }
|
|
// }
|
|
|
}))
|