| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 | 
							- var util = require('../../utils/util.js');
 
- var api = require('../../config/api.js');
 
- var goodsUtil = require('../../utils/goods.js');
 
- var app = getApp();
 
- Page({
 
-   data: {
 
-     bannerInfo: {
 
-       'img_url': '',
 
-       'name': ''
 
-     },
 
-     categoryFilter: false,
 
-     filterCategory: [],
 
-     goodsList: [],
 
-     categoryId: 0,
 
-     currentSortType: 'default',
 
-     currentSortOrder: 'desc',
 
-     page: 1,
 
-     size: 1000,
 
-     showNavList: false,
 
-     footCart: {},
 
-     openAttr: false,
 
-     productList: {},
 
-     specificationList: {},
 
-     checkedSpecText: '请选择规格数量',
 
-     number: 1,
 
-     retailPrice:''
 
-   },
 
-   toggleNav() {
 
-     this.setData({
 
-       showNavList: !this.data.showNavList
 
-     })
 
-   },
 
-   getData: function () {
 
-     let that = this;
 
-     util.request(api.GoodsHot).then(function (res) {
 
-       if (res.errno === 0) {
 
-         that.setData({
 
-           bannerInfo: res.data.bannerInfo,
 
-         });
 
-         that.getGoodsList();
 
-       }
 
-     });
 
-   },
 
-   getGoodsList (){
 
-     var that = this;
 
-     util.request(api.HotGoodsList, { isHot: 1, page: that.data.page, size: that.data.size, order: that.data.currentSortOrder, sort: that.data.currentSortType, categoryId: that.data.categoryId})
 
-       .then(function (res) {
 
-         if (res.errno === 0) {
 
-           that.setData({
 
-             goodsList: res.data.goodsList,
 
-             filterCategory: res.data.filterCategory
 
-           });
 
-           if(that.data.categoryId>0){
 
-             let filterCategory = that.data.filterCategory;
 
-             filterCategory.forEach(function (val, index, arr) {
 
-               if (val.id == that.data.categoryId) {
 
-                 val.checked = true;
 
-                 filterCategory[index] = val;
 
-                 that.setData({ filterCategory: filterCategory });
 
-               }else {
 
-                 val.checked = false;
 
-               }
 
-             }, that);
 
-           }
 
-         }
 
-       });
 
-   },
 
-   switchNav(event) {
 
-     let name = event.currentTarget.dataset.name;
 
-     wx.switchTab({
 
-       url: `/pages/${name}/${name}`,
 
-     });
 
-   },
 
-   onLoad: function (options) {
 
-     // 页面初始化 options为页面跳转所带来的参数
 
-     this.getData();
 
-     this.getFootCart();
 
-   },
 
-   onReady: function () {
 
-     // 页面渲染完成
 
-   },
 
-   onShow: function () {
 
-     // 页面显示
 
-   },
 
-   onHide: function () {
 
-     // 页面隐藏
 
-   },
 
-   onUnload: function () {
 
-     // 页面关闭
 
-   },
 
-   openSortFilter: function (event) {
 
-     let currentId = event.currentTarget.id;
 
-     switch (currentId) {
 
-       case 'categoryFilter':
 
-         this.setData({
 
-           'categoryFilter': !this.data.categoryFilter,
 
-           'currentSortType': 'category',
 
-           'currentSortOrder': 'asc'
 
-         });
 
-         break;
 
-       case 'priceSort':
 
-         let tmpSortOrder = 'asc';
 
-         if (this.data.currentSortOrder == 'asc') {
 
-           tmpSortOrder = 'desc';
 
-         }
 
-         this.setData({
 
-           'currentSortType': 'price',
 
-           'currentSortOrder': tmpSortOrder,
 
-           'categoryFilter': false
 
-         });
 
-         this.getData();
 
-         break;
 
-       default:
 
-         //综合排序
 
-         this.setData({
 
-           'currentSortType': 'default',
 
-           'currentSortOrder': 'desc',
 
-           'categoryFilter': false
 
-         });
 
-         this.getData();
 
-     }
 
-   },
 
-   selectCategory: function(event){
 
-     let that = this;
 
-     let currentIndex = event.target.dataset.categoryIndex;
 
-     this.setData({
 
-       categoryFilter: false,
 
-       categoryId: this.data.filterCategory[currentIndex].id
 
-     });
 
-     this.getData();
 
-   },
 
-   getFootCart: function () {
 
-     let that = this;
 
-     util.request(api.GetFootCart).then(function (res) {
 
-       if (res.errno === 0) {
 
-         that.setData({
 
-           footCart: res.data,
 
-         });
 
-       }
 
-     });
 
-   },
 
-   switchAttrPop: function () {
 
-     this.setData({
 
-       openAttr: !this.data.openAttr
 
-     })
 
-   },
 
-   //购物车增加
 
-   addCart: function (e) {
 
-     let that = this;
 
-     var goodsId = e.currentTarget.dataset.goodsId;
 
-     var retailPrice = e.currentTarget.dataset.retailPrice; 
 
-     util.request(api.GoodsSku, {
 
-       goodsId: goodsId
 
-     }).then(function (res) {
 
-       if (res.errno === 0 && null != res.data) {
 
-         that.setData({
 
-           goodsVo: res.data.goodsVo,
 
-           specificationList: res.data.specificationList,
 
-           productList: res.data.productList,
 
-           openAttr: !that.data.openAttr,
 
-           retailPrice: retailPrice
 
-         });
 
-         //
 
-         let _specificationList = res.data.specificationList;
 
-         for (let i = 0; i < _specificationList.length; i++) {
 
-           if (_specificationList[i].valueList.length == 1) {
 
-             //如果已经选中,则反选
 
-             _specificationList[i].valueList[0].checked = true;
 
-           }
 
-         }
 
-         that.setData({
 
-           'specificationList': _specificationList
 
-         });
 
-       }
 
-     });
 
-   },
 
-   clickSkuValue: function (event) {
 
-     let that = this;
 
-     let specValueId = event.currentTarget.dataset.valueId;
 
-     let index = event.currentTarget.dataset.index;
 
-     let _specificationList = this.data.specificationList;
 
-     for (let j = 0; j < _specificationList[index].valueList.length; j++) {
 
-       if (_specificationList[index].valueList[j].id == specValueId) {
 
-         //如果已经选中,则反选
 
-         if (_specificationList[index].valueList[j].checked) {
 
-           _specificationList[index].valueList[j].checked = false;
 
-         } else {
 
-           _specificationList[index].valueList[j].checked = true;
 
-         }
 
-       } else {
 
-         _specificationList[index].valueList[j].checked = false;
 
-       }
 
-     }
 
-     this.setData({
 
-       'specificationList': _specificationList
 
-     });
 
-     //重新计算spec改变后的信息
 
-     goodsUtil.changeSpecInfo(that);
 
-   },
 
-   cutNumber: function () {
 
-     this.setData({
 
-       number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
 
-     });
 
-   },
 
-   addNumber: function () {
 
-     this.setData({
 
-       number: this.data.number + 1
 
-     });
 
-   },
 
-   //购物车增加
 
-   addToCart: function () {
 
-     let that = this;
 
-     var goodsId = that.data.goodsVo.id;
 
-     //提示选择完整规格
 
-     if (!that.data.productList || !that.data.productList.length) {
 
-       util.showErrorToast('当前门店没有库存');
 
-       return false;
 
-     }
 
-     //提示选择完整规格
 
-     if (!goodsUtil.isCheckedAllSpec(that)) {
 
-       return false;
 
-     }
 
-     //根据选中的规格,判断是否有对应的sku信息
 
-     let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
 
-     if (!checkedProduct || checkedProduct.length <= 0) {
 
-       //找不到对应的product信息,提示没有库存
 
-       return false;
 
-     }
 
-     //验证库存
 
-     if (checkedProduct.stock_num < this.data.number) {
 
-       //找不到对应的product信息,提示没有库存
 
-       return false;
 
-     }
 
-     util.request(api.CartAdd, {
 
-       goodsId: goodsId,
 
-       productId: checkedProduct[0].id,
 
-       number: this.data.number
 
-     }, 'POST').then(function (res) {
 
-       if (res.errno === 0 && null != res.data) {
 
-         wx.showToast({
 
-           title: '添加成功',
 
-           icon: 'success',
 
-           mask: true
 
-         });
 
-         that.setData({
 
-           openAttr: !that.data.openAttr
 
-         })
 
-         that.getFootCart();
 
-       } else {
 
-         util.showErrorToast(res.errmsg)
 
-       }
 
-     });
 
-   },
 
- })
 
 
  |