index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/20241230/r1kr6b044821198.png',
  21. tex: '望仙礼遇',
  22. },
  23. {
  24. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/r1on6t044840728.png',
  25. tex: '妆造旅拍',
  26. },
  27. {
  28. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/v16vb1044858389.png',
  29. tex: '望仙果蔬',
  30. },
  31. {
  32. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/dm2ol9044926231.png',
  33. tex: '房务服务',
  34. },
  35. {
  36. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241231/1pglm9032750560.png',
  37. tex: '商学院',
  38. },
  39. ],
  40. imageUrls: ['https://img95.699pic.com/photo/60072/5330.jpg_wh860.jpg',
  41. 'https://c-ssl.dtstatic.com/uploads/blog/201409/27/20140927230814_4QfVC.thumb.1000_0.jpeg',
  42. 'https://ts1.cn.mm.bing.net/th/id/R-C.37f4077f8eaca918401b84b4ee23af7c?rik=7HYWC88a9q4sZw&riu=http%3a%2f%2fpic.616pic.com%2fphotoone%2f00%2f06%2f03%2f618e27ad7ce8e1124.jpg&ehk=jkc6iZWAg%2bAEjAk6%2br0VAAy1lfffqslT6n%2fMWl293Yc%3d&risl=&pid=ImgRaw&r=0'
  43. ],
  44. date_start: '',
  45. date_end: '',
  46. start: '',
  47. end: '',
  48. istoday: true,
  49. daysBetween: 1,
  50. currentTab: 0
  51. },
  52. lifetimes: {
  53. detached: function () {},
  54. attached: async function () {
  55. const systemInfo = wx.getSystemInfoSync();
  56. const statusBarHeight = systemInfo.statusBarHeight || 0;
  57. const screenHeight = systemInfo.screenHeight || 0;
  58. const custom = wx.getMenuButtonBoundingClientRect();
  59. const customHeight = custom.height + 10 + 2 || 0;
  60. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  61. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  62. this.setData({
  63. statusBarHeight,
  64. screenHeight,
  65. customHeight,
  66. bottomNavHeight,
  67. contentHeight
  68. });
  69. this.gethomestar()
  70. this.getcurrentdate()
  71. },
  72. },
  73. /**
  74. * 组件的方法列表
  75. */
  76. methods: {
  77. switchTab (e) {
  78. const index = e.currentTarget.dataset.index;
  79. this.setData({
  80. currentTab: index
  81. });
  82. console.log(this.data.currentTab);
  83. },
  84. //获取收藏店铺消息
  85. async gethomestar() {
  86. const currentUser = Parse.User.current();
  87. console.log(currentUser);
  88. let ShopStore = new Parse.Query('DramaShopCollect');
  89. ShopStore.equalTo('company', company);
  90. ShopStore.equalTo('user', currentUser.id);
  91. ShopStore.equalTo('isCollect', 'true');
  92. ShopStore.notEqualTo('isDeleted', "true");
  93. ShopStore.include('homestayStore');
  94. let store = await ShopStore.find();
  95. let storeList = store.map(item => item.toJSON());
  96. this.setData({
  97. storeList
  98. });
  99. console.log('123', this.data.storeList);
  100. },
  101. //点击取消
  102. async cancle(e) {
  103. const object = e.currentTarget.dataset.id
  104. const currentUser = Parse.User.current();
  105. let Collect = new Parse.Query('DramaShopCollect');
  106. Collect.equalTo('company', company);
  107. Collect.equalTo('user', currentUser.id);
  108. Collect.equalTo('isCollect', true);
  109. Collect.equalTo('homestayStore', object);
  110. Collect.notEqualTo('isDeleted', "true");
  111. let collect = await Collect.first();
  112. await this.changeiscollect(object)
  113. if (collect) {
  114. collect.set('isCollect', false)
  115. try {
  116. let saveDate = await collect.save();
  117. console.log(saveDate);
  118. console.log("取消成功");
  119. } catch (error) {
  120. console.error("保存数据时出现错误:", error);
  121. }
  122. }
  123. },
  124. // 点击收藏后把storeList中对应的isCollect变成true
  125. changeiscollect(objectId) {
  126. // 创建一个新的 storeList 数组,以确保视图更新
  127. const updatedStoreList = this.data.storeList.map(item => {
  128. if (item.homestayStore.objectId === objectId) {
  129. return {
  130. ...item,
  131. isCollect: !item.isCollect // 切换 iscollect 的值
  132. };
  133. }
  134. return item; // 返回未修改的项
  135. });
  136. // 更新 storeList
  137. this.setData({
  138. storeList: updatedStoreList
  139. });
  140. console.log('修改成功', objectId);
  141. },
  142. //转换日期
  143. formatDate(date) {
  144. date = new Date(date);
  145. return `${date.getMonth() + 1}月${date.getDate()}日`;
  146. },
  147. //获取今日明日日期
  148. getcurrentdate() {
  149. const today = new Date();
  150. const tomorrow = new Date();
  151. tomorrow.setDate(today.getDate() + 1);
  152. this.setData({
  153. date_start: this.formatDate(today),
  154. date_end: this.formatDate(tomorrow),
  155. start: today,
  156. end: tomorrow
  157. });
  158. console.log(this.data.start, this.data.end);
  159. },
  160. //去收藏商铺
  161. gourl(e) {
  162. const url = e.currentTarget.dataset.url;
  163. const id = e.currentTarget.dataset.id;
  164. // 构造要传递的信息
  165. const info = {
  166. objectId: id,
  167. date_start: this.data.date_start,
  168. date_end: this.data.date_end,
  169. daysBetween: this.data.daysBetween,
  170. istoday: this.data.istoday,
  171. start: this.data.start,
  172. end: this.data.end
  173. };
  174. // 将信息转为查询字符串
  175. const queryString = Object.keys(info)
  176. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  177. .join('&');
  178. // 使用查询字符串跳转
  179. wx.navigateTo({
  180. url: `${url}?${queryString}`,
  181. });
  182. },
  183. //去商品详细
  184. gourl2(e){
  185. wx.navigateTo({
  186. url: `../../pages/collect/collect-detail/index`,
  187. });
  188. }
  189. }
  190. })