search.js 3.2 KB

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