index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // nova-tourism/components/collect/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. const uid = Parse.User.current()?.id
  5. const req = require('../../../utils/request')
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. taps: [{
  17. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/r1kr6b044821198.png',
  18. tex: '望仙礼遇',
  19. },
  20. {
  21. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/r1on6t044840728.png',
  22. tex: '妆造旅拍',
  23. },
  24. {
  25. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/v16vb1044858389.png',
  26. tex: '望仙果蔬',
  27. },
  28. {
  29. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241230/dm2ol9044926231.png',
  30. tex: '房务服务',
  31. },
  32. {
  33. url: 'https://file-cloud.fmode.cn/EbxZUK5lBI/20241231/1pglm9032750560.png',
  34. tex: '商学院',
  35. },
  36. ],
  37. imageUrls: ['https://img95.699pic.com/photo/60072/5330.jpg_wh860.jpg',
  38. 'https://c-ssl.dtstatic.com/uploads/blog/201409/27/20140927230814_4QfVC.thumb.1000_0.jpeg',
  39. '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'
  40. ],
  41. date_start: '',
  42. date_end: '',
  43. start: '',
  44. end: '',
  45. istoday: true,
  46. daysBetween: 1,
  47. currentTab: 0, // 云上风物/我的收藏
  48. banner:[],//热门推荐
  49. giftBanner:[],//望仙礼遇-轮播图
  50. gift:[],//望仙礼遇-商品
  51. },
  52. lifetimes: {
  53. detached: function () {},
  54. attached: async function () {
  55. this.gethomestar()
  56. this.getcurrentdate()
  57. this.refersh()
  58. },
  59. },
  60. /**
  61. * 组件的方法列表
  62. */
  63. methods: {
  64. refersh(){
  65. this.getBanner()
  66. this.getGiftBanner()
  67. this.getGift()
  68. },
  69. /**切换 云上风物/我的收藏 */
  70. switchTab(e) {
  71. const index = e.currentTarget.dataset.index;
  72. this.setData({
  73. currentTab: index
  74. });
  75. },
  76. /**获取热门推荐 */
  77. async getBanner(){
  78. let query = new Parse.Query('Banner')
  79. query.equalTo('company',company)
  80. query.notEqualTo('isDeleted',true)
  81. query.equalTo('isEnabled',true)
  82. query.equalTo('type','season')
  83. query.include('shopGoods')
  84. let d = await query.find()
  85. let banner = []
  86. banner=d?.map(item=>{
  87. let obj = {}
  88. obj.image = item?.get('image')||item?.get('shopGoods')?.get('image')
  89. obj.url = item?.get('url')||`/nova-tourism/pages/collect/collect-detail/index?gid=${item?.get('shopGoods')?.id}`
  90. return obj
  91. })
  92. this.setData({banner})
  93. },
  94. /**获取望仙礼遇-轮播图 */
  95. async getGiftBanner(){
  96. let sql = `SELECT good."objectId",good."image"
  97. FROM "ShopGoods" good
  98. WHERE good."company" = 'EbxZUK5lBI'
  99. AND good."isDeleted" IS NOT TRUE
  100. AND good."status" IS TRUE
  101. ORDER BY COALESCE(good."isRecom", FALSE) DESC,
  102. CASE WHEN good."top"= 0 THEN 1 ELSE 0 END,
  103. good."top" ASC
  104. LIMIT 8`
  105. let giftBanner = await req.customSQL(sql)||[]
  106. this.setData({giftBanner})
  107. console.log(giftBanner)
  108. },
  109. /** 获取望仙礼遇-商品*/
  110. async getGift(){
  111. let sql = `SELECT good."objectId",good."name",good."price",good."image"
  112. FROM "ShopGoods" good
  113. WHERE good."company" = '${company}'
  114. AND good."isDeleted" IS NOT TRUE
  115. AND good."status" IS TRUE
  116. ORDER BY COALESCE(good."isHome", FALSE) DESC,
  117. CASE WHEN good."top"= 0 THEN 1 ELSE 0 END,
  118. good."top" ASC,good."createdAt"
  119. LIMIT 4`
  120. let gift = await req.customSQL(sql)||[]
  121. console.log(gift)
  122. this.setData({gift})
  123. },
  124. //获取收藏店铺消息
  125. async gethomestar() {
  126. const currentUser = Parse.User.current();
  127. console.log(currentUser);
  128. let ShopStore = new Parse.Query('DramaShopCollect');
  129. ShopStore.equalTo('company', company);
  130. ShopStore.equalTo('user', currentUser.id);
  131. ShopStore.equalTo('isCollect', 'true');
  132. ShopStore.notEqualTo('isDeleted', "true");
  133. ShopStore.include('homestayStore');
  134. let store = await ShopStore.find();
  135. let storeList = store.map(item => item.toJSON());
  136. this.setData({
  137. storeList
  138. });
  139. console.log('123', this.data.storeList);
  140. },
  141. //点击取消
  142. async cancle(e) {
  143. const object = e.currentTarget.dataset.id
  144. const currentUser = Parse.User.current();
  145. let Collect = new Parse.Query('DramaShopCollect');
  146. Collect.equalTo('company', company);
  147. Collect.equalTo('user', currentUser.id);
  148. Collect.equalTo('isCollect', true);
  149. Collect.equalTo('homestayStore', object);
  150. Collect.notEqualTo('isDeleted', "true");
  151. let collect = await Collect.first();
  152. await this.changeiscollect(object)
  153. if (collect) {
  154. collect.set('isCollect', false)
  155. try {
  156. let saveDate = await collect.save();
  157. console.log(saveDate);
  158. console.log("取消成功");
  159. } catch (error) {
  160. console.error("保存数据时出现错误:", error);
  161. }
  162. }
  163. },
  164. // 点击收藏后把storeList中对应的isCollect变成true
  165. changeiscollect(objectId) {
  166. // 创建一个新的 storeList 数组,以确保视图更新
  167. const updatedStoreList = this.data.storeList.map(item => {
  168. if (item.homestayStore.objectId === objectId) {
  169. return {
  170. ...item,
  171. isCollect: !item.isCollect // 切换 iscollect 的值
  172. };
  173. }
  174. return item; // 返回未修改的项
  175. });
  176. // 更新 storeList
  177. this.setData({
  178. storeList: updatedStoreList
  179. });
  180. console.log('修改成功', objectId);
  181. },
  182. //转换日期
  183. formatDate(date) {
  184. date = new Date(date);
  185. return `${date.getMonth() + 1}月${date.getDate()}日`;
  186. },
  187. //获取今日明日日期
  188. getcurrentdate() {
  189. const today = new Date();
  190. const tomorrow = new Date();
  191. tomorrow.setDate(today.getDate() + 1);
  192. this.setData({
  193. date_start: this.formatDate(today),
  194. date_end: this.formatDate(tomorrow),
  195. start: today,
  196. end: tomorrow
  197. });
  198. console.log(this.data.start, this.data.end);
  199. },
  200. //去收藏商铺
  201. gourl(e) {
  202. const url = e.currentTarget.dataset.url;
  203. const id = e.currentTarget.dataset.id;
  204. // 构造要传递的信息
  205. const info = {
  206. objectId: id,
  207. date_start: this.data.date_start,
  208. date_end: this.data.date_end,
  209. daysBetween: this.data.daysBetween,
  210. istoday: this.data.istoday,
  211. start: this.data.start,
  212. end: this.data.end
  213. };
  214. // 将信息转为查询字符串
  215. const queryString = Object.keys(info)
  216. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  217. .join('&');
  218. // 使用查询字符串跳转
  219. wx.navigateTo({
  220. url: `${url}?${queryString}`,
  221. });
  222. },
  223. /** 跳转*/
  224. tourl(e) {
  225. const url = e.currentTarget.dataset.url
  226. wx.navigateTo({
  227. url: `${url}` // 目标页面的路径
  228. });
  229. },
  230. }
  231. })