index.js 27 KB

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