index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. date_start: '',
  42. date_end: '',
  43. start: '',
  44. end: '',
  45. istoday: true,
  46. daysBetween: 1
  47. },
  48. lifetimes: {
  49. detached: function () {},
  50. attached: async function () {
  51. const systemInfo = wx.getSystemInfoSync();
  52. const statusBarHeight = systemInfo.statusBarHeight || 0;
  53. const screenHeight = systemInfo.screenHeight || 0;
  54. const custom = wx.getMenuButtonBoundingClientRect();
  55. const customHeight = custom.height + 10 + 2 || 0;
  56. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  57. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  58. this.setData({
  59. statusBarHeight,
  60. screenHeight,
  61. customHeight,
  62. bottomNavHeight,
  63. contentHeight
  64. });
  65. this.gethomestar()
  66. this.getcurrentdate()
  67. },
  68. },
  69. /**
  70. * 组件的方法列表
  71. */
  72. methods: {
  73. //获取收藏店铺消息
  74. async gethomestar() {
  75. const currentUser = Parse.User.current();
  76. console.log(currentUser);
  77. let ShopStore = new Parse.Query('DramaShopCollect');
  78. ShopStore.equalTo('company', company);
  79. ShopStore.equalTo('user', currentUser.id);
  80. ShopStore.equalTo('isCollect', 'true');
  81. ShopStore.notEqualTo('isDeleted', "true");
  82. ShopStore.include('homestayStore');
  83. let store = await ShopStore.find();
  84. let storeList = store.map(item => item.toJSON());
  85. this.setData({
  86. storeList
  87. });
  88. console.log('123', this.data.storeList);
  89. },
  90. //点击取消
  91. async cancle(e) {
  92. const object = e.currentTarget.dataset.id
  93. const currentUser = Parse.User.current();
  94. let Collect = new Parse.Query('DramaShopCollect');
  95. Collect.equalTo('company', company);
  96. Collect.equalTo('user', currentUser.id);
  97. Collect.equalTo('isCollect', true);
  98. Collect.equalTo('homestayStore', object);
  99. Collect.notEqualTo('isDeleted', "true");
  100. let collect = await Collect.first();
  101. await this.changeiscollect(object)
  102. if (collect) {
  103. collect.set('isCollect', false)
  104. try {
  105. let saveDate = await collect.save();
  106. console.log(saveDate);
  107. console.log("取消成功");
  108. } catch (error) {
  109. console.error("保存数据时出现错误:", error);
  110. }
  111. }
  112. },
  113. // 点击收藏后把storeList中对应的isCollect变成true
  114. changeiscollect(objectId) {
  115. // 创建一个新的 storeList 数组,以确保视图更新
  116. const updatedStoreList = this.data.storeList.map(item => {
  117. if (item.homestayStore.objectId === objectId) {
  118. return {
  119. ...item,
  120. isCollect: !item.isCollect // 切换 iscollect 的值
  121. };
  122. }
  123. return item; // 返回未修改的项
  124. });
  125. // 更新 storeList
  126. this.setData({
  127. storeList: updatedStoreList
  128. });
  129. console.log('修改成功', objectId);
  130. },
  131. //转换日期
  132. formatDate(date) {
  133. date = new Date(date);
  134. return `${date.getMonth() + 1}月${date.getDate()}日`;
  135. },
  136. //获取今日明日日期
  137. getcurrentdate() {
  138. const today = new Date();
  139. const tomorrow = new Date();
  140. tomorrow.setDate(today.getDate() + 1);
  141. this.setData({
  142. date_start: this.formatDate(today),
  143. date_end: this.formatDate(tomorrow),
  144. start: today,
  145. end: tomorrow
  146. });
  147. console.log(this.data.start, this.data.end);
  148. },
  149. //去收藏商铺
  150. gourl(e) {
  151. const url = e.currentTarget.dataset.url;
  152. const id = e.currentTarget.dataset.id;
  153. // 构造要传递的信息
  154. const info = {
  155. objectId: id,
  156. date_start: this.data.date_start,
  157. date_end: this.data.date_end,
  158. daysBetween: this.data.daysBetween,
  159. istoday: this.data.istoday,
  160. start: this.data.start,
  161. end: this.data.end
  162. };
  163. // 将信息转为查询字符串
  164. const queryString = Object.keys(info)
  165. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  166. .join('&');
  167. // 使用查询字符串跳转
  168. wx.navigateTo({
  169. url: `${url}?${queryString}`,
  170. });
  171. },
  172. //去商品详细
  173. gourl2(e){
  174. wx.navigateTo({
  175. url: `../../pages/collect/collect-detail/index`,
  176. });
  177. }
  178. }
  179. })