index.js 25 KB

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