// nova-tourism/components/collect/index.js let Parse = getApp().Parse; const company = getApp().globalData.company const uid = Parse.User.current()?.id const req = require('../../../utils/request') Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { taps: [{ url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/r1kr6b044821198.png', tex: '望仙礼遇', }, { url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/r1on6t044840728.png', tex: '妆造旅拍', }, { url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/v16vb1044858389.png', tex: '望仙果蔬', }, { url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/dm2ol9044926231.png', tex: '房务服务', }, { url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241231/1pglm9032750560.png', tex: '商学院', }, ], imageUrls: ['https://img95.699pic.com/photo/60072/5330.jpg_wh860.jpg', 'https://c-ssl.dtstatic.com/uploads/blog/201409/27/20140927230814_4QfVC.thumb.1000_0.jpeg', 'https://ts1.cn.mm.bing.net/th/id/R-C.37f4077f8eaca918401b84b4ee23af7c?rik=7HYWC88a9q4sZw&riu=http%3a%2f%2fpic.616pic.com%2fphotoone%2f00%2f06%2f03%2f618e27ad7ce8e1124.jpg&ehk=jkc6iZWAg%2bAEjAk6%2br0VAAy1lfffqslT6n%2fMWl293Yc%3d&risl=&pid=ImgRaw&r=0' ], date_start: '', date_end: '', start: '', end: '', istoday: true, daysBetween: 1, currentTab: 0, // 云上风物/我的收藏 banner:[],//热门推荐 giftBanner:[],//望仙礼遇-轮播图 gift:[],//望仙礼遇-商品 }, lifetimes: { detached: function () {}, attached: async function () { this.gethomestar() this.getcurrentdate() this.refersh() }, }, /** * 组件的方法列表 */ methods: { refersh(){ this.getBanner() this.getGiftBanner() this.getGift() }, /**切换 云上风物/我的收藏 */ switchTab(e) { const index = e.currentTarget.dataset.index; this.setData({ currentTab: index }); }, /**获取热门推荐 */ async getBanner(){ let query = new Parse.Query('Banner') query.equalTo('company',company) query.notEqualTo('isDeleted',true) query.equalTo('isEnabled',true) query.equalTo('type','season') query.include('shopGoods') let d = await query.find() let banner = [] banner=d?.map(item=>{ let obj = {} obj.image = item?.get('image')||item?.get('shopGoods')?.get('image') obj.url = item?.get('url')||`/nova-tourism/pages/collect/collect-detail/index?gid=${item?.get('shopGoods')?.id}` return obj }) this.setData({banner}) }, /**获取望仙礼遇-轮播图 */ async getGiftBanner(){ let sql = `SELECT good."objectId",good."image" FROM "ShopGoods" good WHERE good."company" = 'EbxZUK5lBI' AND good."isDeleted" IS NOT TRUE AND good."status" IS TRUE ORDER BY COALESCE(good."isRecom", FALSE) DESC, CASE WHEN good."top"= 0 THEN 1 ELSE 0 END, good."top" ASC LIMIT 8` let giftBanner = await req.customSQL(sql)||[] this.setData({giftBanner}) console.log(giftBanner) }, /** 获取望仙礼遇-商品*/ async getGift(){ let sql = `SELECT good."objectId",good."name",good."price",good."image" FROM "ShopGoods" good WHERE good."company" = '${company}' AND good."isDeleted" IS NOT TRUE AND good."status" IS TRUE ORDER BY COALESCE(good."isHome", FALSE) DESC, CASE WHEN good."top"= 0 THEN 1 ELSE 0 END, good."top" ASC,good."createdAt" LIMIT 4` let gift = await req.customSQL(sql)||[] console.log(gift) this.setData({gift}) }, //获取收藏店铺消息 async gethomestar() { const currentUser = Parse.User.current(); console.log(currentUser); let ShopStore = new Parse.Query('DramaShopCollect'); ShopStore.equalTo('company', company); ShopStore.equalTo('user', currentUser.id); ShopStore.equalTo('isCollect', 'true'); ShopStore.notEqualTo('isDeleted', "true"); ShopStore.include('homestayStore'); let store = await ShopStore.find(); let storeList = store.map(item => item.toJSON()); this.setData({ storeList }); console.log('123', this.data.storeList); }, //点击取消 async cancle(e) { const object = e.currentTarget.dataset.id const currentUser = Parse.User.current(); let Collect = new Parse.Query('DramaShopCollect'); Collect.equalTo('company', company); Collect.equalTo('user', currentUser.id); Collect.equalTo('isCollect', true); Collect.equalTo('homestayStore', object); Collect.notEqualTo('isDeleted', "true"); let collect = await Collect.first(); await this.changeiscollect(object) if (collect) { collect.set('isCollect', false) try { let saveDate = await collect.save(); console.log(saveDate); console.log("取消成功"); } catch (error) { console.error("保存数据时出现错误:", error); } } }, // 点击收藏后把storeList中对应的isCollect变成true changeiscollect(objectId) { // 创建一个新的 storeList 数组,以确保视图更新 const updatedStoreList = this.data.storeList.map(item => { if (item.homestayStore.objectId === objectId) { return { ...item, isCollect: !item.isCollect // 切换 iscollect 的值 }; } return item; // 返回未修改的项 }); // 更新 storeList this.setData({ storeList: updatedStoreList }); console.log('修改成功', objectId); }, //转换日期 formatDate(date) { date = new Date(date); return `${date.getMonth() + 1}月${date.getDate()}日`; }, //获取今日明日日期 getcurrentdate() { const today = new Date(); const tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1); this.setData({ date_start: this.formatDate(today), date_end: this.formatDate(tomorrow), start: today, end: tomorrow }); console.log(this.data.start, this.data.end); }, //去收藏商铺 gourl(e) { const url = e.currentTarget.dataset.url; const id = e.currentTarget.dataset.id; // 构造要传递的信息 const info = { objectId: id, date_start: this.data.date_start, date_end: this.data.date_end, daysBetween: this.data.daysBetween, istoday: this.data.istoday, start: this.data.start, end: this.data.end }; // 将信息转为查询字符串 const queryString = Object.keys(info) .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`) .join('&'); // 使用查询字符串跳转 wx.navigateTo({ url: `${url}?${queryString}`, }); }, /** 跳转*/ tourl(e) { const url = e.currentTarget.dataset.url wx.navigateTo({ url: `${url}` // 目标页面的路径 }); }, } })