123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- // nova-tourism/components/collect/index.js
- let Parse = getApp().Parse;
- const company = getApp().globalData.company
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- statusBarHeight: 0,
- screenHeight: 0,
- customHeight: 0,
- bottomNavHeight: 0,
- contentHeight: 0,
- active: 0,
- taps: [{
- url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/511ua1025435972.png',
- tex: '望仙礼遇',
- },
- {
- url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/opk1db025446786.png',
- tex: '妆造旅拍',
- },
- {
- url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/f12978025423947.png',
- tex: '望仙果蔬',
- },
- {
- url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/365p16025500910.png',
- tex: '房务服务',
- },
- ],
- imageUrls: ['https://file-cloud.fmode.cn//tmp/srFPqGFAzeT5958c828d985e451ed4c0b452e39ff57a.jpeg',
- 'https://file-cloud.fmode.cn//tmp/P7YTTX6XuEZC607368e1f9745abc429c7c25cbef4c5a.jpeg',
- 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241121/jc17lo114657420.jpg'
- ],
- date_start: '',
- date_end: '',
- start: '',
- end: '',
- istoday: true,
- daysBetween: 1
- },
- lifetimes: {
- detached: function () {},
- attached: async function () {
- const systemInfo = wx.getSystemInfoSync();
- const statusBarHeight = systemInfo.statusBarHeight || 0;
- const screenHeight = systemInfo.screenHeight || 0;
- const custom = wx.getMenuButtonBoundingClientRect();
- const customHeight = custom.height + 10 + 2 || 0;
- const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
- const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
- this.setData({
- statusBarHeight,
- screenHeight,
- customHeight,
- bottomNavHeight,
- contentHeight
- });
- this.gethomestar()
- this.getcurrentdate()
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- //获取收藏店铺消息
- 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}`,
- });
- },
- }
- })
|