123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- // pages/sub-category/sub-category.js
- var http = require("../../utils/http.js");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- subCategoryList: [],
- categoryId: 0,
- prodList: [],
- categoryName:'',
- current: 1,
- pages: 0,
- shopId:0
- },
- // 获取顶栏子分类数据
- getSubCategory() {
- var params = {
- url: "/category/categoryInfo",
- method: "GET",
- data: {
- shopId:this.data.shopId||'',
- parentId: this.data.parentId||0
- },
- callBack: (res) => {
- this.setData({
- subCategoryList: res,
- });
- }
- };
- http.request(params);
- },
- // 根据分类id获取商品数据
- getProdList() {
- var params = {
- url: "/search/searchProdPage",
- method: "GET",
- data: {
- categoryId: this.data.categoryId,
- current: this.data.current,
- size: 10,
- sort: 0,
- isAllProdType: true,
- platform:1
- // lat: wx.getStorageSync('LATITUDE'),
- // lon: wx.getStorageSync('LONGITUDE'),
- // distance: wx.getStorageSync('DISTANCE') || 0
- },
- callBack: (res) => {
- let img = ''
- res.records.forEach(e => {
- img = e.pic.split(',')
- e.pic = img[0]
- })
- this.setData({
- prodList: res.current == 1 ? res.records : this.data.prodList.concat(res.records),
- pages: res.pages
- });
- }
- };
- http.request(params);
- },
- // 切换子分类tab
- onSubCategoryTap(e) {
- this.setData({
- categoryId: e.currentTarget.dataset.id,
- current: 1,
- pages: 0,
- intoView: 'sw' + e.currentTarget.dataset.id,
- })
- this.getProdList()
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options);
- this.setData({
- parentId: options.parentId,
- categoryId: options.categoryId,
- intoView: 'sw' + options.categoryId,
- categoryName:options.categoryName,
- shopId:options.shopId
- })
- this.getSubCategory()
- setTimeout(()=>{
- this.getProdList()
- },500)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- if (this.data.current < this.data.pages) {
- this.setData({
- current: this.data.current + 1,
- })
- this.getProdList()
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|