|
|
@@ -54,9 +54,15 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
-
|
|
|
+ console.log('onload');
|
|
|
this.getRecommended()
|
|
|
- this.get_neighborShop()
|
|
|
+ // this.get_neighborShop()
|
|
|
+ this.setData({
|
|
|
+ shopId:wx.getStorageSync('shopInfo').shopId
|
|
|
+ })
|
|
|
+ this.resetData()
|
|
|
+ this.get_categoryInfo(wx.getStorageSync('shopInfo').shopId)
|
|
|
+ this.getCarData(wx.getStorageSync('shopInfo').shopId)
|
|
|
// this.get_categoryInfo()
|
|
|
},
|
|
|
scroll(){
|
|
|
@@ -123,6 +129,7 @@ Page({
|
|
|
},
|
|
|
resetData(){
|
|
|
this.setData({
|
|
|
+ productList:[],
|
|
|
subIndex:0,
|
|
|
thridIndex:-1,
|
|
|
subCategoryId:0,
|
|
|
@@ -185,58 +192,7 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- // 获取点击位置和购物车位置
|
|
|
- getNodePositions(index) {
|
|
|
- const query = wx.createSelectorQuery().in(this);
|
|
|
-
|
|
|
- // 1. 获取"加入购物车"按钮的位置(动画起始点)
|
|
|
- query.select(`.product-item:nth-child(${index + 1}) .info .price-box .test`).boundingClientRect(btnRect => {
|
|
|
- if (!btnRect) return; // 容错:防止节点未找到
|
|
|
- const startX = btnRect.left + btnRect.width / 2 - 20; // 20 = 40rpx/2(图标宽高)
|
|
|
- const startY = btnRect.top + btnRect.height / 2 - 20;
|
|
|
-
|
|
|
- // 2. 获取购物车位置(动画结束点)
|
|
|
- query.select('.bottom-box .left .icon').boundingClientRect(cartRect => {
|
|
|
- if (!cartRect) return;
|
|
|
- const endX = cartRect.left + cartRect.width / 2 - 20;
|
|
|
- const endY = cartRect.top + cartRect.height / 2 - 20;
|
|
|
-
|
|
|
- // 3. 计算抛物线中间点(控制弧度)
|
|
|
- const midX = (startX + endX) / 2;
|
|
|
- const midY = startY - 80; // 向上凸起80px,可调整弧度
|
|
|
-
|
|
|
- // 4. 创建动画图标
|
|
|
- this.createAnimationIcon(startX, startY, midX, midY, endX, endY);
|
|
|
- }).exec();
|
|
|
- }).exec();
|
|
|
- },
|
|
|
-
|
|
|
- // 创建抛物线动画(数据驱动,无DOM操作)
|
|
|
- createAnimationIcon(startX, startY, midX, midY, endX, endY) {
|
|
|
- // 生成唯一ID,避免key冲突
|
|
|
- const iconId = Date.now() + Math.floor(Math.random() * 1000);
|
|
|
- const newIcon = {
|
|
|
- id: iconId,
|
|
|
- startX,
|
|
|
- startY,
|
|
|
- midX,
|
|
|
- midY,
|
|
|
- endX,
|
|
|
- endY
|
|
|
- };
|
|
|
-
|
|
|
- // 添加动画图标到数组(自动渲染)
|
|
|
- this.setData({
|
|
|
- animationIcons: [...this.data.animationIcons, newIcon]
|
|
|
- });
|
|
|
-
|
|
|
- // 动画结束后移除图标+更新购物车
|
|
|
- setTimeout(() => {
|
|
|
- this.setData({
|
|
|
- animationIcons: this.data.animationIcons.filter(icon => icon.id !== iconId),
|
|
|
- });
|
|
|
- }, 700); // 与动画时长保持一致(0.7s)
|
|
|
- },
|
|
|
+
|
|
|
|
|
|
handleAll(){
|
|
|
this.setData({
|
|
|
@@ -289,7 +245,7 @@ Page({
|
|
|
let that = this
|
|
|
//加载分类列表
|
|
|
var params = {
|
|
|
- // url: "/category/categoryInfo",
|
|
|
+ // url: "/category/categoryInfo",
|
|
|
// url: "/category/listCategoryForUser/"+(this.data.testShopId||shopid),
|
|
|
url: "/category/listCategoryForUser",
|
|
|
method: "GET",
|
|
|
@@ -376,24 +332,23 @@ Page({
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
console.log('show');
|
|
|
- if(this.data.shopId){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 每次重新加载
|
|
|
+ if(this.data.shopId != wx.getStorageSync('shopInfo').shopId){
|
|
|
+ console.log('店铺切换了 刷新');
|
|
|
+ this.setData({
|
|
|
+ shopId:wx.getStorageSync('shopInfo').shopId
|
|
|
+ })
|
|
|
+ this.resetData()
|
|
|
+ this.get_categoryInfo(wx.getStorageSync('shopInfo').shopId)
|
|
|
+ this.getCarData(wx.getStorageSync('shopInfo').shopId)
|
|
|
+ // this.get_neighborShop()
|
|
|
+ }else if(this.data.shopId){
|
|
|
this.getCarData(this.data.shopId)
|
|
|
}
|
|
|
- // if (getApp().globalData.categoryId) {
|
|
|
- // let categoryId = getApp().globalData.categoryId
|
|
|
- // let index = getApp().globalData.index
|
|
|
- // let pic = getApp().globalData.pic
|
|
|
-
|
|
|
- // this.setData({
|
|
|
- // categoryImg: pic,
|
|
|
- // selIndex: index
|
|
|
- // });
|
|
|
- // }else{
|
|
|
- // this.get_neighborShop()
|
|
|
- // }
|
|
|
- // 之前逻辑 每次重新加载
|
|
|
- // this.resetData()
|
|
|
- // this.get_neighborShop()
|
|
|
|
|
|
},
|
|
|
|
|
|
@@ -737,7 +692,6 @@ Page({
|
|
|
toProdPage: function (e) {
|
|
|
var prodid = e.currentTarget.dataset.prodid;
|
|
|
var shopid = e.currentTarget.dataset.shopid;
|
|
|
- console.log(22222222,e);
|
|
|
if (prodid) {
|
|
|
wx.navigateTo({
|
|
|
url: `/pages/prod/prod?prodid=${prodid}&shopid=${shopid}`,
|