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.
 

242 lines
6.0 KiB

// pages/user/likes/index.js
import commonApi from "../../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
type:2,
list:[],
total:1
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getList();
},
touchStart(e){//移动前点击的位置
// 在开始触摸时将所有startTouchMove设置为flase,对当前的为true
this.data.list.forEach(cart =>{
if(cart.isTouchMove)//当istouchMove为true
cart.isTouchMove = false;//其它的对象都为false
})
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
list: this.data.list
})
},
touchmove(e){//移动的位置,用于计算用户滑动的弧度向左还是向右,移动了多少,可以确定删除功能的显示和隐藏
let index = e.currentTarget.dataset.index;
// 获取开始的x,y坐标
let startX = this.data.startX,
startY = this.data.startY;
// 获取移动的x,x坐标
let touchMoveX = e.changedTouches[0].clientX,
touchMoveY = e.changedTouches[0].clientY;
// 调用计算角度的方法,获取角度
var angel = this.angel({ X: startX, Y: startY }, { X: touchMoveX, Y: touchMoveY })
// 遍历cartArray
this.data.list.forEach((cart, i ) =>{
cart.isTouchMove = false;
// 滑动角度大于30,直接return 视为非滑动意思
if(Math.abs(angel) > 30) return;
// 匹配当前所点击的list和滑动的list
if(i == index){
// 匹配上后判断滑动方向
if (touchMoveX > startX){//左滑动隐藏删除
cart.isTouchMove = false;
}else{
cart.isTouchMove = true;
}
}
})
// 更新数据
this.setData({
list:this.data.list
})
},
angel(start,end){//计算滑动的角度
// console.log(start,end)
// 移动坐标减去对应的开始坐标
var _X = end.X - start.X,
_Y = end.Y - start.Y;
// 返回角度 Math.atan() 返回数字的正切值
return 360 * Math.atan(_Y / _X) / (2 * Math.PI)
},
del1:function(e){
let index = e.currentTarget.dataset.index,list = this.data.list;
commonApi.user_post("product/product_cancel_collection",{
product_id:list[index].product_id
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '删除成功',
icon:"success"
})
list.splice(index,1);
this.setData({
list:list
})
}
})
},
del2:function(e){
let index = e.currentTarget.dataset.index,list = this.data.list;
commonApi.user_post("scene/scene_cancel_collection",{
scene_id:list[index].scene_id
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '删除成功',
icon:"success"
})
list.splice(index,1);
this.setData({
list:list
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
changeType:function(e){
this.setData({
type:e.currentTarget.dataset.type,
list:[],
total:1
})
this.getList();
},
getList:function(){
let service = "scene/scene_collection_list",list = this.data.list;
if(list.length>=this.data.total) return;
if(this.data.type==1){
service = "product/get_product_collection_list"
}
commonApi.user_post(service,{
limit:10,
offset:list.length
}).then(res=>{
this.setData({
list:list.concat(res.data.list),
total:res.data.total
})
})
},
gotoDetail:function(e){
let item = e.currentTarget.dataset.item;
console.log(item)
let type = item.product?item.product.type:item.scene.type
if (item.product && item.product.is_package==1) {
wx.navigateTo({
url: '/pages/info/postProductInfo/index?id='+item.product.id
});
return
}
if (item.product &&item.product.is_package==2) {
wx.navigateTo({
url: '/subPackages/goods/oneCardTour/info/index?id='+item.scene_id
});
return
}
switch(type){
case "ticket":
wx.navigateTo({
url: '/pages/info/sceneProductInfo/index?id='+item.product.scene_id
});
break;
case "scenic":
wx.navigateTo({
url: '/pages/info/sceneProductInfo/index?id='+item.scene.id
});
break;
case "food":
wx.navigateTo({
url: '/pages/info/foodProductInfo/index?id='+item.product.id
});
break;
case "room":
wx.navigateTo({
url: '/pages/info/hotelProductInfo/index?id='+item.scene.id
});
break;
case "hotel":
wx.navigateTo({
url: '/pages/info/hotelProductInfo/index?id='+(item.product.scene_id || item.scene.id)
});
break;
case "line":
wx.navigateTo({
url: '/pages/info/roadInfo/index?id='+item.product.id
});
break;
case "venue":
wx.navigateTo({
url: '/pages/info/museumInfo/index?id='+(item.product.scene_id || item.scene.id)
});
break;
case "show":
wx.navigateTo({
url: '/pages/info/showInfo/index?id='+item.product.id
});
break;
case "post":
wx.navigateTo({
url: '/pages/info/postProductInfo/index?id='+item.product.id
});
break;
case "coupon":
wx.navigateTo({
url: '/pages/info/cardInfo/index?id='+item.product.id
});
break;
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getList();
}
})