index.js 38 KB

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