index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. month=month<10?('0'+month):month;
  96. let today = day.getDate();
  97. today=today<10?('0'+today):today;
  98. const data={
  99. projectId:$.store.get('projectId')||$.storage.get('projectId'),
  100. dateTiime:`${year}${month}${today}`
  101. }
  102. let res = await getTransfrom(data);
  103. let {seasonType,type} = (res.content&&res.content[0])||{seasonType:'Warm',type:2};
  104. this.setData({seasonType:seasonType,seasonNum:type},()=>{
  105. let that= this;
  106. wx.createSelectorQuery().select('.param_list').boundingClientRect(function(rect){
  107. that.setData({'tableHight':rect.height})
  108. }).exec()
  109. })
  110. if(seasonType==="Transition"){
  111. // 3 供冷-供暖
  112. if(type==3){
  113. this.data.envLevel[this.data.envType+seasonType+'cold'].forEach(item=>{
  114. levelList.push(item.min)
  115. })
  116. this.setData({'envLevel.temperatureTransition':this.data.envLevel.temperatureTransitioncold});
  117. }
  118. // 4 供暖-供冷
  119. if(type==4){
  120. this.data.envLevel[this.data.envType+seasonType].forEach(item=>{
  121. levelList.push(item.min)
  122. })
  123. }
  124. }else{
  125. this.data.envLevel[this.data.envType+seasonType].forEach(item=>{
  126. levelList.push(item.min)
  127. })
  128. }
  129. }else{
  130. this.data.envLevel[this.data.envType].forEach(item=>{
  131. levelList.push(item.min)
  132. })
  133. }
  134. levelList.push(Number(avg))
  135. let valueIndex = levelList.sort((a,b)=>{return a-b}).findIndex(item=>item===avg);
  136. valueIndex = valueIndex<0?0:valueIndex;
  137. console.log(valueIndex,levelList,"valueIndex")
  138. this.setData({pointerTop:38*valueIndex});
  139. },
  140. initChartdate(propertyData,dayTarget){
  141. if(!Array.isArray(propertyData)||!Array.isArray(dayTarget)){
  142. return ;
  143. }
  144. // 目标 { time: "1951",release:0, sales: 38,标准区间: [ 25, 45 ] },
  145. let baseArr=propertyData&&propertyData.slice(1) || [];
  146. let tragetChart = [];
  147. let initNum={
  148. PM2d5:function(value){
  149. // if(this.data.projectId==="Pj1101080259"){
  150. // return parseInt(1000*value)
  151. // }
  152. return parseInt(value)
  153. },
  154. Tdb:function(value){
  155. return Number(Number(value).toFixed(1))
  156. },
  157. RH:function(value){
  158. return parseInt(value)
  159. },
  160. CO2:function(value){
  161. return parseInt(value)
  162. },
  163. HCHO:function(value){
  164. return Number(Number(value).toFixed(2))
  165. }
  166. }
  167. let funid = this.data.funcid;
  168. let specialProject=$.store.get("specialProject");
  169. let falgPro = (funid==="PM2d5"&&specialProject.includes(this.data.projectId));
  170. (baseArr.length>1)&&baseArr.forEach(item=>{
  171. item[1] = item[1]=="-9999"?null:falgPro?parseInt(item[1]*1000):initNum[funid](item[1]);
  172. });
  173. if(baseArr.length===dayTarget.length){
  174. dayTarget.forEach((item,index)=>{
  175. let time ='';
  176. item.time&&(time = item.time.slice(0,2)+':'+item.time.slice(2,4));
  177. let minarea = Number(item[`${this.data.envType}Min`].toFixed(1));
  178. let maxarea = Number(item[`${this.data.envType}Max`].toFixed(1));
  179. let initObj={
  180. time:time,
  181. release:index,
  182. sales:baseArr[index][1],
  183. 标准区间:[minarea,maxarea],
  184. }
  185. tragetChart.push(initObj);
  186. })
  187. }
  188. this.setData({tragetChart})
  189. },
  190. /**
  191. * 生命周期函数--监听页面加载
  192. */
  193. onLoad: function (options) {
  194. options = JSON.parse(decodeURIComponent(JSON.stringify(options)))
  195. let {param,name,localname,spaceid,funcid,projectid} = options
  196. this.setData({paramName:name,envType:param,localName:localname,spaceId:spaceid,funcid,projectId:projectid})
  197. let that= this;
  198. wx.createSelectorQuery().select('.param_list').boundingClientRect(function(rect){
  199. that.setData({'tableHight':rect.height})
  200. }).exec()
  201. this.getChartDate();
  202. },
  203. })