index.js 37 KB

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