index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // pages/efficient/index.js
  2. import {queryFollowspace,nextOpen,workLeave,powerCheck} from "../../requests/api";
  3. import utils from "../../utils/util";
  4. const app = getApp();
  5. var setTimer=null;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. checkedList:[],
  12. popValue:false,
  13. poptimeValue:false,
  14. secondpopValue:false,
  15. monthDay:'',
  16. monthDaystring:'',
  17. projectId:'',
  18. tenantId:'',
  19. userId:'',
  20. listContent:[],
  21. monthDaystringcope:'',
  22. havePower:'',
  23. latitude:'',
  24. longitude:'',
  25. // imgShow:false,
  26. 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":[]}
  27. },
  28. async getFollowlist(){
  29. const data={
  30. "criteria": {
  31. "userId":this.data.userId,
  32. "projectId": this.data.projectId,
  33. "tenantId": this.data.tenantId
  34. }
  35. }
  36. setTimer = null;
  37. let res = await queryFollowspace(data);
  38. // setTimer = setTimeout(()=>{this.setData({imgShow:true})},1000);
  39. if(res.count){
  40. res.content.map(item=>{
  41. item.picInit=utils.picInit(item.roomFuncType);
  42. })
  43. this.setData({listContent:res.content});
  44. var chooseflag=false;
  45. var flagArr=[]
  46. res.content.forEach((item)=>{
  47. if(!item.isClose&&!chooseflag){
  48. chooseflag=true;
  49. flagArr.push(item.id);
  50. this.setData({checkedList:flagArr});
  51. this.checkChange();
  52. }
  53. })
  54. }
  55. },
  56. allSelect(){
  57. let spaceList=[];
  58. this.data.listContent.forEach(item=>{
  59. if(!item.isClose){
  60. spaceList.push(item.id);
  61. }
  62. })
  63. if(spaceList.length==this.data.checkedList.length){
  64. this.setData({checkedList:[]});
  65. }else{
  66. this.setData({checkedList:spaceList});
  67. }
  68. this.checkChange();
  69. },
  70. // 确认关机
  71. async openClose(){
  72. await this.getUserLocation();
  73. },
  74. // 确认关机二次确认
  75. commitClose(){
  76. wx.redirectTo({
  77. url: '../index/index',
  78. })
  79. },
  80. turnDown(){
  81. let data={
  82. "projectId": this.data.projectId,//项目id
  83. "objectId": this.data.checkedList,//空间id
  84. "nextOpenTime":this.data.monthDaystring//下次开启时间
  85. }
  86. workLeave(data).then(res=>{
  87. // this.setData({checkedList:[]});
  88. // this.getFollowlist();
  89. })
  90. },
  91. /**
  92. * 生命周期函数--监听页面加载
  93. */
  94. onLoad: function (options) {
  95. this.setData({projectId:app.globalData.projectId});
  96. this.setData({tenantId:app.globalData.tenantId});
  97. this.setData({userId:app.globalData.userId});
  98. this.getFollowlist();
  99. },
  100. async getUserLocation() {
  101. var that = this;
  102. wx.getLocation({
  103. altitude: 'false',
  104. type: 'wgs84',
  105. complete: (res) => {},
  106. success:async res=> {
  107. that.setData({
  108. latitude:res.latitude
  109. })
  110. that.setData({
  111. longitude:res.longitude
  112. })
  113. await this.checkPower();
  114. },
  115. fail() {
  116. Toast.fail('未定位到您所在位置');
  117. }
  118. })
  119. },
  120. async checkPower() {
  121. const data = {
  122. "criteria": {
  123. "projectId": this.data.projectId || wx.getStorageSync('projectId'),
  124. "spaceId": this.data.checkedList[0],
  125. "userId": app.globalData.userId,
  126. "tenantId": app.globalData.tenantId,
  127. "longitude": this.data.longitude,
  128. "latitude": this.data.latitude
  129. }
  130. };
  131. await powerCheck(data).then(res => {
  132. this.setData({
  133. havePower: res
  134. })
  135. })
  136. if(this.data.havePower.result === 'fail'){
  137. wx.showToast({
  138. title: this.data.havePower.message,
  139. icon: 'none',
  140. duration: 2000
  141. })
  142. return ;
  143. }else{
  144. this.setData({popValue:false});
  145. this.setData({secondpopValue:true});
  146. this.turnDown();
  147. }
  148. },
  149. checkChange:function(event){
  150. if(event){
  151. this.setData({
  152. checkedList: event.detail,
  153. });
  154. }
  155. if(!this.data.checkedList.length){
  156. this.setData({popValue:false})
  157. }else{
  158. this.getOpentime();
  159. this.setData({popValue:true})
  160. }
  161. },
  162. // 查询下次开启时间
  163. async getOpentime(){
  164. const data={
  165. "projectId": this.data.projectId,
  166. "objectId": this.data.checkedList
  167. }
  168. let res =await nextOpen(data);
  169. if(res.result=="success"){
  170. this.setData({monthDaystring:res.nextOpenTime})
  171. this.setData({monthDay:this.formatTimeall(res.nextOpenTime)});
  172. }
  173. },
  174. popClose() {
  175. this.setData({
  176. 'poptimeValue': false
  177. });
  178. this.setData({popValue:true});
  179. },
  180. changeTime(){
  181. this.setData({popValue:false});
  182. this.setData({poptimeValue:true});
  183. },
  184. commitBtn(){
  185. this.setData({monthDaystring:this.data.monthDaystringcope})
  186. // this.setData({monthDay:this.formatTimeall(this.data.monthDaystringcope)});
  187. this.setData({poptimeValue:false})
  188. this.setData({popValue:true});
  189. },
  190. getTimevalue(e){
  191. // this.setData({monthDaystring:e.detail.monthDaystring})
  192. // this.setData({monthDay:this.formatTimeall(e.detail.monthDaystring)});
  193. this.setData({monthDaystringcope:e.detail.monthDaystring})
  194. // this.setData({monthDay:this.formatTimeall(e.detail.monthDaystring)});
  195. },
  196. fillZore(value){
  197. if(value<10){
  198. value = 0+value
  199. }
  200. return value
  201. },
  202. formatTimeall(value){
  203. let stringValue;
  204. const date = new Date();
  205. var nowMonth = date.getMonth() + 1;
  206. let nowDay=date.getDate();
  207. let torrowDay=new Date(date);
  208. torrowDay.setDate(date.getDate() + 1);
  209. let torrowMonth=torrowDay.getMonth() + 1;
  210. nowDay = this.fillZore(nowDay);
  211. nowMonth = this.fillZore(nowMonth);
  212. torrowMonth = this.fillZore(torrowMonth);
  213. if(nowMonth==value.substring(4,6) ||torrowMonth==value.substring(4,6) ){
  214. if(value.substring(6,8)==nowDay){
  215. stringValue="今日"
  216. }
  217. let torrowVlue = torrowDay.getDate();
  218. torrowVlue = this.fillZore(torrowVlue);
  219. if(value.substring(6,8)==torrowVlue){
  220. stringValue="明日"
  221. }
  222. }
  223. if(stringValue){
  224. stringValue =stringValue + `${value.substring(8,10)}:${value.substring(10,12)}`
  225. }else{
  226. stringValue = `${value.substring(4,6)}月${value.substring(6,8)}日${value.substring(8,10)}:${value.substring(10,12)}`
  227. }
  228. return stringValue
  229. },
  230. /**
  231. * 生命周期函数--监听页面初次渲染完成
  232. */
  233. onReady: function () {
  234. },
  235. /**
  236. * 生命周期函数--监听页面显示
  237. */
  238. onShow: function () {
  239. },
  240. })