index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. let Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const uid = Parse.User.current()?.id
  4. const {
  5. getStores
  6. } = require(".././../service/request")
  7. let sev = require('../../service/request')
  8. const dateF = require('../../../utils/date')
  9. Component({
  10. /**
  11. * 组件的属性列表
  12. */
  13. properties: {},
  14. /**
  15. * 组件的初始数据
  16. */
  17. data: {
  18. statusBarHeight: 0,
  19. screenHeight: 0,
  20. customHeight: 0,
  21. bottomNavHeight: 0,
  22. contentHeight: 0,
  23. topheight: 0,
  24. date_start: '',
  25. date_end: '',
  26. date_start1: '',
  27. date_end1: '',
  28. istoday: true,
  29. daysBetween: 1,
  30. show: false,
  31. //店铺数据
  32. storeList: [],
  33. oddList: [], //单数列-两列布局用到
  34. evenList: [], //双数列-两列布局用到
  35. //价格
  36. price: 211,
  37. value: '', //搜索
  38. valueTimeout: null, //搜索框计时器
  39. start: '',
  40. end: '',
  41. //触底加载
  42. loadedItems: 0,
  43. pageSize: 5,
  44. noMoreItems: false,
  45. specDateMap: {}, //今日-明日 日期对应
  46. showRoom: [], //首页推荐店铺
  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. const topheight = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth
  59. this.setData({
  60. statusBarHeight,
  61. screenHeight,
  62. customHeight,
  63. bottomNavHeight,
  64. contentHeight,
  65. topheight
  66. });
  67. this.getcurrentdate();
  68. this.getShopStore()
  69. this.getShowRoom()
  70. },
  71. },
  72. /**
  73. * 组件的方法列表
  74. */
  75. methods: {
  76. /** 初始日期-今日明日*/
  77. getcurrentdate() {
  78. const today = new Date();
  79. const tomorrow = new Date();
  80. tomorrow.setDate(today.getDate() + 1);
  81. let date_start = this.formatDate(today)
  82. let date_end = this.formatDate(tomorrow)
  83. let specDateMap = {}
  84. specDateMap[date_start] = '今天'
  85. specDateMap[date_end] = '明天'
  86. this.setData({
  87. date_start,
  88. date_end,
  89. specDateMap,
  90. start: today,
  91. end: tomorrow
  92. });
  93. },
  94. /**日历-开*/
  95. onDisplay() {
  96. this.setData({
  97. show: true
  98. });
  99. },
  100. /**日历-关*/
  101. onClose() {
  102. this.setData({
  103. show: false
  104. });
  105. },
  106. /** 选好日期点击完成后*/
  107. async onConfirm(event) {
  108. const [start, end] = event.detail;
  109. const daysBetween = sev.getDays(start, end); // 计算天数差
  110. this.setData({
  111. show: false,
  112. start,
  113. end,
  114. date_start: `${this.formatDate(start)}`,
  115. date_end: `${this.formatDate(end)}`,
  116. daysBetween
  117. });
  118. },
  119. /**获取店铺 */
  120. async getShopStore() {
  121. let {
  122. value,
  123. storeList,
  124. oddList,
  125. evenList
  126. } = this.data
  127. let d = await sev.getStores({
  128. val: value || '',
  129. uid: uid,
  130. skip: storeList?.length || 0,
  131. limit: 8
  132. })
  133. let odd = d?.filter((item, index) => index % 2 != 0) || []
  134. let even = d?.filter((item, index) => index % 2 == 0) || []
  135. oddList = [...oddList, ...odd]
  136. evenList = [...evenList, ...even]
  137. storeList = [...(evenList || []), ...(oddList || [])]
  138. console.log(storeList)
  139. this.setData({
  140. storeList,
  141. oddList,
  142. evenList
  143. })
  144. },
  145. /**获取首页推荐 */
  146. async getShowRoom() {
  147. let d = await sev.getStores({
  148. uid: uid,
  149. skip: 0,
  150. limit: 3,
  151. isShow: true
  152. })
  153. this.setData({
  154. showRoom: d || []
  155. })
  156. },
  157. /**关键字搜索 */
  158. changeValue() {
  159. let {
  160. valueTimeout
  161. } = this.data
  162. clearTimeout(valueTimeout)
  163. let that = this
  164. valueTimeout = setTimeout(() => {
  165. that.setData({
  166. storeList: [],
  167. oddList: [],
  168. evenList: []
  169. })
  170. that.getShopStore()
  171. }, 2000);
  172. this.setData({
  173. valueTimeout
  174. })
  175. },
  176. toStore(e) {
  177. let {store_id} = e.currentTarget.dataset
  178. let {start,end}=this.data
  179. let url = `/nova-tourism/pages/homestay/homestay-detail/index?store_id=${store_id}&start=${dateF.formatTime("YYYY-mm-dd", start)}&end=${dateF.formatTime("YYYY-mm-dd", end)}`
  180. console.log(url)
  181. wx.navigateTo({
  182. url: url,
  183. })
  184. },
  185. /**收藏/取消收藏 */
  186. async collect(e) {
  187. let {
  188. storeList
  189. } = this.data
  190. let index = e.currentTarget.dataset.index
  191. let store = storeList[index]
  192. let query = new Parse.Query('DramaShopCollect');
  193. query.equalTo('company', company);
  194. query.equalTo('user', uid);
  195. query.equalTo('homestayStore', store?.objectId);
  196. query.notEqualTo('isDeleted', "true");
  197. let collect = await query.first();
  198. if (!collect?.id) {
  199. let DramaShopCollect = Parse.Object.extend('DramaShopCollect')
  200. collect = new DramaShopCollect()
  201. collect.set('company', {
  202. __type: 'Pointer',
  203. className: 'Company',
  204. objectId: company
  205. });
  206. collect.set('homestayStore', {
  207. __type: 'Pointer',
  208. className: 'ShopStore',
  209. objectId: store?.objectId
  210. });
  211. collect.set('user', {
  212. __type: 'Pointer',
  213. className: '_User',
  214. objectId: uid
  215. });
  216. collect.set('isCollect', true);
  217. }
  218. collect.set('isCollect', !(store.iscollect || false))
  219. await collect.save()
  220. storeList[index].iscollect = !(storeList[index].iscollect || false)
  221. this.setData({
  222. storeList
  223. })
  224. },
  225. /**搜索框距顶部距离 */
  226. onScroll(event) {
  227. this.setData({scrollTop: event.detail.scrollTop,})
  228. },
  229. /** 转换日期 MM月dd日*/
  230. formatDate(date) {
  231. date = new Date(date);
  232. return `${date.getMonth() + 1}月${date.getDate()}日`;
  233. },
  234. }
  235. });