chargpilemonitor.js 9.4 KB

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