index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import $ from './../../utils/Tool';
  2. import router from './../../utils/router';
  3. import {
  4. getPropertyData,getCurrentSeason,getTransfrom
  5. } from "../../requests/api";
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. envLevel:{
  12. temperatureWarm:[
  13. {name:"偏冷",value:"18-21°C",min:18,active:true},
  14. {name:"舒适",value:"22-24°C",min:22,active:true},
  15. {name:"偏热",value:"25-27°C",min:25,active:true},
  16. ],
  17. temperatureCooling:[
  18. {name:"偏冷",value:"21-23°C",min:21,active:true},
  19. {name:"舒适",value:"24-26°C",min:24,active:true},
  20. {name:"偏热",value:"26-28°C",min:26,active:true},
  21. ],
  22. temperatureTransition:[
  23. {name:"舒适",value:'',min:0,active:true},
  24. {name:"偏热",value:"26°C以上",min:26,active:true},
  25. ],
  26. temperatureTransitioncold:[
  27. {name:"偏冷",value:"18°C以下",min:-10,active:true},
  28. {name:"舒适",value:"",min:18,active:true},
  29. ],
  30. humidity:[
  31. {name:"",value:"0-35%",min:0,active:true},
  32. {name:"",value:"35-45%",min:35},
  33. {name:"适宜",value:"45-55%",min:45},
  34. {name:"",value:"55-65%",min:55,active:true},
  35. {name:"",value:"65-95%",min:65,active:true},
  36. {name:"",value:"95-100%",min:95,active:true},
  37. ],
  38. co2:[
  39. {name:"",value:"0-450ppm",min:0},
  40. {name:"合理范围",value:"450-700ppm",min:450},
  41. {name:"",value:"700-1000ppm",min:700,active:true},
  42. {name:"",value:"1000-2500ppm",min:1000,active:true},
  43. {name:"",value:"2500-5000ppm",min:2500,active:true}
  44. ],
  45. pm25:[
  46. {name:"优",value:"0~35μg/m³",min:0,active:true},
  47. {name:"良",value:"35~75μg/m³",min:35,active:true},
  48. {name:"轻度污染",value:"75~115μg/m³",min:75,active:true},
  49. {name:"中度污染",value:"115~150μg/m³",min:115,active:true},
  50. {name:"重度污染",value:"150~250μg/m³",min:150,active:true},
  51. {name:"严重污染",value:"大于250μg/m³及以上",min:250,active:true},
  52. ],
  53. hcho:[
  54. {name:"",value:"0-0.05mg/m³",min:0},
  55. {name:"合理范围",value:"0.05-0.08mg/m³",min:0.05},
  56. {name:"",value:"0.08-0.1mg/m³",min:0.08,active:true},
  57. {name:"",value:"0.1-0.15mg/m³",min:0.1,active:true},
  58. {name:"",value:"0.15-0.2mg/m³",min:0.15,active:true}
  59. ],
  60. },
  61. paramName:'',
  62. envType:'',
  63. localName:'',
  64. envValue:"",
  65. tableHight:null,
  66. pointerTop:0,
  67. funcid:"",
  68. spaceId:"",
  69. projectId:"",
  70. tragetChart:[],
  71. seasonType:''
  72. },
  73. goBack(){
  74. router.pop()
  75. },
  76. async getChartDate(){
  77. let data={
  78. projectId:this.data.projectId,
  79. spaceId:this.data.spaceId,
  80. funcid:this.data.funcid
  81. }
  82. $.loading();
  83. let res = await getPropertyData(data);
  84. $.hideLoading();
  85. if(!res){
  86. throw "网络错误";
  87. }
  88. let {avg,propertyData,dayTarget}=res;
  89. this.initChartdate(propertyData,dayTarget);
  90. let levelList=[];
  91. if(this.data.envType=="temperature"){
  92. let day = new Date();
  93. let year = day.getFullYear();
  94. let month = day.getMonth() + 1;
  95. let today = day.getDate();
  96. const data={
  97. projectId:$.store.get('projectId')||$.storage.get('projectId'),
  98. dateTiime:`${year}${month}${today}`
  99. }
  100. let res = await getTransfrom(data);
  101. let {seasonType,type} = (res.content&&res.content[0])||{seasonType:'Warm',type:2};
  102. this.setData({seasonType:seasonType,seasonNum:type},()=>{
  103. let that= this;
  104. wx.createSelectorQuery().select('.param_list').boundingClientRect(function(rect){
  105. that.setData({'tableHight':rect.height})
  106. }).exec()
  107. })
  108. if(seasonType==="Transition"){
  109. // 3 供冷-供暖
  110. if(type==3){
  111. this.data.envLevel[this.data.envType+seasonType+'cold'].forEach(item=>{
  112. levelList.push(item.min)
  113. })
  114. this.setData({'envLevel.temperatureTransition':this.data.envLevel.temperatureTransitioncold});
  115. }
  116. // 4 供暖-供冷
  117. if(type==4){
  118. this.data.envLevel[this.data.envType+seasonType].forEach(item=>{
  119. levelList.push(item.min)
  120. })
  121. }
  122. }else{
  123. this.data.envLevel[this.data.envType+seasonType].forEach(item=>{
  124. levelList.push(item.min)
  125. })
  126. }
  127. }else{
  128. this.data.envLevel[this.data.envType].forEach(item=>{
  129. levelList.push(item.min)
  130. })
  131. }
  132. levelList.push(Number(avg))
  133. let valueIndex = levelList.sort((a,b)=>{return a-b}).findIndex(item=>item===avg);
  134. valueIndex = valueIndex<0?0:valueIndex;
  135. console.log(valueIndex,levelList,"valueIndex")
  136. this.setData({pointerTop:38*valueIndex});
  137. },
  138. initChartdate(propertyData,dayTarget){
  139. if(!Array.isArray(propertyData)||!Array.isArray(dayTarget)){
  140. return ;
  141. }
  142. // 目标 { time: "1951",release:0, sales: 38,标准区间: [ 25, 45 ] },
  143. let baseArr=propertyData&&propertyData.slice(1) || [];
  144. let tragetChart = [];
  145. let falgPro = (this.data.funcid==="PM2d5"&&this.data.projectId==="Pj1101080259");
  146. (baseArr.length>1)&&baseArr.forEach(item=>{
  147. item[1] = item[1]=="-9999"?null:(falgPro?item[1]*1000:item[1]);
  148. });
  149. if(baseArr.length===dayTarget.length){
  150. dayTarget.forEach((item,index)=>{
  151. let time ='';
  152. item.time&&(time = item.time.slice(0,2)+':'+item.time.slice(2,4));
  153. let minarea = Number(item[`${this.data.envType}Min`].toFixed(1));
  154. let maxarea = Number(item[`${this.data.envType}Max`].toFixed(1));
  155. let initObj={
  156. time:time,
  157. release:index,
  158. sales:baseArr[index][1],
  159. 标准区间:[minarea,maxarea],
  160. }
  161. tragetChart.push(initObj);
  162. })
  163. }
  164. this.setData({tragetChart})
  165. },
  166. /**
  167. * 生命周期函数--监听页面加载
  168. */
  169. onLoad: function (options) {
  170. options = JSON.parse(decodeURIComponent(JSON.stringify(options)))
  171. let {param,name,localname,spaceid,funcid,projectid} = options
  172. this.setData({paramName:name,envType:param,localName:localname,spaceId:spaceid,funcid,projectId:projectid})
  173. let that= this;
  174. wx.createSelectorQuery().select('.param_list').boundingClientRect(function(rect){
  175. that.setData({'tableHight':rect.height})
  176. }).exec()
  177. this.getChartDate();
  178. },
  179. })