// pages/pbService/sceneComfort/index.js const device = wx.getSystemInfoSync(),radio = device.windowWidth/750; import commonApi from "../../../utils/https/common" Page({ /** * 页面的初始数据 */ data: { radio:radio, comfortLevel:[], comfortIndex:0, areas:[], areaIndex:0, list:[], pageNo:1, total:1, keywords:"", areaObj:{}, comfortObj:{}, searchText:"", sceneLevel:[], sceneLevelIndex:-1, sceneLevelObj:{} }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { commonApi._post("pbservice/Comfort/getComfortLevel").then(res=>{ let comfortObj = {} res.data.map(item=>{ comfortObj[item.level] = { name:item.desc, color:item.color }; }) res.data.unshift({ desc:"不选择" }) this.setData({ comfortLevel:res.data, comfortObj:comfortObj }) }) commonApi._post('pbservice/Other/getSuzhouAreas').then(res=>{ let areaObj = {} res.data.map(item=>{ areaObj[item.area_code] = item.area_name; }) res.data.unshift({ area_name:"不选择" }) if(options.area_code){ let index = res.data.findIndex(item=>item.area_code==options.area_code); this.setData({ areaIndex:index==-1?0:index }) } this.setData({ areas:res.data, areaObj:areaObj }) this.getList(); }) commonApi._post("pbservice/Comfort/getSceneLevel").then(res=>{ console.log(res) let sceneLevelObj = {}; res.data.map(item=>{ sceneLevelObj[item.level] = item.name; }) res.data.unshift({ name:"不选择" }) this.setData({ sceneLevel:res.data, sceneLevelObj:sceneLevelObj }) }) }, changeArea:function(e){ this.setData({ areaIndex:e.detail.value, list:[], pageNo:1, total:1 }) this.getList() }, changeComfortLevel:function(e){ this.setData({ comfortIndex:e.detail.value, list:[], pageNo:1, total:1 }) this.getList() }, changeSceneLevel:function(e){ this.setData({ sceneLevelIndex:e.detail.value, list:[], pageNo:1, total:1 }) this.getList() }, getList:function(){ if(this.data.total<=this.data.list.length) return; commonApi._post("pbservice/Comfort/getComfort",{ scene_name:this.data.keywords, comfort_level:this.data.comfortIndex>0?this.data.comfortLevel[this.data.comfortIndex].level:null, area_key:this.data.areaIndex>0?this.data.areas[this.data.areaIndex].area_code:null, page_no:this.data.pageNo, page_num:10, scene_level:this.data.sceneLevelIndex>0?this.data.sceneLevel[this.data.sceneLevelIndex].level:null }).then(res=>{ this.setData({ list:this.data.list.concat(res.data.rows), total:res.data.total }) }) }, search:function(){ this.setData({ keywords:this.data.searchText, list:[], pageNo:1, total:1 }) this.getList() }, inputKeyword:function(e){ this.setData({ searchText:e.detail.value }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })