123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- let Parse = getApp().Parse
- const company = getApp().globalData.company
- const compute = require('../../../../utils/compute.js')
- let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
- Component({
- /**
- * 组件的属性列表
- */
- properties: {},
- /**
- * 组件的初始数据
- */
- data: {
- imgUrls: [
- 'https://s1.ax1x.com/2023/04/10/ppqifvF.png',
- 'https://s1.ax1x.com/2023/04/10/ppqiWgU.png',
- 'https://s1.ax1x.com/2023/04/10/ppqiR3T.png'
- ],
- list: [],
- hotels: [],
- rooms: [],
- active: 0,
- type:'recommend',
- loadIndex: 1,
- searchVal:'',
- showTab: false,
- stickytop: navigationBarHeight,
- tabs: [
- {
- title: '推荐',
- icon: 'https://s1.ax1x.com/2023/04/10/ppqEqdH.png',
- type:'recommend'
- },
- {
- title: '价格',
- icon: 'https://s1.ax1x.com/2023/04/10/ppqkh79.png',
- type:'price'
- },
- ],
- tabIndex: 0,
- },
- ready: function () {
- // 在组件布局完成后执行,确保options参数中有data信息
- // this.selectComponent('#tabs').resize()
- this.getRooms()
- },
-
- lifetimes: {
- created() {},
- attached() {
- this.loadMore()
- }
- },
-
- /**
- * 组件的方法列表
- */
- methods: {
- async getBanner() {
- let Banner = new Parse.Query('Banner')
- Banner.notEqualTo('isDeleted', "true")
- Banner.equalTo('company', company)
- Banner.equalTo('isEnabled', "true")
- Banner.equalTo('type','gourmet')
- let banner = await Banner.find()
- console.log(banner);
- if (banner && banner.length > 0) {
- let listJSON = []
- banner.forEach(c => {
- listJSON.push(c.toJSON())
- })
- this.setData({
- banner: listJSON
- })
- }
- },
- /**获取分类 */
- async getCategory(){
- let cate = new Parse.Query("Category")
- cate.notEqualTo('isDeleted', "true")
- cate.equalTo("company",company)
- cate.equalTo("type",'stayTag')
- let cateDate = await cate.find()
- let cateList = []
- cateDate.forEach(res=>{
- let item = res.toJSON()
- cateList.push(item)
- })
- if(cateList.length){
- this.setData({
- textItem:cateList[0]?.objectId,
- })
- }
- this.setData({
-
- cateList
- })
- },
- /**获取排行 */
- async getShopRank(id) {
- let ShopStore = new Parse.Query('ShopStore')
- ShopStore.notEqualTo('isDeleted', "true")
- ShopStore.equalTo('company', company)
- ShopStore.equalTo('type', "stay")
- ShopStore.equalTo('category', id)
- ShopStore.include("category")
- let shopStores = await ShopStore.find()
- if (shopStores) {
- let rankList = []
- for (let i = 0; i < shopStores.length; i++) {
- let json = shopStores[i].toJSON()
- rankList.push(json)
- }
- this.setData({
- rankList
- })
- }
- },
- /**选择分类 */
- changeText(e) {
- let {
- id
- } = e.currentTarget.dataset
- console.log(id);
- this.setData({
- textItem: id
- })
- this.getShopRank(id)
- },
- details(e) {
- let {id} = e.currentTarget.dataset
- console.log(e)
- wx.navigateTo({
- url: `/nova-tourism/pages/homestay/room-detail/index?id=${id}`
- })
- },
- async getHotels (type) {
- let Hotel = new Parse.Query('ShopStore')
- Hotel.notEqualTo('isDeleted', "true")
- Hotel.equalTo('company', company)
- Hotel.equalTo('type', 'stay')
- Hotel.select(
- 'cover',
- 'storeName',
- 'perCapita',
- 'address',
- 'type',
- 'isShow'
- )
- Hotel.equalTo('isShow', true)
- Hotel.skip((this.data.loadIndex - 1) * 10)
- if (type == 'price') {
- Hotel.ascending('perCapita')
- }
- Hotel.limit(10)
- let hotels = await Hotel.find()
- hotels = hotels.map((hotel) => hotel.toJSON())
- hotels = this.data.loadIndex == 1 ? hotels : this.data.hotels.concat(hotels)
- this.setData({ hotels })
- },
- toSearch() {
- wx.navigateTo({
- url: '/nova-tourism/pages/search/search'
- })
- },
- goUrl(e){
- let {url} = e.currentTarget.dataset
- wx.navigateTo({
- url: url,
- })
- },
- search(event){
- console.log(event);
- this.getRooms()
- },
- searchClear(){
- this.data.searchVal = '';
- this.getRooms()
- },
- showSearchBtn(){
- this.setData({
- searchBtn:true
- })
- },
- hiddenSearchBtn(){
- this.setData({
- searchBtn:false
- })
- },
- onTabClick(e) {
- let { id , type } = e.currentTarget.dataset;
- this.data.active = id
- this.data.loadIndex = 1
- this.data.type = type
- this.setData({
- tabIndex: id,
- })
- this.getRooms()
- },
- tabChange(event) {
- this.data.active = event.detail.name
- this.data.loadIndex = 1
- this.data.type = event.detail.name
- this.getRooms()
- },
- async loadMore() {
- this.data.loadIndex++
- this.getBanner()
- this.getRooms()
- await this.getCategory()
- this.getShopRank(this.data.textItem)
- },
- async getRooms () {
- let type = this.data.type;
- let Room = new Parse.Query('ShopRoom')
- Room.equalTo('company', company)
- Room.equalTo('isEnabled', true)
- if(this.data.searchVal != ''){
- Room.contains('name',this.data.searchVal)
- }
- if (type == 'price') {
- Room.ascending('price')
- }
- if(type == 'recommend'){
- Room.equalTo('isRecom',true)
- }
- Room.skip((this.data.loadIndex - 1) * 10)
- Room.select(
- 'name',
- 'images',
- 'price',
- 'total',
- 'remaining',
- 'merber',
- 'type',
- 'area',
- 'tags',
- 'address'
- )
- Room.limit(10)
- let rooms = await Room.find()
- rooms = rooms.map((room) => room.toJSON())
- // hotels = hotels.concat(hotels).concat(hotels).concat(hotels).concat(hotels)
- rooms = this.data.loadIndex == 1 ? rooms : this.data.rooms.concat(rooms)
- this.setData({ rooms })
- console.log(rooms)
- }
- }
- })
|