chargpilemonitor.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. brandName:item.brandName,
  54. chargStationId: item.chargStationId,
  55. chargPileName: item.chargPileName,
  56. chargPileId: item.chargPileId,
  57. chargStationName: item.chargStationName,
  58. chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动"
  59. chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流"
  60. chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  61. });
  62. });
  63. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  64. // 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) {
  65. // //充电桩故障
  66. // wx.showModal({
  67. // showCancel: false,
  68. // content: '终端故障,维修中'
  69. // });
  70. // } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  71. // wx.showModal({
  72. // showCancel: false,
  73. // content: '正在充电中'
  74. // });
  75. // } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  76. // wx.setStorage({
  77. // key: "scan_chargpile",
  78. // data: res.data
  79. // });
  80. // log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  81. // let url = `/pages/scan_result/scan_result`;
  82. // wx.navigateTo({
  83. // url
  84. // });
  85. // }
  86. if (res.data.total <= 10) {
  87. that.setData({
  88. chargpiles: show_chargpiles,
  89. total: res.data.total,
  90. showAll: true,
  91. pageNum: 1,
  92. scrollTop: 24
  93. });
  94. } else {
  95. that.setData({
  96. chargpiles: show_chargpiles,
  97. total: res.data.total,
  98. showAll: false,
  99. pageNum: 1,
  100. scrollTop: 24
  101. });
  102. }
  103. wx.hideLoading();
  104. }
  105. }
  106. });
  107. }
  108. },
  109. bindInput(e) {
  110. this.setData({
  111. searchString: e.detail.value
  112. });
  113. },
  114. bindSearch(e) {
  115. let {
  116. searchString: keywords
  117. } = this.data;
  118. if (keywords) {
  119. let url = `/pages/ucenter/chargpilemonitor/chargpilemonitorsearch?keywords=${keywords}`;
  120. wx.navigateTo({
  121. url
  122. });
  123. }
  124. },
  125. scrollFn(e) {
  126. // 防抖,优化性能
  127. // 当滚动时,滚动条位置距离页面顶部小于设定值时,触发下拉刷新
  128. // 通过将设定值尽可能小,并且初始化scroll-view组件竖向滚动条位置为设定值。来实现下拉刷新功能,但没有官方的体验好
  129. // clearTimeout(this.timer)
  130. // if (e.detail.scrollTop < this.data.scrollTop) {
  131. // this.timer = setTimeout(() => {
  132. // this.loadInitData()
  133. // }, 350)
  134. // }
  135. if (e.detail.scrollTop > 24) {
  136. //clearTimeout(this.timer);
  137. this.setData({
  138. showTop: false
  139. });
  140. }
  141. // if (e.detail.scrollTop == 0) {
  142. // this.timer = setTimeout(() => {
  143. // if (!this.data.showTop) {
  144. // this.setData({
  145. // showTop: true
  146. // });
  147. // }
  148. // }, 350)
  149. // }
  150. },
  151. loadInitData(e) {
  152. if (!this.data.showTop) {
  153. //clearTimeout(this.timer);
  154. //this.timer = setTimeout(() => {
  155. this.setData({
  156. showTop: true,
  157. scrollTop: 24
  158. });
  159. //}, 50)
  160. } else {
  161. wx.showLoading({
  162. title: '刷新中',
  163. mask: true
  164. });
  165. let that = this;
  166. // 页面显示
  167. if (that.data.userInfo && that.data.isLogin) {
  168. wx.request({
  169. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargpileList',
  170. data: {
  171. pams: that.data.userInfo.userId,
  172. params: {
  173. pageSize: 10,
  174. pageNum: 1
  175. //orderByColumn:
  176. //isAsc: asc
  177. }
  178. },
  179. method: 'POST',
  180. success(res) {
  181. //console.log(res);
  182. if (res.data && res.data.code == 0) {
  183. let {
  184. rows: chargpiles
  185. } = res.data;
  186. var show_chargpiles = [];
  187. chargpiles.forEach((item, index) => {
  188. show_chargpiles.push({
  189. brandName:item.brandName,
  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. brandName:item.brandName,
  264. chargStationId: item.chargStationId,
  265. chargPileName: item.chargPileName,
  266. chargPileId: item.chargPileId,
  267. chargStationName: item.chargStationName,
  268. chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动"
  269. chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流"
  270. chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  271. });
  272. });
  273. that.setData({
  274. chargpiles: show_chargpiles
  275. });
  276. if (pageNum * 10 >= that.data.total) {
  277. that.setData({
  278. showAll: true
  279. });
  280. }
  281. wx.hideLoading();
  282. }
  283. }
  284. });
  285. }
  286. }
  287. });