chargpilemonitor.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //logs.js
  2. let util = require('../../../utils/util.js');
  3. let wechat = require("../../../utils/wechat");
  4. let amap = require("../../../utils/amap");
  5. Page({
  6. timer: null,
  7. data: {
  8. userInfo: {},
  9. isLogin: false,
  10. searchString: null,
  11. chargpiles: [],
  12. pageNum: 1,
  13. total: 0,
  14. showAll: false,
  15. showTop: true,
  16. scrollTop: 0
  17. },
  18. onLoad(e) {},
  19. //20201207去掉默认加载监控充电桩数据
  20. onLoad_bak(e) {
  21. wx.showLoading({
  22. title: '加载中',
  23. mask: true
  24. });
  25. let userInfo = wx.getStorageSync('userInfo');
  26. let isLogin = wx.getStorageSync('isLogin');
  27. let that = this;
  28. // 页面显示
  29. if (userInfo && isLogin) {
  30. this.setData({
  31. userInfo: userInfo,
  32. isLogin: isLogin
  33. });
  34. wx.request({
  35. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargpileList',
  36. data: {
  37. pams: userInfo.userId,
  38. params: {
  39. pageSize: 10,
  40. pageNum: 1
  41. //orderByColumn:
  42. //isAsc: asc
  43. }
  44. },
  45. method: 'POST',
  46. success(res) {
  47. //console.log(res);
  48. if (res.data && res.data.code == 0) {
  49. let {
  50. rows: chargpiles
  51. } = res.data;
  52. var show_chargpiles = [];
  53. chargpiles.forEach((item, index) => {
  54. show_chargpiles.push({
  55. chargStationId: item.chargStationId,
  56. chargPileName: item.chargPileName,
  57. chargPileId: item.chargPileId,
  58. chargStationName: item.chargStationName,
  59. chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动"
  60. chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流"
  61. chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  62. });
  63. });
  64. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  65. // if (!res.data.chargstatus || res.data.chargstatus == 0 || res.data.chargstatus == 1 || res.data.chargstatus == 4 || res.data.chargstatus == 5 || res.data.chargstatus == 6 || res.data.chargstatus == 9) {
  66. // //充电桩故障
  67. // wx.showModal({
  68. // showCancel: false,
  69. // content: '终端故障,维修中'
  70. // });
  71. // } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  72. // wx.showModal({
  73. // showCancel: false,
  74. // content: '正在充电中'
  75. // });
  76. // } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  77. // wx.setStorage({
  78. // key: "scan_chargpile",
  79. // data: res.data
  80. // });
  81. // log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  82. // let url = `/pages/scan_result/scan_result`;
  83. // wx.navigateTo({
  84. // url
  85. // });
  86. // }
  87. if (res.data.total <= 10) {
  88. that.setData({
  89. chargpiles: show_chargpiles,
  90. total: res.data.total,
  91. showAll: true,
  92. pageNum: 1,
  93. scrollTop: 24
  94. });
  95. } else {
  96. that.setData({
  97. chargpiles: show_chargpiles,
  98. total: res.data.total,
  99. showAll: false,
  100. pageNum: 1,
  101. scrollTop: 24
  102. });
  103. }
  104. wx.hideLoading();
  105. }
  106. }
  107. });
  108. }
  109. },
  110. bindInput(e) {
  111. this.setData({
  112. searchString: e.detail.value
  113. });
  114. },
  115. bindSearch(e) {
  116. let {
  117. searchString: keywords
  118. } = this.data;
  119. if (keywords) {
  120. let url = `/pages/ucenter/chargpilemonitor/chargpilemonitorsearch?keywords=${keywords}`;
  121. wx.navigateTo({
  122. url
  123. });
  124. }
  125. },
  126. scrollFn(e) {
  127. // 防抖,优化性能
  128. // 当滚动时,滚动条位置距离页面顶部小于设定值时,触发下拉刷新
  129. // 通过将设定值尽可能小,并且初始化scroll-view组件竖向滚动条位置为设定值。来实现下拉刷新功能,但没有官方的体验好
  130. // clearTimeout(this.timer)
  131. // if (e.detail.scrollTop < this.data.scrollTop) {
  132. // this.timer = setTimeout(() => {
  133. // this.loadInitData()
  134. // }, 350)
  135. // }
  136. if (e.detail.scrollTop > 24) {
  137. //clearTimeout(this.timer);
  138. this.setData({
  139. showTop: false
  140. });
  141. }
  142. // if (e.detail.scrollTop == 0) {
  143. // this.timer = setTimeout(() => {
  144. // if (!this.data.showTop) {
  145. // this.setData({
  146. // showTop: true
  147. // });
  148. // }
  149. // }, 350)
  150. // }
  151. },
  152. loadInitData(e) {
  153. if (!this.data.showTop) {
  154. //clearTimeout(this.timer);
  155. //this.timer = setTimeout(() => {
  156. this.setData({
  157. showTop: true,
  158. scrollTop: 24
  159. });
  160. //}, 50)
  161. } else {
  162. wx.showLoading({
  163. title: '刷新中',
  164. mask: true
  165. });
  166. let that = this;
  167. // 页面显示
  168. if (that.data.userInfo && that.data.isLogin) {
  169. wx.request({
  170. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargpileList',
  171. data: {
  172. pams: that.data.userInfo.userId,
  173. params: {
  174. pageSize: 10,
  175. pageNum: 1
  176. //orderByColumn:
  177. //isAsc: asc
  178. }
  179. },
  180. method: 'POST',
  181. success(res) {
  182. //console.log(res);
  183. if (res.data && res.data.code == 0) {
  184. let {
  185. rows: chargpiles
  186. } = res.data;
  187. var show_chargpiles = [];
  188. chargpiles.forEach((item, index) => {
  189. show_chargpiles.push({
  190. chargStationId: item.chargStationId,
  191. chargPileName: item.chargPileName,
  192. chargPileId: item.chargPileId,
  193. chargStationName: item.chargStationName,
  194. chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动"
  195. chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流"
  196. chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  197. });
  198. });
  199. if (res.data.total <= 10) {
  200. that.setData({
  201. chargpiles: show_chargpiles,
  202. total: res.data.total,
  203. showAll: true,
  204. pageNum: 1,
  205. scrollTop: 24
  206. });
  207. } else {
  208. that.setData({
  209. chargpiles: show_chargpiles,
  210. total: res.data.total,
  211. showAll: false,
  212. pageNum: 1,
  213. scrollTop: 24
  214. });
  215. }
  216. wx.hideLoading();
  217. }
  218. }
  219. });
  220. }
  221. }
  222. },
  223. loadMoreData(e) {
  224. var totalPage = parseInt((this.data.total + 10 - 1) / 10);
  225. if ((this.data.pageNum + 1) > totalPage) {
  226. this.setData({
  227. showAll: true
  228. });
  229. return;
  230. }
  231. wx.showLoading({
  232. title: '加载中',
  233. mask: true
  234. });
  235. let that = this;
  236. let pageNum = this.data.pageNum + 1;
  237. this.setData({
  238. pageNum
  239. });
  240. // 页面显示
  241. if (that.data.userInfo && that.data.isLogin) {
  242. wx.request({
  243. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargpileList',
  244. data: {
  245. pams: that.data.userInfo.userId,
  246. params: {
  247. pageSize: 10,
  248. pageNum: pageNum
  249. //orderByColumn:
  250. //isAsc: asc
  251. }
  252. },
  253. method: 'POST',
  254. success(res) {
  255. //console.log(res);
  256. if (res.data && res.data.code == 0) {
  257. let {
  258. rows: chargpiles
  259. } = res.data;
  260. var show_chargpiles = that.data.chargpiles;
  261. chargpiles.forEach((item, index) => {
  262. show_chargpiles.push({
  263. chargStationId: item.chargStationId,
  264. chargPileName: item.chargPileName,
  265. chargPileId: item.chargPileId,
  266. chargStationName: item.chargStationName,
  267. chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动"
  268. chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流"
  269. chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  270. });
  271. });
  272. that.setData({
  273. chargpiles: show_chargpiles
  274. });
  275. if (pageNum * 10 >= that.data.total) {
  276. that.setData({
  277. showAll: true
  278. });
  279. }
  280. wx.hideLoading();
  281. }
  282. }
  283. });
  284. }
  285. }
  286. });