index.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  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. this.setData({
  216. notice: '', // 默认无值
  217. willAvg:'--'
  218. });
  219. if(this.data.bgSeasonType=="Transition"){
  220. wx.showModal({
  221. title: '现在是过渡季不可调节',
  222. showCancel: false,
  223. confirmText:"我知道了",//默认是“确定”
  224. // confirmColor: 'skyblue',//确定文字的颜色
  225. success: function (res) {
  226. },
  227. fail: function (res) { },//接口调用失败的回调函数
  228. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  229. })
  230. return ;
  231. }
  232. if(this.data.havePower.result!=="success"){
  233. Toast.fail(this.data.havePower.message);
  234. return
  235. }
  236. var currentIndex = e.currentTarget.dataset.index;
  237. if (e.currentTarget.dataset.type === "temp") {
  238. this.setData({
  239. tempTypeValue: currentIndex,
  240. currentIndex:currentIndex,
  241. checkType:'temp',
  242. feedBack:true
  243. });
  244. } else {
  245. this.setData({
  246. windTypeValue: currentIndex,
  247. currentIndex:currentIndex,
  248. checkType:'wind',
  249. feedBack:true
  250. });
  251. }
  252. let data = {
  253. "projectId":this.data.spaceDetail.projectId, //项目id
  254. "objectId": this.data.spaceDetail.id, //空间id
  255. "valueType": 1, //固定为1
  256. "itemId": currentIndex,
  257. "model":this.data.StandardMode?1:2,
  258. userId:$.store.get('userId')
  259. }
  260. getEquipmentAction(data).then(res => {
  261. this.setData({
  262. equipmentStatus: res.equipmentStatus
  263. });
  264. let textMsg = "";
  265. let textMsgarr=[];
  266. this.data.equipmentStatus && this.data.equipmentStatus.forEach(item => {
  267. if (item.actions) {
  268. item.actions.forEach(items => {
  269. let textMsgobj={};
  270. textMsgobj.name=item.localName;
  271. textMsgobj.actions=items;
  272. textMsgarr.push(textMsgobj);
  273. textMsg = textMsg + item.localName + '--' + items + ' ';
  274. })
  275. }
  276. })
  277. this.setData({
  278. equipmentStatustext: textMsgarr
  279. });
  280. })
  281. getfeedBack(data).then(res => {
  282. let notice = res.notice ? res.notice.split('。') : [];
  283. this.setData({
  284. spaceStatus: res.spaceStatus || res.message,
  285. spaceStatusId: res.icon - 1,
  286. notice: notice,
  287. willAvg:res.avg||'--',
  288. });
  289. this.buildContact();
  290. })
  291. },
  292. // 建立租户关联
  293. async buildContact(){
  294. // let tenatList=$.store.get("tenants");
  295. let currentTenantId=$.storage.get('tenantId');
  296. // let flag=false;
  297. // if(tenatList&&tenatList.length){
  298. // flag = tenatList.some(item=>{
  299. // return item.tenantId === currentTenantId;
  300. // })
  301. // }
  302. // if(flag){
  303. // return;
  304. // }
  305. if(currentTenantId!==this.data.spaceDetail.tenantId){
  306. // 通过扫码改变租户
  307. $.store.set('projectId',this.data.spaceDetail.projectId);
  308. $.store.set('tenantId',this.data.spaceDetail.tenantId);
  309. $.store.set('changeTenantId',true);
  310. $.storage.set('projectId',this.data.spaceDetail.projectId);
  311. $.storage.set('tenantId',this.data.spaceDetail.tenantId);
  312. }
  313. this.data.spaceDetail.top=(this.data.spaceDetail.top+''==="undefined")?false:this.data.spaceDetail.top;
  314. let top = (this.data.spaceDetail.top.toString())=="false"?0:1;
  315. const data={
  316. "userId":$.store.get('userId'),//用户id
  317. "projectId":this.data.spaceDetail.projectId,//项目id
  318. "spaceId":this.data.spaceDetail.id,//空间id
  319. "openId":$.store.get('openId'),
  320. flag:1,
  321. top:top,
  322. }
  323. await contactTenant(data).then(res=>{
  324. console.log("成功")
  325. })
  326. },
  327. // 下班节能
  328. turnDown(){
  329. if(this.data.havePower.result!=="success"){
  330. Toast.fail(this.data.havePower.message);
  331. return
  332. }
  333. let data = {
  334. model:1,
  335. "projectId":this.data.spaceDetail.projectId, //项目id
  336. "objectId":[this.data.spaceDetail.id], //空间id
  337. userId:$.store.get('userId'),
  338. nextOpenTime:this.data.spaceDetail.nextOpenTime||"",
  339. }
  340. workLeave(data).then(res=>{
  341. // TODO 关
  342. this.setData({trunAction:true,failmessage:res.message || ''});
  343. this.buildContact();
  344. })
  345. },
  346. // 重新开启
  347. turnUp(){
  348. if(this.data.bgSeasonType=="Transition"){
  349. wx.showModal({
  350. title: '现在是过渡季不可调节',
  351. showCancel: false,
  352. confirmText:"我知道了",//默认是“确定”
  353. // confirmColor: 'skyblue',//确定文字的颜色
  354. success: function (res) {
  355. },
  356. fail: function (res) { },//接口调用失败的回调函数
  357. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  358. })
  359. return ;
  360. }
  361. if(this.data.havePower.result!=="success"){
  362. Toast.fail(this.data.havePower.message);
  363. return
  364. }
  365. let data = {
  366. "projectId":this.data.spaceDetail.projectId, //项目id
  367. "objectId": this.data.spaceDetail.id, //空间id
  368. model:1,
  369. userId:$.store.get('userId')
  370. }
  371. openSpace(data).then(res=>{
  372. // TODO kai
  373. // if (res.message) {
  374. // this.setData({failmessage:res.message, trunupAction: true})
  375. // }else{
  376. this.setData({
  377. secondSpaceStatus: res.spaceStatus,
  378. secondNotice: res.notice,
  379. secondIcon: res.icon,
  380. failmessage:res.message || '',
  381. trunupAction: true
  382. });
  383. // }
  384. this.buildContact();
  385. })
  386. },
  387. commitClose(){
  388. this.setData({trunupAction:false},()=>{
  389. this.isfeeded(true);
  390. this.getDetail();
  391. })
  392. },
  393. knowClick(){
  394. this.setData({feedBack:false,tempTypeValue:-1,windTypeValue:-1,},()=>{
  395. this.isfeeded();
  396. });
  397. },
  398. knowCloseClick(){
  399. this.setData({feedBack:false,trunAction:false},()=>{
  400. this.getDetail();
  401. this.isfeeded(true);
  402. });
  403. },
  404. // 获取容器高度
  405. getPageheight:function(){
  406. let that =this;
  407. wx.createSelectorQuery().select('#j_page').boundingClientRect(function(rect){
  408. that.setData({'pageHight':rect.height})
  409. }).exec()
  410. },
  411. //使页面滚动到容器底部
  412. pageScrollToBottom: function() {
  413. wx.pageScrollTo({
  414. scrollTop: this.data.pageHight
  415. })
  416. },
  417. // 步骤引导函数
  418. nextStep(e){
  419. if(this.data.guideStep==2){
  420. $.storage.set('guideInit',true);
  421. this.setData({'guideInit':false})
  422. }
  423. this.setData({'guideStep':2})
  424. this.pageScrollToBottom();
  425. },
  426. async isGetSetting(value) {
  427. let {authSetting} = await getSetting();
  428. if(authSetting['scope.userLocation']){
  429. await this.getUserLocation();
  430. }else{
  431. wx.showModal({
  432. title: '是否授权当前位置',
  433. content: '需要获取您的地理位置,请确认授权',
  434. confirmColor: '#f16765',
  435. success: res => {
  436. if (res.confirm) {
  437. wx.openSetting({
  438. success: async data => {
  439. await this.getUserLocation();
  440. value&&this.checkPower();
  441. },
  442. })
  443. } else {
  444. this.setData({havePower: {result: "fail",message: "未定位到您的位置"}})
  445. }
  446. }
  447. })
  448. }
  449. },
  450. // 获取位置信息
  451. async getUserLocation(cb) {
  452. var that = this;
  453. let {latitude,longitude} = await getLocation();
  454. this.setData({latitude,longitude});
  455. },
  456. // 是否有操作权限
  457. async checkPower() {
  458. await this.isGetSetting('cb');
  459. const data = {
  460. "criteria": {
  461. "projectId":this.data.spaceDetail.projectId,
  462. "spaceId": this.data.spaceDetail.id,
  463. "userId": $.store.get('userId'),
  464. "tenantId": this.data.spaceDetail.tenantId,
  465. "longitude": this.data.longitude,
  466. "latitude": this.data.latitude
  467. }
  468. };
  469. await powerCheck(data).then(res => {
  470. this.setData({
  471. havePower: res
  472. })
  473. })
  474. },
  475. // 获取实时曲线
  476. async getChartDate(){
  477. wx.showLoading({
  478. title:"加载中"
  479. });
  480. let data={
  481. projectId:this.data.spaceDetail.projectId,
  482. spaceId:this.data.spaceDetail.id,
  483. funcid:'Tdb'
  484. }
  485. let res = await getPropertyData(data);
  486. if(!res){
  487. throw "网络错误";
  488. }
  489. let {propertyData,dayTarget}=res;
  490. // 获取期望温度
  491. this.getHopeTemp(dayTarget).then(()=>{
  492. this.initDaytarget(dayTarget);
  493. this.initChartdate(propertyData,dayTarget);
  494. });
  495. wx.hideLoading();
  496. },
  497. initChartdate(propertyData,dayTarget){
  498. if(!propertyData&&!propertyData.length&&dayTarget&&!dayTarget.length){
  499. return ;
  500. }
  501. // 目标 { time: "1951",release:0, sales: 38,标准区间: [ 25, 45 ] },
  502. let baseArr=propertyData&&propertyData.slice(1) || [];
  503. let tragetChart = [];
  504. baseArr.forEach(item=>{
  505. item[1] = (item[1]=="-9999")?null:Number(Number(item[1]).toFixed(1));
  506. })
  507. if(baseArr.length===dayTarget.length){
  508. dayTarget.forEach((item,index)=>{
  509. let time ='';
  510. item.time&&(time = item.time.slice(0,2)+':'+item.time.slice(2,4));
  511. item['temperatureMin']&&(item['temperatureMin']=Number(item['temperatureMin'].toFixed(1)));
  512. item['temperatureMax']&&(item['temperatureMax']=Number(item['temperatureMax'].toFixed(1)));
  513. let initObj={
  514. time:time,
  515. release:index,
  516. sales:baseArr[index][1],
  517. 标准区间:[item['temperatureMin'],item['temperatureMax']],
  518. }
  519. tragetChart.push(initObj);
  520. })
  521. }
  522. this.setData({tragetChart,tragetChartcopy:tragetChart})
  523. },
  524. initDaytarget(value){
  525. if(!value||!value.length){
  526. return
  527. }
  528. let customPlan=[];
  529. // 格式化单位 15px为1度 28 18
  530. let lenpx=25;
  531. value.forEach((item,index)=>{
  532. if(item.time.slice(2,6)=="0000"){
  533. let obj={};
  534. obj.time=item.date+item.time;
  535. obj.id=index;
  536. obj.name=item.time.slice(0,2)+':'+item.time.slice(2,4);
  537. obj.maxValue= item.temperatureMax;
  538. obj.minValue = item.temperatureMin || 0;
  539. obj.distance=(obj.maxValue-obj.minValue)|| 0;
  540. obj.height=obj.distance*lenpx;
  541. obj.planTemp=Number(((obj.maxValue+obj.minValue)/2).toFixed(1));
  542. obj.y=(28 - obj.maxValue)*lenpx;
  543. customPlan.push(obj)
  544. }
  545. })
  546. this.setData({customPlancopy:this.copyobj(customPlan)})
  547. },
  548. getHopeTemp(value){
  549. return new Promise((reslove,reject)=>{
  550. if(!value||!value.length){
  551. return
  552. }
  553. let data=new Date();
  554. let hour = data.getHours();
  555. let min = data.getMinutes();
  556. let minIndex = Math.floor(min/15);
  557. if(minIndex>=3){
  558. hour = hour + 1;
  559. min = 0;
  560. }else{
  561. min = (minIndex+1)*15;
  562. }
  563. let targetTime = (hour>=10?`${hour}`:`0${hour}`)+(min>=10?`${min}`:`0${min}`);
  564. let isDatelist=[];
  565. let targetTemp;
  566. let targetIndex;
  567. value.forEach((item,index)=>{
  568. if(item.temperatureMax&&item.temperatureMin){
  569. isDatelist.push(index)
  570. }
  571. if(item.time===`${targetTime}00`){
  572. targetTemp= parseInt((item.temperatureMax + item.temperatureMin)/2);
  573. targetIndex = index
  574. }
  575. })
  576. if(targetTemp){
  577. this.setData({targetTemp:targetTemp,targetIndex:targetIndex})
  578. }else{
  579. let index = isDatelist.pop();
  580. targetTemp = parseInt((value[index].temperatureMax + value[index].temperatureMin)/2);
  581. this.setData({targetTemp:targetTemp,targetIndex:targetIndex})
  582. }
  583. reslove();
  584. })
  585. // 获取当前时间最近的15分钟
  586. },
  587. // 更改即时调节选项
  588. effectChange(event){
  589. this.setData({
  590. effectTime: event.detail,
  591. },()=>{
  592. let changeDate=JSON.parse(JSON.stringify(this.data.tragetChartcopy));
  593. if(event.detail==='1'){
  594. let len = (this.data.targetIndex+8)>changeDate.length?changeDate.length:(this.data.targetIndex+8)
  595. for(var i=this.data.targetIndex;i<len;i++){
  596. changeDate[i].sales = this.data.targetTemp;
  597. changeDate[i]['标准区间'] =[changeDate[i].sales-1,changeDate[i].sales+1];
  598. }
  599. }else if(event.detail==='2'){
  600. let len = changeDate.length;
  601. for(var i=this.data.targetIndex;i<len;i++){
  602. changeDate[i].sales = this.data.targetTemp;
  603. changeDate[i]['标准区间'] =[changeDate[i].sales-1,changeDate[i].sales+1];
  604. }
  605. }else{
  606. let len = (this.data.targetIndex+4)>changeDate.length?changeDate.length:(this.data.targetIndex+4);
  607. let start = (this.data.targetIndex-4)<0?0:(this.data.targetIndex-4);
  608. for(var i=start;i<len;i++){
  609. changeDate[i].sales = this.data.targetTemp;
  610. changeDate[i]['标准区间'] =[changeDate[i].sales-1,changeDate[i].sales+1];
  611. }
  612. }
  613. this.setData({tragetChart:changeDate});
  614. });
  615. },
  616. // 加期望温度
  617. addClick(){
  618. let tepNum=this.data.targetTemp;
  619. let firstNum = tepNum.toString().split('.')[0];
  620. let lastNum = tepNum.toString().split('.')[1];
  621. if(firstNum>=28){
  622. return
  623. }
  624. if(lastNum>=5){
  625. this.setData({targetTemp:Number(firstNum)+1})
  626. }else{
  627. this.setData({targetTemp:Number(firstNum)+0.5})
  628. }
  629. },
  630. // 减期望温度
  631. minusClick(){
  632. let tepNum=this.data.targetTemp;
  633. let firstNum = tepNum.toString().split('.')[0]
  634. let lastNum = tepNum.toString().split('.')[1]
  635. if(firstNum<=18&&!lastNum){
  636. return ;
  637. }
  638. if(lastNum>5){
  639. this.setData({targetTemp:Number(firstNum)+0.5})
  640. }else if(lastNum<=5){
  641. this.setData({targetTemp:Number(firstNum)})
  642. }else{
  643. this.setData({targetTemp:Number(firstNum)-0.5})
  644. }
  645. },
  646. // 修改期望温度
  647. taboneSubmit(){
  648. if(this.data.havePower.result!=="success"){
  649. Toast.fail(this.data.havePower.message);
  650. return
  651. }
  652. if(!this.data.effectTime||this.data.effectTime<0){
  653. wx.showToast({
  654. title:"未选择保持时间",
  655. icon:"none",
  656. duration: 1500
  657. })
  658. return
  659. }
  660. const data={
  661. "projectId": this.data.spaceDetail.projectId,
  662. "objectId": this.data.spaceDetail.id,
  663. "valueType": 2,
  664. "model":2,
  665. "durationType":this.data.effectTime || '',
  666. "value":this.data.targetTemp
  667. }
  668. submitAdjust(data).then(async res=>{
  669. if(res.result="success"){
  670. wx.hideLoading();
  671. setTimeout(function () {
  672. wx.showToast({
  673. title:"提交成功",
  674. duration: 2000
  675. })
  676. }, 300)
  677. }
  678. // this.setData({effectTime:-1})
  679. await this.buildContact();
  680. this.isfeeded();
  681. // this.getChartDate();
  682. })
  683. },
  684. // 修改全天温度
  685. tabtwoSubmit(){
  686. if(this.data.havePower.result!=="success"){
  687. Toast.fail(this.data.havePower.message);
  688. return
  689. }
  690. let customPlan = JSON.parse(JSON.stringify(this.data.customPlan));
  691. customPlan.forEach(item=>{
  692. delete item.id;
  693. delete item.name;
  694. delete item.planTemp;
  695. delete item.y;
  696. delete item.height;
  697. delete item.distance;
  698. })
  699. const data={
  700. "projectId": this.data.spaceDetail.projectId,
  701. "objectId": this.data.spaceDetail.id,
  702. "valueType": 3,
  703. "model":2,
  704. "value":this.data.targetTemp,
  705. "customPlan":customPlan
  706. }
  707. submitAdjust(data).then(async res=>{
  708. wx.hideLoading();
  709. setTimeout(function () {
  710. wx.showToast({
  711. title:"提交成功",
  712. duration: 2000
  713. })
  714. }, 300)
  715. await this.buildContact();
  716. this.isfeeded();
  717. // this.getChartDate();
  718. })
  719. },
  720. showTips(){
  721. wx.showModal({
  722. title: '提示',
  723. content: '非工作时间如需使用空调,或遇特殊问题,请联系环境管理员',
  724. showCancel:false,
  725. success: function (res) {
  726. }
  727. })
  728. },
  729. chartChange(e){
  730. let y =e.detail.y;
  731. this.throttle(this.updateChart(y,e),500)
  732. },
  733. preventTouchMove: function () {
  734. return
  735. },
  736. updateChart(y,e){
  737. let lenpx=25;
  738. let planTempMax = 28 - y/lenpx;
  739. let {index,distance} =e.currentTarget.dataset;
  740. let planTemp = Number(((planTempMax*2 - distance)/2).toFixed(1));
  741. let target=`customPlan[${index}].y`;
  742. let targetplan=`customPlan[${index}].planTemp`;
  743. let targetTempMax=`customPlan[${index}].maxValue`;
  744. let targetTempMin=`customPlan[${index}].minValue`;
  745. this.setData({[target]:y,[targetplan]:planTemp,chartIndex:index,[targetTempMax]:planTempMax,[targetTempMin]:planTempMax-2});
  746. },
  747. throttle(func, delay) {
  748. let prev = Date.now();
  749.   return function() {
  750. let context = this;
  751. let args = arguments;
  752. let now = Date.now();
  753.     if (now - prev >= delay) {
  754.       func.apply(context, args);
  755.       prev = Date.now();
  756.     }
  757.   }
  758. },
  759. fillZore(value) {
  760. if (value < 10) {
  761. value = 0 + value
  762. }
  763. return value
  764. },
  765. formatTimeall(value) {
  766. let stringValue;
  767. const date = new Date();
  768. var nowMonth = date.getMonth() + 1;
  769. let nowDay = date.getDate();
  770. let torrowDay = new Date(date);
  771. torrowDay.setDate(date.getDate() + 1);
  772. let torrowMonth = torrowDay.getMonth() + 1;
  773. nowDay = this.fillZore(nowDay);
  774. nowMonth = this.fillZore(nowMonth);
  775. torrowMonth = this.fillZore(torrowMonth);
  776. if (nowMonth == value.substring(4, 6) || torrowMonth == value.substring(4, 6)) {
  777. if (value.substring(6, 8) == nowDay) {
  778. stringValue = "今日"
  779. }
  780. let torrowVlue = torrowDay.getDate();
  781. torrowVlue = this.fillZore(torrowVlue);
  782. if (value.substring(6, 8) == torrowVlue) {
  783. stringValue = "明日"
  784. }
  785. }
  786. if (stringValue) {
  787. stringValue = stringValue + `${value.substring(8,10)}:${value.substring(10,12)}`
  788. } else {
  789. stringValue = `${value.substring(4,6)}月${value.substring(6,8)}日${value.substring(8,10)}:${value.substring(10,12)}`
  790. }
  791. return stringValue
  792. },
  793. isfeeded(value){
  794. !value&&router.pop();
  795. },
  796. copyobj(a){
  797. var c={};
  798. c=JSON.parse(JSON.stringify(a));
  799. return c;
  800. },
  801. tabChange(event){
  802. let that = this;
  803. if(event.detail.name==1){
  804. that.setData({customPlan:null,chartIndex:null},()=>{
  805. that.setData({customPlan:this.copyobj(this.data.customPlancopy)})
  806. })
  807. }else{
  808. this.setData({effectTime:-1})
  809. this.getChartDate();
  810. }
  811. },
  812. getnowSeason(){
  813. let day = new Date();
  814. let year = day.getFullYear();
  815. let month = day.getMonth() + 1;
  816. month=month<10?('0'+month):month;
  817. let today = day.getDate();
  818. today=today<10?('0'+today):today;
  819. const data={
  820. projectId:this.data.spaceDetail.projectId,
  821. date:`${year}${month}${today}`
  822. }
  823. getCurrentSeason(data).then(res=>{
  824. if(res.result=="success"){
  825. this.setData({bgSeasonType:res.data})
  826. }
  827. })
  828. },
  829. // 自动刷新
  830. autoRefresh(fn){
  831. if(refreshTimer){
  832. clearInterval(refreshTimer);
  833. refreshTimer = null;
  834. }
  835. let refreshTime=$.store.get("autoRefreshTime");
  836. refreshTimer = setTimeout(()=>{
  837. fn();
  838. this.autoRefresh(fn);
  839. },refreshTime)
  840. },
  841. /**
  842. * 生命周期函数--监听页面加载
  843. */
  844. onLoad: function (options) {
  845. options = JSON.parse(decodeURIComponent(JSON.stringify(options)));
  846. if(options.md1){
  847. this.getDetail(options.md1);
  848. this.autoRefresh(this.getDetail);
  849. }else{
  850. options.humidity&&(options.humiditylevel = this.checkLevel(options.humidity,"humidity"));
  851. options.co2&&(options.co2level = this.checkLevel(options.co2,"co2"));
  852. options.pm25&&(options.pm25level = this.checkLevel(options.pm25,"pm25"));
  853. options.hcho&&(options.hcholevel = this.checkLevel(options.hcho,"hcho"));
  854. options.isPassengerPassShow&&(options.isPassengerPassShow=JSON.parse(options.isPassengerPassShow));
  855. // if(typeof options.isPassengerPass==="undefined"){
  856. // options.isPassengerPassShow=false;
  857. // }else{
  858. // options.isPassengerPassShow=true;
  859. // options.isPassengerPass=options.isPassengerPass?'有人':'无人'
  860. // }
  861. this.setData({spaceDetail:options},()=>{
  862. this.checkGuide();
  863. this.getnowSeason();
  864. let higthSpace=["311","312"];
  865. if(this.data.spaceDetail.roomFuncType&&higthSpace.includes(this.data.spaceDetail.roomFuncType)){
  866. this.setData({singleOffice:true})
  867. }
  868. this.checkPower();
  869. this.autoRefresh(this.getDetail);
  870. })
  871. }
  872. },
  873. async getDetail(value){
  874. let data;
  875. if(value){
  876. let projectId = 'Pj' + value.substring(2, 12);
  877. this.setData({spaceId:value,projectId:projectId});
  878. data= {
  879. criteria: {
  880. "spaceId": value,
  881. "userId": $.store.get('userId')||$.storage.get('userId'),
  882. "projectId": projectId
  883. }
  884. }
  885. }else{
  886. data= {
  887. criteria: {
  888. "spaceId": this.data.spaceDetail.id,
  889. "userId": $.store.get('userId')||$.storage.get('userId'),
  890. "projectId": this.data.spaceDetail.projectId
  891. }
  892. }
  893. }
  894. // wx.showLoading();
  895. let res = await getSpacedetail(data);
  896. // wx.hideLoading();
  897. // res.content[0].pm25= 0.034
  898. let {content} = res;
  899. if(content){
  900. (content[0].humidity||content[0].humidity==0)&&(content[0].humiditylevel = this.checkLevel(content[0].humidity,"humidity"));
  901. (content[0].co2||content[0].co2==0)&&(content[0].co2level = this.checkLevel(content[0].co2,"co2"));
  902. (content[0].pm25||content[0].pm25==0)&&(content[0].pm25level = this.checkLevel(content[0].pm25,"pm25"));
  903. (content[0].hcho||content[0].hcho==0)&&(content[0].hcholevel = this.checkLevel(content[0].hcho,"hcho"));
  904. if(typeof content[0].isPassengerPass==="undefined"){
  905. content[0].isPassengerPassShow=false;
  906. }else{
  907. content[0].isPassengerPassShow=true;
  908. content[0].isPassengerPass=content[0].isPassengerPass?'有人':'无人'
  909. }
  910. }
  911. this.setData({spaceDetail:content[0]},()=>{
  912. this.checkGuide(value);
  913. this.getnowSeason();
  914. // if(this.data.spaceDetail.nextOpenTime){
  915. // let value = this.formatTimeall(this.data.spaceDetail.nextOpenTime);
  916. // this.setData({nextOpenTime:value})
  917. // }
  918. if(this.data.spaceDetail.roomFuncType&&this.data.spaceDetail.roomFuncType.startsWith("31")){
  919. this.setData({singleOffice:true})
  920. }
  921. });
  922. $.storage.get("wxqcode")&&$.storage.set("wxqcode",'');
  923. // 判断是否可以调节
  924. await this.checkPower();
  925. },
  926. /**
  927. * 生命周期函数--监听页面初次渲染完成
  928. */
  929. onReady: function () {
  930. setTimeout(()=>{
  931. this.setData({'headerShow':true})
  932. },500)
  933. },
  934. })