// pages/list/six/index.js import commonApi from "../../../utils/https/common" import util from "../../../utils/util" Page({ /** * 页面的初始数据 */ data: { types:[], areaIndex:0, areas:[], typeIndex:0, total:1, list:[], keywords:"" }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 获取地区 commonApi._post("act/get_suzhou_areas",{}).then(res=>{ let areaIndex = 0; res.data.map((item,index)=>{ if(options.area && item.area_key==options.area && areaIndex==0){ areaIndex = index; } }) this.setData({ areas:res.data, areaIndex:areaIndex }) this.getTypes() }) }, getTypes:function(){ // 获取苏城六纪下面的分类 commonApi._post("act/get_type_by_area",{ area_id:this.data.areas[this.data.areaIndex].area_id, tag_id:16 }).then(res=>{ res.data.unshift({ type_name:"全部", type_id:"" }) this.setData({ types:res.data, typeIndex:0 }) this.getList(); }) }, changeArea:function(e){ this.setData({ areaIndex:e.detail.value, list:[], total:1 }) this.getTypes(); }, changeType:function(e){ this.setData({ typeIndex:e.detail.value, list:[], total:1 }) this.getList() }, search:function(e){ this.setData({ keywords:e.detail.keywords, list:[], total:1 }) this.getList() }, getList:function(){ let list = this.data.list; if(list.length>=this.data.total) return; if(!this.data.types[this.data.typeIndex]) return; commonApi._post('product/get_product_by_tag',{ areas_id:this.data.areas[this.data.areaIndex].area_id, type_id:this.data.types[this.data.typeIndex].type_id, tag_id:16, offset:list.length, limit:10, sort:"weight", order:"desc", title:this.data.keywords }).then(res=>{ this.setData({ list:list.concat(res.data.list), total:res.data.total }) }) }, gotoDetail:function(e){ let item = e.currentTarget.dataset.item; console.log(item) util.gotoDetail(item); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })