|
@@ -1,4 +1,6 @@
|
|
// nova-tourism/components/collect/index.js
|
|
// nova-tourism/components/collect/index.js
|
|
|
|
+let Parse = getApp().Parse;
|
|
|
|
+const company = getApp().globalData.company
|
|
Component({
|
|
Component({
|
|
/**
|
|
/**
|
|
* 组件的属性列表
|
|
* 组件的属性列表
|
|
@@ -11,13 +13,101 @@ Component({
|
|
* 组件的初始数据
|
|
* 组件的初始数据
|
|
*/
|
|
*/
|
|
data: {
|
|
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: {
|
|
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);
|
|
|
|
+ },
|
|
}
|
|
}
|
|
-})
|
|
|
|
|
|
+})
|