index.js 38 KB

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