index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. taps: [{
  21. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/511ua1025435972.png',
  22. tex: '望仙礼遇',
  23. },
  24. {
  25. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/opk1db025446786.png',
  26. tex: '妆造旅拍',
  27. },
  28. {
  29. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/f12978025423947.png',
  30. tex: '望仙果蔬',
  31. },
  32. {
  33. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241126/365p16025500910.png',
  34. tex: '房务服务',
  35. },
  36. ],
  37. imageUrls: ['https://file-cloud.fmode.cn//tmp/srFPqGFAzeT5958c828d985e451ed4c0b452e39ff57a.jpeg',
  38. 'https://file-cloud.fmode.cn//tmp/P7YTTX6XuEZC607368e1f9745abc429c7c25cbef4c5a.jpeg',
  39. 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241121/jc17lo114657420.jpg'
  40. ]
  41. },
  42. lifetimes: {
  43. detached: function () {},
  44. attached: async function () {
  45. const systemInfo = wx.getSystemInfoSync();
  46. const statusBarHeight = systemInfo.statusBarHeight || 0;
  47. const screenHeight = systemInfo.screenHeight || 0;
  48. const custom = wx.getMenuButtonBoundingClientRect();
  49. const customHeight = custom.height + 10 + 2 || 0;
  50. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  51. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  52. this.setData({
  53. statusBarHeight,
  54. screenHeight,
  55. customHeight,
  56. bottomNavHeight,
  57. contentHeight
  58. });
  59. this.gethomestar()
  60. },
  61. },
  62. /**
  63. * 组件的方法列表
  64. */
  65. methods: {
  66. //获取收藏店铺消息
  67. async gethomestar() {
  68. const currentUser = Parse.User.current();
  69. console.log(currentUser);
  70. let ShopStore = new Parse.Query('DramaShopCollect');
  71. ShopStore.equalTo('company', company);
  72. ShopStore.equalTo('user', currentUser.id);
  73. ShopStore.equalTo('isCollect', 'true');
  74. ShopStore.notEqualTo('isDeleted', "true");
  75. ShopStore.include('homestayStore');
  76. let store = await ShopStore.find();
  77. let storeList = store.map(item => item.toJSON());
  78. this.setData({
  79. storeList
  80. });
  81. console.log('123', this.data.storeList);
  82. },
  83. //点击取消
  84. async cancle(e) {
  85. const object = e.currentTarget.dataset.id
  86. const currentUser = Parse.User.current();
  87. let Collect = new Parse.Query('DramaShopCollect');
  88. Collect.equalTo('company', company);
  89. Collect.equalTo('user', currentUser.id);
  90. Collect.equalTo('isCollect', true);
  91. Collect.equalTo('homestayStore', object);
  92. Collect.notEqualTo('isDeleted', "true");
  93. let collect = await Collect.first();
  94. await this.changeiscollect(object)
  95. if (collect) {
  96. collect.set('isCollect', false)
  97. try {
  98. let saveDate = await collect.save();
  99. console.log(saveDate);
  100. console.log("取消成功");
  101. } catch (error) {
  102. console.error("保存数据时出现错误:", error);
  103. }
  104. }
  105. },
  106. // 点击收藏后把storeList中对应的isCollect变成true
  107. changeiscollect(objectId) {
  108. // 创建一个新的 storeList 数组,以确保视图更新
  109. const updatedStoreList = this.data.storeList.map(item => {
  110. if (item.homestayStore.objectId === objectId) {
  111. return {
  112. ...item,
  113. isCollect: !item.isCollect // 切换 iscollect 的值
  114. };
  115. }
  116. return item; // 返回未修改的项
  117. });
  118. // 更新 storeList
  119. this.setData({
  120. storeList: updatedStoreList
  121. });
  122. console.log('修改成功', objectId);
  123. },
  124. }
  125. })