123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- // pages/efficient/index.js
- import {queryFollowspace,nextOpen,workLeave,powerCheck} from "../../requests/api";
- import utils from "../../utils/util";
- const app = getApp();
- var setTimer=null;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- checkedList:[],
- popValue:false,
- poptimeValue:false,
- secondpopValue:false,
- monthDay:'',
- monthDaystring:'',
- projectId:'',
- tenantId:'',
- userId:'',
- listContent:[],
- monthDaystringcope:'',
- havePower:'',
- latitude:'',
- longitude:'',
- // imgShow:false,
- 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_8.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":[]}
- },
- async getFollowlist(){
- const data={
- "criteria": {
- "userId":this.data.userId,
- "projectId": this.data.projectId,
- "tenantId": this.data.tenantId
- }
- }
- setTimer = null;
- let res = await queryFollowspace(data);
- // setTimer = setTimeout(()=>{this.setData({imgShow:true})},1000);
- if(res.count){
- res.content.map(item=>{
- item.picInit=utils.picInit(item.roomFuncType);
- })
- this.setData({listContent:res.content});
- var chooseflag=false;
- var flagArr=[]
- res.content.forEach((item)=>{
- if(!item.isClose&&!chooseflag){
- chooseflag=true;
- flagArr.push(item.id);
- this.setData({checkedList:flagArr});
- this.checkChange();
- }
- })
- }
- },
- allSelect(){
- let spaceList=[];
- this.data.listContent.forEach(item=>{
- if(!item.isClose){
- spaceList.push(item.id);
- }
-
- })
- if(spaceList.length==this.data.checkedList.length){
- this.setData({checkedList:[]});
- }else{
- this.setData({checkedList:spaceList});
- }
- this.checkChange();
- },
- // 确认关机
- async openClose(){
- await this.getUserLocation();
-
- },
- // 确认关机二次确认
- commitClose(){
- wx.redirectTo({
- url: '../index/index',
- })
- },
- turnDown(){
- let data={
- "projectId": this.data.projectId,//项目id
- "objectId": this.data.checkedList,//空间id
- "nextOpenTime":this.data.monthDaystring//下次开启时间
- }
- workLeave(data).then(res=>{
- // this.setData({checkedList:[]});
- // this.getFollowlist();
-
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({projectId:app.globalData.projectId});
- this.setData({tenantId:app.globalData.tenantId});
- this.setData({userId:app.globalData.userId});
- this.getFollowlist();
- },
- async getUserLocation() {
- var that = this;
- wx.getLocation({
- altitude: 'false',
- type: 'wgs84',
- complete: (res) => {},
- success:async res=> {
- that.setData({
- latitude:res.latitude
- })
- that.setData({
- longitude:res.longitude
- })
- await this.checkPower();
-
- },
- fail() {
- Toast.fail('未定位到您所在位置');
- }
- })
- },
- async checkPower() {
- const data = {
- "criteria": {
- "projectId": this.data.projectId || wx.getStorageSync('projectId'),
- "spaceId": this.data.checkedList[0],
- "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
- })
- })
- if(this.data.havePower.result === 'fail'){
- wx.showToast({
- title: this.data.havePower.message,
- icon: 'none',
- duration: 2000
- })
- return ;
- }else{
- this.setData({popValue:false});
- this.setData({secondpopValue:true});
- this.turnDown();
- }
- },
- checkChange:function(event){
- if(event){
- this.setData({
- checkedList: event.detail,
- });
- }
- if(!this.data.checkedList.length){
- this.setData({popValue:false})
- }else{
- this.getOpentime();
- this.setData({popValue:true})
- }
-
- },
- // 查询下次开启时间
- async getOpentime(){
- const data={
- "projectId": this.data.projectId,
- "objectId": this.data.checkedList
- }
- let res =await nextOpen(data);
- if(res.result=="success"){
-
- this.setData({monthDaystring:res.nextOpenTime})
- this.setData({monthDay:this.formatTimeall(res.nextOpenTime)});
- }
- },
- popClose() {
- this.setData({
- 'poptimeValue': false
- });
-
- this.setData({popValue:true});
- },
- changeTime(){
- this.setData({popValue:false});
- this.setData({poptimeValue:true});
- },
- commitBtn(){
- this.setData({monthDaystring:this.data.monthDaystringcope})
- // this.setData({monthDay:this.formatTimeall(this.data.monthDaystringcope)});
- this.setData({poptimeValue:false})
- this.setData({popValue:true});
- },
- getTimevalue(e){
- // this.setData({monthDaystring:e.detail.monthDaystring})
- // this.setData({monthDay:this.formatTimeall(e.detail.monthDaystring)});
- this.setData({monthDaystringcope:e.detail.monthDaystring})
- // this.setData({monthDay:this.formatTimeall(e.detail.monthDaystring)});
- },
- 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
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- })
|