index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // nova-tourism/components/collect/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. statusBarHeight: 0,
  15. screenHeight: 0,
  16. customHeight: 0,
  17. bottomNavHeight: 0,
  18. contentHeight: 0,
  19. active: 0,
  20. },
  21. lifetimes: {
  22. detached: function () {},
  23. attached: async function () {
  24. const systemInfo = wx.getSystemInfoSync();
  25. const statusBarHeight = systemInfo.statusBarHeight || 0;
  26. const screenHeight = systemInfo.screenHeight || 0;
  27. const custom = wx.getMenuButtonBoundingClientRect();
  28. const customHeight = custom.height + 10 + 2 || 0;
  29. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  30. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  31. this.setData({
  32. statusBarHeight,
  33. screenHeight,
  34. customHeight,
  35. bottomNavHeight,
  36. contentHeight
  37. });
  38. this.gethomestar()
  39. },
  40. },
  41. /**
  42. * 组件的方法列表
  43. */
  44. methods: {
  45. //获取收藏店铺消息
  46. async gethomestar() {
  47. const currentUser = Parse.User.current();
  48. console.log(currentUser);
  49. let ShopStore = new Parse.Query('DramaShopCollect');
  50. ShopStore.equalTo('company', company);
  51. ShopStore.equalTo('user', currentUser.id);
  52. ShopStore.equalTo('isCollect', 'true');
  53. ShopStore.notEqualTo('isDeleted', "true");
  54. ShopStore.include('homestayStore');
  55. let store = await ShopStore.find();
  56. let storeList = store.map(item => item.toJSON());
  57. this.setData({
  58. storeList
  59. });
  60. console.log('123', this.data.storeList);
  61. },
  62. //点击取消
  63. async cancle(e) {
  64. const object = e.currentTarget.dataset.id
  65. const currentUser = Parse.User.current();
  66. let Collect = new Parse.Query('DramaShopCollect');
  67. Collect.equalTo('company', company);
  68. Collect.equalTo('user', currentUser.id);
  69. Collect.equalTo('isCollect', true);
  70. Collect.equalTo('homestayStore', object);
  71. Collect.notEqualTo('isDeleted', "true");
  72. let collect = await Collect.first();
  73. await this.changeiscollect(object)
  74. if (collect) {
  75. collect.set('isCollect', false)
  76. try {
  77. let saveDate = await collect.save();
  78. console.log(saveDate);
  79. console.log("取消成功");
  80. } catch (error) {
  81. console.error("保存数据时出现错误:", error);
  82. }
  83. }
  84. },
  85. // 点击收藏后把storeList中对应的isCollect变成true
  86. changeiscollect(objectId) {
  87. // 创建一个新的 storeList 数组,以确保视图更新
  88. const updatedStoreList = this.data.storeList.map(item => {
  89. if (item.homestayStore.objectId === objectId) {
  90. return {
  91. ...item,
  92. isCollect: !item.isCollect // 切换 iscollect 的值
  93. };
  94. }
  95. return item; // 返回未修改的项
  96. });
  97. // 更新 storeList
  98. this.setData({
  99. storeList: updatedStoreList
  100. });
  101. console.log('修改成功', objectId);
  102. },
  103. }
  104. })