index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. taps: [{
  20. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241212/1eil1p104028966.png',
  21. tex: '望仙礼遇',
  22. },
  23. {
  24. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241212/hb84u2104029067.png',
  25. tex: '妆造旅拍',
  26. },
  27. {
  28. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241212/8jb180104028856.png',
  29. tex: '望仙果蔬',
  30. },
  31. {
  32. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241212/hjo5t1104029406.png',
  33. tex: '房务服务',
  34. },
  35. ],
  36. imageUrls: ['https://file-cloud.fmode.cn//tmp/srFPqGFAzeT5958c828d985e451ed4c0b452e39ff57a.jpeg',
  37. 'https://file-cloud.fmode.cn//tmp/P7YTTX6XuEZC607368e1f9745abc429c7c25cbef4c5a.jpeg',
  38. 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241121/jc17lo114657420.jpg'
  39. ],
  40. date_start: '',
  41. date_end: '',
  42. start: '',
  43. end: '',
  44. istoday: true,
  45. daysBetween: 1,
  46. currentTab: 0
  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. switchTab (e) {
  74. const index = e.currentTarget.dataset.index;
  75. this.setData({
  76. currentTab: index
  77. });
  78. console.log(this.data.currentTab);
  79. },
  80. //获取收藏店铺消息
  81. async gethomestar() {
  82. const currentUser = Parse.User.current();
  83. console.log(currentUser);
  84. let ShopStore = new Parse.Query('DramaShopCollect');
  85. ShopStore.equalTo('company', company);
  86. ShopStore.equalTo('user', currentUser.id);
  87. ShopStore.equalTo('isCollect', 'true');
  88. ShopStore.notEqualTo('isDeleted', "true");
  89. ShopStore.include('homestayStore');
  90. let store = await ShopStore.find();
  91. let storeList = store.map(item => item.toJSON());
  92. this.setData({
  93. storeList
  94. });
  95. console.log('123', this.data.storeList);
  96. },
  97. //点击取消
  98. async cancle(e) {
  99. const object = e.currentTarget.dataset.id
  100. const currentUser = Parse.User.current();
  101. let Collect = new Parse.Query('DramaShopCollect');
  102. Collect.equalTo('company', company);
  103. Collect.equalTo('user', currentUser.id);
  104. Collect.equalTo('isCollect', true);
  105. Collect.equalTo('homestayStore', object);
  106. Collect.notEqualTo('isDeleted', "true");
  107. let collect = await Collect.first();
  108. await this.changeiscollect(object)
  109. if (collect) {
  110. collect.set('isCollect', false)
  111. try {
  112. let saveDate = await collect.save();
  113. console.log(saveDate);
  114. console.log("取消成功");
  115. } catch (error) {
  116. console.error("保存数据时出现错误:", error);
  117. }
  118. }
  119. },
  120. // 点击收藏后把storeList中对应的isCollect变成true
  121. changeiscollect(objectId) {
  122. // 创建一个新的 storeList 数组,以确保视图更新
  123. const updatedStoreList = this.data.storeList.map(item => {
  124. if (item.homestayStore.objectId === objectId) {
  125. return {
  126. ...item,
  127. isCollect: !item.isCollect // 切换 iscollect 的值
  128. };
  129. }
  130. return item; // 返回未修改的项
  131. });
  132. // 更新 storeList
  133. this.setData({
  134. storeList: updatedStoreList
  135. });
  136. console.log('修改成功', objectId);
  137. },
  138. //转换日期
  139. formatDate(date) {
  140. date = new Date(date);
  141. return `${date.getMonth() + 1}月${date.getDate()}日`;
  142. },
  143. //获取今日明日日期
  144. getcurrentdate() {
  145. const today = new Date();
  146. const tomorrow = new Date();
  147. tomorrow.setDate(today.getDate() + 1);
  148. this.setData({
  149. date_start: this.formatDate(today),
  150. date_end: this.formatDate(tomorrow),
  151. start: today,
  152. end: tomorrow
  153. });
  154. console.log(this.data.start, this.data.end);
  155. },
  156. //去收藏商铺
  157. gourl(e) {
  158. const url = e.currentTarget.dataset.url;
  159. const id = e.currentTarget.dataset.id;
  160. // 构造要传递的信息
  161. const info = {
  162. objectId: id,
  163. date_start: this.data.date_start,
  164. date_end: this.data.date_end,
  165. daysBetween: this.data.daysBetween,
  166. istoday: this.data.istoday,
  167. start: this.data.start,
  168. end: this.data.end
  169. };
  170. // 将信息转为查询字符串
  171. const queryString = Object.keys(info)
  172. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  173. .join('&');
  174. // 使用查询字符串跳转
  175. wx.navigateTo({
  176. url: `${url}?${queryString}`,
  177. });
  178. },
  179. //去商品详细
  180. gourl2(e){
  181. wx.navigateTo({
  182. url: `../../pages/collect/collect-detail/index`,
  183. });
  184. }
  185. }
  186. })