findstation.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. data: {
  7. lonlat: "",
  8. city: "",
  9. longitude: null,
  10. latitude: null,
  11. tips: [],
  12. searchString: '',
  13. keywords: '',
  14. pagesize:30,
  15. pagenum:1,
  16. total:-1,
  17. loadTotal: 0,
  18. dataLoading: false,
  19. finishedLoadTap: 0,
  20. finishedLoadShowTimes: 0,
  21. chargList: [],
  22. },
  23. onLoad(e) {
  24. this.getNextPage()
  25. },
  26. bindScrollTolowerEvent: function(){
  27. this.getNextPage();
  28. },
  29. bindInput2(e) {
  30. let {
  31. value
  32. } = e.detail;
  33. let {
  34. lonlat,
  35. city
  36. } = this.data;
  37. amap.getInputtips(city, lonlat, value)
  38. .then(d => {
  39. //console.log(d);
  40. if (d && d.tips) {
  41. this.setData({
  42. tips: d.tips
  43. });
  44. }
  45. })
  46. .catch(e => {
  47. console.log(e);
  48. })
  49. },
  50. bindInput(e) {
  51. this.setData({
  52. searchString: e.detail.value
  53. });
  54. },
  55. bindSearch2(e) {
  56. let {
  57. keywords
  58. } = e.currentTarget.dataset;
  59. //console.log(pages);
  60. //console.log(e);
  61. // console.log(keywords);
  62. if (keywords) {
  63. //------------新增code 解决异步请求数据回显问题----------------------------
  64. let api = getApp().globalData.postHeadAgreement
  65. let path = 'restapi/wechat/getuserstation'
  66. let params = keywords.id
  67. console.log(params);
  68. //调用微信封装的Promise 携带的参数根据需求写为json{} 还是Long类型
  69. wechat.request(api,path,params)
  70. .then(response=>{
  71. let userInfo = wx.getStorageSync('userInfo');
  72. console.log("用户");
  73. console.log(userInfo);
  74. let pages = getCurrentPages();
  75. let prevPage = pages[pages.length - 2]; //上一个页面
  76. let worksheetinfo = prevPage.data.worksheetinfo;
  77. let chargStationName = keywords.chargStationName
  78. worksheetinfo.chargStationId = keywords.id;
  79. worksheetinfo.mainLocation = keywords.address;
  80. worksheetinfo.accendant = '';
  81. //处理数据
  82. let {
  83. data: items
  84. } = response;
  85. items.forEach((item, index) => {
  86. if (item.userName.includes(userInfo.userName)){
  87. worksheetinfo.accendant =userInfo.userName
  88. }
  89. });
  90. worksheetinfo.pams = [];
  91. prevPage.setData({
  92. chargStationName,
  93. chargStationNameClearFlag:false,
  94. worksheetinfo,
  95. accendantids:[userInfo.userId],
  96. });
  97. console.log("异步慢");
  98. console.log(prevPage.data.worksheetinfo);
  99. wx.navigateBack({
  100. delta: 1
  101. });
  102. })
  103. .catch(error=>{
  104. console.log("请求失败");
  105. wx.navigateBack({//返回上一个页面
  106. delta: 1
  107. });
  108. });
  109. }
  110. //let url = `/pages/index/index`;
  111. //wx.navigateBack({
  112. // url
  113. // });
  114. },
  115. bindSearch(e) {
  116. let {
  117. searchString: keywords
  118. } = this.data;
  119. console.info(keywords)
  120. this.setData({
  121. keywords,
  122. pagenum:1,
  123. chargList: []
  124. })
  125. console.log(this.data);
  126. console.log("7898");
  127. this.getNextPage();
  128. },
  129. cancel(e) {
  130. console.log(e);
  131. wx.navigateBack();
  132. },
  133. getNextPage(){
  134. let userInfo = wx.getStorageSync('userInfo');
  135. let isLogin = wx.getStorageSync('isLogin');
  136. //必须排除返回结果值为空的情况,负责一直搜索为空
  137. if(this.data.chargList.length == this.data.total && this.data.chargList.length != 0){
  138. this.setData({
  139. finishedLoadTap:this.data.finishedLoadTap+1
  140. })
  141. if(this.data.finishedLoadTap>0 && this.data.finishedLoadShowTimes==0){
  142. this.setData({
  143. finishedLoadShowTimes:this.data.finishedLoadShowTimes+1
  144. })
  145. wx.showToast({
  146. title: '全部加载完毕',
  147. icon: 'success',
  148. duration: 2000
  149. })
  150. }
  151. return
  152. }
  153. if(this.data.dataLoading){
  154. return
  155. }
  156. this.setData({
  157. dataLoading: true
  158. })
  159. wx.showLoading({
  160. title: '数据加载中....',
  161. })
  162. let that = this;
  163. if (userInfo && isLogin) {
  164. wx.request({
  165. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/userChargStationsWeb',
  166. data: {
  167. userId: userInfo.userId,
  168. searchString:that.data.keywords,
  169. pagenum: this.data.pagenum++,
  170. pagesize: this.data.pagesize,
  171. },
  172. method: 'POST',
  173. success(res) {
  174. let chargList = res.data.rows;
  175. // console.log(chargList);
  176. // that.rechargeTimeOrder(chargemoneylogs);
  177. wx.hideLoading()
  178. that.setData({
  179. chargList: that.data.chargList.concat(chargList),
  180. total: res.data.total,
  181. dataLoading: false,
  182. });
  183. }
  184. });
  185. }
  186. },
  187. });