index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. import $ from './../../utils/Tool'
  2. import router from './../../utils/router'
  3. import {getSetting,getLocation} from './../../utils/auth'
  4. const AUTH = require('../../utils/auth')
  5. import icons from "../../utils/icon"
  6. import {getPropertyData,submitAdjust,getCurrentSeason} from '../../requests/api';
  7. import Toast from '../../vant-weapp/dist/toast/toast';
  8. import {
  9. userCheck,
  10. powerCheck,
  11. getEquipmentAction,
  12. getfeedBack,
  13. getSpacedetail,
  14. openSpace,
  15. workLeave,
  16. contactTenant
  17. } from "../../requests/api";
  18. let timer=null;
  19. Page({
  20. /**
  21. * 页面的初始数据
  22. */
  23. data: {
  24. spaceDetail:null,
  25. effectTime:-1,
  26. statusList: icons.statusList,
  27. spacestatusList:icons.spacestatusList,
  28. spaceStatus: "",
  29. spaceStatusId:null,
  30. tempType: [
  31. {
  32. id: 1,
  33. value: "有点冷",
  34. checked: false,
  35. imgSrc: "../../static/images/cold.png"
  36. },
  37. {
  38. id: 3,
  39. value: "有点热",
  40. checked: false,
  41. imgSrc: "../../static/images/hot.png"
  42. },
  43. {
  44. id: 2,
  45. value: "太冷了",
  46. checked: false,
  47. imgSrc: "../../static/images/severityCold.png"
  48. },
  49. {
  50. id: 4,
  51. value: "太热了",
  52. checked: false,
  53. imgSrc: "../../static/images/severityHot.png"
  54. },
  55. ],
  56. windType: [{
  57. id: 5,
  58. value: '风太大',
  59. checked: false,
  60. imgSrc: "../../static/images/severityWind.png"
  61. }],
  62. windTypeValue:-1,
  63. tempTypeValue:-1,
  64. currentIndex:-1,
  65. StandardMode:true, //模式选择
  66. envNamelist:$.store.get("envNamelist"),
  67. imgbaseUrl:$.store.get("imgbaseUrl"),
  68. headerShow:false,
  69. pageHight:0,
  70. guideInit:false,
  71. guideStep:1,
  72. longitude:null,
  73. latitude:null,
  74. feedBack:false, //控制反馈弹窗
  75. targetTemp:null,
  76. trunAction:false,
  77. equipmentStatustext:'',
  78. equipmentStatus:null,
  79. willAvg:null,
  80. tragetChart:[],
  81. tragetChartcopy:[],
  82. customPlan:[],
  83. customPlancopy:null,
  84. planTemp:null,
  85. trunupAction:false, //开机提示框
  86. secondIcon:0,
  87. secondSpaceStatus:null,
  88. chartIndex:null,
  89. targetIndex:0,
  90. singleOffice:false,
  91. nextOpenTime:'',
  92. bgSeasonType:null,
  93. havePower:{
  94. result:"fail",
  95. message:""
  96. },
  97. picInitUrl:$.store.get("picInitUrl"),
  98. },
  99. goBack(){
  100. router.pop()
  101. },
  102. changeMode(){
  103. if(this.data.spaceDetail.isClose.toString()!=="true"){
  104. this.setData({StandardMode:!this.data.StandardMode},()=>{
  105. if(!this.data.StandardMode){
  106. this.setData({effectTime:-1})
  107. this.getChartDate();
  108. }
  109. })
  110. }
  111. },
  112. toDetail(e){
  113. if(Object.keys(e.currentTarget.dataset).length){
  114. router.push("detail",e.currentTarget.dataset)
  115. }else{
  116. router.push("detail",{name:"温度",
  117. localname:"温度",
  118. param:"temperature",
  119. funcid:"Tdb",
  120. spaceid:this.data.spaceDetail.id,
  121. projectid:this.data.spaceDetail.projectId})
  122. }
  123. },
  124. checkLevel(value,name){
  125. let objList={
  126. humidity:{
  127. range:[30,70],
  128. text:["干燥","适宜","湿润"]
  129. },
  130. co2:{
  131. range:[800,1500],
  132. text:["适宜","偏高","超标"]
  133. },
  134. pm25:{
  135. range:[35,75],
  136. text:["优","良","差"]
  137. },
  138. hcho:{
  139. range:[0.05,0.08],
  140. text:["适宜","偏高","超标"]
  141. }
  142. };
  143. value =Number(value)
  144. let sortArr=[value,...objList[name].range].sort((a,b)=>{return a-b});
  145. let level=sortArr.findIndex(item=>item===value);
  146. let levelTxt = objList[name].text[level];
  147. return {level,levelTxt}
  148. },
  149. // 检查是否过引导
  150. checkGuide(){
  151. if(this.data.spaceDetail.isClose.toString()=="true"){
  152. return
  153. }
  154. !$.storage.get('guideInit')&&this.getPageheight();
  155. this.setData({'guideInit':!$.storage.get('guideInit')})
  156. },
  157. // 反馈数据
  158. changeType(e) {
  159. if(this.data.bgSeasonType=="Transition"){
  160. wx.showModal({
  161. title: '现在是过渡季不可调节',
  162. showCancel: false,
  163. confirmText:"我知道了",//默认是“确定”
  164. // confirmColor: 'skyblue',//确定文字的颜色
  165. success: function (res) {
  166. },
  167. fail: function (res) { },//接口调用失败的回调函数
  168. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  169. })
  170. return ;
  171. }
  172. if(this.data.havePower.result!=="success"){
  173. Toast.fail(this.data.havePower.message);
  174. return
  175. }
  176. var currentIndex = e.currentTarget.dataset.index;
  177. if (e.currentTarget.dataset.type === "temp") {
  178. this.setData({
  179. tempTypeValue: currentIndex,
  180. currentIndex:currentIndex,
  181. feedBack:true
  182. });
  183. } else {
  184. this.setData({
  185. windTypeValue: currentIndex,
  186. currentIndex:currentIndex,
  187. feedBack:true
  188. });
  189. }
  190. let data = {
  191. "projectId":this.data.spaceDetail.projectId, //项目id
  192. "objectId": this.data.spaceDetail.id, //空间id
  193. "valueType": 1, //固定为1
  194. "itemId": currentIndex,
  195. "model":this.data.StandardMode?1:2,
  196. userId:$.store.get('userId')
  197. }
  198. getEquipmentAction(data).then(res => {
  199. this.setData({
  200. equipmentStatus: res.equipmentStatus
  201. });
  202. let textMsg = "";
  203. let textMsgarr=[];
  204. this.data.equipmentStatus.forEach(item => {
  205. if (item.actions) {
  206. item.actions.forEach(items => {
  207. let textMsgobj={};
  208. textMsgobj.name=item.localName;
  209. textMsgobj.actions=items;
  210. textMsgarr.push(textMsgobj);
  211. textMsg = textMsg + item.localName + '--' + items + ' ';
  212. })
  213. }
  214. })
  215. this.setData({
  216. equipmentStatustext: textMsgarr
  217. });
  218. })
  219. getfeedBack(data).then(res => {
  220. let notice = res.notice ? res.notice.split('。') : [];
  221. this.setData({
  222. spaceStatus: res.spaceStatus,
  223. spaceStatusId: res.icon - 1,
  224. notice: notice,
  225. willAvg:res.avg||'--',
  226. });
  227. this.buildContact();
  228. })
  229. },
  230. // 建立租户关联
  231. async buildContact(){
  232. let currentTenantId=$.storage.get('tenantId');
  233. if(currentTenantId!==this.data.spaceDetail.tenantId){
  234. // 通过扫码改变租户
  235. $.store.set('projectId',this.data.spaceDetail.projectId);
  236. $.store.set('tenantId',this.data.spaceDetail.tenantId);
  237. $.store.set('changeTenantId',true);
  238. $.storage.set('projectId',this.data.spaceDetail.projectId);
  239. $.storage.set('tenantId',this.data.spaceDetail.tenantId);
  240. }
  241. let top = (this.data.spaceDetail.top.toString())=="false"?0:1;
  242. const data={
  243. "userId":$.store.get('userId'),//用户id
  244. "projectId":this.data.spaceDetail.projectId,//项目id
  245. "spaceId":this.data.spaceDetail.id,//空间id
  246. "openId":$.store.get('openId'),
  247. flag:1,
  248. top:top,
  249. }
  250. console.log(this.data.spaceDetail.top,"this.data.spaceDetail.top?")
  251. await contactTenant(data).then(res=>{
  252. console.log("成功")
  253. })
  254. },
  255. // 下班节能
  256. turnDown(){
  257. if(this.data.havePower.result!=="success"){
  258. Toast.fail(this.data.havePower.message);
  259. return
  260. }
  261. let data = {
  262. model:1,
  263. "projectId":this.data.spaceDetail.projectId, //项目id
  264. "objectId":[this.data.spaceDetail.id], //空间id
  265. userId:$.store.get('userId'),
  266. nextOpenTime:this.data.spaceDetail.nextOpenTime||"",
  267. }
  268. workLeave(data).then(res=>{
  269. this.setData({trunAction:true});
  270. this.buildContact();
  271. })
  272. },
  273. // 重新开启
  274. turnUp(){
  275. if(this.data.havePower.result!=="success"){
  276. Toast.fail(this.data.havePower.message);
  277. return
  278. }
  279. let data = {
  280. "projectId":this.data.spaceDetail.projectId, //项目id
  281. "objectId": this.data.spaceDetail.id, //空间id
  282. model:1,
  283. userId:$.store.get('userId')
  284. }
  285. openSpace(data).then(res=>{
  286. this.setData({
  287. secondSpaceStatus: res.spaceStatus,
  288. secondNotice: res.notice,
  289. secondIcon: res.icon,
  290. trunupAction: true
  291. });
  292. this.buildContact();
  293. })
  294. },
  295. commitClose(){
  296. this.setData({trunupAction:false},()=>{
  297. this.isfeeded(true);
  298. this.getDetail();
  299. })
  300. },
  301. knowClick(){
  302. this.setData({feedBack:false,tempTypeValue:-1,windTypeValue:-1,},()=>{
  303. this.isfeeded();
  304. });
  305. },
  306. knowCloseClick(){
  307. this.setData({feedBack:false,trunAction:false},()=>{
  308. this.getDetail();
  309. this.isfeeded(true);
  310. });
  311. },
  312. // 获取容器高度
  313. getPageheight:function(){
  314. let that =this;
  315. wx.createSelectorQuery().select('#j_page').boundingClientRect(function(rect){
  316. that.setData({'pageHight':rect.height})
  317. }).exec()
  318. },
  319. //使页面滚动到容器底部
  320. pageScrollToBottom: function() {
  321. wx.pageScrollTo({
  322. scrollTop: this.data.pageHight
  323. })
  324. },
  325. // 步骤引导函数
  326. nextStep(e){
  327. if(this.data.guideStep==2){
  328. $.storage.set('guideInit',true);
  329. this.setData({'guideInit':false})
  330. }
  331. this.setData({'guideStep':2})
  332. this.pageScrollToBottom();
  333. },
  334. async isGetSetting(value) {
  335. let {authSetting} = await getSetting();
  336. if(authSetting['scope.userLocation']){
  337. await this.getUserLocation();
  338. }else{
  339. wx.showModal({
  340. title: '是否授权当前位置',
  341. content: '需要获取您的地理位置,请确认授权',
  342. confirmColor: '#f16765',
  343. success: res => {
  344. if (res.confirm) {
  345. wx.openSetting({
  346. success: async data => {
  347. await this.getUserLocation();
  348. value&&this.checkPower();
  349. },
  350. })
  351. } else {
  352. this.setData({havePower: {result: "fail",message: "未定位到您的位置"}})
  353. }
  354. }
  355. })
  356. }
  357. },
  358. // 获取位置信息
  359. async getUserLocation(cb) {
  360. var that = this;
  361. let {latitude,longitude} = await getLocation();
  362. this.setData({latitude,longitude});
  363. },
  364. // 是否有操作权限
  365. async checkPower() {
  366. await this.isGetSetting('cb');
  367. const data = {
  368. "criteria": {
  369. "projectId":this.data.spaceDetail.projectId,
  370. "spaceId": this.data.spaceDetail.id,
  371. "userId": $.store.get('userId'),
  372. "tenantId": this.data.spaceDetail.tenantId,
  373. "longitude": this.data.longitude,
  374. "latitude": this.data.latitude
  375. }
  376. };
  377. await powerCheck(data).then(res => {
  378. this.setData({
  379. havePower: res
  380. })
  381. })
  382. },
  383. // 获取实时曲线
  384. async getChartDate(){
  385. wx.showLoading({
  386. title:"加载中"
  387. });
  388. let data={
  389. projectId:this.data.spaceDetail.projectId,
  390. spaceId:this.data.spaceDetail.id,
  391. funcid:'Tdb'
  392. }
  393. let res = await getPropertyData(data);
  394. if(!res){
  395. throw "网络错误";
  396. }
  397. let {propertyData,dayTarget}=res;
  398. // 获取期望温度
  399. this.getHopeTemp(dayTarget).then(()=>{
  400. this.initDaytarget(dayTarget);
  401. this.initChartdate(propertyData,dayTarget);
  402. });
  403. wx.hideLoading();
  404. },
  405. initChartdate(propertyData,dayTarget){
  406. if(!propertyData&&!propertyData.length&&dayTarget&&!dayTarget.length){
  407. return ;
  408. }
  409. // 目标 { time: "1951",release:0, sales: 38,标准区间: [ 25, 45 ] },
  410. let baseArr=propertyData&&propertyData.slice(1) || [];
  411. let tragetChart = [];
  412. baseArr.forEach(item=>{
  413. item[1] = (item[1]=="-9999")?null:item[1];
  414. })
  415. if(baseArr.length===dayTarget.length){
  416. dayTarget.forEach((item,index)=>{
  417. let time ='';
  418. item.time&&(time = item.time.slice(0,2)+':'+item.time.slice(2,4));
  419. item['temperatureMin']&&(item['temperatureMin']=Number(item['temperatureMin'].toFixed(1)));
  420. item['temperatureMax']&&(item['temperatureMax']=Number(item['temperatureMax'].toFixed(1)));
  421. let initObj={
  422. time:time,
  423. release:index,
  424. sales:baseArr[index][1],
  425. 标准区间:[item['temperatureMin'],item['temperatureMax']],
  426. }
  427. tragetChart.push(initObj);
  428. })
  429. }
  430. this.setData({tragetChart,tragetChartcopy:tragetChart})
  431. },
  432. initDaytarget(value){
  433. if(!value||!value.length){
  434. return
  435. }
  436. let customPlan=[];
  437. // 格式化单位 15px为1度 28 18
  438. let lenpx=25;
  439. value.forEach((item,index)=>{
  440. if(item.time.slice(2,6)=="0000"){
  441. let obj={};
  442. obj.time=item.date+item.time;
  443. obj.id=index;
  444. obj.name=item.time.slice(0,2)+':'+item.time.slice(2,4);
  445. obj.maxValue= item.temperatureMax;
  446. obj.minValue = item.temperatureMin || 0;
  447. obj.distance=(obj.maxValue-obj.minValue)|| 0;
  448. obj.height=obj.distance*lenpx;
  449. obj.planTemp=Number(((obj.maxValue+obj.minValue)/2).toFixed(1));
  450. obj.y=(28 - obj.maxValue)*lenpx;
  451. customPlan.push(obj)
  452. }
  453. })
  454. this.setData({customPlancopy:this.copyobj(customPlan)})
  455. },
  456. getHopeTemp(value){
  457. return new Promise((reslove,reject)=>{
  458. if(!value||!value.length){
  459. return
  460. }
  461. let data=new Date();
  462. let hour = data.getHours();
  463. let min = data.getMinutes();
  464. let minIndex = Math.floor(min/15);
  465. if(minIndex>=3){
  466. hour = hour + 1;
  467. min = 0;
  468. }else{
  469. min = (minIndex+1)*15;
  470. }
  471. let targetTime = (hour>=10?`${hour}`:`0${hour}`)+(min>=10?`${min}`:`0${min}`);
  472. let isDatelist=[];
  473. let targetTemp;
  474. let targetIndex;
  475. value.forEach((item,index)=>{
  476. if(item.temperatureMax&&item.temperatureMin){
  477. isDatelist.push(index)
  478. }
  479. if(item.time===`${targetTime}00`){
  480. targetTemp= parseInt((item.temperatureMax + item.temperatureMin)/2);
  481. targetIndex = index
  482. }
  483. })
  484. if(targetTemp){
  485. this.setData({targetTemp:targetTemp,targetIndex:targetIndex})
  486. }else{
  487. let index = isDatelist.pop();
  488. targetTemp = parseInt((value[index].temperatureMax + value[index].temperatureMin)/2);
  489. this.setData({targetTemp:targetTemp,targetIndex:targetIndex})
  490. }
  491. reslove();
  492. })
  493. // 获取当前时间最近的15分钟
  494. },
  495. // 更改即时调节选项
  496. effectChange(event){
  497. this.setData({
  498. effectTime: event.detail,
  499. },()=>{
  500. let changeDate=JSON.parse(JSON.stringify(this.data.tragetChartcopy));
  501. if(event.detail==='1'){
  502. let len = (this.data.targetIndex+8)>changeDate.length?changeDate.length:(this.data.targetIndex+8)
  503. for(var i=this.data.targetIndex;i<len;i++){
  504. changeDate[i].sales = this.data.targetTemp;
  505. changeDate[i]['标准区间'] =[changeDate[i].sales-1,changeDate[i].sales+1];
  506. }
  507. }else if(event.detail==='2'){
  508. let len = changeDate.length;
  509. for(var i=this.data.targetIndex;i<len;i++){
  510. changeDate[i].sales = this.data.targetTemp;
  511. changeDate[i]['标准区间'] =[changeDate[i].sales-1,changeDate[i].sales+1];
  512. }
  513. }else{
  514. let len = (this.data.targetIndex+4)>changeDate.length?changeDate.length:(this.data.targetIndex+4);
  515. let start = (this.data.targetIndex-4)<0?0:(this.data.targetIndex-4);
  516. for(var i=start;i<len;i++){
  517. changeDate[i].sales = this.data.targetTemp;
  518. changeDate[i]['标准区间'] =[changeDate[i].sales-1,changeDate[i].sales+1];
  519. }
  520. }
  521. this.setData({tragetChart:changeDate});
  522. });
  523. },
  524. // 加期望温度
  525. addClick(){
  526. let tepNum=this.data.targetTemp;
  527. let firstNum = tepNum.toString().split('.')[0];
  528. let lastNum = tepNum.toString().split('.')[1];
  529. if(firstNum>=28){
  530. return
  531. }
  532. if(lastNum>=5){
  533. this.setData({targetTemp:Number(firstNum)+1})
  534. }else{
  535. this.setData({targetTemp:Number(firstNum)+0.5})
  536. }
  537. },
  538. // 减期望温度
  539. minusClick(){
  540. let tepNum=this.data.targetTemp;
  541. let firstNum = tepNum.toString().split('.')[0]
  542. let lastNum = tepNum.toString().split('.')[1]
  543. if(firstNum<=18&&!lastNum){
  544. return ;
  545. }
  546. if(lastNum>5){
  547. this.setData({targetTemp:Number(firstNum)+0.5})
  548. }else if(lastNum<=5){
  549. this.setData({targetTemp:Number(firstNum)})
  550. }else{
  551. this.setData({targetTemp:Number(firstNum)-0.5})
  552. }
  553. },
  554. // 修改期望温度
  555. taboneSubmit(){
  556. if(this.data.havePower.result!=="success"){
  557. Toast.fail(this.data.havePower.message);
  558. return
  559. }
  560. if(!this.data.effectTime||this.data.effectTime<0){
  561. wx.showToast({
  562. title:"未选择保持时间",
  563. icon:"none",
  564. duration: 1500
  565. })
  566. return
  567. }
  568. const data={
  569. "projectId": this.data.spaceDetail.projectId,
  570. "objectId": this.data.spaceDetail.id,
  571. "valueType": 2,
  572. "model":2,
  573. "durationType":this.data.effectTime || '',
  574. "value":this.data.targetTemp
  575. }
  576. submitAdjust(data).then(async res=>{
  577. if(res.result="success"){
  578. wx.hideLoading();
  579. setTimeout(function () {
  580. wx.showToast({
  581. title:"提交成功",
  582. duration: 2000
  583. })
  584. }, 300)
  585. }
  586. // this.setData({effectTime:-1})
  587. await this.buildContact();
  588. this.isfeeded();
  589. // this.getChartDate();
  590. })
  591. },
  592. // 修改全天温度
  593. tabtwoSubmit(){
  594. if(this.data.havePower.result!=="success"){
  595. Toast.fail(this.data.havePower.message);
  596. return
  597. }
  598. let customPlan = JSON.parse(JSON.stringify(this.data.customPlan));
  599. customPlan.forEach(item=>{
  600. delete item.id;
  601. delete item.name;
  602. delete item.planTemp;
  603. delete item.y;
  604. delete item.height;
  605. delete item.distance;
  606. })
  607. const data={
  608. "projectId": this.data.spaceDetail.projectId,
  609. "objectId": this.data.spaceDetail.id,
  610. "valueType": 3,
  611. "model":2,
  612. "value":this.data.targetTemp,
  613. "customPlan":customPlan
  614. }
  615. submitAdjust(data).then(async res=>{
  616. wx.hideLoading();
  617. setTimeout(function () {
  618. wx.showToast({
  619. title:"提交成功",
  620. duration: 2000
  621. })
  622. }, 300)
  623. await this.buildContact();
  624. this.isfeeded();
  625. // this.getChartDate();
  626. })
  627. },
  628. showTips(){
  629. wx.showModal({
  630. title: '提示',
  631. content: '非工作时间如需使用空调,或遇特殊问题,请联系环境管理员',
  632. showCancel:false,
  633. success: function (res) {
  634. }
  635. })
  636. },
  637. chartChange(e){
  638. let y =e.detail.y;
  639. this.throttle(this.updateChart(y,e),500)
  640. },
  641. preventTouchMove: function () {
  642. return
  643. },
  644. updateChart(y,e){
  645. let lenpx=25;
  646. let planTempMax = 28 - y/lenpx;
  647. let {index,distance} =e.currentTarget.dataset;
  648. let planTemp = Number(((planTempMax*2 - distance)/2).toFixed(1));
  649. let target=`customPlan[${index}].y`;
  650. let targetplan=`customPlan[${index}].planTemp`;
  651. let targetTempMax=`customPlan[${index}].maxValue`;
  652. let targetTempMin=`customPlan[${index}].minValue`;
  653. this.setData({[target]:y,[targetplan]:planTemp,chartIndex:index,[targetTempMax]:planTempMax,[targetTempMin]:planTempMax-2});
  654. },
  655. throttle(func, delay) {
  656. let prev = Date.now();
  657.   return function() {
  658. let context = this;
  659. let args = arguments;
  660. let now = Date.now();
  661.     if (now - prev >= delay) {
  662.       func.apply(context, args);
  663.       prev = Date.now();
  664.     }
  665.   }
  666. },
  667. fillZore(value) {
  668. if (value < 10) {
  669. value = 0 + value
  670. }
  671. return value
  672. },
  673. formatTimeall(value) {
  674. let stringValue;
  675. const date = new Date();
  676. var nowMonth = date.getMonth() + 1;
  677. let nowDay = date.getDate();
  678. let torrowDay = new Date(date);
  679. torrowDay.setDate(date.getDate() + 1);
  680. let torrowMonth = torrowDay.getMonth() + 1;
  681. nowDay = this.fillZore(nowDay);
  682. nowMonth = this.fillZore(nowMonth);
  683. torrowMonth = this.fillZore(torrowMonth);
  684. if (nowMonth == value.substring(4, 6) || torrowMonth == value.substring(4, 6)) {
  685. if (value.substring(6, 8) == nowDay) {
  686. stringValue = "今日"
  687. }
  688. let torrowVlue = torrowDay.getDate();
  689. torrowVlue = this.fillZore(torrowVlue);
  690. if (value.substring(6, 8) == torrowVlue) {
  691. stringValue = "明日"
  692. }
  693. }
  694. if (stringValue) {
  695. stringValue = stringValue + `${value.substring(8,10)}:${value.substring(10,12)}`
  696. } else {
  697. stringValue = `${value.substring(4,6)}月${value.substring(6,8)}日${value.substring(8,10)}:${value.substring(10,12)}`
  698. }
  699. return stringValue
  700. },
  701. isfeeded(value){
  702. !value&&router.pop();
  703. },
  704. copyobj(a){
  705. var c={};
  706. c=JSON.parse(JSON.stringify(a));
  707. return c;
  708. },
  709. tabChange(event){
  710. let that = this;
  711. if(event.detail.name==1){
  712. that.setData({customPlan:null,chartIndex:null},()=>{
  713. that.setData({customPlan:this.copyobj(this.data.customPlancopy)})
  714. })
  715. }else{
  716. this.setData({effectTime:-1})
  717. this.getChartDate();
  718. }
  719. },
  720. getnowSeason(){
  721. let day = new Date();
  722. let year = day.getFullYear();
  723. let month = day.getMonth() + 1;
  724. let today = day.getDate();
  725. const data={
  726. projectId:this.data.spaceDetail.projectId,
  727. date:`${year}${month}${today}`
  728. }
  729. getCurrentSeason(data).then(res=>{
  730. if(res.result=="success"){
  731. this.setData({bgSeasonType:res.data})
  732. }
  733. })
  734. },
  735. /**
  736. * 生命周期函数--监听页面加载
  737. */
  738. onLoad: function (options) {
  739. options = JSON.parse(decodeURIComponent(JSON.stringify(options)));
  740. if(options.md1){
  741. this.getDetail(options.md1);
  742. }else{
  743. options.humidity&&(options.humiditylevel = this.checkLevel(options.humidity,"humidity"));
  744. options.co2&&(options.co2level = this.checkLevel(options.co2,"co2"));
  745. options.pm25&&(options.pm25level = this.checkLevel(options.pm25,"pm25"));
  746. options.hcho&&(options.hcholevel = this.checkLevel(options.hcho,"hcho"));
  747. this.setData({spaceDetail:options},()=>{
  748. this.checkGuide();
  749. this.getnowSeason();
  750. let higthSpace=["311","312"];
  751. if(this.data.spaceDetail.roomFuncType&&higthSpace.includes(this.data.spaceDetail.roomFuncType)){
  752. this.setData({singleOffice:true})
  753. }
  754. this.checkPower();
  755. })
  756. }
  757. },
  758. async getDetail(value){
  759. let data;
  760. if(value){
  761. let projectId = 'Pj' + value.substring(2, 12);
  762. this.setData({spaceId:value,projectId:projectId});
  763. data= {
  764. criteria: {
  765. "spaceId": value,
  766. "userId": $.store.get('userId')||$.storage.get('userId'),
  767. "projectId": projectId
  768. }
  769. }
  770. }else{
  771. data= {
  772. criteria: {
  773. "spaceId": this.data.spaceDetail.id,
  774. "userId": $.store.get('userId')||$.storage.get('userId'),
  775. "projectId": this.data.spaceDetail.projectId
  776. }
  777. }
  778. }
  779. wx.showLoading();
  780. let res = await getSpacedetail(data);
  781. wx.hideLoading();
  782. let {content} = res;
  783. if(content){
  784. (content[0].humidity||content[0].humidity==0)&&(content[0].humiditylevel = this.checkLevel(content[0].humidity,"humidity"));
  785. (content[0].co2||content[0].co2==0)&&(content[0].co2level = this.checkLevel(content[0].co2,"co2"));
  786. (content[0].pm25||content[0].pm25==0)&&(content[0].pm25level = this.checkLevel(content[0].pm25,"pm25"));
  787. (content[0].hcho||content[0].hcho==0)&&(content[0].hcholevel = this.checkLevel(content[0].hcho,"hcho"));
  788. }
  789. this.setData({spaceDetail:content[0]},()=>{
  790. this.checkGuide();
  791. this.getnowSeason();
  792. // if(this.data.spaceDetail.nextOpenTime){
  793. // let value = this.formatTimeall(this.data.spaceDetail.nextOpenTime);
  794. // this.setData({nextOpenTime:value})
  795. // }
  796. if(this.data.spaceDetail.roomFuncType&&this.data.spaceDetail.roomFuncType.startsWith("31")){
  797. this.setData({singleOffice:true})
  798. }
  799. });
  800. $.storage.get("wxqcode")&&$.storage.set("wxqcode",'');
  801. // 判断是否可以调节
  802. await this.checkPower();
  803. },
  804. /**
  805. * 生命周期函数--监听页面初次渲染完成
  806. */
  807. onReady: function () {
  808. setTimeout(()=>{
  809. this.setData({'headerShow':true})
  810. },500)
  811. },
  812. })