findstation.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 brandName = keywords.brandName;
  78. let chargStationName = keywords.chargStationName
  79. worksheetinfo.chargStationId = keywords.id;
  80. worksheetinfo.mainLocation = keywords.address;
  81. worksheetinfo.accendant = '';
  82. //处理数据
  83. let {
  84. data: items
  85. } = response;
  86. items.forEach((item, index) => {
  87. if (item.userName.includes(userInfo.userName)){
  88. worksheetinfo.accendant =userInfo.userName
  89. }
  90. });
  91. worksheetinfo.pams = [];
  92. prevPage.setData({
  93. brandName,
  94. chargStationName,
  95. chargStationNameClearFlag:false,
  96. worksheetinfo,
  97. accendantids:[userInfo.userId],
  98. });
  99. console.log("异步慢");
  100. console.log(prevPage.data.worksheetinfo);
  101. wx.navigateBack({
  102. delta: 1
  103. });
  104. })
  105. .catch(error=>{
  106. console.log("请求失败");
  107. wx.navigateBack({//返回上一个页面
  108. delta: 1
  109. });
  110. });
  111. }
  112. //let url = `/pages/index/index`;
  113. //wx.navigateBack({
  114. // url
  115. // });
  116. },
  117. bindSearch(e) {
  118. let {
  119. searchString: keywords
  120. } = this.data;
  121. console.info(keywords)
  122. this.setData({
  123. keywords,
  124. pagenum:1,
  125. chargList: []
  126. })
  127. console.log(this.data);
  128. console.log("7898");
  129. this.getNextPage();
  130. },
  131. cancel(e) {
  132. console.log(e);
  133. wx.navigateBack();
  134. },
  135. getNextPage(){
  136. let userInfo = wx.getStorageSync('userInfo');
  137. let isLogin = wx.getStorageSync('isLogin');
  138. //必须排除返回结果值为空的情况,负责一直搜索为空
  139. if(this.data.chargList.length == this.data.total && this.data.chargList.length != 0){
  140. this.setData({
  141. finishedLoadTap:this.data.finishedLoadTap+1
  142. })
  143. if(this.data.finishedLoadTap>0 && this.data.finishedLoadShowTimes==0){
  144. this.setData({
  145. finishedLoadShowTimes:this.data.finishedLoadShowTimes+1
  146. })
  147. wx.showToast({
  148. title: '全部加载完毕',
  149. icon: 'success',
  150. duration: 2000
  151. })
  152. }
  153. return
  154. }
  155. if(this.data.dataLoading){
  156. return
  157. }
  158. this.setData({
  159. dataLoading: true
  160. })
  161. wx.showLoading({
  162. title: '数据加载中....',
  163. })
  164. let that = this;
  165. if (userInfo && isLogin) {
  166. wx.request({
  167. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/userChargStationsWeb',
  168. data: {
  169. userId: userInfo.userId,
  170. searchString:that.data.keywords,
  171. pagenum: this.data.pagenum++,
  172. pagesize: this.data.pagesize,
  173. },
  174. method: 'POST',
  175. success(res) {
  176. let chargList = res.data.rows;
  177. // console.log(chargList);
  178. // that.rechargeTimeOrder(chargemoneylogs);
  179. wx.hideLoading()
  180. that.setData({
  181. chargList: that.data.chargList.concat(chargList),
  182. total: res.data.total,
  183. dataLoading: false,
  184. });
  185. }
  186. });
  187. }
  188. },
  189. });