index.js 38 KB

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