You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
6.3 KiB

5 years ago
// pages/info/roadInfo/index.js
let device = wx.getSystemInfoSync();
const ratio = device.windowWidth / 750;
import commonApi from "../../../utils/https/common"
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
fixed:false,
type:1,
top:0,
isLike:0,
commentTotal:0,
comment:[],
info:null,
skuFlag:null,
producNum:1,
5 years ago
skuIndex:0,
retailId:""
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let rect = wx.getMenuButtonBoundingClientRect();
let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight;
console.log(height)
this.setData({
top:height,
id:options.id
})
5 years ago
if(options.retailId){
this.setData({
retailId:options.retailId
})
}
5 years ago
commonApi._post("product/get_product_detail",{
id:options.id
}).then(res=>{
5 years ago
res.data.display_tags = (res.data.display_tags?res.data.display_tags.split(","):[]).splice(0,2);
if(options.skuid){
let sku = res.data.sku.find(item=>item.id==options.skuid);
res.data.sku = [sku];
}
5 years ago
this.setData({
info:res.data
})
5 years ago
this.BroswerRecord()
5 years ago
})
if(wx.getStorageSync("jstrip_token")){
commonApi.user_post("product/is_product_collection",{
product_id:options.id
}).then(res=>{
this.setData({
isLike:res.data
})
})
}
// 获取评价列表
commonApi._post("product/product_comment_list",{
product_id:options.id
}).then(res=>{
res.data.list.map(item=>{
item.rate = Number(item.rate)
})
this.setData({
comment:res.data.list,
commentTotal:res.data.total
})
})
},
5 years ago
BroswerRecord:function(){
setTimeout(()=>{
if(app.globalData.uuid){
commonApi._post('browse/browse_record',{
type:"goods",
title:this.data.info.title,
drive:"mini",
source_id:this.data.info.id,
url:"/pages/info/postProductInfo/index?id="+this.data.info.id,
uuid:app.globalData.uuid
}).then(res=>{
})
}
else {
this.BroswerRecord();
}
},500)
},
5 years ago
like:function(){
let id = this.data.id,isLike = this.data.isLike;
commonApi.user_post("product/"+(isLike==1?"product_cancel_collection":"product_collection"),{
product_id:id
}).then(res=>{
if(res.code==1){
this.setData({
isLike:isLike==1?0:1
})
}
})
},
changeMenu:function(e){
let index = e.currentTarget.dataset.index,that = this;
const query=wx.createSelectorQuery(); //创建节点查询器
query.select("#box"+index).boundingClientRect() //选择toViewid获取位置信息
query.selectViewport().scrollOffset() //获取页面查询位置的
query.exec(function(res) {
let scrollTop = res[0].top + res[1].scrollTop - 110 * ratio - that.data.top;
wx.pageScrollTo({
scrollTop: scrollTop + 4,
duration: 0
})
that.setData({
type:index
})
})
},
onPageScroll:function(e){
let that = this,height = this.data.top;
let topHeight = height;
wx.createSelectorQuery().select('#menus').boundingClientRect(function(rect){
console.log(rect.top,topHeight)
if(rect.top<=topHeight){
// 此时应该把menus固定在顶部
that.setData({
fixed:true
})
}
else{
that.setData({
fixed:false
})
}
// 滚动时判断滚动到哪个部分了
const query=wx.createSelectorQuery(); //创建节点查询器
query.select("#box1").boundingClientRect() //选择toViewid获取位置信息
query.select("#box2").boundingClientRect() //选择toViewid获取位置信息
query.select("#box3").boundingClientRect() //选择toViewid获取位置信息
let minHeight = that.data.fixed?(110 * ratio + height): topHeight;
query.exec(function(res) {
if(res[2].top<minHeight){
that.setData({
type:3
})
}
else if(res[1].top<minHeight){
that.setData({
type:2
})
}
else {
that.setData({
type:1
})
}
})
}).exec()
},
showCart:function(){
this.setData({
skuFlag:"cart"
})
},
hideSku:function(){
this.setData({
skuFlag:null
})
},
minus:function(){
if(this.data.producNum==1) return;
this.setData({
producNum:this.data.producNum-1
})
},
add:function(){
this.setData({
producNum:this.data.producNum+1
})
},
selectSku:function(e){
let index = e.currentTarget.dataset.index;
this.setData({
skuIndex:index
})
},
showOrder:function(){
this.setData({
skuFlag:'order'
})
},
order:function(){
if(this.data.skuFlag=='order'){
app.globalData.couponInfo = null;
// 购买
let product = [{
product:this.data.info,
sku:this.data.info.sku[this.data.skuIndex],
productNum:this.data.producNum
}];
app.globalData.postProduct = product;
5 years ago
app.globalData.retailId = this.data.retailId;
5 years ago
wx.navigateTo({
url: '/pages/order/postOrder/index',
})
}
else {
commonApi.user_post("cart/add_sku",{
sku_id:this.data.info.sku[this.data.skuIndex].id,
num:this.data.producNum
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '加入购物车成功',
icon:"success"
});
this.setData({
skuFlag:null
})
}
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})