index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. const Parse = getApp().Parse;
  2. const app = getApp();
  3. const company = getApp().globalData.company;
  4. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. storeId: null,
  11. loadIndex: 1,
  12. rooms: []
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. let merchant = wx.getStorageSync('merchant')
  19. let store = wx.getStorageSync('store')
  20. if (!merchant) {
  21. wx.navigateTo({
  22. url: `/nova-tourism/pages/index/index`
  23. })
  24. }
  25. this.setData({
  26. storeId: store.objectId,
  27. store: store,
  28. merchant: merchant
  29. })
  30. this.getRooms()
  31. },
  32. async getStore() {
  33. let Store = new Parse.Query('ShopStore')
  34. let hotel = await Store.get(this.data.hotelId)
  35. hotel = hotel.toJSON()
  36. if (hotel.content) {
  37. hotel.content = rechText.formatRichText(hotel.content)
  38. }
  39. console.log(hotel)
  40. this.setData({
  41. hotel
  42. })
  43. },
  44. async getRooms() {
  45. let Room = new Parse.Query('ShopRoom')
  46. Room.equalTo('company', company)
  47. Room.equalTo("shop", this.data.storeId)
  48. Room.select(
  49. 'name',
  50. 'images',
  51. 'price',
  52. 'total',
  53. 'remaining',
  54. 'merber',
  55. 'type',
  56. 'area',
  57. 'tags'
  58. )
  59. Room.skip((this.data.loadIndex - 1) * 10)
  60. Room.limit(10)
  61. let rooms = await Room.find()
  62. rooms = rooms.map((room) => {
  63. room = room.toJSON()
  64. room.tags.slice(0, 5)
  65. return room
  66. })
  67. console.log(rooms)
  68. if (this.data.loadIndex != 1) {
  69. rooms = this.data.rooms.concat(rooms)
  70. }
  71. this.setData({
  72. rooms
  73. })
  74. },
  75. loadMore() {
  76. this.data.loadIndex++;
  77. this.getRooms()
  78. },
  79. edit(event) {
  80. console.log(event);
  81. let id = event.detail.id;
  82. wx.navigateTo({
  83. url: `/nova-tourism/pages/my/merchant/room-manage/room-edit/index?roomId=${id}`
  84. })
  85. },
  86. addRoom() {
  87. wx.navigateTo({
  88. url: `/nova-tourism/pages/my/merchant/room-manage/room-edit/index?storeId=${this.data.storeId}`
  89. })
  90. },
  91. /**
  92. * 生命周期函数--监听页面初次渲染完成
  93. */
  94. onReady: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow: function () {
  100. this.getRooms()
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. }
  127. })