| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 | 
							- var util = require('../../utils/util.js');
 
- var api = require('../../config/api.js');
 
- //获取应用实例
 
- const app = getApp();
 
- Page({
 
-   data: {
 
-     navList: [],
 
-     categoryList: [],
 
-     currentCategory: {},
 
-     scrollLeft: 0,
 
-     scrollTop: 0,
 
-     goodsCount: 0,
 
-     scrollHeight: 0,
 
-     //
 
-     filterCategory: [],
 
-     goodsList: [],
 
-     categoryId: 0,
 
-     currentSortType: 'default',
 
-     currentSortOrder: 'desc',
 
-     filterDiscount: 0,// 0不限 1特价 2活动
 
-     goodsBizType: app.globalData.appGoodsBizType,//业务类型
 
-     page: 1,
 
-     size: 50,
 
-     showNavList: false,
 
-     footCart: {},
 
-     referrer: 0,
 
-     sourceKey: '',
 
-     openCoupon: false
 
-   },
 
-   toggleNav() {
 
-     this.setData({
 
-       showNavList: !this.data.showNavList
 
-     })
 
-   },
 
-   switchNav(event) {
 
-     let name = event.currentTarget.dataset.name;
 
-     wx.switchTab({
 
-       url: `/pages/${name}/${name}`,
 
-     });
 
-   },
 
-   onLoad: function (options) {
 
-     let that = this;
 
-     // 页面初始化 options为页面跳转所带来的参数
 
-     if (options.referrer){
 
-       that.setData({
 
-         referrer: parseInt(options.referrer),
 
-         sourceKey: options.sourceKey,
 
-         openCoupon: true
 
-       });
 
-     }
 
-     // that.setData({
 
-     //   goodsBizType: app.globalData.appGoodsBizType
 
-     // });
 
-     wx.setNavigationBarTitle({
 
-       title: '分类'
 
-     });
 
-   },
 
-   getCatalog: function () {
 
-     //CatalogList
 
-     let that = this;
 
-     util.request(api.CatalogList).then(function (res) {
 
-       if (that.data.currentCategory && that.data.currentCategory.id > 0) {
 
-         that.setData({
 
-           navList: res.data.categoryList,
 
-         });
 
-       } else {
 
-         that.setData({
 
-           navList: res.data.categoryList,
 
-           currentCategory: res.data.currentCategory
 
-         });
 
-       }
 
-       that.getCategoryData();
 
-     });
 
-     util.request(api.GoodsCount).then(function (res) {
 
-       that.setData({
 
-         goodsCount: res.data.goodsCount
 
-       });
 
-     });
 
-   },
 
-   getCurrentCategory: function (id) {
 
-     let that = this;
 
-     util.request(api.CatalogCurrent, { id: id })
 
-       .then(function (res) {
 
-         that.setData({
 
-           currentCategory: res.data.currentCategory
 
-         });
 
-         that.getGoodsList();
 
-       });
 
-   },
 
-   onReady: function () {
 
-     // 页面渲染完成
 
-   },
 
-   onShow: function () {
 
-     this.setData({
 
-       goodsBizType: app.globalData.appGoodsBizType
 
-     });
 
-     // 页面显示
 
-     if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
 
-       this.getFootCart();
 
-       this.getCatalog();
 
-     } else {
 
-       wx.navigateTo({
 
-         url: '/pages/auth/btnAuth/btnAuth',
 
-       })
 
-     }
 
-   },
 
-   onHide: function () {
 
-     // 页面隐藏
 
-     this.setData({
 
-       showNavList: false
 
-     })
 
-   },
 
-   onUnload: function () {
 
-     // 页面关闭
 
-   },
 
-   getList: function () {
 
-     var that = this;
 
-     util.request(api.ApiRootUrl + 'api/catalog/' + that.data.currentCategory.id)
 
-       .then(function (res) {
 
-         that.setData({
 
-           categoryList: res.data,
 
-         });
 
-       });
 
-   },
 
-   switchCate: function (event) {
 
-     var that = this;
 
-     var currentTarget = event.currentTarget;
 
-     if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
 
-       return false;
 
-     }
 
-     this.getCurrentCategory(event.currentTarget.dataset.id);
 
-   },
 
