index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. //index.js
  2. //获取应用实例
  3. import {
  4. getopenId,
  5. userCheck,
  6. powerCheck,
  7. queryRotation,
  8. queryChart,
  9. getfeedBack,
  10. getSpacedetail,
  11. followRoom,
  12. openSpace,
  13. getEquipmentAction
  14. } from "../../requests/api";
  15. import utils from "../../utils/util"
  16. import icons from "../../utils/icon"
  17. import Toast from '../../vant-weapp/dist/toast/toast';
  18. var chartbox = null;
  19. const AUTH = require('../../utils/auth')
  20. const wxCharts = require('../../utils/wxcharts.js');
  21. const app = getApp();
  22. Page({
  23. data: {
  24. hasUserInfo: false,
  25. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  26. swiperCurrent: 0, //首页轮播图
  27. popswiperCurrent: 0, //弹窗轮播图按钮
  28. statusList: icons.statusList,
  29. spacestatusList:icons.spacestatusList ,
  30. popstatusList: [{
  31. id: 0,
  32. nowind: [{}],
  33. wind: []
  34. }],
  35. popShow: false, //下弹框显示问题
  36. meauList: [{
  37. id: 1,
  38. title: '扫码调节',
  39. des: '调节二维码对应空间的环境',
  40. imgSrc: "../../static/images/qrcode.png"
  41. },
  42. {
  43. id: 2,
  44. title: '收藏的空间',
  45. des: '对已收藏的空间进行调节',
  46. imgSrc: "../../static/images/adjust.png"
  47. },
  48. {
  49. id: 3,
  50. title: '关闭空调',
  51. des: '下班了让环境节能控制',
  52. imgSrc: "../../static/images/lamp.png"
  53. },
  54. ],
  55. envList: [{
  56. name: "温度",
  57. value: "--",
  58. unit:"°C"
  59. },
  60. {
  61. name: "湿度",
  62. value: "--",
  63. unit:"%"
  64. },
  65. {
  66. name: "CO₂",
  67. value: "--",
  68. unit:"ppm",
  69. },
  70. {
  71. name: "PM2.5",
  72. value: "--",
  73. unit:"μg/m³",
  74. },
  75. ],
  76. tempType: [{
  77. id: 2,
  78. value: "太冷了",
  79. checked: false,
  80. imgSrc: "../../static/images/severityCold.png"
  81. },
  82. {
  83. id: 1,
  84. value: "有点冷",
  85. checked: false,
  86. imgSrc: "../../static/images/cold.png"
  87. },
  88. {
  89. id: 11,
  90. value: "赞",
  91. checked: false,
  92. imgSrc: "../../static/images/good.png"
  93. },
  94. {
  95. id: 3,
  96. value: "有点热",
  97. checked: false,
  98. imgSrc: "../../static/images/hot.png"
  99. },
  100. {
  101. id: 4,
  102. value: "太热了",
  103. checked: false,
  104. imgSrc: "../../static/images/severityHot.png"
  105. },
  106. ],
  107. tempTypeValue: -1,
  108. envType: [{
  109. id: 5,
  110. value: '风太大',
  111. checked: false,
  112. imgSrc: "../../static/images/severityWind.png"
  113. }, ],
  114. envTypeValue: -1,
  115. imageWidth: 0,
  116. feedBack: true,
  117. projectId: "",
  118. tenantName: "",
  119. tenantId: "",
  120. userId: "",
  121. imgbaseUrl: app.globalData.imgbaseUrl,
  122. swiperDate: [{
  123. "localName": "",
  124. id: "init",
  125. initPic:"../../static/images/room.png",
  126. // "pic": "../../static/images/room.png",
  127. isInit: true
  128. }],
  129. popswiperDate: {},
  130. chartDate: [],
  131. chartShow: false,
  132. spaceStatus: "",
  133. notice: "",
  134. equipmentStatus: "",
  135. equipmentStatustext: [],
  136. speedValue: 60,
  137. addFollow: '1',
  138. latitude: '',
  139. longitude: '',
  140. havePower: '',
  141. spaceStatusId: null,
  142. monthDay: '',
  143. tenants: [],
  144. fromFollowpage: false,
  145. secondpopValue: false,
  146. secondSpaceStatus: '',
  147. secondNotice: '',
  148. secondIcon: '',
  149. isEdit: false,
  150. wxqcode: '',
  151. formWxcode: false,
  152. formAuth: false,
  153. hideFlag: false,
  154. changeTenant:false, //是否通过调节改变项目
  155. formList:false, //是否改变项目
  156. imgShow:false,
  157. isRefresh:false
  158. },
  159. //事件处理函数
  160. bindViewTap: function () {},
  161. // 获取扫码结果
  162. getScancode: function () {
  163. if (!wx.getStorageSync('logined')) {
  164. wx.navigateTo({
  165. url: `../auth/index`,
  166. })
  167. return
  168. }
  169. // 只允许从相机扫码
  170. wx.scanCode({
  171. onlyFromCamera: true,
  172. complete: (res) => {
  173. if (res.errMsg === '"scanCode:fail cancel"') {
  174. Toast.fail('已取消扫描');
  175. }
  176. },
  177. success: (res) => {
  178. // console.log(res)
  179. this.checkCode(res.result);
  180. },
  181. fail: (res) => {
  182. Toast.fail('未扫描到结果');
  183. }
  184. })
  185. },
  186. // 检查是否位置授权
  187. isGetSetting() {
  188. wx.getSetting({
  189. success: async (res) => {
  190. var statu = res.authSetting;
  191. if (!statu['scope.userLocation']) {
  192. wx.showModal({
  193. title: '是否授权当前位置',
  194. content: '需要获取您的地理位置,请确认授权',
  195. confirmColor: '#f16765',
  196. success: res => {
  197. if (res.confirm) {
  198. wx.openSetting({
  199. success: async data => {
  200. // if (data.authSetting["scope.userLocation"]) {
  201. // await this.getUserLocation();
  202. // } else {
  203. await this.getUserLocation();
  204. // }
  205. },
  206. })
  207. } else {
  208. this.setData({
  209. havePower: {
  210. result: "fail",
  211. message: "未定位到您的位置"
  212. }
  213. })
  214. }
  215. }
  216. })
  217. } else {
  218. await this.getUserLocation();
  219. }
  220. }
  221. })
  222. },
  223. // 检查二维码
  224. async checkCode(value) {
  225. let scanArr = value.split("?");
  226. let domain = scanArr[0];
  227. let qualifiedUrl=["http://meos.sagacloud.cn/scan",'https://duoduoenv.sagacloud.cn/scan']
  228. if (qualifiedUrl.includes(domain)) {
  229. let md = scanArr[1].split('=');
  230. let md1 = md[1];
  231. let data = {
  232. "criteria": {
  233. "spaceId": md1,
  234. "userId": this.data.userId || wx.getStorageSync('userId'),
  235. "projectId": 'Pj' + md1.substring(2, 12)
  236. }
  237. }
  238. this.setData({
  239. "popswiperDate.id": md1,
  240. "popswiperDate.projectId": 'Pj' + md1.substring(2, 12)
  241. });
  242. // this.setData({
  243. // projectId: 'Pj' + md1.substring(2, 12)
  244. // })
  245. let changeProjectid = wx.getStorageSync('projectId')
  246. if (changeProjectid && changeProjectid !== ('Pj' + md1.substring(2, 12))) {
  247. // this.setData()
  248. }
  249. let res = await getSpacedetail(data);
  250. this.setData({
  251. wxqcode: ''
  252. })
  253. wx.setStorageSync("wxqcode",'');
  254. this.setData({
  255. popswiperDate: res.content[0] || {}
  256. });
  257. this.initOpenTime();
  258. this.changePop()
  259. } else {
  260. Toast.fail('不支持的二维码');
  261. }
  262. },
  263. // 检查是否注册
  264. async check(data={}) {
  265. var that=this;
  266. async function cb(){
  267. data.latitude='';
  268. if(data.latitude==''){
  269. data.longitude=that.data.longitude || '';
  270. data.latitude=that.data.latitude || '';
  271. }
  272. let res = await userCheck(data);
  273. if (res.result === "fail" && !that.data.formAuth) {
  274. wx.setStorageSync('logined', false);
  275. wx.navigateTo({
  276. url: `../auth/index`,
  277. })
  278. } else {
  279. that.getTenant(res);
  280. }
  281. }
  282. if(wx.getStorageSync('logined') || !that.data.longitude){
  283. await this.getUserLocation(cb);
  284. }else{
  285. await cb();
  286. }
  287. },
  288. imageLoad(e){
  289. var index = e.currentTarget.dataset.index;
  290. // var item = this.data.swiperDate[index];
  291. var param = {};
  292. var str = "swiperDate["+index+"].imgShow"; //index为下标
  293. param[str] = true;
  294. // item.imgShow = true;
  295. // var str=`swiperDate[${index}]`;
  296. // console.log(param,"str");
  297. this.setData(param);
  298. },
  299. changeImgshow(){
  300. setTimeout(function (){
  301. this.data.dataset
  302. },1000)
  303. },
  304. getTenant(res) {
  305. app.globalData.openId = res.content.openId || '';
  306. app.globalData.userId = res.content.id || '';
  307. app.globalData.tenants = res.content.tenants || [];
  308. // 检查定位哪个租户 优先定位再根据最近使用
  309. let currentTenant = this.checkTenant(app.globalData.tenants);
  310. app.globalData.projectId =currentTenant.projectId ||wx.getStorageSync('projectId') || '';
  311. app.globalData.projectName =currentTenant.projectName||wx.getStorageSync('projectName')|| '';
  312. app.globalData.tenantId = currentTenant.tenantId||wx.getStorageSync('tenantId')|| '';
  313. app.globalData.tenantName =currentTenant.tenantName|| wx.getStorageSync('tenantName') || '';
  314. wx.setStorageSync('logined', true);
  315. wx.setStorageSync('openId', res.content.openId);
  316. wx.setStorageSync('userId', res.content.id);
  317. wx.setStorageSync('projectId', app.globalData.projectId);
  318. wx.setStorageSync('projectName', app.globalData.projectName);
  319. wx.setStorageSync('tenantId', app.globalData.tenantId);
  320. wx.setStorageSync('tenantName', app.globalData.tenantName);
  321. this.setData({
  322. projectId: app.globalData.projectId,
  323. tenantId: app.globalData.tenantId,
  324. tenantName: app.globalData.tenantName,
  325. tenants: app.globalData.tenants,
  326. userId: app.globalData.userId
  327. });
  328. if (this.data.wxqcode) {
  329. this.checkCode(this.data.wxqcode);
  330. this.setData({
  331. formWxcode: false
  332. });
  333. }
  334. this.getswiperDate();
  335. },
  336. // 查询定位租户
  337. checkTenant(value = []) {
  338. var currntProjectId=wx.getStorageSync('projectId') || '';
  339. var currntProjectName=wx.getStorageSync('projectName') || '';
  340. var currntProjecttenantId=wx.getStorageSync('tenantId') || '';
  341. var currntProjecttenantName=wx.getStorageSync('tenantName') || '';
  342. var current = {};
  343. if (value.length) {
  344. // 定位到的租户id
  345. var currentTens=[];
  346. // 定位到的租户详情
  347. var currentTensArr=[];
  348. value.forEach(item => {
  349. if(item.current){
  350. currentTens.push(item.tenantId);
  351. currentTensArr.push(item);
  352. }
  353. })
  354. if(currentTens.length){
  355. if(!currentTens.includes(currntProjecttenantId)&&!this.data.changeTenant&&!this.data.formList){
  356. // 定位改变 但不是通过调节改变 切换改变
  357. current = currentTensArr[0];
  358. }else if(this.data.changeTenant){
  359. current.projectId = currntProjectId
  360. current.projectName = currntProjectName
  361. current.tenantId = currntProjecttenantId
  362. current.tenantName = currntProjecttenantName
  363. }
  364. }else{
  365. if(currntProjecttenantId!=''&&currntProjecttenantName!=''){
  366. current.projectId = currntProjectId
  367. current.projectName = currntProjectName
  368. current.tenantId = currntProjecttenantId
  369. current.tenantName = currntProjecttenantName
  370. }else{
  371. current = value[0]
  372. }
  373. }
  374. return current
  375. }else{
  376. current.projectId = currntProjectId
  377. current.projectName = currntProjectName
  378. current.tenantId = currntProjecttenantId
  379. current.tenantName = currntProjecttenantName
  380. return current
  381. }
  382. },
  383. // 查询租户名称
  384. changeTenantname(value){
  385. let tenarr=app.globalData.tenants;
  386. tenarr.forEach(item=>{
  387. if(item.tenantId == value){
  388. this.setData({changeTenant:true,tenantName:item.tenantName});
  389. wx.setStorageSync('tenantName', item.tenantName)
  390. }
  391. })
  392. },
  393. onHide: function () {
  394. this.setData({
  395. formAuth: false,
  396. hideFlag: true,
  397. formList: false
  398. })
  399. },
  400. onLoad: async function (options) {
  401. // 是否从微信直接进来
  402. if (options.q !== undefined) {
  403. let q = decodeURIComponent(options.q);
  404. console.log(q);
  405. this.setData({
  406. wxqcode: q
  407. });
  408. wx.setStorageSync('wxqcode', q);
  409. //截取参数 options.q ='域名地址?bedcode=12345678';
  410. // this.checkCode(q,true);
  411. }
  412. this.setData({
  413. imageWidth: wx.getSystemInfoSync().windowWidth
  414. });
  415. var isLogined = await AUTH.checkHasLogined();
  416. if (!isLogined) {
  417. await AUTH.login().then(async result => {
  418. await getopenId(result.code).then(async res => {
  419. app.globalData.openId = res.openId;
  420. wx.setStorage({
  421. data: app.globalData.openId,
  422. key: 'openId',
  423. })
  424. await this.check({
  425. openid: res.openId
  426. });
  427. });
  428. });
  429. } else {
  430. await this.check();
  431. }
  432. },
  433. onShow: async function () {
  434. if (this.data.fromFollowpage) {
  435. this.setData({
  436. fromFollowpage: false
  437. });
  438. // this.setData({
  439. // popswiperDate: JSON.parse(options.data)
  440. // });
  441. this.initOpenTime();
  442. setTimeout(() => {
  443. this.changePop();
  444. }, 300)
  445. }
  446. if(this.data.formList || this.data.formWxcode){
  447. await this.check();
  448. }
  449. },
  450. // 阻止滚动穿透
  451. preventTouchMove: function () {
  452. return
  453. },
  454. swiperChange(e) {
  455. this.setData({
  456. swiperCurrent: e.detail.current
  457. })
  458. },
  459. popswiperChange(e) {
  460. this.setData({
  461. popswiperCurrent: e.detail.current
  462. })
  463. },
  464. // 图表数据
  465. async drawChart() {
  466. var windowW = this.data.imageWidth / 375;
  467. let chartValue = this.data.chartDate;
  468. this.setData({
  469. chartShow: false
  470. })
  471. if (!chartValue.length) {
  472. return;
  473. }
  474. let dataX = [];
  475. let dataY = [];
  476. chartValue.forEach(item => {
  477. if (item[1] === -9999) {
  478. dataY.push(null)
  479. } else {
  480. this.setData({
  481. chartShow: true
  482. })
  483. // 只显示9点后的
  484. dataY.push(item[1].toFixed(1))
  485. }
  486. dataX.push(utils.formatDate(item[0]))
  487. })
  488. if (!this.data.chartShow) {
  489. return
  490. }
  491. chartbox = null;
  492. chartbox = new wxCharts({
  493. canvasId: 'areaCanvas',
  494. type: 'line', // line area
  495. categories: dataX,
  496. dataLabel: false,
  497. dataPointShape: false,
  498. animation: false,
  499. extra: {
  500. lineStyle: 'curve' //线条的形状(弧形)
  501. },
  502. series: [{
  503. name: '当日温度',
  504. data: dataY,
  505. }],
  506. yAxis: {
  507. min: 20,
  508. max: 30, //max+max*0.2
  509. format: function (val) {
  510. return val;
  511. },
  512. },
  513. xAxis: {
  514. disableGrid: true,
  515. },
  516. width: (windowW * 330), //(windowW * 300)
  517. height: (windowW * 115)
  518. });
  519. },
  520. touchHandler: function (e) {
  521. console.log(chartbox.getCurrentDataIndex(e));
  522. chartbox.showToolTip(e, {
  523. // background: '#7cb5ec',
  524. format: function (item, category) {
  525. return category + '温度:' + item.data
  526. }
  527. });
  528. },
  529. getUserInfo() {
  530. if (app.globalData.userInfo) {
  531. this.setData({
  532. userInfo: app.globalData.userInfo,
  533. hasUserInfo: true
  534. })
  535. } else if (this.data.canIUse) {
  536. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  537. // 所以此处加入 callback 以防止这种情况
  538. app.userInfoReadyCallback = res => {
  539. this.setData({
  540. userInfo: res.userInfo,
  541. hasUserInfo: true
  542. })
  543. }
  544. } else {
  545. // 在没有 open-type=getUserInfo 版本的兼容处理
  546. wx.getUserInfo({
  547. success: res => {
  548. app.globalData.userInfo = res.userInfo
  549. this.setData({
  550. userInfo: res.userInfo,
  551. hasUserInfo: true
  552. })
  553. }
  554. })
  555. }
  556. },
  557. // 获取位置信息
  558. async getUserLocation(cb) {
  559. var that = this;
  560. await wx.getLocation({
  561. altitude: 'false',
  562. type: 'wgs84',
  563. complete: (res) => {},
  564. success: async res => {
  565. that.setData({
  566. latitude: res.latitude
  567. })
  568. that.setData({
  569. longitude: res.longitude
  570. })
  571. if(cb){
  572. await cb()
  573. }else{
  574. this.checkPower();
  575. }
  576. },
  577. fail() {
  578. if(cb){
  579. // console.log(cb);
  580. cb()
  581. }
  582. Toast.fail('未定位到您所在位置');
  583. // that.checkPower();
  584. that.setData({
  585. havePower: {
  586. result: "fail",
  587. message: "未定位到您的位置"
  588. }
  589. })
  590. }
  591. })
  592. },
  593. // 是否有操作权限
  594. async checkPower() {
  595. const data = {
  596. "criteria": {
  597. "projectId":this.data.popswiperDate.projectId,
  598. "spaceId": this.data.popswiperDate.id,
  599. "userId": app.globalData.userId,
  600. "tenantId": app.globalData.tenantId,
  601. "longitude": this.data.longitude,
  602. "latitude": this.data.latitude
  603. }
  604. };
  605. await powerCheck(data).then(res => {
  606. this.setData({
  607. havePower: res
  608. })
  609. })
  610. },
  611. // 获取轮播图数据
  612. async getswiperDate() {
  613. const data = {
  614. "criteria": {
  615. "userId": app.globalData.userId || wx.getStorageSync('userId'),
  616. "projectId": app.globalData.projectId || wx.getStorageSync('projectId'),
  617. "tenantId": app.globalData.tenantId || wx.getStorageSync('tenantId')
  618. }
  619. }
  620. console.log(data, "getswiperDate")
  621. let res = await queryRotation(data);
  622. console.log(res, "res.count")
  623. if (res.count) {
  624. this.setData({
  625. swiperCurrent:0,
  626. swiperDate: [{
  627. "localName": "",
  628. id: "init",
  629. // "pic": "../../static/images/room.png",
  630. isInit: true,
  631. imgShow:true,
  632. initPic:"../../static/images/room.png",
  633. }]
  634. })
  635. let list = res.content;
  636. if (res.count > 5) {
  637. list = list.slice(0, 5);
  638. }
  639. list.map(item=>{
  640. item.imgShow=false;
  641. item.initPic=utils.picInit(item.roomFuncType);
  642. })
  643. this.setData({
  644. swiperDate: list
  645. })
  646. }else{
  647. this.setData({
  648. swiperDate: [{
  649. "localName": "",
  650. id: "init",
  651. // "pic": "../../static/images/room.png",
  652. isInit: true,
  653. imgShow:true,
  654. initPic:"../../static/images/room.png",
  655. }]
  656. })
  657. }
  658. },
  659. // 获取温度曲线
  660. async getChart() {
  661. // if(this.popswiperDate.isClose){
  662. // this.setData({
  663. // 'popShow': true
  664. // });
  665. // return
  666. // }
  667. let data = {
  668. projectId:this.data.popswiperDate.projectId,
  669. spaceId: this.data.popswiperDate.id
  670. }
  671. let res = await queryChart(data) || [];
  672. if (res.result == "success") {
  673. let date = res.data.slice(1);
  674. this.setData({
  675. chartDate: date
  676. });
  677. this.drawChart();
  678. }
  679. this.setData({
  680. 'popShow': true
  681. });
  682. },
  683. // 按钮点击
  684. itemClick: function (value) {
  685. var btnType = value.currentTarget.id;
  686. if (btnType === '2') {
  687. wx.navigateTo({
  688. url: '../search/index',
  689. })
  690. } else if (btnType === '3') {
  691. wx.navigateTo({
  692. url: '../efficient/index',
  693. })
  694. } else {
  695. this.getScancode();
  696. }
  697. },
  698. async changePop(e) {
  699. if (!wx.getStorageSync('logined') || (e && this.data.swiperDate[e.currentTarget.dataset.index].id == "init")) {
  700. return;
  701. }
  702. if (!this.data.formWxcode) {
  703. this.isGetSetting();
  704. }
  705. this.setData({
  706. addFollow: '1',
  707. isEdit: false,
  708. feedBack: true,
  709. tempTypeValue: -1,
  710. envTypeValue: -1
  711. });
  712. if (e) {
  713. let index = e.currentTarget.dataset.index;
  714. this.setData({
  715. popswiperDate: this.data.swiperDate[index]
  716. });
  717. this.initOpenTime();
  718. }
  719. this.setData({
  720. "envList[0].value": this.data.popswiperDate.temperature || '--',
  721. "envList[1].value": this.data.popswiperDate.humidity || '--',
  722. "envList[2].value": this.data.popswiperDate.co2 || '--',
  723. "envList[3].value": this.data.popswiperDate.pm25 || '--'
  724. });
  725. this.getChart();
  726. },
  727. // 是否加入关注列表
  728. addonChange(e) {
  729. if (this.data.addFollow == "0") {
  730. this.setData({
  731. addFollow: '1'
  732. })
  733. } else {
  734. this.setData({
  735. addFollow: '0'
  736. })
  737. }
  738. },
  739. async colseFeedback() {
  740. // this.setData({isEdit:true});
  741. if (!this.data.popswiperDate.subscribe && this.data.addFollow == "1" && !this.data.feedBack) {
  742. let data = {
  743. "userId": app.globalData.userId || wx.getStorageSync('userId'), //用户id
  744. "projectId":this.data.popswiperDate.projectId , //项目id
  745. "spaceId": this.data.popswiperDate.id, //空间id
  746. flag: 1
  747. }
  748. // 关注空间
  749. await followRoom(data);
  750. await this.check();
  751. } else {
  752. this.getswiperDate();
  753. }
  754. this.setData({
  755. popShow: false
  756. })
  757. // this.setData({
  758. // feedBack: true
  759. // })
  760. },
  761. // 弹窗的显示隐藏
  762. popClose(e) {
  763. if (this.data.isEdit) {
  764. this.colseFeedback();
  765. }
  766. // this.colseFeedback();
  767. this.setData({
  768. 'popShow': false
  769. });
  770. // chartbox = null;
  771. // this.setData({popswiperCurrent:0})
  772. },
  773. // 提交反馈
  774. submitFeedback() {
  775. if (this.data.tempTypeValue != -1 || this.data.envTypeValue != -1) {
  776. this.setData({
  777. isEdit: true,
  778. notice: [],
  779. equipmentStatustext: []
  780. });
  781. let data = {
  782. "projectId": this.data.popswiperDate.projectId, //项目id
  783. "objectId": this.data.popswiperDate.id, //空间id
  784. "valueType": 1, //固定为1
  785. "itemIds": []
  786. }
  787. this.data.tempTypeValue != -1 ? data.itemIds.push(this.data.tempTypeValue) : '';
  788. this.data.envTypeValue != -1 ? data.itemIds.push(this.data.envTypeValue) : '';
  789. getEquipmentAction(data).then(res => {
  790. this.setData({
  791. equipmentStatus: res.equipmentStatus
  792. });
  793. let textMsg = "";
  794. let textMsgarr=[];
  795. this.data.equipmentStatus.forEach(item => {
  796. if (item.actions) {
  797. item.actions.forEach(items => {
  798. let textMsgobj={};
  799. textMsgobj.name=item.localName;
  800. textMsgobj.actions=items;
  801. textMsgarr.push(textMsgobj);
  802. textMsg = textMsg + item.localName + '--' + items + ' ';
  803. })
  804. }
  805. })
  806. this.setData({
  807. equipmentStatustext: textMsgarr
  808. });
  809. })
  810. getfeedBack(data).then(res => {
  811. this.setData({
  812. spaceStatus: res.spaceStatus,
  813. spaceStatusId: res.icon - 1
  814. });
  815. let notice = res.notice ? res.notice.split('。') : [];
  816. this.setData({
  817. notice: notice
  818. });
  819. let currentTenantId=wx.getStorageSync('tenantId');
  820. if(currentTenantId!==res.tenantId){
  821. app.globalData.projectId = res.projectId;
  822. app.globalData.tenantId = res.tenantId;
  823. wx.setStorageSync('projectId', res.projectId);
  824. wx.setStorageSync('tenantId', res.tenantId);
  825. this.changeTenantname(res.tenantId);
  826. }
  827. })
  828. this.setData({
  829. feedBack: false,
  830. popswiperCurrent: 0
  831. });
  832. }
  833. },
  834. // 反馈数据
  835. changeType(e) {
  836. if (this.data.havePower.result === 'fail' && wx.getStorageSync('logined')) {
  837. Toast.fail(this.data.havePower.message);
  838. return
  839. }
  840. var currentIndex = e.currentTarget.dataset.index;
  841. if (e.currentTarget.dataset.type === "temp") {
  842. currentIndex = currentIndex == this.data.tempTypeValue ? -1 : currentIndex;
  843. this.setData({
  844. "tempTypeValue": currentIndex
  845. });
  846. } else {
  847. currentIndex = currentIndex == this.data.envTypeValue ? -1 : currentIndex;
  848. this.setData({
  849. "envTypeValue": currentIndex
  850. });
  851. }
  852. },
  853. async openEnv() {
  854. // await this.checkPower();
  855. if (this.data.havePower.result === 'fail' && wx.getStorageSync('logined')) {
  856. Toast.fail(this.data.havePower.message);
  857. return
  858. }
  859. let data = {
  860. "projectId":this.data.popswiperDate.projectId, //项目id
  861. "objectId": this.data.popswiperDate.id //空间id
  862. }
  863. openSpace(data).then(res => {
  864. this.getswiperDate();
  865. this.setData({
  866. secondSpaceStatus: res.spaceStatus,
  867. secondNotice: res.notice,
  868. secondIcon: res.icon,
  869. popShow: false,
  870. secondpopValue: true
  871. });
  872. })
  873. },
  874. // 选择项目
  875. goProject(e) {
  876. wx.navigateTo({
  877. url: '../projectlist/index',
  878. })
  879. },
  880. fillZore(value) {
  881. if (value < 10) {
  882. value = 0 + value
  883. }
  884. return value
  885. },
  886. formatTimeall(value) {
  887. let stringValue;
  888. const date = new Date();
  889. var nowMonth = date.getMonth() + 1;
  890. let nowDay = date.getDate();
  891. let torrowDay = new Date(date);
  892. torrowDay.setDate(date.getDate() + 1);
  893. let torrowMonth = torrowDay.getMonth() + 1;
  894. nowDay = this.fillZore(nowDay);
  895. nowMonth = this.fillZore(nowMonth);
  896. torrowMonth = this.fillZore(torrowMonth);
  897. if (nowMonth == value.substring(4, 6) || torrowMonth == value.substring(4, 6)) {
  898. if (value.substring(6, 8) == nowDay) {
  899. stringValue = "今日"
  900. }
  901. let torrowVlue = torrowDay.getDate();
  902. torrowVlue = this.fillZore(torrowVlue);
  903. if (value.substring(6, 8) == torrowVlue) {
  904. stringValue = "明日"
  905. }
  906. }
  907. if (stringValue) {
  908. stringValue = stringValue + `${value.substring(8,10)}:${value.substring(10,12)}`
  909. } else {
  910. stringValue = `${value.substring(4,6)}月${value.substring(6,8)}日${value.substring(8,10)}:${value.substring(10,12)}`
  911. }
  912. return stringValue
  913. },
  914. initOpenTime() {
  915. // 是否为关闭状态
  916. if (this.data.popswiperDate.isClose) {
  917. this.setData({
  918. popswiperCurrent: 0
  919. })
  920. this.setData({
  921. monthDay: this.formatTimeall(this.data.popswiperDate.nextOpenTime)
  922. });
  923. }
  924. },
  925. commitClose() {
  926. this.setData({
  927. secondpopValue: false
  928. })
  929. }
  930. })