123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- var app = getApp();
- Page({
- data: {
- addressInfo:{},
- bannerInfo: {
- 'imgUrl': 'https://jzmall.lifejingzhi.com/file/jzmall/weixin/new/img-hot.png',
- 'name': '大家都在买的'
- },
- categoryFilter: false,
- filterCategory: [],
- goodsList: [],
- categoryId: 0,
- currentSortType: 'default',
- currentSort: 'create_time',
- currentSortOrder: 'desc',
- page: 1,
- limit: 10
- },
- getCategoryList: function() {
- var that = this;
- util.request(api.GoodsFilter, {
- isHot: 1
- })
- .then(function(res) {
- if (res.errno === 0) {
- that.setData({
- filterCategory: res.data.filterCategoryList,
- });
- }
- });
- },
- getGoodsList: function() {
- var that = this;
- util.request(api.GoodsList, {
- isHot: true,
- page: that.data.page,
- limit: that.data.limit,
- order: that.data.currentSortOrder,
- sort: that.data.currentSort,
- categoryId: that.data.categoryId,
- city:that.data.addressInfo.city,
- shopId:that.data.addressInfo.shopId
- })
- .then(function(res) {
- console.info(res)
- if (res.errno === 0) {
- that.setData({
- goodsList: res.data.list,
- filterCategory: res.data.filterCategoryList
- });
- }
- });
- },
- onLoad: function(options) {
- // 页面初始化 options为页面跳转所带来的参数
- var addressInfo=wx.getStorageSync('addressInfo');
- if(addressInfo){
- this.setData({
- addressInfo:addressInfo
- })
- }
- this.getGoodsList();
- },
- 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',
- currentSort: 'create_time',
- currentSortOrder: 'desc'
- });
- break;
- case 'priceSort':
- let tmpSortOrder = 'asc';
- if (this.data.currentSortOrder == 'asc') {
- tmpSortOrder = 'desc';
- }
- this.setData({
- currentSortType: 'price',
- currentSort: 'retail_price',
- currentSortOrder: tmpSortOrder,
- categoryFilter: false
- });
- this.getGoodsList();
- break;
- default:
- //综合排序
- this.setData({
- currentSortType: 'default',
- currentSort: 'create_time',
- currentSortOrder: 'desc',
- categoryFilter: false,
- categoryId: 0,
- });
- this.getGoodsList();
- }
- },
- selectCategory: function(event) {
- let currentIndex = event.target.dataset.categoryIndex;
- this.setData({
- 'categoryFilter': false,
- 'categoryId': this.data.filterCategory[currentIndex].id
- });
- this.getGoodsList();
- }
- })
|