-   //
 
-   getCategoryData: function () {
 
-     let that = this;
 
-     that.getGoodsList();
 
-   },
 
-   getGoodsList() {
 
-     wx.showLoading({
 
-       title: '加载中...',
 
-     });
 
-     var that = this;
 
-     if (that.data.currentCategory){
 
-       util.request(api.CatalogProductList, {
 
-         page: that.data.page,
 
-         size: that.data.size,
 
-         order: that.data.currentSortOrder,
 
-         sort: that.data.currentSortType,
 
-         // discount: that.data.filterDiscount,
 
-         goodsBizType: that.data.goodsBizType,
 
-         categoryId: that.data.currentCategory.id
 
-       })
 
-         .then(function (res) {
 
-           if (res.errno === 0) {
 
-             that.setData({
 
-               goodsList: res.data.data,
 
-               filterCategory: res.data.filterCategory
 
-             });
 
-             wx.hideLoading();
 
-           }
 
-         });
 
-     }
 
-     wx.hideLoading();
 
-   },
 
-   getFootCart: function () {
 
-     let that = this;
 
-     util.request(api.GetFootCart).then(function (res) {
 
-       if (res.errno === 0) {
 
-         that.setData({
 
-           footCart: res.data,
 
-         });
 
-       }
 
-     });
 
-   },
 
-   //购物车减少
 
-   cutNumber: function (e) {
 
-     let that = this;
 
-     var goodsId = e.currentTarget.dataset.goodsId;
 
-     var productId = e.currentTarget.dataset.productId;
 
-     var goodsList = that.data.goodsList;
 
-     // goodsList.forEach(function (val, index, arr) {
 
-     //     if (val.product_id == productId) {
 
-     //         val.cart_num = val.cart_num - 1;
 
-     //         if (val.cart_num >= 0) {
 
-     //             goodsList[index] = val;
 
-     //             that.setData({goodsList: goodsList});
 
-     //         }
 
-     //     }
 
-     // });
 
-     // that.setData({goodsList: goodsList});
 
-     util.request(api.CartMinus, { goodsId: goodsId, productId: productId, number: 1 }, 'POST').then(function (res) {
 
-       if (res.errno === 0 && null != res.data) {
 
-         var goodsList = that.data.goodsList;
 
-         that.getFootCart();
 
-         goodsList.forEach(function (val, index, arr) {
 
-           if (val.product_id == productId) {
 
-             val.cart_num = res.data;
 
-             goodsList[index] = val;
 
-             if(val.cart_num == 0){
 
-               util.showErrorToast('不能再减了');
 
-             }
 
-           }
 
-         }, that);
 
-         that.setData({ goodsList: goodsList });
 
-       }
 
-     });
 
-   },
 
-   //购物车增加
 
-   addNumber: function (e) {
 
-     let that = this;
 
-     var goodsId = e.currentTarget.dataset.goodsId;
 
-     var productId = e.currentTarget.dataset.productId;
 
-     var goodsList = that.data.goodsList;
 
-     // goodsList.forEach(function (val, index, arr) {
 
-     //     if (val.product_id == productId) {
 
-     //         val.cart_num = val.cart_num + 1;
 
-     //         goodsList[index] = val;
 
-     //     }
 
-     // });
 
-     // that.setData({goodsList: goodsList});
 
-     util.request(api.CartAdd, { goodsId: goodsId, productId: productId, number: 1 }, 'POST').then(function (res) {
 
-       if (res.errno === 0 && null != res.data) {
 
-         that.getFootCart();
 
-         goodsList.forEach(function (val, index, arr) {
 
-           res.data.cartList.forEach(function (cartVal, cartIndex, cartArr) {
 
-             if (val.product_id == cartVal.product_id) {
 
-               val.cart_num = cartVal.number;
 
-               goodsList[index] = val;
 
-             }
 
-           });
 
-         }, that);
 
-         that.setData({ goodsList: goodsList });
 
-       }
 
-     });
 
-   },
 
