import $ from './../../utils/Tool'; import router from './../../utils/router'; import { getPropertyData,getCurrentSeason,getTransfrom } from "../../requests/api"; Page({ /** * 页面的初始数据 */ data: { envLevel:{ temperatureWarm:[ {name:"偏冷",value:"小于24°C",min:-10,active:true}, {name:"舒适",value:"18-24°C",min:18,active:true}, {name:"偏热",value:"大于24°C",min:24.1,active:true}, ], temperatureCooling:[ {name:"偏冷",value:"小于22°C",min:-10,active:true}, {name:"舒适",value:"22-26°C",min:22,active:true}, {name:"偏热",value:"大于26°C",min:26.1,active:true}, ], temperatureTransition:[ {name:"偏冷",value:"小于18°C",min:-10,active:true}, {name:"舒适",value:'18-26°C',min:18,active:true}, {name:"偏热",value:"大于26°C",min:26.1,active:true}, ], temperatureTransitioncold:[ {name:"偏冷",value:"小于18°C",min:-10,active:true}, {name:"舒适",value:'18-26°C',min:18,active:true}, {name:"偏热",value:"大于26°C",min:26.1,active:true}, ], humidity:[ {name:"",value:"0-30%",min:0,active:true}, {name:"",value:"30-45%",min:35}, {name:"适宜",value:"45-55%",min:45}, {name:"",value:"55-70%",min:55,active:true}, {name:"",value:"70-100%",min:70,active:true}, ], co2:[ {name:"",value:"0-450ppm",min:0}, {name:"合理范围",value:"450-700ppm",min:450}, {name:"",value:"700-1000ppm",min:700,active:true}, {name:"",value:"1000-2500ppm",min:1000,active:true}, {name:"",value:"2500-5000ppm",min:2500,active:true} ], pm25:[ {name:"健康",value:"0~35μg/m³",min:0,active:true}, {name:"良",value:"35~75μg/m³",min:35,active:true}, {name:"轻度污染",value:"75~115μg/m³",min:75,active:true}, {name:"中度污染",value:"115~150μg/m³",min:115,active:true}, {name:"重度污染",value:"150~250μg/m³",min:150,active:true}, {name:"严重污染",value:"大于250μg/m³及以上",min:250,active:true}, ], hcho:[ {name:"",value:"0-0.05mg/m³",min:0}, {name:"合理范围",value:"0.05-0.08mg/m³",min:0.05}, {name:"",value:"0.08-0.1mg/m³",min:0.08,active:true}, {name:"",value:"0.1-0.15mg/m³",min:0.1,active:true}, {name:"",value:"0.15-0.2mg/m³",min:0.15,active:true} ], }, paramName:'', envType:'', localName:'', envValue:"", tableHight:null, pointerTop:0, funcid:"", spaceId:"", projectId:"", // 项目id tragetChart:[], seasonType:'' }, goBack(){ router.pop() }, async getChartDate(){ let data={ projectId:$.store.get('projectId')||$.storage.get('projectId'), spaceId:this.data.spaceId, funcid:this.data.funcid } $.loading(); let res = await getPropertyData(data); $.hideLoading(); if(!res){ throw "网络错误"; } let {avg,propertyData,dayTarget}=res; // console.log(res,'返回数据集值'); this.initChartdate(propertyData,dayTarget); let levelList=[]; if(this.data.envType=="temperature"){ let day = new Date(); let year = day.getFullYear(); let month = day.getMonth() + 1; month=month<10?('0'+month):month; let today = day.getDate(); today=today<10?('0'+today):today; const data={ projectId:$.store.get('projectId')||$.storage.get('projectId'), dateTiime:`${year}${month}${today}` } let res = await getTransfrom(data); let {seasonType,type} = (res.content&&res.content[0])||{seasonType:'Warm',type:2}; this.setData({seasonType:seasonType,seasonNum:type},()=>{ let that= this; wx.createSelectorQuery().select('.param_list').boundingClientRect(function(rect){ that.setData({'tableHight':rect.height}) }).exec() }) if(seasonType==="Transition"){ // 3 供冷-供暖 if(type==3){ this.data.envLevel[this.data.envType+seasonType+'cold'].forEach(item=>{ levelList.push(item.min) }) this.setData({'envLevel.temperatureTransition':this.data.envLevel.temperatureTransitioncold}); } // 4 供暖-供冷 if(type==4){ this.data.envLevel[this.data.envType+seasonType].forEach(item=>{ levelList.push(item.min) }) } }else{ this.data.envLevel[this.data.envType+seasonType].forEach(item=>{ levelList.push(item.min) }) } }else{ this.data.envLevel[this.data.envType].forEach(item=>{ levelList.push(item.min) }) } levelList.push(Number(avg)) let valueIndex = levelList.sort((a,b)=>{return a-b}).findIndex(item=>item===avg); valueIndex = valueIndex<0?0:valueIndex; console.log(valueIndex,levelList,"valueIndex") this.setData({pointerTop:38*valueIndex}); }, initChartdate(propertyData,dayTarget){ if(!Array.isArray(propertyData)||!Array.isArray(dayTarget)){ return ; } // 目标 { time: "1951",release:0, sales: 38,标准区间: [ 25, 45 ] }, let baseArr=propertyData&&propertyData.slice(1) || []; let tragetChart = []; let initNum={ PM2d5:function(value){ // if(this.data.projectId==="Pj1101080259"){ // return parseInt(1000*value) // } return parseInt(value) }, Tdb:function(value){ return Number(Number(value).toFixed(1)) }, RH:function(value){ return parseInt(value) }, CO2:function(value){ return parseInt(value) }, HCHO:function(value){ return Number(Number(value).toFixed(2)) } } let funid = this.data.funcid; // 由项目 projectId 判断改为 租户 tenantId 做判断 /* let specialProject=$.store.get("specialProject"); // let falgPro = (funid==="PM2d5"&&specialProject.includes(this.data.projectId)); let tenantId = $.store.get("tenantId"); let falgPro = (funid==="PM2d5"&&specialProject.includes(tenantId)); */ (baseArr.length>1)&&baseArr.forEach(item=>{ //PM2d5 不用乘 1000 // item[1] = item[1]=="-9999"?null:falgPro?parseInt(item[1]*1000):initNum[funid](item[1]); item[1] = item[1]=="-9999"?null:initNum[funid](item[1]); }); if(baseArr.length===dayTarget.length){ dayTarget.forEach((item,index)=>{ let time =''; item.time&&(time = item.time.slice(0,2)+':'+item.time.slice(2,4)); let minarea = item[`${this.data.envType}Min`] ? Number(item[`${this.data.envType}Min`].toFixed(1)) : 0; let maxarea = item[`${this.data.envType}Max`] ? Number(item[`${this.data.envType}Max`].toFixed(1)) : 0; let initObj={ time:time, release:index, sales:baseArr[index][1], 标准区间:[minarea,maxarea], } tragetChart.push(initObj); }) } this.setData({tragetChart}) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { options = JSON.parse(decodeURIComponent(JSON.stringify(options))) let {param,name,localname,spaceid,funcid,projectid} = options this.setData({paramName:name,envType:param,localName:localname,spaceId:spaceid,funcid,projectId:projectid}) let that= this; wx.createSelectorQuery().select('.param_list').boundingClientRect(function(rect){ that.setData({'tableHight':rect.height}) }).exec() this.getChartDate(); }, })