search.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. let Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. searchVal: '',
  9. rooms: [],
  10. showSearchBtn: true
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {},
  16. /**
  17. * 生命周期函数--监听页面初次渲染完成
  18. */
  19. onReady: function () {},
  20. /**
  21. * 生命周期函数--监听页面显示
  22. */
  23. onShow: function () {},
  24. /**
  25. * 生命周期函数--监听页面隐藏
  26. */
  27. onHide: function () {},
  28. /**
  29. * 生命周期函数--监听页面卸载
  30. */
  31. onUnload: function () {},
  32. /**
  33. * 页面相关事件处理函数--监听用户下拉动作
  34. */
  35. onPullDownRefresh: function () {},
  36. /**
  37. * 页面上拉触底事件的处理函数
  38. */
  39. onReachBottom: function () {},
  40. /**
  41. * 用户点击右上角分享
  42. */
  43. onShareAppMessage: function () {},
  44. async onSearch() {
  45. // this.data.showSearchBtn = false;
  46. this.setData({
  47. showSearchBtn: false
  48. })
  49. console.log(this.data.searchVal.trim(), this.data.showSearchBtn)
  50. let Room = new Parse.Query('ShopRoom')
  51. // Room.equalTo('type', 'stay')
  52. Room.equalTo('company', company)
  53. Room.equalTo('isEnabled', true)
  54. Room.contains('name', this.data.searchVal.trim())
  55. Room.limit(10)
  56. let rooms = await Room.find()
  57. rooms = rooms.map((room) => room.toJSON())
  58. console.log(rooms)
  59. this.setData({
  60. rooms
  61. })
  62. },
  63. onFocus() {
  64. // this.data.showSearchBtn = true
  65. this.setData({
  66. showSearchBtn: true
  67. })
  68. },
  69. onChange(event) {
  70. console.log(event.detail, this.data.searchVal)
  71. },
  72. details(e) {
  73. console.log(e)
  74. let id = e.detail.id
  75. wx.navigateTo({
  76. url: `/nova-tourism/pages/homestay/room-detail/index?id=${id}`
  77. })
  78. }
  79. })