index.js 7.5 KB

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