123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- // 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,
- },
- 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()
- },
- },
- /**
- * 组件的方法列表
- */
- 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);
- },
- }
- })
|