index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. // nova-tourism/pages/homestay/homestay-detail/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. import dateServ from '../../../service/date';
  5. const dateF = require("../../../../utils/date")
  6. let sev = require("../../../service/request")
  7. const uid = Parse.User.current()?.id
  8. const req = require('../../../../utils/request')
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. //屏幕高度
  15. statusBarHeight: 0, // 状态栏高度
  16. screenHeight: 0, // 屏幕高度
  17. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  18. bottomNavHeight: 0, // 底部导航栏高度
  19. contentHeight: 0, // 可用内容高度
  20. // 轮播图数组
  21. imageUrls: [],
  22. index: 1,
  23. roomIndex: 1,
  24. //
  25. decodedDateStart: '',
  26. decodedDateEnd: '',
  27. objectId: "",
  28. daysBetween: 0,
  29. istoday: null,
  30. storeList: [],
  31. roomList: [],
  32. //地图
  33. longitude: 0,
  34. latitude: 0,
  35. markers: [],
  36. //
  37. start: '',
  38. end: '',
  39. //
  40. show: false,
  41. date_start1: '',
  42. date_end1: '',
  43. showRoom: false, //显示房间详情
  44. chickRoom: null, //选中的房间
  45. specDateMap: {}, //特殊日期标识-今天/明天
  46. gift: [], //望仙礼遇-商品
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. const today = new Date();
  53. const tomorrow = new Date();
  54. tomorrow.setDate(today.getDate() + 1);
  55. let specDateMap = {}
  56. specDateMap[dateF.formatTime('mm月dd日', today)] = '今天'
  57. specDateMap[dateF.formatTime('mm月dd日', tomorrow)] = '明天'
  58. // 计算
  59. const systemInfo = wx.getSystemInfoSync();
  60. const statusBarHeight = systemInfo.statusBarHeight || 0;
  61. const screenHeight = systemInfo.screenHeight || 0;
  62. const custom = wx.getMenuButtonBoundingClientRect();
  63. const customHeight = custom.height + 10 + 2 || 0;
  64. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  65. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  66. if (bottomNavHeight) {
  67. const padding_bottom = bottomNavHeight * 750 / systemInfo.windowWidth
  68. this.setData({
  69. bottomNavHeight: padding_bottom
  70. })
  71. } else {
  72. this.setData({
  73. bottomNavHeight: 40
  74. })
  75. }
  76. this.setData({
  77. statusBarHeight,
  78. screenHeight,
  79. customHeight,
  80. contentHeight
  81. });
  82. const {
  83. store_id,
  84. start,
  85. end,
  86. } = options;
  87. let startDate = new Date(`${start} 12:00:00`)
  88. let endDate = new Date(`${end} 14:00:00`)
  89. this.setData({
  90. decodedDateStart: dateF.formatTime('mm月dd日', startDate),
  91. decodedDateEnd: dateF.formatTime('mm月dd日', endDate),
  92. objectId: store_id,
  93. daysBetween: sev.getDays(startDate, endDate),
  94. start: startDate,
  95. end: endDate,
  96. specDateMap
  97. })
  98. console.log(this.data.start, this.data.end);
  99. // this.hanshu()
  100. this.refersh()
  101. },
  102. async refersh() {
  103. this.getShopStore()
  104. this.getRoom()
  105. this.getGift()
  106. },
  107. /**获取当前店铺 */
  108. async getShopStore() {
  109. let {
  110. objectId
  111. } = this.data
  112. let query = new Parse.Query('ShopStore')
  113. let d = await query.get(objectId)
  114. let shopStore = d?.toJSON()
  115. let cQuery = new Parse.Query('DramaShopCollect')
  116. cQuery.equalTo('company', company)
  117. cQuery.equalTo('user', uid)
  118. cQuery.equalTo('homestayStore', objectId)
  119. cQuery.equalTo('isCollect', 'true')
  120. cQuery.notEqualTo('isDeleted', "true")
  121. let count = await cQuery.count()
  122. shopStore.iscollect = count
  123. console.log(shopStore)
  124. let longitude = shopStore?.location?.longitude || 0
  125. let latitude = shopStore?.location?.latitude || 0
  126. this.setData({
  127. shopStore,
  128. longitude,
  129. latitude,
  130. markers: [{
  131. id: 1,
  132. longitude,
  133. latitude,
  134. iconPath: 'https://file-cloud.fmode.cn/13WZ0W7u3l/20240724/7ebg0k104325941.png?imageView2/1/w/200/h/200', /// 自定义标记图标
  135. width: 20,
  136. height: 20,
  137. }]
  138. })
  139. },
  140. /**获取店铺房间 */
  141. async getRoom() {
  142. let {
  143. objectId
  144. } = this.data
  145. let query = new Parse.Query('ShopRoom');
  146. query.equalTo('company', company);
  147. query.equalTo('shop', objectId);
  148. query.equalTo('isEnabled', 'true');
  149. query.notEqualTo('isDeleted', 'true');
  150. query.ascending('index')
  151. let d = await query.find();
  152. let roomList = d?.map(item => item?.toJSON())
  153. await this.setData({
  154. roomList
  155. })
  156. this.judRoom()
  157. },
  158. /**打开地图 */
  159. callMap() {
  160. let {
  161. shopStore,
  162. latitude,
  163. longitude,
  164. } = this.data
  165. wx.openLocation({
  166. name: shopStore?.storeName || '',
  167. latitude,
  168. longitude,
  169. scale: 18
  170. })
  171. },
  172. /** 开日历*/
  173. openCalendar() {
  174. this.setData({
  175. show: true
  176. });
  177. },
  178. /** 关日历*/
  179. closeCalendar() {
  180. this.setData({
  181. show: false
  182. });
  183. },
  184. /** 选好日期点击完成后*/
  185. async onConfirm(event) {
  186. const [start, end] = event.detail;
  187. let daysBetween = sev.getDays(start, end)
  188. await this.setData({
  189. start: new Date(start.setHours(12, 0, 0)),
  190. end: new Date(end.setHours(14, 0, 0)),
  191. decodedDateStart: dateF.formatTime('mm月dd日', start),
  192. decodedDateEnd: dateF.formatTime('mm月dd日', end),
  193. daysBetween
  194. });
  195. this.judRoom()
  196. this.closeCalendar()
  197. },
  198. /**遍历房间判断当前时段房间状态 */
  199. async judRoom() {
  200. let {
  201. start,
  202. end,
  203. roomList
  204. } = this.data
  205. for (let i in roomList) {
  206. let item = roomList[i]
  207. /**是否空闲-true(可预约),false(不可预约) */
  208. let isFree = await sev.isFree({
  209. from: start,
  210. to: end
  211. }, item.objectId)
  212. roomList[i].isFree = isFree
  213. }
  214. this.setData({
  215. roomList
  216. })
  217. },
  218. /** 点击预定*/
  219. navigate(e) {
  220. const {
  221. index
  222. } = e.currentTarget.dataset;
  223. let {
  224. start,
  225. end,
  226. roomList
  227. } = this.data
  228. console.log(roomList, roomList[index])
  229. if (!roomList[index].isFree) {
  230. wx.showToast({
  231. title: '时段内房间被预约',
  232. icon: 'none'
  233. })
  234. return
  235. }
  236. let date_start = dateF.formatTime("YYYY-mm-dd", start)
  237. let date_end = dateF.formatTime("YYYY-mm-dd", end)
  238. wx.navigateTo({
  239. url: `../homestay-order2/index?objectId=${roomList[index].objectId}&date_start=${date_start}&date_end=${date_end}`
  240. })
  241. },
  242. /** 点击预定*/
  243. navigatePopup() {
  244. let {
  245. start,
  246. end,
  247. chickRoom
  248. } = this.data
  249. if (!chickRoom.isFree) {
  250. wx.showToast({
  251. title: '时段内房间被预约',
  252. icon: 'none'
  253. })
  254. return
  255. }
  256. let date_start = dateF.formatTime("YYYY-mm-dd", start)
  257. let date_end = dateF.formatTime("YYYY-mm-dd", end)
  258. wx.navigateTo({
  259. url: `../homestay-order2/index?objectId=${chickRoom.objectId}&date_start=${date_start}&date_end=${date_end}`
  260. })
  261. },
  262. /**房间弹框-开 */
  263. showRoom(e) {
  264. let {
  265. roomList
  266. } = this.data
  267. let {
  268. index
  269. } = e.currentTarget.dataset
  270. console.log(roomList[index])
  271. this.setData({
  272. chickRoom: roomList[index],
  273. showRoom: true
  274. });
  275. },
  276. /**房间弹框-关 */
  277. onCloseRoom() {
  278. this.setData({
  279. showRoom: false
  280. });
  281. },
  282. /**拨打电话 */
  283. phone() {
  284. let phone = this.data.storeList[0].mobile
  285. console.log(phone);
  286. wx.makePhoneCall({
  287. phoneNumber: phone
  288. })
  289. },
  290. /** 获取望仙礼遇-商品*/
  291. async getGift() {
  292. let {
  293. objectId
  294. } = this.data
  295. let sql = `SELECT good."objectId",good."name",good."price",good."image"
  296. FROM "ShopGoods" good
  297. WHERE good."company" = '${company}'
  298. AND good."isDeleted" IS NOT TRUE
  299. AND good."status" IS TRUE
  300. AND good."shopStore"='${objectId}'
  301. ORDER BY COALESCE(good."isHome", FALSE) DESC,
  302. CASE WHEN good."top"= 0 THEN 1 ELSE 0 END,
  303. good."top" ASC,good."createdAt"
  304. LIMIT 4`
  305. let gift = await req.customSQL(sql) || []
  306. console.log(gift)
  307. this.setData({
  308. gift
  309. })
  310. },
  311. /** 跳转*/
  312. tourl(e) {
  313. const url = e.currentTarget.dataset.url
  314. wx.navigateTo({
  315. url: `${url}` // 目标页面的路径
  316. });
  317. },
  318. /**
  319. * 生命周期函数--监听页面初次渲染完成
  320. */
  321. onReady: function () {
  322. },
  323. /**
  324. * 生命周期函数--监听页面显示
  325. */
  326. onShow: function () {
  327. let {
  328. roomList
  329. } = this.data
  330. if (roomList?.length) {
  331. this.judRoom()
  332. }
  333. },
  334. /**
  335. * 生命周期函数--监听页面隐藏
  336. */
  337. onHide: function () {
  338. },
  339. /**
  340. * 生命周期函数--监听页面卸载
  341. */
  342. onUnload: function () {
  343. },
  344. /**
  345. * 页面相关事件处理函数--监听用户下拉动作
  346. */
  347. onPullDownRefresh: function () {
  348. },
  349. /**
  350. * 页面上拉触底事件的处理函数
  351. */
  352. onReachBottom: function () {
  353. },
  354. /**
  355. * 用户点击右上角分享
  356. */
  357. onShareAppMessage: function () {
  358. },
  359. //随轮播图变化而变化
  360. onSwiperChange: function (event) {
  361. const currentIndex = event.detail.current; // 获取当前索引
  362. this.setData({
  363. index: currentIndex + 1
  364. })
  365. },
  366. //随轮播图变化而变化
  367. onRoomChange: function (event) {
  368. const currentIndex = event.detail.current; // 获取当前索引
  369. this.setData({
  370. roomIndex: currentIndex + 1
  371. })
  372. },
  373. })