searchRoom.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.getRoomList()
  48. } else {
  49. wx.showToast({
  50. title: '请输入VR场景名称',
  51. icon: 'none'
  52. })
  53. }
  54. },
  55. getRoomList() {
  56. if (this.data.fetcherData.type == '21') { //商家
  57. this.setData({
  58. 'fetcherData.address': '',
  59. })
  60. } else {
  61. if (app.globalData.city == '全国') {
  62. this.setData({
  63. 'fetcherData.address': '',
  64. })
  65. } else {
  66. this.setData({
  67. 'fetcherData.address': app.globalData.city,
  68. })
  69. }
  70. }
  71. if (!this.data.loading) {
  72. this.setData({
  73. loading: true
  74. })
  75. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  76. this.setData({
  77. loading: false
  78. })
  79. wx.hideLoading()
  80. if (res.errno === 0) {
  81. if (this.data.fetcherData.type == '21') {
  82. this.setData({
  83. storeList: res.data.data,
  84. isSearch: true
  85. })
  86. } else {
  87. this.setData({
  88. roomList: res.data.data,
  89. isSearch: true
  90. })
  91. }
  92. }
  93. }).catch(err => {
  94. this.setData({
  95. loading: false
  96. })
  97. });
  98. }
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad: function (options) {
  104. getApp().checkNetStatu();
  105. this.setData({
  106. 'fetcherData.type': options.type || 21,
  107. })
  108. if (this.data.typeName[options.type]) {
  109. this.setData({
  110. isSearch: true
  111. })
  112. this.getRoomList()
  113. wx.setNavigationBarTitle({
  114. title: this.data.typeName[options.type]
  115. })
  116. }
  117. },
  118. /**
  119. * 生命周期函数--监听页面初次渲染完成
  120. */
  121. onReady: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面显示
  125. */
  126. onShow: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面隐藏
  130. */
  131. onHide: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function () {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function () {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {},
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function () {
  151. }
  152. })