//index.js //获取应用实例 import { getopenId, userCheck, powerCheck, queryRotation, queryChart, getfeedBack, getSpacedetail, followRoom, openSpace, getEquipmentAction } from "../../requests/api"; import utils from "../../utils/util" import Toast from '../../vant-weapp/dist/toast/toast'; var chartbox = null; const AUTH = require('../../utils/auth') const wxCharts = require('../../utils/wxcharts.js'); const app = getApp(); Page({ data: { hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo'), swiperCurrent: 0, //首页轮播图 popswiperCurrent: 0, //弹窗轮播图按钮 statusList: [{ id: 0, name: "缺数无法判断", canvasDate:{"v":"5.6.6","fr":25,"ip":0,"op":50,"w":100,"h":100,"nm":"恒温","ddd":0,"assets":[{"id":"image_0","w":60,"h":60,"u":"images/","p":"img_1.png","e":0}],"layers":[{"ddd":0,"ind":1,"ty":2,"nm":"恒温.png","cl":"png","refId":"image_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":50,"s":[-360]}],"ix":10},"p":{"a":0,"k":[50,50,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"ip":0,"op":50,"st":0,"bm":0}],"markers":[]} }, { id: 1, name: "恒温保持", imgSrc: "../../static/images/envtype1.png", canvasDate:{"v":"5.6.6","fr":25,"ip":0,"op":50,"w":100,"h":100,"nm":"恒温","ddd":0,"assets":[{"id":"image_0","w":60,"h":60,"u":"images/","p":"img_1.png","e":0}],"layers":[{"ddd":0,"ind":1,"ty":2,"nm":"恒温.png","cl":"png","refId":"image_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":50,"s":[-360]}],"ix":10},"p":{"a":0,"k":[50,50,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"ip":0,"op":50,"st":0,"bm":0}],"markers":[]} }, { id: 2, name: "正在为您快速降温", imgSrc: "../../static/images/envtype5.png", canvasDate:{"v":"5.6.6","fr":25,"ip":0,"op":31,"w":100,"h":100,"nm":"高数降低","ddd":0,"assets":[{"id":"image_0","w":60,"h":60,"u":"images/","p":"img_5.png","e":0}],"layers":[{"ddd":0,"ind":1,"ty":2,"nm":"高速降低.eps","cl":"eps","refId":"image_0","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":15,"s":[100]},{"t":31,"s":[0]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":0,"s":[50,30,0],"to":[0,3.333,0],"ti":[0,-6.667,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":15,"s":[50,50,0],"to":[0,6.667,0],"ti":[0,-3.333,0]},{"t":31,"s":[50,70,0]}],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"ip":0,"op":31,"st":0,"bm":0}],"markers":[]} }, { id: 3, name: "正在逐步调高温度", imgSrc: "../../static/images/envtype3.png", canvasDate:{"v":"5.6.6","fr":25,"ip":0,"op":50,"w":100,"h":100,"nm":"逐步提升","ddd":0,"assets":[{"id":"image_0","w":60,"h":60,"u":"images/","p":"img_3.png","e":0}],"layers":[{"ddd":0,"ind":1,"ty":2,"nm":"逐步提升.eps","cl":"eps","refId":"image_0","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":25,"s":[100]},{"t":50,"s":[0]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":0,"s":[30,70,0],"to":[3.333,-3.333,0],"ti":[-6.667,6.667,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":25,"s":[50,50,0],"to":[6.667,-6.667,0],"ti":[-3.333,3.333,0]},{"t":50,"s":[70,30,0]}],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"ip":0,"op":50,"st":0,"bm":0}],"markers":[]} }, { id: 4, name: "关机状态", imgSrc: "../../static/images/envtype4.png", canvasDate:{"v":"5.6.6","fr":25,"ip":0,"op":50,"w":100,"h":100,"nm":"节能运行","ddd":0,"assets":[{"id":"image_0","w":60,"h":60,"u":"images/","p":"img_4.png","e":0}],"layers":[{"ddd":0,"ind":1,"ty":2,"nm":"节能运行.eps","cl":"eps","refId":"image_0","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[20]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":25,"s":[100]},{"t":50,"s":[20]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[50,50,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"ip":0,"op":50,"st":0,"bm":0}],"markers":[]} } ], spacestatusList: [{ id: 1, name: "加速升温", imgSrc: "../../static/images/envtype6.png", canvasDate: { "v": "5.6.6", "fr": 25, "ip": 0, "op": 31, "w": 100, "h": 100, "nm": "高速提升", "ddd": 0, "assets": [{ "id": "image_0", "w": 60, "h": 60, "u": "images/", "p": "img_6.png", "e": 0 }], "layers": [{ "ddd": 0, "ind": 1, "ty": 2, "nm": "高速提升.eps", "cl": "eps", "refId": "image_0", "sr": 1, "ks": { "o": { "a": 1, "k": [{ "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 0, "s": [0] }, { "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 15, "s": [100] }, { "t": 31, "s": [0] }], "ix": 11 }, "r": { "a": 0, "k": 0, "ix": 10 }, "p": { "a": 1, "k": [{ "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 0, "s": [50, 70, 0], "to": [0, -3.333, 0], "ti": [0, 6.667, 0] }, { "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 15, "s": [50, 50, 0], "to": [0, -6.667, 0], "ti": [0, 3.333, 0] }, { "t": 31, "s": [50, 30, 0] }], "ix": 2 }, "a": { "a": 0, "k": [30, 30, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100, 100], "ix": 6 } }, "ao": 0, "ip": 0, "op": 31, "st": 0, "bm": 0 }], "markers": [] } }, { id: 2, name: "逐步升温", imgSrc: "../../static/images/envtype3.png", canvasDate: { "v": "5.6.6", "fr": 25, "ip": 0, "op": 50, "w": 100, "h": 100, "nm": "逐步提升", "ddd": 0, "assets": [{ "id": "image_0", "w": 60, "h": 60, "u": "images/", "p": "img_3.png", "e": 0 }], "layers": [{ "ddd": 0, "ind": 1, "ty": 2, "nm": "逐步提升.eps", "cl": "eps", "refId": "image_0", "sr": 1, "ks": { "o": { "a": 1, "k": [{ "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 0, "s": [0] }, { "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 25, "s": [100] }, { "t": 50, "s": [0] }], "ix": 11 }, "r": { "a": 0, "k": 0, "ix": 10 }, "p": { "a": 1, "k": [{ "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 0, "s": [30, 70, 0], "to": [3.333, -3.333, 0], "ti": [-6.667, 6.667, 0] }, { "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 25, "s": [50, 50, 0], "to": [6.667, -6.667, 0], "ti": [-3.333, 3.333, 0] }, { "t": 50, "s": [70, 30, 0] }], "ix": 2 }, "a": { "a": 0, "k": [30, 30, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100, 100], "ix": 6 } }, "ao": 0, "ip": 0, "op": 50, "st": 0, "bm": 0 }], "markers": [] } }, { id: 3, name: "加速降温", imgSrc: "../../static/images/envtype5.png", canvasDate: { "v": "5.6.6", "fr": 25, "ip": 0, "op": 31, "w": 100, "h": 100, "nm": "高数降低", "ddd": 0, "assets": [{ "id": "image_0", "w": 60, "h": 60, "u": "images/", "p": "img_5.png", "e": 0 }], "layers": [{ "ddd": 0, "ind": 1, "ty": 2, "nm": "高速降低.eps", "cl": "eps", "refId": "image_0", "sr": 1, "ks": { "o": { "a": 1, "k": [{ "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 0, "s": [0] }, { "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 15, "s": [100] }, { "t": 31, "s": [0] }], "ix": 11 }, "r": { "a": 0, "k": 0, "ix": 10 }, "p": { "a": 1, "k": [{ "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 0, "s": [50, 30, 0], "to": [0, 3.333, 0], "ti": [0, -6.667, 0] }, { "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 15, "s": [50, 50, 0], "to": [0, 6.667, 0], "ti": [0, -3.333, 0] }, { "t": 31, "s": [50, 70, 0] }], "ix": 2 }, "a": { "a": 0, "k": [30, 30, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100, 100], "ix": 6 } }, "ao": 0, "ip": 0, "op": 31, "st": 0, "bm": 0 }], "markers": [] } }, { id: 4, name: "逐步降温", imgSrc: "../../static/images/envtype2.png", canvasDate: { "v": "5.6.6", "fr": 25, "ip": 0, "op": 50, "w": 100, "h": 100, "nm": "逐步提升", "ddd": 0, "assets": [{ "id": "image_0", "w": 60, "h": 60, "u": "images/", "p": "img_2.png", "e": 0 }], "layers": [{ "ddd": 0, "ind": 1, "ty": 2, "nm": "逐步提升.eps", "cl": "eps", "refId": "image_0", "sr": 1, "ks": { "o": { "a": 1, "k": [{ "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 0, "s": [0] }, { "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 25, "s": [100] }, { "t": 50, "s": [0] }], "ix": 11 }, "r": { "a": 0, "k": 0, "ix": 10 }, "p": { "a": 1, "k": [{ "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 0, "s": [30, 70, 0], "to": [3.333, -3.333, 0], "ti": [-6.667, 6.667, 0] }, { "i": { "x": 0.833, "y": 0.833 }, "o": { "x": 0.167, "y": 0.167 }, "t": 25, "s": [50, 50, 0], "to": [6.667, -6.667, 0], "ti": [-3.333, 3.333, 0] }, { "t": 50, "s": [70, 30, 0] }], "ix": 2 }, "a": { "a": 0, "k": [30, 30, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100, 100], "ix": 6 } }, "ao": 0, "ip": 0, "op": 50, "st": 0, "bm": 0 }], "markers": [] } }, { id: 5, name: ".恒温保持", imgSrc: "../../static/images/envtype1.png", canvasDate: { "v": "5.6.6", "fr": 25, "ip": 0, "op": 50, "w": 100, "h": 100, "nm": "恒温", "ddd": 0, "assets": [{ "id": "image_0", "w": 60, "h": 60, "u": "images/", "p": "img_1.png", "e": 0 }], "layers": [{ "ddd": 0, "ind": 1, "ty": 2, "nm": "恒温.png", "cl": "png", "refId": "image_0", "sr": 1, "ks": { "o": { "a": 0, "k": 100, "ix": 11 }, "r": { "a": 1, "k": [{ "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 0, "s": [0] }, { "t": 50, "s": [-360] }], "ix": 10 }, "p": { "a": 0, "k": [50, 50, 0], "ix": 2 }, "a": { "a": 0, "k": [30, 30, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100, 100], "ix": 6 } }, "ao": 0, "ip": 0, "op": 50, "st": 0, "bm": 0 }], "markers": [] } }, { id: 6, name: "正在开启环境调节", imgSrc: "../../static/images/envtype7.png", canvasDate: { "v": "5.6.6", "fr": 25, "ip": 0, "op": 50, "w": 100, "h": 100, "nm": "开启环境调节", "ddd": 0, "assets": [{ "id": "image_0", "w": 60, "h": 60, "u": "images/", "p": "img_7.png", "e": 0 }], "layers": [{ "ddd": 0, "ind": 1, "ty": 2, "nm": "开启环境调节.png", "cl": "png", "refId": "image_0", "sr": 1, "ks": { "o": { "a": 1, "k": [{ "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 0, "s": [20] }, { "i": { "x": [0.833], "y": [0.833] }, "o": { "x": [0.167], "y": [0.167] }, "t": 25, "s": [100] }, { "t": 50, "s": [20] }], "ix": 11 }, "r": { "a": 0, "k": 0, "ix": 10 }, "p": { "a": 0, "k": [50, 50, 0], "ix": 2 }, "a": { "a": 0, "k": [30, 30, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100, 100], "ix": 6 } }, "ao": 0, "ip": 0, "op": 50, "st": 0, "bm": 0 }], "markers": [] } } ], popstatusList: [{ id: 0, nowind: [{}], wind: [] }], popShow: false, //下弹框显示问题 meauList: [{ id: 1, title: '扫码调节', des: '调节二维码对应空间的环境', imgSrc: "../../static/images/qrcode.png" }, { id: 2, title: '关注列表', des: '对关注的房间进行调节', imgSrc: "../../static/images/adjust.png" }, { id: 3, title: '关机', des: '下班了让环境节能控制', imgSrc: "../../static/images/lamp.png" }, ], envList: [{ name: "温度", value: "--", unit:"°C" }, { name: "湿度", value: "--", unit:"%" }, { name: "CO₂", value: "--", unit:"μg/m³", }, { name: "PM2.5", value: "--", unit:"ppm", }, ], tempType: [{ id: 2, value: "太冷了", checked: false, imgSrc: "../../static/images/severityCold.png" }, { id: 1, value: "有点冷", checked: false, imgSrc: "../../static/images/cold.png" }, { id: 11, value: "赞", checked: false, imgSrc: "../../static/images/good.png" }, { id: 3, value: "有点热", checked: false, imgSrc: "../../static/images/hot.png" }, { id: 4, value: "太热了", checked: false, imgSrc: "../../static/images/severityHot.png" }, ], tempTypeValue: -1, envType: [{ id: 5, value: '风太大', checked: false, imgSrc: "../../static/images/severityWind.png" }, ], envTypeValue: -1, imageWidth: 0, feedBack: true, projectId: "", tenantName: "", tenantId: "", userId: "", imgbaseUrl: app.globalData.imgbaseUrl, swiperDate: [{ "localName": "", id: "init", initPic:"../../static/images/room.png", // "pic": "../../static/images/room.png", isInit: true }], popswiperDate: {}, chartDate: [], chartShow: false, spaceStatus: "", notice: "", equipmentStatus: "", equipmentStatustext: [], speedValue: 60, addFollow: '1', latitude: '', longitude: '', havePower: '', spaceStatusId: null, monthDay: '', tenants: [], fromFollowpage: false, secondpopValue: false, secondSpaceStatus: '', secondNotice: '', secondIcon: '', isEdit: false, wxqcode: '', formWxcode: false, formAuth: false, hideFlag: false, changeTenant:false, //是否通过调节改变项目 formList:false, //是否改变项目 imgShow:false, isRefresh:false }, //事件处理函数 bindViewTap: function () {}, // 获取扫码结果 getScancode: function () { if (!wx.getStorageSync('logined')) { wx.navigateTo({ url: `../auth/index`, }) return } // 只允许从相机扫码 wx.scanCode({ onlyFromCamera: true, complete: (res) => { if (res.errMsg === '"scanCode:fail cancel"') { Toast.fail('已取消扫描'); } }, success: (res) => { // console.log(res) this.checkCode(res.result); }, fail: (res) => { Toast.fail('未扫描到结果'); } }) }, // 检查是否位置授权 isGetSetting() { wx.getSetting({ success: async (res) => { var statu = res.authSetting; if (!statu['scope.userLocation']) { wx.showModal({ title: '是否授权当前位置', content: '需要获取您的地理位置,请确认授权', confirmColor: '#f16765', success: res => { if (res.confirm) { wx.openSetting({ success: async data => { if (data.authSetting["scope.userLocation"]) { await this.getUserLocation(); } else { await this.getUserLocation(); } }, }) } else { this.setData({ havePower: { result: "fail", message: "未定位到您的位置" } }) } } }) } else { await this.getUserLocation(); } } }) }, // 检查二维码 async checkCode(value) { let scanArr = value.split("?"); let domain = scanArr[0]; if (domain === "http://meos.sagacloud.cn/scan" || domain === 'https://duoduoenv.sagacloud.cn/scan') { let md = scanArr[1].split('='); let md1 = md[1]; let data = { "criteria": { "spaceId": md1, "userId": this.data.userId || wx.getStorageSync('userId'), "projectId": 'Pj' + md1.substring(2, 12) } } this.setData({ "popswiperDate.id": md1 }); this.setData({ "popswiperDate.projectId": 'Pj' + md1.substring(2, 12) }); // this.setData({ // projectId: 'Pj' + md1.substring(2, 12) // }) let changeProjectid = wx.getStorageSync('projectId') if (changeProjectid && changeProjectid !== ('Pj' + md1.substring(2, 12))) { // this.setData() } let res = await getSpacedetail(data); this.setData({ wxqcode: '' }) wx.setStorageSync("wxqcode",''); this.setData({ popswiperDate: res.content[0] || {} }); this.initOpenTime(); this.changePop() } else { Toast.fail('不支持的二维码'); } }, // 检查是否注册 async check(data={}) { var that=this; async function cb(){ data.latitude=''; if(data.latitude==''){ data.longitude=that.data.longitude || ''; data.latitude=that.data.latitude || ''; } let res = await userCheck(data); if (res.result === "fail" && !that.data.formAuth) { wx.setStorageSync('logined', false); wx.navigateTo({ url: `../auth/index`, }) } else { that.getTenant(res); } } if(wx.getStorageSync('logined') || !that.data.longitude){ await this.getUserLocation(cb); }else{ await cb(); } }, imageLoad(e){ var index = e.currentTarget.dataset.index; // var item = this.data.swiperDate[index]; var param = {}; var str = "swiperDate["+index+"].imgShow"; //index为下标 param[str] = true; // item.imgShow = true; // var str=`swiperDate[${index}]`; console.log(param,"str"); this.setData(param); }, changeImgshow(){ setTimeout(function (){ this.data.dataset },1000) }, getTenant(res) { app.globalData.openId = res.content.openId || ''; app.globalData.userId = res.content.id || ''; app.globalData.tenants = res.content.tenants || []; // 检查定位哪个租户 优先定位再根据最近使用 let currentTenant = this.checkTenant(app.globalData.tenants); app.globalData.projectId =currentTenant.projectId ||wx.getStorageSync('projectId') || ''; app.globalData.projectName =currentTenant.projectName||wx.getStorageSync('projectName')|| ''; app.globalData.tenantId = currentTenant.tenantId||wx.getStorageSync('tenantId')|| ''; app.globalData.tenantName =currentTenant.tenantName|| wx.getStorageSync('tenantName') || ''; wx.setStorageSync('logined', true); wx.setStorageSync('openId', res.content.openId); wx.setStorageSync('userId', res.content.id); wx.setStorageSync('projectId', app.globalData.projectId); wx.setStorageSync('projectName', app.globalData.projectName); wx.setStorageSync('tenantId', app.globalData.tenantId); wx.setStorageSync('tenantName', app.globalData.tenantName); this.setData({ projectId: app.globalData.projectId }); this.setData({ tenantId: app.globalData.tenantId }); this.setData({ tenantName: app.globalData.tenantName }); this.setData({ tenants: app.globalData.tenants }); this.setData({ userId: app.globalData.userId }); if (this.data.wxqcode) { this.checkCode(this.data.wxqcode); this.setData({ formWxcode: false }); } this.getswiperDate(); }, // 查询定位租户 checkTenant(value = []) { var currntProjectId=wx.getStorageSync('projectId') || ''; var currntProjectName=wx.getStorageSync('projectName') || ''; var currntProjecttenantId=wx.getStorageSync('tenantId') || ''; var currntProjecttenantName=wx.getStorageSync('tenantName') || ''; var current = {}; if (value.length) { // 定位到的租户id var currentTens=[]; // 定位到的租户详情 var currentTensArr=[]; value.forEach(item => { if(item.current){ currentTens.push(item.tenantId); currentTensArr.push(item); } }) if(currentTens.length){ if(!currentTens.includes(currntProjecttenantId)&&!this.data.changeTenant&&!this.data.formList){ // 定位改变 但不是通过调节改变 切换改变 current = currentTensArr[0]; }else if(this.data.changeTenant){ current.projectId = currntProjectId current.projectName = currntProjectName current.tenantId = currntProjecttenantId current.tenantName = currntProjecttenantName } }else{ if(currntProjecttenantId!=''&&currntProjecttenantName!=''){ current.projectId = currntProjectId current.projectName = currntProjectName current.tenantId = currntProjecttenantId current.tenantName = currntProjecttenantName }else{ current = value[0] } } return current }else{ current.projectId = currntProjectId current.projectName = currntProjectName current.tenantId = currntProjecttenantId current.tenantName = currntProjecttenantName return current } }, // 查询租户名称 changeTenantname(value){ let tenarr=app.globalData.tenants; tenarr.forEach(item=>{ if(item.tenantId == value){ this.setData({changeTenant:true}); this.setData({tenantName:item.tenantName}) wx.setStorageSync('tenantName', item.tenantName) } }) }, onHide: function () { this.setData({ formAuth: false }) this.setData({ hideFlag: true }) this.setData({ formList: false }) }, onLoad: async function (options) { // 是否从微信直接进来 if (options.q !== undefined) { let q = decodeURIComponent(options.q); console.log(q); this.setData({ wxqcode: q }); wx.setStorageSync('wxqcode', q); //截取参数 options.q ='域名地址?bedcode=12345678'; // this.checkCode(q,true); } this.setData({ imageWidth: wx.getSystemInfoSync().windowWidth }); var isLogined = await AUTH.checkHasLogined(); if (!isLogined) { await AUTH.login().then(async result => { await getopenId(result.code).then(async res => { app.globalData.openId = res.openId; wx.setStorage({ data: app.globalData.openId, key: 'openId', }) await this.check({ openid: res.openId }); }); }); } else { await this.check(); } }, onShow: async function () { if (this.data.fromFollowpage) { this.setData({ fromFollowpage: false }); // this.setData({ // popswiperDate: JSON.parse(options.data) // }); this.initOpenTime(); setTimeout(() => { this.changePop(); }, 300) } if(this.data.formList || this.data.formWxcode){ await this.check(); } }, // 阻止滚动穿透 preventTouchMove: function () { return }, swiperChange(e) { this.setData({ swiperCurrent: e.detail.current }) }, popswiperChange(e) { this.setData({ popswiperCurrent: e.detail.current }) }, // 图表数据 async drawChart() { var windowW = this.data.imageWidth / 375; let chartValue = this.data.chartDate; this.setData({ chartShow: false }) if (!chartValue.length) { return; } let dataX = []; let dataY = []; chartValue.forEach(item => { if (item[1] === -9999) { dataY.push(null) } else { this.setData({ chartShow: true }) // 只显示9点后的 dataY.push(item[1].toFixed(1)) } dataX.push(utils.formatDate(item[0])) }) if (!this.data.chartShow) { return } chartbox = null; chartbox = new wxCharts({ canvasId: 'areaCanvas', type: 'line', // line area categories: dataX, dataLabel: false, dataPointShape: false, animation: false, extra: { lineStyle: 'curve' //线条的形状(弧形) }, series: [{ name: '当日温度', data: dataY, }], yAxis: { min: 20, max: 30, //max+max*0.2 format: function (val) { return val; }, }, xAxis: { disableGrid: true, }, width: (windowW * 330), //(windowW * 300) height: (windowW * 115) }); }, touchHandler: function (e) { console.log(chartbox.getCurrentDataIndex(e)); chartbox.showToolTip(e, { // background: '#7cb5ec', format: function (item, category) { return category + '温度:' + item.data } }); }, getUserInfo() { if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, hasUserInfo: true }) } else if (this.data.canIUse) { // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } } else { // 在没有 open-type=getUserInfo 版本的兼容处理 wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) } }, // 获取位置信息 async getUserLocation(cb) { var that = this; await wx.getLocation({ altitude: 'false', type: 'wgs84', complete: (res) => {}, success: async res => { that.setData({ latitude: res.latitude }) that.setData({ longitude: res.longitude }) if(cb){ await cb() }else{ this.checkPower(); } }, fail() { if(cb){ // console.log(cb); cb() } Toast.fail('未定位到您所在位置'); // that.checkPower(); that.setData({ havePower: { result: "fail", message: "未定位到您的位置" } }) } }) }, // 是否有操作权限 async checkPower() { const data = { "criteria": { "projectId":this.data.popswiperDate.projectId, "spaceId": this.data.popswiperDate.id, "userId": app.globalData.userId, "tenantId": app.globalData.tenantId, "longitude": this.data.longitude, "latitude": this.data.latitude } }; await powerCheck(data).then(res => { this.setData({ havePower: res }) }) }, // 获取轮播图数据 async getswiperDate() { const data = { "criteria": { "userId": app.globalData.userId || wx.getStorageSync('userId'), "projectId": app.globalData.projectId || wx.getStorageSync('projectId'), "tenantId": app.globalData.tenantId || wx.getStorageSync('tenantId') } } console.log(data, "getswiperDate") let res = await queryRotation(data); console.log(res, "res.count") if (res.count) { this.setData({swiperCurrent:0}) this.setData({ swiperDate: [{ "localName": "", id: "init", // "pic": "../../static/images/room.png", isInit: true, imgShow:true, initPic:"../../static/images/room.png", }] }) let list = res.content; if (res.count > 5) { list = list.slice(0, 5); } list.map(item=>{ item.imgShow=false; item.initPic=utils.picInit(item.roomFuncType); }) this.setData({ swiperDate: list }) }else{ this.setData({ swiperDate: [{ "localName": "", id: "init", // "pic": "../../static/images/room.png", isInit: true, imgShow:true, initPic:"../../static/images/room.png", }] }) } }, // 获取温度曲线 async getChart() { // if(this.popswiperDate.isClose){ // this.setData({ // 'popShow': true // }); // return // } let data = { projectId:this.data.popswiperDate.projectId, spaceId: this.data.popswiperDate.id } let res = await queryChart(data) || []; if (res.result == "success") { let date = res.data.slice(1); this.setData({ chartDate: date }); this.drawChart(); } this.setData({ 'popShow': true }); }, // 按钮点击 itemClick: function (value) { var btnType = value.currentTarget.id; if (btnType === '2') { wx.navigateTo({ url: '../search/index', }) } else if (btnType === '3') { wx.navigateTo({ url: '../efficient/index', }) } else { this.getScancode(); } }, async changePop(e) { if (!wx.getStorageSync('logined') || (e && this.data.swiperDate[e.currentTarget.dataset.index].id == "init")) { return; } if (!this.data.formWxcode) { this.isGetSetting(); } this.setData({ addFollow: '1' }); this.setData({ isEdit: false }); this.setData({ feedBack: true }); this.setData({ tempTypeValue: -1 }); this.setData({ envTypeValue: -1 }); if (e) { let index = e.currentTarget.dataset.index; this.setData({ popswiperDate: this.data.swiperDate[index] }); this.initOpenTime(); } this.setData({ "envList[0].value": this.data.popswiperDate.temperature || '--', "envList[1].value": this.data.popswiperDate.humidity || '--', "envList[2].value": this.data.popswiperDate.co2 || '--', "envList[3].value": this.data.popswiperDate.pm25 || '--' }); this.getChart(); }, // 是否加入关注列表 addonChange(e) { if (this.data.addFollow == "0") { this.setData({ addFollow: '1' }) } else { this.setData({ addFollow: '0' }) } }, async colseFeedback() { // this.setData({isEdit:true}); if (!this.data.popswiperDate.subscribe && this.data.addFollow == "1" && !this.data.feedBack) { let data = { "userId": app.globalData.userId || wx.getStorageSync('userId'), //用户id "projectId":this.data.popswiperDate.projectId , //项目id "spaceId": this.data.popswiperDate.id, //空间id flag: 1 } // 关注空间 await followRoom(data); await this.check(); } else { this.getswiperDate(); } this.setData({ popShow: false }) // this.setData({ // feedBack: true // }) }, // 弹窗的显示隐藏 popClose(e) { if (this.data.isEdit) { this.colseFeedback(); } // this.colseFeedback(); this.setData({ 'popShow': false }); // chartbox = null; // this.setData({popswiperCurrent:0}) }, // 提交反馈 submitFeedback() { if (this.data.tempTypeValue != -1 || this.data.envTypeValue != -1) { this.setData({ isEdit: true }); this.setData({ notice: [] }); this.setData({ equipmentStatustext: [] }); let data = { "projectId": this.data.popswiperDate.projectId, //项目id "objectId": this.data.popswiperDate.id, //空间id "valueType": 1, //固定为1 "itemIds": [] } this.data.tempTypeValue != -1 ? data.itemIds.push(this.data.tempTypeValue) : ''; this.data.envTypeValue != -1 ? data.itemIds.push(this.data.envTypeValue) : ''; getEquipmentAction(data).then(res => { this.setData({ equipmentStatus: res.equipmentStatus }); let textMsg = ""; let textMsgarr=[]; this.data.equipmentStatus.forEach(item => { if (item.actions) { item.actions.forEach(items => { let textMsgobj={}; textMsgobj.name=item.localName; textMsgobj.actions=items; textMsgarr.push(textMsgobj); textMsg = textMsg + item.localName + '--' + items + ' '; }) } }) this.setData({ equipmentStatustext: textMsgarr }); }) getfeedBack(data).then(res => { this.setData({ spaceStatus: res.spaceStatus }); this.setData({ spaceStatusId: res.icon - 1 }); let notice = res.notice ? res.notice.split('。') : []; this.setData({ notice: notice }); let currentTenantId=wx.getStorageSync('tenantId'); if(currentTenantId!==res.tenantId){ app.globalData.projectId = res.projectId; app.globalData.tenantId = res.tenantId; wx.setStorageSync('projectId', res.projectId); wx.setStorageSync('tenantId', res.tenantId); this.changeTenantname(res.tenantId); } }) this.setData({ feedBack: false }); this.setData({ popswiperCurrent: 0 }) } }, // 反馈数据 changeType(e) { if (this.data.havePower.result === 'fail' && wx.getStorageSync('logined')) { Toast.fail(this.data.havePower.message); return } var currentIndex = e.currentTarget.dataset.index; if (e.currentTarget.dataset.type === "temp") { currentIndex = currentIndex == this.data.tempTypeValue ? -1 : currentIndex; this.setData({ "tempTypeValue": currentIndex }); } else { currentIndex = currentIndex == this.data.envTypeValue ? -1 : currentIndex; this.setData({ "envTypeValue": currentIndex }); } }, async openEnv() { // await this.checkPower(); if (this.data.havePower.result === 'fail' && wx.getStorageSync('logined')) { Toast.fail(this.data.havePower.message); return } let data = { "projectId":this.data.popswiperDate.projectId, //项目id "objectId": this.data.popswiperDate.id //空间id } openSpace(data).then(res => { this.getswiperDate(); this.setData({ secondSpaceStatus: res.spaceStatus }); this.setData({ secondNotice: res.notice }); this.setData({ secondIcon: res.icon }); this.setData({ popShow: false }); this.setData({ secondpopValue: true }) }) }, // 选择项目 goProject(e) { wx.navigateTo({ url: '../projectlist/index', }) }, fillZore(value) { if (value < 10) { value = 0 + value } return value }, formatTimeall(value) { let stringValue; const date = new Date(); var nowMonth = date.getMonth() + 1; let nowDay = date.getDate(); let torrowDay = new Date(date); torrowDay.setDate(date.getDate() + 1); let torrowMonth = torrowDay.getMonth() + 1; nowDay = this.fillZore(nowDay); nowMonth = this.fillZore(nowMonth); torrowMonth = this.fillZore(torrowMonth); if (nowMonth == value.substring(4, 6) || torrowMonth == value.substring(4, 6)) { if (value.substring(6, 8) == nowDay) { stringValue = "今日" } let torrowVlue = torrowDay.getDate(); torrowVlue = this.fillZore(torrowVlue); if (value.substring(6, 8) == torrowVlue) { stringValue = "明日" } } if (stringValue) { stringValue = stringValue + `${value.substring(8,10)}:${value.substring(10,12)}` } else { stringValue = `${value.substring(4,6)}月${value.substring(6,8)}日${value.substring(8,10)}:${value.substring(10,12)}` } return stringValue }, initOpenTime() { // 是否为关闭状态 if (this.data.popswiperDate.isClose) { this.setData({ popswiperCurrent: 0 }) this.setData({ monthDay: this.formatTimeall(this.data.popswiperDate.nextOpenTime) }); } }, commitClose() { this.setData({ secondpopValue: false }) } })