index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. let Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. const compute = require('../../../../utils/compute.js')
  4. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {},
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. imgUrls: [
  15. 'https://s1.ax1x.com/2023/04/10/ppqifvF.png',
  16. 'https://s1.ax1x.com/2023/04/10/ppqiWgU.png',
  17. 'https://s1.ax1x.com/2023/04/10/ppqiR3T.png'
  18. ],
  19. list: [],
  20. hotels: [],
  21. rooms: [],
  22. active: 0,
  23. type:'recommend',
  24. loadIndex: 1,
  25. searchVal:'',
  26. showTab: false,
  27. stickytop: navigationBarHeight,
  28. tabs: [
  29. {
  30. title: '推荐',
  31. icon: 'https://s1.ax1x.com/2023/04/10/ppqEqdH.png',
  32. type:'recommend'
  33. },
  34. {
  35. title: '价格',
  36. icon: 'https://s1.ax1x.com/2023/04/10/ppqkh79.png',
  37. type:'price'
  38. },
  39. ],
  40. tabIndex: 0,
  41. },
  42. ready: function () {
  43. // 在组件布局完成后执行,确保options参数中有data信息
  44. // this.selectComponent('#tabs').resize()
  45. this.getRooms()
  46. },
  47. lifetimes: {
  48. created() {},
  49. attached() {
  50. this.loadMore()
  51. }
  52. },
  53. /**
  54. * 组件的方法列表
  55. */
  56. methods: {
  57. async getBanner() {
  58. let Banner = new Parse.Query('Banner')
  59. Banner.notEqualTo('isDeleted', "true")
  60. Banner.equalTo('company', company)
  61. Banner.equalTo('isEnabled', "true")
  62. Banner.equalTo('type','gourmet')
  63. let banner = await Banner.find()
  64. console.log(banner);
  65. if (banner && banner.length > 0) {
  66. let listJSON = []
  67. banner.forEach(c => {
  68. listJSON.push(c.toJSON())
  69. })
  70. this.setData({
  71. banner: listJSON
  72. })
  73. }
  74. },
  75. /**获取分类 */
  76. async getCategory(){
  77. let cate = new Parse.Query("Category")
  78. cate.notEqualTo('isDeleted', "true")
  79. cate.equalTo("company",company)
  80. cate.equalTo("type",'stayTag')
  81. let cateDate = await cate.find()
  82. let cateList = []
  83. cateDate.forEach(res=>{
  84. let item = res.toJSON()
  85. cateList.push(item)
  86. })
  87. if(cateList.length){
  88. this.setData({
  89. textItem:cateList[0]?.objectId,
  90. })
  91. }
  92. this.setData({
  93. cateList
  94. })
  95. },
  96. /**获取排行 */
  97. async getShopRank(id) {
  98. let ShopStore = new Parse.Query('ShopStore')
  99. ShopStore.notEqualTo('isDeleted', "true")
  100. ShopStore.equalTo('company', company)
  101. ShopStore.equalTo('type', "stay")
  102. ShopStore.equalTo('category', id)
  103. ShopStore.include("category")
  104. let shopStores = await ShopStore.find()
  105. if (shopStores) {
  106. let rankList = []
  107. for (let i = 0; i < shopStores.length; i++) {
  108. let json = shopStores[i].toJSON()
  109. rankList.push(json)
  110. }
  111. this.setData({
  112. rankList
  113. })
  114. }
  115. },
  116. /**选择分类 */
  117. changeText(e) {
  118. let {
  119. id
  120. } = e.currentTarget.dataset
  121. console.log(id);
  122. this.setData({
  123. textItem: id
  124. })
  125. this.getShopRank(id)
  126. },
  127. details(e) {
  128. let {id} = e.currentTarget.dataset
  129. console.log(e)
  130. wx.navigateTo({
  131. url: `/nova-tourism/pages/homestay/room-detail/index?id=${id}`
  132. })
  133. },
  134. async getHotels (type) {
  135. let Hotel = new Parse.Query('ShopStore')
  136. Hotel.notEqualTo('isDeleted', "true")
  137. Hotel.equalTo('company', company)
  138. Hotel.equalTo('type', 'stay')
  139. Hotel.select(
  140. 'cover',
  141. 'storeName',
  142. 'perCapita',
  143. 'address',
  144. 'type',
  145. 'isShow'
  146. )
  147. Hotel.equalTo('isShow', true)
  148. Hotel.skip((this.data.loadIndex - 1) * 10)
  149. if (type == 'price') {
  150. Hotel.ascending('perCapita')
  151. }
  152. Hotel.limit(10)
  153. let hotels = await Hotel.find()
  154. hotels = hotels.map((hotel) => hotel.toJSON())
  155. hotels = this.data.loadIndex == 1 ? hotels : this.data.hotels.concat(hotels)
  156. this.setData({ hotels })
  157. },
  158. toSearch() {
  159. wx.navigateTo({
  160. url: '/nova-tourism/pages/search/search'
  161. })
  162. },
  163. goUrl(e){
  164. let {url} = e.currentTarget.dataset
  165. wx.navigateTo({
  166. url: url,
  167. })
  168. },
  169. search(event){
  170. console.log(event);
  171. this.getRooms()
  172. },
  173. searchClear(){
  174. this.data.searchVal = '';
  175. this.getRooms()
  176. },
  177. showSearchBtn(){
  178. this.setData({
  179. searchBtn:true
  180. })
  181. },
  182. hiddenSearchBtn(){
  183. this.setData({
  184. searchBtn:false
  185. })
  186. },
  187. onTabClick(e) {
  188. let { id , type } = e.currentTarget.dataset;
  189. this.data.active = id
  190. this.data.loadIndex = 1
  191. this.data.type = type
  192. this.setData({
  193. tabIndex: id,
  194. })
  195. this.getRooms()
  196. },
  197. tabChange(event) {
  198. this.data.active = event.detail.name
  199. this.data.loadIndex = 1
  200. this.data.type = event.detail.name
  201. this.getRooms()
  202. },
  203. async loadMore() {
  204. this.data.loadIndex++
  205. this.getBanner()
  206. this.getRooms()
  207. await this.getCategory()
  208. this.getShopRank(this.data.textItem)
  209. },
  210. async getRooms () {
  211. let type = this.data.type;
  212. let Room = new Parse.Query('ShopRoom')
  213. Room.equalTo('company', company)
  214. Room.equalTo('isEnabled', true)
  215. if(this.data.searchVal != ''){
  216. Room.contains('name',this.data.searchVal)
  217. }
  218. if (type == 'price') {
  219. Room.ascending('price')
  220. }
  221. if(type == 'recommend'){
  222. Room.equalTo('isRecom',true)
  223. }
  224. Room.skip((this.data.loadIndex - 1) * 10)
  225. Room.select(
  226. 'name',
  227. 'images',
  228. 'price',
  229. 'total',
  230. 'remaining',
  231. 'merber',
  232. 'type',
  233. 'area',
  234. 'tags',
  235. 'address'
  236. )
  237. Room.limit(10)
  238. let rooms = await Room.find()
  239. rooms = rooms.map((room) => room.toJSON())
  240. // hotels = hotels.concat(hotels).concat(hotels).concat(hotels).concat(hotels)
  241. rooms = this.data.loadIndex == 1 ? rooms : this.data.rooms.concat(rooms)
  242. this.setData({ rooms })
  243. console.log(rooms)
  244. }
  245. }
  246. })