searchRoom.js 3.2 KB

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