var app = getApp(); Page({ /** * 页面的初始数据 */ data: { options: {}, link: '', // 分类信息列表 cate_list:{}, two_cate_list: {}, three_cate_list: {}, selected_one_cate: 0, selected_two_cate: 0, selected_three_cate: 0, supplier_id: 0, // 商品信息列表 list: [], page: 0, total_page: 0, isLoadMore: true, cate_id: 0,// 分类id 取最小级分类id // 是否显示H5 is_show_h5: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 参数获取 let page = getCurrentPages(); let params = options || page[page.length - 1].options; //获取加载的页面 this.setData({ options: params, }); // 信息获取 this.getCateList(); this.getGoodsList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { let data = this.data; // 判断是否没有下一页了 if (data.page >= data.total_page) console.log('没有更多页了'); else if(data.isLoadMore) this.getGoodsList(); else console.log('没有更多数据'); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, /****** 自定义方法 *****************************************************************/ // 获取分类列表 getCateList(){ let _this = this; _this.loading(true,'正在加载中...'); app._getNetWork({ url: app.getNetAddresss("plugin.supplier.api.controllers.goods.getCateList"), success: function (res) { _this.loading(false); let data = res.data; if (data.result === 1) { _this.setData({ cate_list: data.data, }); } else { wx.showToast({ icon: 'none', title: data.msg, duration: 1500 }); } }, fail: function (res) { _this.loading(false); console.log(res); } }); }, // 点击切换分类 clickOneMenu(e){ // 参数获取 let _this = this; _this.loading(true,'正在加载中...'); let item = e.currentTarget.dataset.item; // 信息处理 let level = 1,id = 0; let two_cate_list = {}, three_cate_list = {}; if(!item){ level = parseInt(e.currentTarget.dataset.level); id = 0; }else{ level = item.level; id = item.id; } // 选中操作 switch (level) { case 1: if(item){ two_cate_list = item.has_many_children; if(two_cate_list[0]) three_cate_list = two_cate_list[0].has_many_children; } _this.setData({ selected_one_cate: id, selected_two_cate: 0, selected_three_cate: 0, two_cate_list: two_cate_list, three_cate_list: three_cate_list, cate_id: id, }); break; case 2: if(item) three_cate_list = item.has_many_children; _this.setData({ selected_two_cate: id, selected_three_cate: 0, three_cate_list: three_cate_list, cate_id: id > 0 ? id : _this.data.selected_one_cate, }); break; case 3: _this.setData({ selected_three_cate: id, cate_id: id > 0 ? id : _this.data.selected_two_cate, }); break; } // 重新获取数据 _this.setData({ isLoadMore: false,// 防止多次请求分页数据 page: 0, list: [] }); _this.getGoodsList(); }, // 加载动画 loading(type = true,msg = '正在加载中...'){ if(type){ wx.showLoading({ title: msg, mask: true }); }else{ wx.hideLoading(); } }, // 获取企业商品信息 getGoodsList(){ let _this = this; let page = _this.data.page + 1; let cate_id = _this.data.cate_id; let supplier_id = _this.data.options.supplier_id; // 判断是否存在企业id if (!supplier_id) { wx.showToast({ icon: 'none', title: '参数错误,企业id不存在!', duration: 1500, success: function() { setTimeout(function() { wx.navigateBack({ delta: 1 }); }, 1500); }, }); return false; } // 开始获取数据 _this.loading(true,'正在加载中...'); _this.setData({ isLoadMore: false,// 防止多次请求分页数据 page: page }); app._getNetWork({ url: app.getNetAddresss("plugin.supplier.api.controllers.goods.goodsList"), data: { supplier_id: supplier_id, page: page, cate_id: cate_id }, success: function (res) { _this.loading(false); let data = res.data; if (data.result === 1) { _this.setData({ list: _this.data.list.concat(data.data.data), total_page: data.data.last_page, isLoadMore: true }); } else { wx.showToast({ icon: 'none', title: data.msg, duration: 1500 }); } }, fail: function (res) { _this.loading(false); console.log(res); } }); }, // 点击跳转商品详情(H5页面) goToDetail(e){ // 参数获取 let goodsId = e.currentTarget.dataset.goods_id; let domainName = app.data.host; this.setData({ link: domainName+`/yhmobile/yun_shop/?menu#/goods/${goodsId}?i=1`, is_show_h5: true }); } });