// 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 }) this.getList(); }) 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 }) }) 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_name: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=>{ let resData = res.data.rows // 处理舒适度 resData.forEach(v=>{ v.comforLevel = this.data.comfortLevel.find(x=>x.level == v.comfort_level) // v.comfort_level_str = comforLevel.desc v.hourflowLeve = this.data.comfortLevel.find(x=>x.level == v.hour_flow_level) // v.hour_flow_level_str = hourflowLeve.desc }) this.setData({ list:this.data.list.concat(res.data.rows), total:res.data.total }) console.log(this.data.list.length); console.log(res.data.total); if (this.data.list.length