浏览代码

分类功能上线

wenjie 10 小时之前
父节点
当前提交
23a2cf064c

+ 387 - 83
pages/category/category.js

@@ -3,36 +3,130 @@
 var http = require("../../utils/http.js");
 var util = require('../../utils/util.js');
 var config = require("../../utils/config.js");
-
+import eventBus from '../../utils/eventBus';
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
+    rightView:'',
+    paramsObj:{
+      sort:0,
+      orderBy:0
+    },
+    type:'bottom',
+    toViewId:'test1',
+    topHeight:300,
+    sort:0,
+    imgUrl:'https://zswl-shop.oss-cn-chengdu.aliyuncs.com/',
+    testShopId:0,//109
+    totalInfo:{"totalMoney":0,"finalMoney":0,"subtractMoney":0.0,"count":0},
+    shopId:0,
     show:false,
-    showCar:true,
+    showCar:false,
     selIndex: 0,
+    selCategory:0,
     subIndex:0,
+    thridIndex:-1,
+    subCategoryId:0,
     categoryList: [],
     categoryImg: '',
     subCategoryList: [],
+    thridCategoryList:[],
     pageTopHeight: wx.getWindowInfo().statusBarHeight,
     hotList: [],
     topCurrentIndex: 0,
+    productList:[],
+    carData:[],//购物车数据
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    
     this.getRecommended()
-    this.get_neighborShop()
+    // this.get_neighborShop()
     // this.get_categoryInfo()
   },
+  scroll(){
+  },
+  scrollTop(){
+    console.log('top',);
+    if(this.data.subIndex==0||this.data.subCategoryList.length==0) return
+    this.setData({
+      type:'top'
+    })
+    let data = {currentTarget:{
+      dataset:{
+        index:this.data.subIndex-1
+      }
+    }}
+    this.onleftMenuTab(data)
+    // this.setData({
+    //   topHeight:0
+    // })
+  },
+  scrollBottom(){
+    console.log('bottom');
+    if(this.data.subIndex==(this.data.subCategoryList.length-1)||this.data.subCategoryList.length==0) return
+    this.setData({
+      type:'bottom'
+    })
+    let data = {currentTarget:{
+      dataset:{
+        index:this.data.subIndex+1
+      }
+    }}
+    this.onleftMenuTab(data)
+    // this.setData({
+    //   topHeight:0
+    // })
+  },
+  handleSale(){
+    this.setData({
+      sort:1,
+      paramsObj:{sort:1,orderBy:0}
+    })
+    this.getData(this.data.subCategoryList[this.data.subIndex])
+  },
+  handlePrice(){
+    // 没点击价格
+    if(this.data.sort !=2&&this.data.sort!=3){
+      this.setData({
+        sort:2,
+        paramsObj:{sort:2,orderBy:0}
+      })
+    }else{
+     let sort = this.data.sort ==2?3:2
+     this.setData({
+      sort,
+      paramsObj:{sort:2,orderBy:this.data.sort ==2?0:1}
+    })
+    }
+    this.getData(this.data.subCategoryList[this.data.subIndex])
+  },
+  resetData(){
+    this.setData({
+      subIndex:0,
+      thridIndex:-1,
+      subCategoryId:0,
+    })
+  },
   // 点击购物车内加减按钮
-  handleNum(){
-
+  handleNum(e){
+    let {num,item} = e.currentTarget.dataset
+    console.log(num,item);
+    let data = {
+      "basketId": item.basketId||0,
+      "count": num,
+      "distributionCardNo": item.distributionCardNo||'',
+      "prodId": item.prodId,
+      "shopId": item.shopId,
+      "skuId": item.skuId||item.skuList[0].skuId
+    }
+    this.changeCar(data)
   },
   handleAll(){
     this.setData({
@@ -44,6 +138,12 @@ Page({
       show:false
     })
   },
+  openCar(){
+    console.log(111111);
+    this.setData({
+      showCar:true
+    })
+  },
   onCarClose(){
     this.setData({
       showCar:false
@@ -53,7 +153,7 @@ Page({
    * 获取距离最近店铺id
    * @param {*} e 
    */
-  get_neighborShop: function () {
+   get_neighborShop: function () {
     var params = {
       url: "/shop/neighborShop",
       method: "GET",
@@ -63,44 +163,66 @@ Page({
       },
       callBack: (res) => {
         // this.get_categoryInfo(res)
+    console.log(99999999,res);
 
-        if(typeof res == 'number'){
-          this.get_categoryInfo(res)
-        }else{
+        this.setData({
+          shopId:res.shopId
+        })
           this.get_categoryInfo(res.shopId)
-        }
+          this.getCarData(this.data.shopId)
       }
     };
     http.request(params);
   },
   get_categoryInfo: function (shopid) {
     var ths = this;
+    let that = this
     //加载分类列表
     var params = {
-      url: "/category/categoryInfo",
+      // url: "/category/categoryInfo",
+      url: "/category/listCategoryForUser/"+(this.data.testShopId||shopid),
       method: "GET",
-      data: {
-        shopId:shopid
-      },
       callBack: function (res) {
-        let categoryName = ''
-        res.records.forEach(e => {
-          categoryName = e.categoryName.split('>')
-          e.categoryName = categoryName[0]
-        })
+
         ths.setData({
-          categoryList: res.records,
+          categoryList: res,
+          subCategoryList: res[ths.data.selIndex].children
         });
-        if (!getApp().globalData.categoryId) {
-          ths.getProdList(res.records[0].categoryId)
-          ths.setData({
-            categoryImg: res.records[0].pic,
+        eventBus.on('categoryId', (data) => {
+          that.data.categoryList.map((item,index)=>{
+              if(item.categoryId == data){
+                
+                that.setData({
+                  selCategory:data,
+                  selIndex:index,
+                  subCategoryList:res[index].children
+                })
+                eventBus.clear('categoryId')
+              }
           })
-        }
+        });
+        console.log(ths.data.subCategoryList);
+        ths.getData(ths.data.subCategoryList[0])
+   
       }
     };
     http.request(params);
   },
+  getData(data){
+      this.setData({
+        thridCategoryList:[]
+      })
+      // 二级分类有商品
+      if(data.productBeBound == 1){
+        this.getProdList(data.categoryId)
+      }else{//二级分类有三级分类
+        this.getAllProList(data.categoryId)
+        this.setData({
+          thridCategoryList:data.children,
+          subCategoryId:data.categoryId
+        })
+      }
+  },
  /**
    * 选择定位后更新列表
    */
@@ -118,18 +240,21 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-    if (getApp().globalData.categoryId) {
-      let categoryId = getApp().globalData.categoryId
-      let index = getApp().globalData.index
-      let pic = getApp().globalData.pic
-      this.getProdList(categoryId);
-      this.setData({
-        categoryImg: pic,
-        selIndex: index
-      });
-    }else{
+    this.resetData()
+    // 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.get_neighborShop()
-    }
+
   },
 
   /**
@@ -171,13 +296,19 @@ Page({
   onMenuTab: function (e) {
     var id = e.currentTarget.dataset.id;
     var index = e.currentTarget.dataset.index;
-    // this.getProdList(id);
-    this.getProdList(this.data.categoryList[index].categoryId);
     this.setData({
       categoryImg: this.data.categoryList[index].pic,
+      subCategoryList:this.data.categoryList[index].children,
       selIndex: index,
-      subIndex:0
+      selCategory:id,
+      productList:[],
+      subIndex:0,
+      paramsObj:{sort:0,orderBy:0},
+      sort:0
+
     });
+    // this.getProdList(this.data.subCategoryList[0].categoryId)
+    this.getData(this.data.subCategoryList[0])
     getApp().globalData.categoryId = ''
     getApp().globalData.index = ''
     getApp().globalData.pic = ''
@@ -214,78 +345,251 @@ Page({
   topHotSearch: function () {
     const topname = this.data.hotList[this.data.topCurrentIndex].name
     wx.navigateTo({
-      url: '/pages/search-prod-show/search-prod-show?prodName=' + topname,
+      url: `/pages/search-prod-show/search-prod-show?prodName=${topname}&shopId=${this.data.shopId}`,
     })
   },
 
   // 跳转搜索页
   toSearchPage: function () {
     wx.navigateTo({
-      url: '/pages/search-page/search-page',
+      url: `/pages/search-page/search-page?shopId=${this.data.shopId}`,
     })
   },
-  getProdList(categoryId) {
+  /**
+   * 跳转到定位页面
+   */
+  toLocationPage: function () {
+    wx.navigateTo({
+      url: '/pages/locationAdd/locationAdd',
+    })
+  },
+  // 点击二级分类
+  onleftMenuTab(e){
+    const {
+      index,
+      id
+    } = e.currentTarget.dataset
+    if(id){
+      this.setData({
+        type:'click'
+      })
+      console.log('click');
+    }
     this.setData({
-      parentId: categoryId
+      subIndex:index,
+      paramsObj:{sort:0,orderBy:0},
+      sort:0
     })
-    //加载子分类列表
+    // this.getProdList(this.data.subCategoryList[index].categoryId)
+    this.getData(this.data.subCategoryList[index])
+
+  },
+
+  // 根据分类id获取商品数据
+  getProdList(categoryId) {
     var params = {
-      url: "/category/categoryInfo",
+      url: "/search/searchProdPage",
       method: "GET",
       data: {
-        parentId: categoryId
+        categoryId,
+        current: 1,
+        size: 999999,
+        orderBy:this.data.paramsObj.orderBy,
+        sort:this.data.paramsObj.sort,
+        isAllProdType: true,
+        // lat: wx.getStorageSync('LATITUDE'),
+        // lon: wx.getStorageSync('LONGITUDE'),
+        // distance: wx.getStorageSync('DISTANCE') || 0
       },
       callBack: (res) => {
-        let str='https://zswl-shop.oss-cn-chengdu.aliyuncs.com'
-        res.records.forEach(item=>{
-          item.categories.forEach(e=>{
-            if(e.pic!=null){
-              if(!e.pic.includes(str)){
-                e.pic='https://zswl-shop.oss-cn-chengdu.aliyuncs.com/'+e.pic
-              }
-            }
-          })
-        })
+      console.log(res);
+      let productList = res.records
+      let img = ''
+      productList.map(e => {
+        img = e.pic.split(',')
+        e.pic = img[0]
+      })
         this.setData({
-          subCategoryList: res.records,
-        });
+          productList,
+          topHeight:15
+        })
+        if(productList.length == 0){
+          if(this.data.type == 'top'){
+            this.scrollTop()
+          }else{
+            this.scrollBottom()
+          }
+        }
+        this.addParmasProduct()
       }
     };
     http.request(params);
   },
-  /**
-   * 跳转到定位页面
-   */
-  toLocationPage: function () {
-    wx.navigateTo({
-      url: '/pages/locationAdd/locationAdd',
-    })
+  // 根据分类id获取所有三级商品数据
+  getAllProList(categoryId) {
+    var params = {
+      url: "/prod/listProdByCategoryIdAndShopId",
+      method: "post",
+      data: {
+        orderBy:this.data.paramsObj.orderBy,
+        sort:this.data.paramsObj.sort,
+        categoryId,
+        current: 1,
+        size: 999999,
+        shopId:this.data.testShopId||this.data.shopId
+      },
+      callBack: (res) => {
+      let productList = res.records
+      let img = ''
+      productList.map(e => {
+        img = e.pic.split(',')
+        e.pic = img[0]
+      })
+        this.setData({
+          productList,
+          topHeight:15
+        })
+        if(productList.length == 0){
+          if(this.data.type == 'top'){
+            this.scrollTop()
+          }else if(this.data.type == 'bottom'){
+            this.scrollBottom()
+          }
+        }
+        this.addParmasProduct()
+
+      }
+    };
+    http.request(params);
   },
-  // 点击二级分类
-  onleftMenuTab(e){
-    const {
-      index
+  // 点击三级分类
+  handleThrid(e){
+    let {
+      index,
+      categoryid
     } = e.currentTarget.dataset
+    console.log(33333333333,e.currentTarget.dataset);
     this.setData({
-      subIndex:index
+      thridIndex:index
     })
+    if(index == -1){
+      categoryid = this.data.subCategoryId
+    }
+    this.getAllProList(categoryid)
   },
-  // 跳转子分类商品页面
-  toCatePage: function (e) {
-    console.log(e);
-    const {
-      type,
-      parentid,
-      categoryid,
-      subcateindex
-    } = e.currentTarget.dataset
-    wx.navigateTo({
-      url: `/pages/sub-category/sub-category?parentId=${parentid}&categoryId=${type=='all'?this.data.subCategoryList[subcateindex].categoryId:categoryid}`,
+  // 除了产品列表数据 给产品列表添加显示和数量  同步购物车数据
+  addParmasProduct(){
+    if(this.data.productList.length >0){
+      let productList = JSON.parse(JSON.stringify( this.data.productList))
+      productList.map(i=>{
+        i.show = false
+        this.data.carData.map(item=>{
+          if(item.prodId == i.prodId){
+            i.prodCount = item.prodCount
+            i.show = true
+          }
+        })
+      })
+      this.setData({
+        productList
+      })
+    }
+  },
+  // 获取购物车数据
+  getCarData() {
+    var params = {
+      url: "/p/shopCart/info",
+      method: "post",
+      data: [{
+        "basketId": 0,
+        "discountId": 0,
+        "shopId":this.data.testShopId||this.data.shopId
+      }],
+      callBack: (res) => {
+        if(res.length){
+          let carData = res[0].shopCartItemDiscounts[0].shopCartItems
+          let img = ''
+          carData.map(e => {
+            img = e.pic.split(',')
+            e.pic = img[0]
+          })
+          this.setData({
+            carData
+          },()=>{
+           
+            this.getCarTotal()
+          })
+          
+
+
+      }else{
+        this.setData({
+          carData:[]
+        },()=>{
+          this.getCarTotal()
+        })
+      }
+      // 给产品列表添加显示和数量  同步购物车数据
+      this.addParmasProduct()
+      }
+    };
+    http.request(params);
+  },
+
+  // 获取购物车数量和总价
+  getCarTotal() {
+    let basketIds = this.data.carData.map(item=>{
+      return  item.basketId
+       
     })
+    var params = {
+      url: "/p/shopCart/totalPay?t="+new Date().getTime(),
+      method: "post",
+      data: basketIds,
+      callBack: (res) => {
+       this.setData({
+         totalInfo:res
+       })
+      }
+    };
+    http.request(params);
+  },
+  // 添加修改购物车数量
+  changeCar(data) {
+    var params = {
+      url: "/p/shopCart/changeItem?t="+new Date().getTime(),
+      method: "post",
+      data,
+      callBack: (res) => {
+        this.getCarData()
+      }
+    };
+    http.request(params);
+  },
+   /**
+   * 跳转到商品详情页
+   */
+  toProdPage: function (e) {
+    var prodid = e.currentTarget.dataset.prodid;
+    console.log(22222222,e);
+    if (prodid) {
+      wx.navigateTo({
+        url: '/pages/prod/prod?prodid=' + prodid,
+      })
+    }
   },
-  toCategoryPage: function () {
+
+  handleBuy(){
+    if(this.data.carData.length == 0){
+      return 
+    }
+    let basketIds = this.data.carData.map(item=>{
+      return item.basketId
+    })
+    wx.setStorageSync("basketIds", JSON.stringify(basketIds));
     wx.navigateTo({
-      url: `/pages/sub-category/sub-category?categoryId=${this.data.parentId}`,
+      url: '/pages/submit-order/submit-order?orderEntry=0',
     })
   }
+
 })

+ 2 - 1
pages/category/category.json

@@ -1,5 +1,6 @@
 {
   "backgroundTextStyle": "light",
   "navigationBarTitleText": "分类商品",
-  "navigationStyle":"custom"
+  "navigationStyle":"custom",
+  "disableScroll": true
 }

+ 108 - 85
pages/category/category.wxml

@@ -12,48 +12,53 @@
   </navbar>
 
   <!-- 全部分类弹窗 -->
-  <van-popup show="{{ show }}"  position="top" close-on-click-overlay="{{false}}" z-index="{{99999}}" round bind:close="onClose">
-    <view style="padding-top: {{pageTopHeight}}px;">
-    <!-- 搜索 -->
-        <navbar>
-          <view class="top-search-input">
-            <swiper vertical="true" circular="true" autoplay="true" interval="3000" class="top-search-swiper" bindtap="toSearchPage" bindchange="topSwiperChange">
-              <swiper-item wx:for="{{hotList}}" wx:key="index">{{item.name}}</swiper-item>
-            </swiper>
-            <view class="top-search-line">|</view>
-            <view class="top-search-text" bindtap="topHotSearch">搜索</view>
-          </view>
+  <van-popup show="{{ show }}" position="top" close-on-click-overlay="{{false}}" z-index="{{99999}}" round bind:close="onClose">
+    <view class="popup-box" style="padding-top: {{pageTopHeight}}px;">
+      <!-- 搜索 -->
+      <navbar>
+        <view class="top-search-input">
+          <swiper vertical="true" circular="true" autoplay="true" interval="3000" class="top-search-swiper" bindtap="toSearchPage" bindchange="topSwiperChange">
+            <swiper-item wx:for="{{hotList}}" wx:key="index">{{item.name}}</swiper-item>
+          </swiper>
+          <view class="top-search-line">|</view>
+          <view class="top-search-text" bindtap="topHotSearch">搜索</view>
+        </view>
       </navbar>
       <!-- 分类 -->
       <view class="top-box top-all-box">
-        <view wx:for='{{categoryList}}' class="type-item" wx:key='categoryId'>
-          <view class="icon"></view>
-          <view class='name {{selIndex==index?"active":""}} ' data-index="{{index}}" data-id="{{item.categoryId}}" bindtap='onMenuTab'>
+        <view wx:for='{{categoryList}}' class="type-item" wx:key='categoryId' data-index="{{index}}" data-id="{{item.categoryId}}" bindtap='onMenuTab'>
+          <!-- <view class="icon"></view> -->
+          <image class="icon" src="{{imgUrl+item.icon}}" mode="" />
+          <view class='name {{selIndex==index?"active":""}} '>
             {{item.categoryName}}
           </view>
         </view>
+        <view wx:if="{{5-(categoryList.length%5) >0}}" style="width: 100rpx;height: 100rpx;"></view>
+        <view wx:if="{{5-(categoryList.length%5) >1}}" style="width: 100rpx;height: 100rpx;"></view>
+        <view wx:if="{{5-(categoryList.length%5) >2}}" style="width: 100rpx;height: 100rpx;"></view>
+        <view wx:if="{{5-(categoryList.length%5) >3}}" style="width: 100rpx;height: 100rpx;"></view>
       </view>
 
       <view class="close-box" bind:tap="onClose">
-          点击收起
-          <image class="icon" src="../../images/icon/more-icon.png" mode=""/>
+        点击收起
+        <image class="icon" src="../../images/icon/more-icon.png" mode="" />
       </view>
     </view>
   </van-popup>
 
-<!-- 顶部滚动分类 -->
+  <!-- 顶部滚动分类 -->
   <view class="top-content">
-    <scroll-view scroll-x="true"  class='top-box'>
-      <view wx:for='{{categoryList}}' class="type-item" wx:key='categoryId'>
-        <view class="icon"></view>
-        <view class='name {{selIndex==index?"active":""}} ' data-index="{{index}}" data-id="{{item.categoryId}}" bindtap='onMenuTab'>
+    <scroll-view scroll-x="true" class='top-box' scroll-into-view="{{'item'+selCategory}}">
+      <view wx:for='{{categoryList}}' id="{{'item'+item.categoryId}}" class="type-item" wx:key='{{item.categoryId}}' data-index="{{index}}" data-id="{{item.categoryId}}" bindtap='onMenuTab'>
+        <image class="icon" src="{{imgUrl+item.icon}}" mode="" />
+        <view class='name {{selIndex==index?"active":""}} '>
           {{item.categoryName}}
         </view>
       </view>
     </scroll-view>
-      <view class="all" bind:tap="handleAll">全部
-        <image class="icon" src="../../images/icon/more-icon.png" mode=""/>
-      </view>
+    <view wx:if="{{categoryList.length}}" class="all" bind:tap="handleAll">全部
+      <image class="icon" src="../../images/icon/more-icon.png" mode="" />
+    </view>
   </view>
 
 
@@ -61,47 +66,54 @@
   <!-- 滚动内容区 -->
   <view class="main" wx:if="{{categoryList.length>0}}">
     <!-- 左侧菜单start -->
-    <scroll-view scroll-y="true" class='leftmenu'>
-      <block wx:for='{{categoryList}}' wx:key='categoryId'>
+    <scroll-view scroll-y="true" class='leftmenu'  scroll-into-view="{{'item'+subIndex}}">
+      <view wx:for='{{subCategoryList}}' id="{{'item'+index}}" wx:key='categoryId'>
         <view class='menu-item {{subIndex==index?"active":""}} ' data-index="{{index}}" data-id="{{item.categoryId}}" bindtap='onleftMenuTab'>
-          二级{{item.categoryName}}
+          {{item.categoryName}}
         </view>
-      </block>
+      </view>
+        <view style="height: 200rpx;"></view>
     </scroll-view>
     <!-- 左侧菜单end -->
 
     <!-- 右侧内容start -->
-    <scroll-view scroll-y="true" class='rightcontent' scroll-into-view="{{toViewId}}">
-      <!-- <view class='adver-map'>
-        <view class='item-a'>
-          <image src='{{categoryImg}}'></image>
+    <scroll-view scroll-y="true" class='rightcontent' 	enable-passive scroll-into-view="{{rightView}}"	upper-threshold="10" 	lower-threshold="10"  scroll-top="{{topHeight}}" bindscroll="scroll"bindscrolltoupper="scrollTop" bindscrolltolower="scrollBottom">
+      <!-- <text wx:if="{{subCategoryList.length>0}}" class="sub-title" >{{subCategoryList[subIndex].categoryName}}</text> -->
+      <view class="right-top-box">
+        <view class="thrid-type-box" wx:if="{{thridCategoryList.length>0}}">
+          <view class='thrid-type-item {{thridIndex==-1?"active":""}}' data-index="-1" bind:tap="handleThrid">全部</view>
+          <view class='thrid-type-item {{thridIndex==index?"active":""}}' data-index="{{index}}" data-categoryId="{{item.categoryId}}" wx:for="{{thridCategoryList}}" bind:tap="handleThrid">{{item.categoryName}}</view>
         </view>
-      </view> -->
-      <block wx:if="{{subCategoryList.length>0}}">
-        <block wx:for="{{subCategoryList}}" wx:key='categoryId' wx:for-index='subCateIndex'>
-          <view class='sub-category'>
-            <view class="sub-category-con">
-              <view class="sub-cate-title">
-                <text class="sub-cate-text">{{item.categoryName}}</text>
-                <text class="view-all" bindtap="toCatePage" data-type="all" data-subcateindex="{{subCateIndex}}" data-parentid="{{item.parentId}}" data-categoryId="{{item.categoryId}}">查看全部</text>
-                <van-icon name="arrow" color="#999999" size="14" />
-              </view>
-              <view class="th-cate-con">
-                <block wx:for="{{item.categories}}" wx:key='categoryId' wx:for-item='thCateItem'>
-                  <view class='sub-category-item' bindtap='toCatePage' data-categoryid="{{thCateItem.categoryId}}" data-parentid="{{item.categoryId}}">
-                    <image src='{{thCateItem.pic}}' mode='widthFix' class="sub-category-item-pic"></image>
-                    <text>{{thCateItem.categoryName}}</text>
-                  </view>
-                </block>
+        <view class="filter-box">
+          <view class="filter-item {{sort == 1 ?'active':''}}" bind:tap="handleSale">销量</view>
+          <view class="filter-item" bind:tap="handlePrice">价格 
+            <view class="icon-box"> 
+              <van-icon class="down" size="20rpx" color="{{sort ==2? '#04358D':'#AAAAAA'}}" name="play" />
+              <van-icon class="up" size="20rpx" color="{{sort ==3? '#04358D':'#AAAAAA'}}" name="play" />
+            </view> 
+          </view>
+        </view>
+      </view>
+      <view class="right-box">
+        <view class="product-item" id="{{'test'+index}}" wx:for="{{productList}}">
+          <image class="pic" src="{{item.pic}}" mode="" data-prodId="{{item.prodId}}" bind:tap="toProdPage" />
+          <view class="info">
+            <view class="title" data-prodId="{{item.prodId}}" bind:tap="toProdPage">{{item.prodName}}</view>
+              <view class="salesVolume">已售{{item.salesVolume||0}}</view>
+            <view class="price-box">
+              <view class="price">¥{{item.price}}</view>
+              <view wx:if="{{item.show}}" class="num-box">
+                <view class="btn" data-num="-1" data-item="{{item}}" bind:tap="handleNum">-</view>
+                <view class="num">{{item.prodCount}}</view>
+                <view class="btn" data-num="1" data-item="{{item}}" bind:tap="handleNum">+</view>
               </view>
+              <image wx:else style="width:52rpx;height:52rpx;" src="/images/icon/car-btn.png" mode="" data-num="1" data-item="{{item}}" bind:tap="handleNum" />
             </view>
           </view>
-        </block>
-      </block>
-      <view class="sub-cate-title not-category-data" wx:else>
-        <view class="sub-cate-text">无二级分类</view>
-        <view class="view-all" bindtap="toCategoryPage">查看全部
-          <van-icon name="arrow" color="#999999" size="14" />
+        </view>
+        <view id="empty" class="block" style="height: 90vh;"></view>
+        <view class="sub-cate-title not-category-data" wx:if="{{subCategoryList.length==0}}">
+          <view class="sub-cate-text">无二级分类</view>
         </view>
       </view>
     </scroll-view>
@@ -113,45 +125,56 @@
   </view>
 
   <!-- 购物车弹窗 -->
-  <van-popup show="{{ showCar }}"  position="bottom" safe-area-inset-bottom="{{false}}" close-on-click-overlay="{{true}}" z-index="{{99999}}" round bind:close="onCarClose">
-  <view class="car-box">
-    <view class="item">
-    <view class="img"></view>
-    <view class="info">
-      <view class="title">1000g~1500g | 阳光玫瑰葡萄</view>
-      <view class="desc">规格:500ml+冰袋</view>
-      <view class="price-box">
-        <view class="price">
-          <view class="unit">¥</view>
-          <view class="num">13.95</view>
+  <van-popup show="{{ showCar }}" position="bottom" safe-area-inset-bottom="{{false}}" close-on-click-overlay="{{true}}" z-index="{{99999}}" round bind:close="onCarClose">
+    <view class="car-box">
+      <view wx:if="{{carData.length}}">
+        <view class="item" wx:for="{{carData}}">
+          <image class="img" src="{{item.pic}}" mode="" />
+          <view class="info">
+            <view class="title">{{item.prodName}}</view>
+            <view class="desc">规格:{{item.weight}}{{item.weightUnit}}</view>
+            <view class="price-box">
+              <view class="price">
+                <view class="unit">¥</view>
+                <view class="num">{{item.price}}</view>
+              </view>
+              <view class="num-box">
+                <view class="btn" data-num="-1" data-item="{{item}}" bind:tap="handleNum">-</view>
+                <view class="num">{{item.prodCount}}</view>
+                <view class="btn" data-num="1" data-item="{{item}}" bind:tap="handleNum">+</view>
+              </view>
+
+            </view>
+          </view>
         </view>
-        <view class="num-box">
-          <view class="btn" data-num="-1" bind:tap="handleNum">-</view>
-          <view class="num">1</view>
-          <view class="btn" data-num="1" bind:tap="handleNum">+</view>
+      </view>
+      <!-- 空 -->
+      <view class="empty" wx:else="{{!carData.length}}">
+        <view class="empty-icon">
+          <image src="../../images/icon/empty-basket.png"></image>
         </view>
-
+        <view class="empty-text">您还没有添加商品到购物车哦~</view>
       </view>
     </view>
-    </view>
+    
 
-  </view>
-    <view class="bottom-box">
-      <view class="left">
-        <image class="icon" src="../../images/icon/car-icon.png" mode=""/>
-        <view class="price-box">
-          <view class="top">
-            <view class="price">¥13.95</view>
-            <view class="reduce-price">共减¥5</view>
-          </view>
-          <view class="shipping-fee">配送费¥0</view>
+  </van-popup>
+
+  <view class="bottom-box">
+    <view class="left" bindtap="openCar">
+      <view class="num" wx:if="{{totalInfo.count}}">{{totalInfo.count}}</view>
+      <image class="icon" src="../../images/icon/car-icon.png" mode="" />
+      <view class="price-box">
+        <view class="top">
+          <view class="price">¥{{totalInfo.finalMoney}}</view>
+          <view class="reduce-price">共减¥{{totalInfo.subtractMoney}}</view>
         </view>
+        <view class="shipping-fee">配送费¥0</view>
       </view>
-
-      <view class="btn">去结算</view>
     </view>
 
-  </van-popup>
+    <view class="btn" bind:tap="handleBuy">去结算</view>
+  </view>
 
 </view>
 <wxs module="wxs" src="../../wxs/number.wxs" />

+ 186 - 10
pages/category/category.wxss

@@ -15,7 +15,7 @@ page {
   display: flex;
   overflow: hidden;
   /* margin-top: 78rpx; */
-  height: calc(100% - 100rpx);
+  height: calc(100% - 270rpx);
 }
 
 /* 搜索栏 */
@@ -96,7 +96,12 @@ color: #222222;
   display: flex;
   flex-wrap: wrap;
   justify-content: space-between;
-  padding: 0 32rpx;
+  align-items: flex-start;
+  padding: 0 32rpx 150rpx;
+  box-sizing: border-box;
+  max-height: 750rpx;
+  overflow-y: auto;
+  overflow-x: hidden;
 }
 
 .top-all-box .type-item{
@@ -110,8 +115,9 @@ margin-bottom: 24rpx;
 .top-box .type-item .icon{
   width: 100rpx;
   height: 100rpx;
-  background: red;
+  background: #F6F6F6;
   margin-left: 8rpx;
+  border-radius: 50%;
 
 }
 .top-box .type-item .name{
@@ -122,6 +128,9 @@ margin-bottom: 24rpx;
   line-height: 36rpx;
   text-align: center;
   margin-top: 12rpx;
+  white-space: nowrap;
+  text-overflow: ellipsis;
+  overflow: hidden;
 }
 
 .top-box .type-item .name.active{
@@ -130,14 +139,21 @@ margin-bottom: 24rpx;
 }
 
 
-
+.popup-box{
+  position: relative;
+}
  .close-box{
+   position: absolute;
+   bottom: 0;
+   left: 0;
+   z-index: 999;
   font-size: 24rpx;
   color: #AAAAAA;
   width: 100%;
   text-align: center;
   line-height: 82rpx;
   border-top: 1rpx solid #F0F0F0;
+  background: #fff;
 }
 
  .close-box .icon{
@@ -215,6 +231,124 @@ scroll-view ::-webkit-scrollbar {
   box-sizing: border-box;
   background-color: #fff;
   z-index: 1;
+  position: relative;
+}
+.rightcontent .right-top-box{
+  position: fixed;
+  z-index: 9999;
+  background-color: #fff;
+
+}
+
+.rightcontent .filter-box{
+  display: flex;
+  justify-content: flex-end;
+  width: 550rpx;
+}
+.rightcontent .filter-box .filter-item{
+  font-size: 24rpx;
+  color: #222222;
+  margin-left: 40rpx;
+  display: flex;
+}
+.rightcontent .filter-box .filter-item.active{
+  color: #04358D;
+}
+
+.rightcontent .filter-box .filter-item .icon-box{
+  display: flex;
+  flex-direction: column;
+}
+.rightcontent .filter-box .filter-item .icon-box .down{
+  transform: rotateZ(270deg);
+  margin-bottom: -6rpx;
+}
+
+.rightcontent .filter-box .filter-item .icon-box .up{
+  transform: rotateZ(90deg);
+  margin-left: 4rpx;
+}
+
+.rightcontent .thrid-type-box{
+  display: flex;
+  flex-wrap: nowrap;
+  
+  padding: 10rpx 20rpx 10rpx 0;
+  width: 530rpx;
+  overflow: auto;
+  margin-left: 20rpx;
+  background: #fff;
+}
+.rightcontent .thrid-type-box .thrid-type-item{
+  height: 36rpx;
+  line-height: 36rpx;
+  background: #F0F0F0;
+  padding: 2rpx 16rpx;
+  border-radius: 22rpx;
+  font-size: 24rpx;
+  color: #222222;
+  flex-shrink: 0;
+  margin-right: 20rpx;
+}
+
+.rightcontent .thrid-type-box .thrid-type-item.active{
+  background: #04358D;
+  color: #FFFFFF;
+}
+
+.rightcontent .right-box{
+  /* padding-bottom: 300rpx; */
+  /* padding-bottom: 500rpx; */
+  padding-top: 98rpx;
+
+}
+
+.rightcontent  .product-item{
+  display: flex;
+  padding: 0 20rpx;
+}
+
+.rightcontent  .product-item .pic{
+  width: 200rpx;
+  height: 200rpx;
+  background: #F6F6F6;
+  border-radius: 16rpx;
+  flex-shrink: 0;
+  margin: 20rpx 0;
+}
+.rightcontent  .product-item .info{
+  display: flex;
+  flex-direction: column;
+  justify-content: space-between;
+  border-bottom: 1rpx solid #F0F0F0;
+  padding: 20rpx 0 20rpx 20rpx;
+}
+
+.rightcontent  .product-item .info .title{
+  font-weight: bold;
+  font-size: 28rpx;
+  color: #222222;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  display: -webkit-box;
+  -webkit-line-clamp: 2;  /* 限制显示的行数 */
+  -webkit-box-orient: vertical;
+}
+
+.rightcontent  .product-item .info .price-box{
+  display: flex;
+justify-content: space-between;
+align-items: center;
+}
+.rightcontent  .product-item .info .price{
+  font-weight: 800;
+  font-size: 28rpx;
+  color: #FF4D3A;
+}
+
+.rightcontent  .product-item .info  .salesVolume{
+  font-size: 22rpx;
+  color: #AAAAAA;
 }
 
 .rightcontent .adver-map {
@@ -303,14 +437,16 @@ scroll-view ::-webkit-scrollbar {
 /* 购物车 */
 
 .car-box{
-  padding: 28rpx 24rpx 0;
+  padding: 28rpx 24rpx 123rpx;
+  max-height: 700rpx;
+  overflow: auto;
 }
 
 .car-box .item{
   display: flex;
   align-items: center;
   padding-bottom: 30rpx;
-  border-bottom: 2rpx solid #F0F0F0;
+  /* border-bottom: 2rpx solid #F0F0F0; */
 }
 
 .car-box .item .img{
@@ -355,12 +491,14 @@ scroll-view ::-webkit-scrollbar {
   font-size: 48rpx;
 }
 
-.car-box .item .info .price-box .num-box{
+/* .car-box .item .info .price-box .num-box{ */
+ .num-box{
   display: flex;
   align-items: center;
 }
 
-.car-box .item .info .price-box .num-box .btn{
+/* .car-box .item .info .price-box .num-box .btn{ */
+ .num-box .btn{
   color: #AAAAAA;
   font-size: 20rpx;
   width: 40rpx;
@@ -370,8 +508,8 @@ scroll-view ::-webkit-scrollbar {
   background: #F0F0F0;
 
 }
-
-.car-box .item .info .price-box .num-box .num{
+/* .car-box .item .info .price-box .num-box .num{ */
+ .num-box .num{
   width: 80rpx;
   height: 40rpx;
   background: #F0F0F0;
@@ -383,6 +521,12 @@ scroll-view ::-webkit-scrollbar {
 }
 
 .bottom-box{
+  position: fixed;
+  bottom: 0;
+  left: 0;
+  z-index: 999999;
+  box-sizing: border-box;
+  width: 100%;
   display: flex;
   justify-content: space-between;
   padding: 20rpx 24rpx;
@@ -390,6 +534,16 @@ scroll-view ::-webkit-scrollbar {
   box-shadow: 0rpx -6rpx 12rpx 2rpx rgba(0,0,0,0.05);
   border-radius: 32rpx 32rpx 0rpx 0rpx;
 }
+.bottom-box .num{
+  position: absolute;
+  top: 20rpx;
+  left: 80rpx;
+  border-radius: 30rpx;
+  font-size: 24rpx;
+  color: #fff;
+  background: #FF4D3A;
+  padding: 2rpx 6rpx;
+}
 .bottom-box .left{
   display: flex;
   
@@ -430,3 +584,25 @@ scroll-view ::-webkit-scrollbar {
   font-size: 28rpx;
   color: #FFFFFF;
 }
+/* 购物车为空 */
+.empty {
+  margin-top: 100rpx;
+  text-align: cneter;
+}
+.empty-icon {
+  display: block;
+  width: 100rpx;
+  height: 100rpx;
+  margin: 0 auto; 
+  margin-bottom: 20rpx;
+}
+.empty-icon > image {
+  width: 100%;
+  height: 100%;
+}
+.empty-text {
+  font-size: 28rpx;
+  text-align: center;
+  color: #999;
+  line-height: 2em;
+}

+ 26 - 17
pages/index/index.js

@@ -5,6 +5,7 @@ var util = require('../../utils/util.js');
 var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
 var qqmapsdk;
 const updateManager = wx.getUpdateManager()
+import eventBus from '../../utils/eventBus';
 
 Page({
   isHand:false,
@@ -323,7 +324,9 @@ Page({
   topHotSearch: function () {
     const topname = this.data.hotList[this.data.topCurrentIndex].name
     wx.navigateTo({
-      url: '/pages/search-prod-show/search-prod-show?prodName=' + topname,
+      // url: '/pages/search-prod-show/search-prod-show?prodName=' + topname,
+      url: `/pages/search-prod-show/search-prod-show?prodName=${topname}&shopId=${this.data.shop_id}`,
+
     })
   },
   swiperChange: function (e) {
@@ -334,13 +337,15 @@ Page({
   inputSearch: function () {
     const currentName = this.data.hotList[this.data.currentIndex].name;
     wx.navigateTo({
-      url: '/pages/search-prod-show/search-prod-show?prodName=' + currentName,
+      // url: '/pages/search-prod-show/search-prod-show?prodName=' + currentName,
+      url: `/pages/search-prod-show/search-prod-show?prodName=${currentName}&shopId=${this.data.shop_id}`,
+
     })
   },
   recommendedSearch: function (e) {
     let name = e.currentTarget.dataset.name
     wx.navigateTo({
-      url: '/pages/search-prod-show/search-prod-show?prodName=' + name,
+      url: `/pages/search-prod-show/search-prod-show?prodName=${name}&shopId=${this.data.shop_id}`,
     })
   },
   /**
@@ -419,18 +424,22 @@ Page({
     let index = e.currentTarget.dataset.index + this.data.currentTop
     let pic = e.currentTarget.dataset.pic
     let categories = e.currentTarget.dataset.categories
-    if (categories == null || categories.length < 1) {
-      wx.navigateTo({
-        url: `/pages/sub-category/sub-category?categoryId=${categoryId}&shopId=${this.data.shop_id}`,
-      })
-    } else {
-      getApp().globalData.categoryId = categoryId
-      getApp().globalData.index = index
-      getApp().globalData.pic = pic
-      wx.switchTab({
-        url: '/pages/category/category'
-      })
-    }
+    // if (categories == null || categories.length < 1) {
+    //   wx.navigateTo({
+    //     url: `/pages/sub-category/sub-category?categoryId=${categoryId}&shopId=${this.data.shop_id}`,
+    //   })
+    // } else {
+    //   getApp().globalData.categoryId = categoryId
+    //   getApp().globalData.index = index
+    //   getApp().globalData.pic = pic
+    //   wx.switchTab({
+    //     url: '/pages/category/category'
+    //   })
+    // }
+    eventBus.emit('categoryId', categoryId);
+    wx.switchTab({
+      url: '/pages/category/category'
+    })
   },
 
   // 领红包
@@ -600,7 +609,6 @@ Page({
    * @param {*} e 
    */
   get_neighborShop: function () {
-    console.log('get_neighborShop');
     var params = {
       url: "/shop/neighborShop",
       method: "GET",
@@ -733,7 +741,8 @@ Page({
   // 跳转搜索页
   toSearchPage: function () {
     wx.navigateTo({
-      url: '/pages/search-page/search-page',
+      // url: '/pages/search-page/search-page',
+      url: `/pages/search-page/search-page?shopId=${this.data.shop_id}`,
     })
   },
 

+ 3 - 2
pages/index/index.wxml

@@ -57,7 +57,8 @@
   </view>
 
   <!-- 板块 -->
-  <view class="swiper-grid-box" wx:if="{{categoryList1.length>0}}">
+  <!-- <view class="swiper-grid-box" wx:if="{{categoryList1.length>0}}"> -->
+  <view class="swiper-grid-box" wx:if="{{categoryList.length>0}}">
   <view class="grid-box">
     <van-grid border="{{false}}" column-num="5">
           <van-grid-item class="my-grid-item" use-slot bind:click="selectMenu" wx:for="{{categoryList}}" wx:key="categoryId" data-pic="{{item.pic}}" data-itemid="{{item.categoryId}}" data-index="{{index}}" data-categories="{{item.categories}}" data-categoryName="{{item.categoryName}}">
@@ -67,7 +68,7 @@
         </van-grid>
   </view>
     
-    <swiper class="swiper-grid" indicator-dots="true" indicator-active-color="#04358D" bindchange="menuSwiper">
+    <swiper class="swiper-grid" wx-if="{{categoryList1.length>0}}" indicator-dots="true" indicator-active-color="#04358D" bindchange="menuSwiper">
       <swiper-item wx:for="{{categoryList1}}" wx:key="index">
         <van-grid border="{{false}}" column-num="5">
           <van-grid-item class="my-grid-item" use-slot bind:click="selectMenu" wx:for="{{item}}" wx:key="categoryId" data-pic="{{item.pic}}" data-itemid="{{item.categoryId}}" data-index="{{index}}" data-categories="{{item.categories}}" data-categoryName="{{item.categoryName}}">

+ 8 - 3
pages/search-page/search-page.js

@@ -10,14 +10,19 @@ Page({
     hotSearchList: [],
     prodName:"",
     recentSearch: [],
-    
+    shopId:0
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    if(options.shopId){
+      this.setData({
+        shopId:options.shopId
+      })
+    }
+    
   },
 
   /**
@@ -81,7 +86,7 @@ Page({
 
       // 跳转到商品列表页
       wx.navigateTo({
-        url: '/pages/search-prod-show/search-prod-show?prodName=' + this.data.prodName,
+        url: `/pages/search-prod-show/search-prod-show?prodName=${this.data.prodName}&shopId=${this.data.shopId}`,
       })
     }
   },

+ 18 - 12
pages/search-prod-show/search-prod-show.js

@@ -13,7 +13,8 @@ Page({
     prodName: "",
     pages: 0,
     current: 1,
-    size:10
+    size:10,
+    shopId:0
   },
 
   changeShowType: function() {
@@ -32,7 +33,8 @@ Page({
    */
   onLoad: function(options) {
     this.setData({
-      prodName: options.prodName
+      prodName: options.prodName,
+      shopId: options.shopId||0
     });
 
   },
@@ -62,20 +64,24 @@ Page({
   toLoadData: function() {
     wx.showLoading()
     var ths = this;
+    let data = {
+      current: this.data.current,
+      prodName: this.data.prodName,
+      size: this.data.size,
+      sort: this.data.sts,
+      isAllProdType: true,
+      lat: wx.getStorageSync('LATITUDE'),
+      lon: wx.getStorageSync('LONGITUDE'),
+      distance: wx.getStorageSync('DISTANCE') || 0
+    }
+    if(ths.data.shopId !=0){
+      data.shopId = this.data.shopId
+    }
     //热门搜索
     var params = {
       url: "/search/searchProdPage",
       method: "GET",
-      data: {
-        current: this.data.current,
-        prodName: this.data.prodName,
-        size: this.data.size,
-        sort: this.data.sts,
-        isAllProdType: true,
-        lat: wx.getStorageSync('LATITUDE'),
-        lon: wx.getStorageSync('LONGITUDE'),
-        distance: wx.getStorageSync('DISTANCE') || 0
-      },
+      data ,
       callBack: function(res) {
         wx.hideLoading()
         let img=''

+ 1 - 0
pages/submit-order/submit-order.wxss

@@ -8,6 +8,7 @@ page {
 
 .submit-order {
   margin: 20rpx 24rpx 120rpx;
+  padding-bottom: 200rpx;
 }
 
 .submit-order .delivery-addr {

+ 8 - 1
project.private.config.json

@@ -3,11 +3,18 @@
   "projectname": "%E6%B5%B7%E9%A9%AC%E8%B4%AD%E5%95%86%E5%9F%8E",
   "setting": {
     "compileHotReLoad": true,
-    "urlCheck": false
+    "urlCheck": true
   },
   "condition": {
     "miniprogram": {
       "list": [
+        {
+          "name": "pages/prod/prod",
+          "pathName": "pages/prod/prod",
+          "query": "prodid=21",
+          "launchMode": "default",
+          "scene": null
+        },
         {
           "name": "pages/prod/prod",
           "pathName": "pages/prod/prod",

+ 4 - 4
utils/config.js

@@ -2,10 +2,10 @@
 // var domain = "https://shop-h5.zswllife.cn/api"; //统一接口域名,正式环境 
 // var wsDomain = "wss://shop-h5.zswllife.cn/api"; //统一接口域名,正式环境 
 
-var domain = "https://shop-h5.dev.zswllife.cn/api"; //统一接口域名,测试环境 
-var wsDomain = "wss://shop-h5.dev.zswllife.cn/api"; //统一接口域名,测试环境 
-// var domain = "https://shop.haimamart.com/api"; //统一接口域名,正式环境 
-// var wsDomain = "wss://shop.haimamart.com/api"; //统一接口域名,正式环境 
+// var domain = "https://shop-h5.dev.zswllife.cn/api"; //统一接口域名,测试环境 
+// var wsDomain = "wss://shop-h5.dev.zswllife.cn/api"; //统一接口域名,测试环境 
+var domain = "https://shop.haimamart.com/api"; //统一接口域名,正式环境 
+var wsDomain = "wss://shop.haimamart.com/api"; //统一接口域名,正式环境 
 
 // var domain = "http://192.168.1.120:8086"; //统一接口域名,测试环境
 // var wsDomain = "ws://192.168.1.120:8086"; //统一接口域名,测试环境

+ 37 - 0
utils/eventBus.js

@@ -0,0 +1,37 @@
+// event-bus.js(改进版)
+const eventBus = {
+  events: {},
+  cachedEvents: {}, // 缓存已触发的事件
+  
+  // 监听事件(支持获取历史缓存事件)
+  on(event, callback, getCached = true) {
+    if (!this.events[event]) {
+      this.events[event] = [];
+    }
+    this.events[event].push(callback);
+    
+    // 如果有缓存事件,立即执行回调
+    if (getCached && this.cachedEvents[event]) {
+      callback(this.cachedEvents[event]);
+    }
+  },
+  
+  // 触发事件(缓存最新数据)
+  emit(event, data) {
+    this.cachedEvents[event] = data;
+    if (this.events[event]) {
+      this.events[event].forEach(callback => callback(data));
+    }
+  },
+  
+  // 清除缓存事件
+  clear(event) {
+    if (event) {
+      delete this.cachedEvents[event];
+    } else {
+      this.cachedEvents = {};
+    }
+  }
+};
+
+export default eventBus;