index.js 10 KB

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