search.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // lionfish_comshop/pages/position/search.js
  2. var wcache = require('../../utils/wcache.js');
  3. var status = require('../../utils/index.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. communities: [],
  11. city: {
  12. districtName: ""
  13. },
  14. cityName: "",
  15. inputValue: "",
  16. loadMore: false,
  17. noResult: true,
  18. latitude: '',
  19. longitude: '',
  20. hasRefeshin: false,
  21. pageNum: 1,
  22. groupInfo: {
  23. group_name: '社区',
  24. owner_name: '团长'
  25. },
  26. tip: "" // 没有更多社区了 / 没有搜索到社区"
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function(options) {
  32. var that = this;
  33. status.setNavBgColor();
  34. var city = wx.getStorageSync('city');
  35. var shopname = wcache.get('shopname');
  36. if (shopname) wx.setNavigationBarTitle({
  37. title: shopname
  38. });
  39. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  40. that.setData({
  41. city: city,
  42. cityName: city.districtName
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面初次渲染完成
  47. */
  48. onReady: function() {
  49. },
  50. onInput: function(event) {
  51. //inputValue
  52. console.log(event.detail.value);
  53. this.setData({
  54. inputValue: event.detail.value
  55. })
  56. },
  57. subInput: function() {
  58. this.setData({
  59. pageNum: 1,
  60. hasRefeshin: false
  61. })
  62. this.load_gps_community_list();
  63. },
  64. load_gps_community_list: function() {
  65. var token = wx.getStorageSync('token');
  66. var latitude = wx.getStorageSync('latitude');
  67. var longitude = wx.getStorageSync('longitude');
  68. var that = this;
  69. var inputValue = this.data.inputValue;
  70. if (!that.data.hasRefeshin) {
  71. that.setData({
  72. hasRefeshin: true,
  73. loadMore: true
  74. });
  75. app.util.request({
  76. 'url': 'entry/wxapp/index',
  77. 'data': {
  78. controller: 'index.load_gps_community',
  79. token: token,
  80. inputValue: inputValue,
  81. pageNum: that.data.pageNum,
  82. longitude: longitude,
  83. latitude: latitude
  84. },
  85. dataType: 'json',
  86. success: function(res) {
  87. if (res.data.code == 0) {
  88. let communities = that.data.communities.concat(res.data.list);
  89. that.setData({
  90. communities: communities,
  91. pageNum: that.data.pageNum + 1,
  92. loadMore: false,
  93. hasRefeshin: false,
  94. tip: ''
  95. });
  96. } else if (res.data.code == 1) {
  97. //go data
  98. that.setData({
  99. loadMore: false,
  100. tip: '^_^已经到底了'
  101. })
  102. } else if (res.data.code == 2) {
  103. //no login
  104. }
  105. }
  106. })
  107. }
  108. },
  109. /**
  110. * 生命周期函数--监听页面显示
  111. */
  112. onShow: function() {
  113. },
  114. /**
  115. * 生命周期函数--监听页面隐藏
  116. */
  117. onHide: function() {
  118. },
  119. /**
  120. * 生命周期函数--监听页面卸载
  121. */
  122. onUnload: function() {
  123. },
  124. /**
  125. * 页面相关事件处理函数--监听用户下拉动作
  126. */
  127. onPullDownRefresh: function() {
  128. },
  129. /**
  130. * 页面上拉触底事件的处理函数
  131. */
  132. onReachBottom: function() {
  133. this.load_gps_community_list();
  134. }
  135. })