index.js 38 KB

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