index.js 26 KB

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