-   openSortFilter: function (event) {
 
-     let that = this; 
 
-     let currentId = event.currentTarget.id;
 
-     console.log('currentId:'+currentId);
 
-     switch (currentId) {
 
-       case 'defaultActivity':
 
-         that.setData({
 
-           'goodsBizType': '00'
 
-         });
 
-         app.globalData.appGoodsBizType = '00';
 
-         this.getGoodsList();
 
-         break;
 
-       case 'discountActivity':
 
-         that.setData({
 
-           'goodsBizType': '02'
 
-         });
 
-         app.globalData.appGoodsBizType = '02';
 
-         this.getGoodsList();
 
-         break;
 
-       case 'groupActivity':
 
-         that.setData({
 
-           'goodsBizType': '10'
 
-         });
 
-         app.globalData.appGoodsBizType = '10';
 
-         this.getGoodsList();
 
-         break;
 
-       case 'ordActivity':
 
-         that.setData({
 
-           'goodsBizType': '11'
 
-         });
 
-         app.globalData.appGoodsBizType = '11';
 
-         this.getGoodsList();
 
-         break;
 
-       case 'sellSort':
 
-         let tmpSortOrder = 'asc';
 
-         if (this.data.currentSortOrder == 'asc') {
 
-           tmpSortOrder = 'desc';
 
-         }
 
-         this.setData({
 
-           'currentSortType': 'sell',
 
-           'currentSortOrder': tmpSortOrder,
 
-         });
 
-         this.getGoodsList();
 
-         break;
 
-       case 'priceSort':
 
-         tmpSortOrder = 'asc';
 
-         if (this.data.currentSortOrder == 'asc') {
 
-           tmpSortOrder = 'desc';
 
-         }
 
-         this.setData({
 
-           'currentSortType': 'price',
 
-           'currentSortOrder': tmpSortOrder,
 
-         });
 
-         this.getGoodsList();
 
-         break;
 
-       default:
 
-         //综合排序
 
-         this.setData({
 
-           'currentSortType': 'default',
 
-           'currentSortOrder': 'desc',
 
-         });
 
-         this.getGoodsList();
 
-     }
 
-   },
 
-   takeShareCoupon() {
 
-     let that = this;
 
-     util.request(api.CouponTransActivit, {
 
-       referrer: that.data.sourceKey,
 
-       sourceKey: that.data.sourceKey
 
-     }).then(function (res) {
 
-       if (res.errno === 0) {
 
-         util.showErrorToast("领取成功");
 
-         that.setData({
 
-           couponList: res.data,
 
-           openCoupon: false
 
-         });
 
-       } else if (res.errno === 2) {
 
-         util.showErrorToast(res.errmsg)
 
-         that.setData({
 
-           couponList: res.data,
 
-           openCoupon: false
 
-         });
 
-       }
 
-     });
 
-   },
 
-   closeCoupon: function () {
 
-     var that = this;
 
-     that.setData({
 
-       openCoupon: false
 
-     });
 
-   },
 
-   bindtapGoodsDetail: function (e) {
 
-     var that = this;
 
-     let url = '';
 
-     var itemId = e.currentTarget.dataset.itemId;
 
-     if (that.data.filterDiscount != 2) {
 
-       url = '/pages/goods/goods?id=' + itemId;
 
-     } else {
 
-       url = '/pages/groupDetail/groupDetail?id=' + itemId;
 
-     }
 
-     wx.navigateTo({
 
-       url: url,
 
-     })
 
-   }, 
 
-   sercherCategory: function (e) {
 
-     var that = this;
 
-     let url = '';
 
-     var replyType = e.currentTarget.dataset.replyType;
 
-     var currentIndex = e.currentTarget.dataset.currentIndex;
 
-     // console.log('replyType:' + e.currentTarget.dataset.replyType);
 
-     // console.log('goodsBizType:' + that.data.goodsBizType);
 
-     // 跳转页面
 
-     wx.navigateTo({
 
-       url: '/pages/category/category?id=' + replyType + '&&goodsBizType=' + that.data.goodsBizType + '&¤tIndex=' + currentIndex
 
-     })
 
-   }
 
- })
 
 
  |