searchRoom.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // pages/searchRoom/searchRoom.js
  2. const util = require('../../utils/util.js');
  3. const api = require('../../config/api.js');
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. searchKey: '',
  11. roomList: [],
  12. storeList: [],
  13. isSearch: false,
  14. loading: false,
  15. fetcherData: {
  16. type: null,
  17. address: app.globalData.city,
  18. page: 1,
  19. size: 20,
  20. name: ''
  21. },
  22. typeName: {
  23. 0: '新房',
  24. 1: '二手房',
  25. 2: '公寓',
  26. 3: '民宿',
  27. 4: '装修'
  28. },
  29. },
  30. gotoWV: function (event) {
  31. let {
  32. id
  33. } = event.detail
  34. wx.navigateTo({
  35. url: `/pages/webview/index?id=${id}`,
  36. })
  37. },
  38. inputChange(e) {
  39. this.setData({
  40. 'fetcherData.name': e.detail.value,
  41. });
  42. },
  43. search() {
  44. // if (this.data.fetcherData.name != '') {
  45. wx.showLoading({
  46. title: '加载中...',
  47. });
  48. // console.log(this.data.searchKey)
  49. if (this.data.fetcherData.type == '21') { //商家
  50. this.setData({
  51. storeList: []
  52. })
  53. } else {
  54. this.setData({
  55. roomList: []
  56. })
  57. }
  58. this.setData({
  59. 'fetcherData.page': 1,
  60. })
  61. this.getRoomList()
  62. // } else {
  63. // wx.showToast({
  64. // title: '请输入VR场景名称',
  65. // icon: 'none'
  66. // })
  67. // }
  68. },
  69. getRoomList() {
  70. if (this.data.fetcherData.type == '21') { //商家
  71. this.setData({
  72. 'fetcherData.address': '',
  73. })
  74. } else {
  75. if (app.globalData.city == '全国') {
  76. this.setData({
  77. 'fetcherData.address': '',
  78. })
  79. } else {
  80. this.setData({
  81. 'fetcherData.address': app.globalData.city,
  82. })
  83. }
  84. }
  85. if (!this.data.loading) {
  86. this.setData({
  87. loading: true
  88. })
  89. wx.showLoading({
  90. title: '加载中...',
  91. });
  92. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  93. this.setData({
  94. loading: false
  95. })
  96. wx.hideLoading()
  97. if (res.errno === 0) {
  98. if (this.data.fetcherData.type == '21') {
  99. this.setData({
  100. storeList: this.data.storeList.concat(res.data.data),
  101. // storeList: res.data.data,
  102. 'fetcherData.page': this.data.fetcherData.page + 1,
  103. isSearch: true
  104. })
  105. } else {
  106. this.setData({
  107. roomList: this.data.roomList.concat(res.data.data),
  108. // roomList: res.data.data,
  109. 'fetcherData.page': this.data.fetcherData.page + 1,
  110. isSearch: true
  111. })
  112. }
  113. }
  114. }).catch(err => {
  115. this.setData({
  116. loading: false
  117. })
  118. });
  119. }
  120. },
  121. /**
  122. * 生命周期函数--监听页面加载
  123. */
  124. onLoad: function (options) {
  125. getApp().checkNetStatu();
  126. this.setData({
  127. 'fetcherData.type': options.type || 21,
  128. })
  129. if (this.data.typeName[options.type]) {
  130. this.setData({
  131. isSearch: true
  132. })
  133. this.getRoomList()
  134. wx.setNavigationBarTitle({
  135. title: this.data.typeName[options.type]
  136. })
  137. }
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面显示
  146. */
  147. onShow: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. this.getRoomList()
  169. },
  170. /**
  171. * 用户点击右上角分享
  172. */
  173. onShareAppMessage: function () {
  174. }
  175. })