|
@@ -2,6 +2,11 @@
|
|
let Parse = getApp().Parse;
|
|
let Parse = getApp().Parse;
|
|
const company = getApp().globalData.company
|
|
const company = getApp().globalData.company
|
|
import dateServ from '../../../service/date';
|
|
import dateServ from '../../../service/date';
|
|
|
|
+const dateF = require("../../../../utils/date")
|
|
|
|
+let sev = require("../../../service/request")
|
|
|
|
+const uid = Parse.User.current()?.id
|
|
|
|
+const req = require('../../../../utils/request')
|
|
|
|
+
|
|
Page({
|
|
Page({
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -17,7 +22,7 @@ Page({
|
|
// 轮播图数组
|
|
// 轮播图数组
|
|
imageUrls: [],
|
|
imageUrls: [],
|
|
index: 1,
|
|
index: 1,
|
|
- roomIndex:1,
|
|
|
|
|
|
+ roomIndex: 1,
|
|
//
|
|
//
|
|
decodedDateStart: '',
|
|
decodedDateStart: '',
|
|
decodedDateEnd: '',
|
|
decodedDateEnd: '',
|
|
@@ -42,12 +47,21 @@ Page({
|
|
date_end1: '',
|
|
date_end1: '',
|
|
showRoom: false, //显示房间详情
|
|
showRoom: false, //显示房间详情
|
|
chickRoom: null, //选中的房间
|
|
chickRoom: null, //选中的房间
|
|
|
|
+ specDateMap: {}, //特殊日期标识-今天/明天
|
|
|
|
+ gift: [], //望仙礼遇-商品
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
onLoad: function (options) {
|
|
onLoad: function (options) {
|
|
|
|
+ const today = new Date();
|
|
|
|
+ const tomorrow = new Date();
|
|
|
|
+ tomorrow.setDate(today.getDate() + 1);
|
|
|
|
+ let specDateMap = {}
|
|
|
|
+ specDateMap[dateF.formatTime('mm月dd日', today)] = '今天'
|
|
|
|
+ specDateMap[dateF.formatTime('mm月dd日', tomorrow)] = '明天'
|
|
// 计算
|
|
// 计算
|
|
const systemInfo = wx.getSystemInfoSync();
|
|
const systemInfo = wx.getSystemInfoSync();
|
|
const statusBarHeight = systemInfo.statusBarHeight || 0;
|
|
const statusBarHeight = systemInfo.statusBarHeight || 0;
|
|
@@ -55,14 +69,12 @@ Page({
|
|
const custom = wx.getMenuButtonBoundingClientRect();
|
|
const custom = wx.getMenuButtonBoundingClientRect();
|
|
const customHeight = custom.height + 10 + 2 || 0;
|
|
const customHeight = custom.height + 10 + 2 || 0;
|
|
const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
|
|
const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
|
|
-
|
|
|
|
const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
|
|
const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
|
|
if (bottomNavHeight) {
|
|
if (bottomNavHeight) {
|
|
const padding_bottom = bottomNavHeight * 750 / systemInfo.windowWidth
|
|
const padding_bottom = bottomNavHeight * 750 / systemInfo.windowWidth
|
|
this.setData({
|
|
this.setData({
|
|
bottomNavHeight: padding_bottom
|
|
bottomNavHeight: padding_bottom
|
|
})
|
|
})
|
|
- console.log(this.data.bottomNavHeight);
|
|
|
|
} else {
|
|
} else {
|
|
this.setData({
|
|
this.setData({
|
|
bottomNavHeight: 40
|
|
bottomNavHeight: 40
|
|
@@ -77,33 +89,187 @@ Page({
|
|
});
|
|
});
|
|
|
|
|
|
const {
|
|
const {
|
|
- objectId,
|
|
|
|
- date_start,
|
|
|
|
- date_end,
|
|
|
|
- daysBetween,
|
|
|
|
- istoday,
|
|
|
|
|
|
+ store_id,
|
|
start,
|
|
start,
|
|
end,
|
|
end,
|
|
} = options;
|
|
} = options;
|
|
- console.log(options);
|
|
|
|
- // 解码接收到的参数
|
|
|
|
- const decodedDateStart = decodeURIComponent(date_start);
|
|
|
|
- const decodedDateEnd = decodeURIComponent(date_end);
|
|
|
|
- const Start = decodeURIComponent(start);
|
|
|
|
- const End = decodeURIComponent(end);
|
|
|
|
|
|
+ let startDate = new Date(`${start} 12:00:00`)
|
|
|
|
+ let endDate = new Date(`${end} 14:00:00`)
|
|
this.setData({
|
|
this.setData({
|
|
- decodedDateStart,
|
|
|
|
- decodedDateEnd,
|
|
|
|
- objectId,
|
|
|
|
- daysBetween,
|
|
|
|
- istoday,
|
|
|
|
- start: Start,
|
|
|
|
- end: End,
|
|
|
|
|
|
+ decodedDateStart: dateF.formatTime('mm月dd日', startDate),
|
|
|
|
+ decodedDateEnd: dateF.formatTime('mm月dd日', endDate),
|
|
|
|
+ objectId: store_id,
|
|
|
|
+ daysBetween: sev.getDays(startDate, endDate),
|
|
|
|
+ start: startDate,
|
|
|
|
+ end: endDate,
|
|
|
|
+ specDateMap
|
|
})
|
|
})
|
|
- console.log('istoday', this.data.istoday);
|
|
|
|
- this.hanshu()
|
|
|
|
|
|
+ console.log(this.data.start, this.data.end);
|
|
|
|
+ // this.hanshu()
|
|
|
|
+ this.refersh()
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ async refersh() {
|
|
|
|
+ this.getShopStore()
|
|
|
|
+ this.getRoom()
|
|
|
|
+ this.getGift()
|
|
|
|
+ },
|
|
|
|
+ /**获取当前店铺 */
|
|
|
|
+ async getShopStore() {
|
|
|
|
+ let {
|
|
|
|
+ objectId
|
|
|
|
+ } = this.data
|
|
|
|
+ let query = new Parse.Query('ShopStore')
|
|
|
|
+ let d = await query.get(objectId)
|
|
|
|
+ let shopStore = d?.toJSON()
|
|
|
|
+ let cQuery = new Parse.Query('DramaShopCollect')
|
|
|
|
+ cQuery.equalTo('company', company)
|
|
|
|
+ cQuery.equalTo('user', uid)
|
|
|
|
+ cQuery.equalTo('homestayStore', objectId)
|
|
|
|
+ cQuery.equalTo('isCollect', 'true')
|
|
|
|
+ cQuery.notEqualTo('isDeleted', "true")
|
|
|
|
+ let count = await cQuery.count()
|
|
|
|
+ shopStore.iscollect = count
|
|
|
|
+ console.log(shopStore)
|
|
|
|
+ let longitude = shopStore?.location?.longitude || 0
|
|
|
|
+ let latitude = shopStore?.location?.latitude || 0
|
|
|
|
+ this.setData({
|
|
|
|
+ shopStore,
|
|
|
|
+ longitude,
|
|
|
|
+ latitude,
|
|
|
|
+ markers: [{
|
|
|
|
+ id: 1,
|
|
|
|
+ longitude,
|
|
|
|
+ latitude,
|
|
|
|
+ iconPath: 'https://file-cloud.fmode.cn/13WZ0W7u3l/20240724/7ebg0k104325941.png?imageView2/1/w/200/h/200', /// 自定义标记图标
|
|
|
|
+ width: 20,
|
|
|
|
+ height: 20,
|
|
|
|
+ }]
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /**获取店铺房间 */
|
|
|
|
+ async getRoom() {
|
|
|
|
+ let {
|
|
|
|
+ objectId
|
|
|
|
+ } = this.data
|
|
|
|
+ let query = new Parse.Query('ShopRoom');
|
|
|
|
+ query.equalTo('company', company);
|
|
|
|
+ query.equalTo('shop', objectId);
|
|
|
|
+ query.equalTo('isEnabled', 'true');
|
|
|
|
+ query.notEqualTo('isDeleted', 'true');
|
|
|
|
+ query.ascending('index')
|
|
|
|
+ let d = await query.find();
|
|
|
|
+ let roomList = d?.map(item => item?.toJSON())
|
|
|
|
+ await this.setData({
|
|
|
|
+ roomList
|
|
|
|
+ })
|
|
|
|
+ this.judRoom()
|
|
|
|
+ },
|
|
|
|
+ /**打开地图 */
|
|
|
|
+ callMap() {
|
|
|
|
+ let {
|
|
|
|
+ shopStore,
|
|
|
|
+ latitude,
|
|
|
|
+ longitude,
|
|
|
|
+ } = this.data
|
|
|
|
+ wx.openLocation({
|
|
|
|
+ name: shopStore?.storeName || '',
|
|
|
|
+ latitude,
|
|
|
|
+ longitude,
|
|
|
|
+ scale: 18
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /** 开日历*/
|
|
|
|
+ openCalendar() {
|
|
|
|
+ this.setData({
|
|
|
|
+ show: true
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /** 关日历*/
|
|
|
|
+ closeCalendar() {
|
|
|
|
+ this.setData({
|
|
|
|
+ show: false
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /** 选好日期点击完成后*/
|
|
|
|
+ async onConfirm(event) {
|
|
|
|
+ const [start, end] = event.detail;
|
|
|
|
+ let daysBetween = sev.getDays(start, end)
|
|
|
|
+ await this.setData({
|
|
|
|
+ start: new Date(start.setHours(12, 0, 0)),
|
|
|
|
+ end: new Date(end.setHours(14, 0, 0)),
|
|
|
|
+ decodedDateStart: dateF.formatTime('mm月dd日', start),
|
|
|
|
+ decodedDateEnd: dateF.formatTime('mm月dd日', end),
|
|
|
|
+ daysBetween
|
|
|
|
+ });
|
|
|
|
+ this.judRoom()
|
|
|
|
+ this.closeCalendar()
|
|
|
|
+ },
|
|
|
|
+ /**遍历房间判断当前时段房间状态 */
|
|
|
|
+ async judRoom() {
|
|
|
|
+ let {
|
|
|
|
+ start,
|
|
|
|
+ end,
|
|
|
|
+ roomList
|
|
|
|
+ } = this.data
|
|
|
|
+ for (let i in roomList) {
|
|
|
|
+ let item = roomList[i]
|
|
|
|
+ /**是否空闲-true(可预约),false(不可预约) */
|
|
|
|
+ let isFree = await sev.isFree({
|
|
|
|
+ from: start,
|
|
|
|
+ to: end
|
|
|
|
+ }, item.objectId)
|
|
|
|
+ roomList[i].isFree = isFree
|
|
|
|
+ }
|
|
|
|
+ this.setData({
|
|
|
|
+ roomList
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /** 点击预定*/
|
|
|
|
+ navigate(e) {
|
|
|
|
+ const {
|
|
|
|
+ index
|
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
|
+ let {
|
|
|
|
+ start,
|
|
|
|
+ end,
|
|
|
|
+ roomList
|
|
|
|
+ } = this.data
|
|
|
|
+ console.log(roomList, roomList[index])
|
|
|
|
+ if (!roomList[index].isFree) {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '时段内房间被预约',
|
|
|
|
+ icon: 'none'
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let date_start = dateF.formatTime("YYYY-mm-dd", start)
|
|
|
|
+ let date_end = dateF.formatTime("YYYY-mm-dd", end)
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: `../homestay-order2/index?objectId=${roomList[index].objectId}&date_start=${date_start}&date_end=${date_end}`
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /** 点击预定*/
|
|
|
|
+ navigatePopup() {
|
|
|
|
+ let {
|
|
|
|
+ start,
|
|
|
|
+ end,
|
|
|
|
+ chickRoom
|
|
|
|
+ } = this.data
|
|
|
|
+ if (!chickRoom.isFree) {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '时段内房间被预约',
|
|
|
|
+ icon: 'none'
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let date_start = dateF.formatTime("YYYY-mm-dd", start)
|
|
|
|
+ let date_end = dateF.formatTime("YYYY-mm-dd", end)
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: `../homestay-order2/index?objectId=${chickRoom.objectId}&date_start=${date_start}&date_end=${date_end}`
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /**房间弹框-开 */
|
|
showRoom(e) {
|
|
showRoom(e) {
|
|
let {
|
|
let {
|
|
roomList
|
|
roomList
|
|
@@ -117,20 +283,56 @@ Page({
|
|
showRoom: true
|
|
showRoom: true
|
|
});
|
|
});
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+ /**房间弹框-关 */
|
|
onCloseRoom() {
|
|
onCloseRoom() {
|
|
this.setData({
|
|
this.setData({
|
|
showRoom: false
|
|
showRoom: false
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- async hanshu() {
|
|
|
|
- await this.gethomestay()
|
|
|
|
- await this.getroom()
|
|
|
|
- // await this.getpic()
|
|
|
|
- await this.getcurrentdate()
|
|
|
|
|
|
+ /**拨打电话 */
|
|
|
|
+ phone() {
|
|
|
|
+ let phone = this.data.storeList[0].mobile
|
|
|
|
+ console.log(phone);
|
|
|
|
+ wx.makePhoneCall({
|
|
|
|
+ phoneNumber: phone
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /** 获取望仙礼遇-商品*/
|
|
|
|
+ async getGift() {
|
|
|
|
+ let {
|
|
|
|
+ objectId
|
|
|
|
+ } = this.data
|
|
|
|
+ let sql = `SELECT good."objectId",good."name",good."price",good."image"
|
|
|
|
+ FROM "ShopGoods" good
|
|
|
|
+ WHERE good."company" = '${company}'
|
|
|
|
+ AND good."isDeleted" IS NOT TRUE
|
|
|
|
+ AND good."status" IS TRUE
|
|
|
|
+ AND good."shopStore"='${objectId}'
|
|
|
|
+ ORDER BY COALESCE(good."isHome", FALSE) DESC,
|
|
|
|
+ CASE WHEN good."top"= 0 THEN 1 ELSE 0 END,
|
|
|
|
+ good."top" ASC,good."createdAt"
|
|
|
|
+ LIMIT 4`
|
|
|
|
+ let gift = await req.customSQL(sql) || []
|
|
|
|
+ console.log(gift)
|
|
|
|
+ this.setData({
|
|
|
|
+ gift
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /** 跳转*/
|
|
|
|
+ tourl(e) {
|
|
|
|
+ const url = e.currentTarget.dataset.url
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: `${url}` // 目标页面的路径
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
*/
|
|
@@ -142,7 +344,12 @@ Page({
|
|
* 生命周期函数--监听页面显示
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
*/
|
|
onShow: function () {
|
|
onShow: function () {
|
|
-
|
|
|
|
|
|
+ let {
|
|
|
|
+ roomList
|
|
|
|
+ } = this.data
|
|
|
|
+ if (roomList?.length) {
|
|
|
|
+ this.judRoom()
|
|
|
|
+ }
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -186,331 +393,11 @@ Page({
|
|
index: currentIndex + 1
|
|
index: currentIndex + 1
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- //随轮播图变化而变化
|
|
|
|
- onRoomChange: function (event) {
|
|
|
|
- const currentIndex = event.detail.current; // 获取当前索引
|
|
|
|
- this.setData({
|
|
|
|
- roomIndex: currentIndex + 1
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- //获取名宿信息
|
|
|
|
- async gethomestay() {
|
|
|
|
- let ShopStore = new Parse.Query('ShopStore');
|
|
|
|
- ShopStore.equalTo('company', company);
|
|
|
|
- ShopStore.equalTo('type', "stay");
|
|
|
|
- ShopStore.equalTo('objectId', this.data.objectId);
|
|
|
|
- ShopStore.notEqualTo('isDeleted', "true");
|
|
|
|
- ShopStore.include('location');
|
|
|
|
-
|
|
|
|
- let store = await ShopStore.find();
|
|
|
|
- let storeListPromises = store.map(async item => {
|
|
|
|
- let storeItem = item.toJSON();
|
|
|
|
- storeItem.iscollect = await this.iscollect(storeItem.objectId); // 等待iscollect的结果
|
|
|
|
- return storeItem;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- let storeList = await Promise.all(storeListPromises); // 等待所有的Promise完成
|
|
|
|
-
|
|
|
|
- this.setData({
|
|
|
|
- storeList
|
|
|
|
- });
|
|
|
|
- this.setData({
|
|
|
|
- imageUrls: storeList[0].image
|
|
|
|
- })
|
|
|
|
- this.Getlocation()
|
|
|
|
- console.log(this.data.storeList);
|
|
|
|
- },
|
|
|
|
- //获取房间信息
|
|
|
|
- async getroom() {
|
|
|
|
- let room = new Parse.Query('ShopRoom');
|
|
|
|
- room.equalTo('company', company);
|
|
|
|
- room.equalTo('shop', this.data.objectId);
|
|
|
|
- room.equalTo('isEnabled', 'true');
|
|
|
|
- room.include('benefitMap');
|
|
|
|
- room.notEqualTo('isDeleted', 'true');
|
|
|
|
-
|
|
|
|
- let room2 = await room.find();
|
|
|
|
- // 使用 Promise.all 来处理异步操作
|
|
|
|
- let roomList = await Promise.all(room2.map(async item => {
|
|
|
|
- let roomItem = item.toJSON();
|
|
|
|
- let count = await this.checkOrderCount(roomItem.objectId, this.data.start, this.data.end);
|
|
|
|
- console.log(count, roomItem.total);
|
|
|
|
- roomItem.isroom = count < roomItem.total; // 简化判断
|
|
|
|
- return roomItem;
|
|
|
|
- }));
|
|
|
|
- // 对 roomList 进行排序
|
|
|
|
- roomList.sort(this.compareFunction);
|
|
|
|
-
|
|
|
|
- this.setData({
|
|
|
|
- roomList
|
|
|
|
- });
|
|
|
|
- console.log('房间', this.data.roomList);
|
|
|
|
- },
|
|
|
|
- //排序
|
|
|
|
- compareFunction(a, b) {
|
|
|
|
- // 先比较 isroom 的值
|
|
|
|
- if (a.isroom !== b.isroom) {
|
|
|
|
- return a.isroom ? -1 : 1;
|
|
|
|
- }
|
|
|
|
- // 如果 isroom 相同,再比较 index 是否有值
|
|
|
|
- const hasIndexA = a.index !== undefined;
|
|
|
|
- const hasIndexB = b.index !== undefined;
|
|
|
|
- if (hasIndexA !== hasIndexB) {
|
|
|
|
- return hasIndexA ? -1 : 1;
|
|
|
|
- }
|
|
|
|
- // 如果 index 都有值或者都没值,按 index 大小排序(都没值时顺序其实不变)
|
|
|
|
- return (a.index || 0) - (b.index || 0);
|
|
|
|
- },
|
|
|
|
- async checkOrderCount(roomId, start, end) {
|
|
|
|
- const startTime = new Date(start);
|
|
|
|
- const endTime = new Date(end);
|
|
|
|
- let startTime2 = dateServ.changeDateTime(startTime, '14:00:00')
|
|
|
|
- let endTime2 = dateServ.changeDateTime(endTime, '12:00:00')
|
|
|
|
- let Order = new Parse.Query("RoomOrder")
|
|
|
|
- Order.equalTo("room", roomId)
|
|
|
|
- Order.equalTo("company", company)
|
|
|
|
- Order.exists("status")
|
|
|
|
- Order.notContainedIn('status', [400, 601, 700, 800, 103])
|
|
|
|
- Order.lessThan("startTime", endTime2);
|
|
|
|
- Order.greaterThan("endTime", startTime2);
|
|
|
|
- Order.select("startTime", "endTime")
|
|
|
|
- let count = await Order.count()
|
|
|
|
- return count
|
|
|
|
- },
|
|
|
|
- //收藏功能
|
|
|
|
- async iscollect(object) {
|
|
|
|
- const currentUser = Parse.User.current();
|
|
|
|
- let Collect = new Parse.Query('DramaShopCollect');
|
|
|
|
- Collect.equalTo('company', company);
|
|
|
|
- Collect.equalTo('user', currentUser.id);
|
|
|
|
- Collect.equalTo('homestayStore', object);
|
|
|
|
- Collect.equalTo('isCollect', 'true');
|
|
|
|
- Collect.notEqualTo('isDeleted', "true");
|
|
|
|
- let collect = await Collect.first();
|
|
|
|
- if (collect) {
|
|
|
|
- return true
|
|
|
|
- } else {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- //获取轮播图
|
|
|
|
- // async getpic() {
|
|
|
|
- // let Banner = new Parse.Query('Banner');
|
|
|
|
- // Banner.equalTo('company', company);
|
|
|
|
- // Banner.equalTo('store', this.data.objectId);
|
|
|
|
- // Banner.equalTo('isEnabled', 'true');
|
|
|
|
- // Banner.notEqualTo('isDeleted', 'true');
|
|
|
|
- // Banner.select('image');
|
|
|
|
-
|
|
|
|
- // let Banner2 = await Banner.find();
|
|
|
|
-
|
|
|
|
- // // 提取 image 属性并存储到 imageUrls 中
|
|
|
|
- // let imageUrls = Banner2.map(item => item.get('image')); // 使用 get() 方法获取 image 属性
|
|
|
|
-
|
|
|
|
- // this.setData({
|
|
|
|
- // imageUrls // 将提取的 imageUrls 存储到组件状态中
|
|
|
|
- // });
|
|
|
|
-
|
|
|
|
- // console.log(this.data.imageUrls); // 输出 imageUrls
|
|
|
|
- // },
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //获取当前位置信息
|
|
|
|
- Getlocation() {
|
|
|
|
- // 假设 this.storeList[0].location 是一个 Parse.GeoPoint 对象
|
|
|
|
- if (this.data.storeList[0].location) {
|
|
|
|
- const storeLocation = this.data.storeList[0].location;
|
|
|
|
- console.log('地址存在');
|
|
|
|
- // 从 GeoPoint 对象中获取经纬度
|
|
|
|
- const latitude = storeLocation.latitude; // 纬度
|
|
|
|
- const longitude = storeLocation.longitude; // 经度
|
|
|
|
-
|
|
|
|
- console.log('获取到的经纬度:', latitude, longitude); // 添加日志
|
|
|
|
-
|
|
|
|
- // 调用 API 解析地址
|
|
|
|
- wx.request({
|
|
|
|
- url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
|
|
|
|
- data: {},
|
|
|
|
- header: {
|
|
|
|
- 'Content-Type': 'application/json'
|
|
|
|
- },
|
|
|
|
- success: (ops) => { // 使用箭头函数
|
|
|
|
- console.log(ops);
|
|
|
|
- const address = ops.data.result.formatted_address;
|
|
|
|
- this.setData({
|
|
|
|
- address: address,
|
|
|
|
- latitude: latitude, // 保证 latitude 被设置
|
|
|
|
- longitude: longitude, // 保证 longitude 被设置
|
|
|
|
- markers: [{ // 设置 markers
|
|
|
|
- id: 1,
|
|
|
|
- latitude: latitude,
|
|
|
|
- longitude: longitude,
|
|
|
|
- iconPath: 'https://file-cloud.fmode.cn/13WZ0W7u3l/20240724/7ebg0k104325941.png?imageView2/1/w/200/h/200', // 自定义标记图标
|
|
|
|
- width: 20,
|
|
|
|
- height: 20,
|
|
|
|
- // callout: {
|
|
|
|
- // content: this.data.storeList[0].storeName, // 可以显示解析出的地址
|
|
|
|
- // color: '#ffffff',
|
|
|
|
- // bgColor: '#7F56B2',
|
|
|
|
- // padding: 4,
|
|
|
|
- // fontSize: 8,
|
|
|
|
- // borderRadius: 3,
|
|
|
|
- // display: 'ALWAYS'
|
|
|
|
- // }
|
|
|
|
- }]
|
|
|
|
- });
|
|
|
|
- // console.log(this.data.address);
|
|
|
|
- },
|
|
|
|
- fail: function (resq) {
|
|
|
|
- wx.showModal({
|
|
|
|
- title: '信息提示',
|
|
|
|
- content: '请求失败',
|
|
|
|
- showCancel: false,
|
|
|
|
- confirmColor: '#f37938'
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- complete: function () {}
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
- //点击预定
|
|
|
|
- navigate(e) {
|
|
|
|
- const objectId = e.currentTarget.dataset.id;
|
|
|
|
- // let currentUser = Parse.User.current()
|
|
|
|
- // currentUser = currentUser.toJSON()
|
|
|
|
- // console.log(currentUser, currentUser.idcard);
|
|
|
|
-
|
|
|
|
- // if (currentUser.idcard) {
|
|
|
|
- // // 构造要传递的信息
|
|
|
|
- // const info = {
|
|
|
|
- // objectId: objectId,
|
|
|
|
- // date_start: this.data.start,
|
|
|
|
- // date_end: this.data.end,
|
|
|
|
- // };
|
|
|
|
- // // console.log('info',info);
|
|
|
|
-
|
|
|
|
- // // 将信息转为查询字符串
|
|
|
|
- // var queryString = Object.keys(info)
|
|
|
|
- // .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
|
|
|
|
- // .join('&');
|
|
|
|
- // console.log(queryString);
|
|
|
|
- // wx.navigateTo({
|
|
|
|
- // url: `../homestay-order/index?${queryString}`
|
|
|
|
- // })
|
|
|
|
- // } else {
|
|
|
|
- // wx.showToast({
|
|
|
|
- // title: '请先进行实名认证',
|
|
|
|
- // icon: 'none'
|
|
|
|
- // })
|
|
|
|
- //实名
|
|
|
|
- // wx.navigateTo({
|
|
|
|
- // url: `/common-page/pages/info/cauth/cauth?themeColor=#FFE300`
|
|
|
|
- // })
|
|
|
|
-
|
|
|
|
- // 构造要传递的信息
|
|
|
|
- const info = {
|
|
|
|
- objectId: objectId,
|
|
|
|
- date_start: this.data.start,
|
|
|
|
- date_end: this.data.end,
|
|
|
|
- };
|
|
|
|
- console.log('info', info);
|
|
|
|
-
|
|
|
|
- // 将信息转为查询字符串
|
|
|
|
- var queryString = Object.keys(info)
|
|
|
|
- .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
|
|
|
|
- .join('&');
|
|
|
|
- console.log(queryString);
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: `../homestay-order2/index?${queryString}`
|
|
|
|
- })
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //获取今日明日日期
|
|
|
|
- getcurrentdate() {
|
|
|
|
- const today = new Date();
|
|
|
|
- const tomorrow = new Date();
|
|
|
|
- tomorrow.setDate(today.getDate() + 1);
|
|
|
|
-
|
|
|
|
- this.setData({
|
|
|
|
- date_start1: this.formatDate(today),
|
|
|
|
- date_end1: this.formatDate(tomorrow),
|
|
|
|
- });
|
|
|
|
- console.log(this.data.start, this.data.end);
|
|
|
|
- },
|
|
|
|
- //转换日期
|
|
|
|
- formatDate(date) {
|
|
|
|
- date = new Date(date);
|
|
|
|
- return `${date.getMonth() + 1}月${date.getDate()}日`;
|
|
|
|
- },
|
|
|
|
- // 计算两个日期之间的天数
|
|
|
|
- calculateDaysBetween(startDate, endDate) {
|
|
|
|
- const start = new Date(startDate);
|
|
|
|
- const end = new Date(endDate);
|
|
|
|
- const timeDifference = end - start; // 计算时间差(毫秒)
|
|
|
|
- const daysDifference = timeDifference / (1000 * 3600 * 24); // 转换为天数
|
|
|
|
- return daysDifference; // 返回天数差
|
|
|
|
- },
|
|
|
|
- //开日历
|
|
|
|
- onDisplay() {
|
|
|
|
- this.setData({
|
|
|
|
- show: true
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- //关日历
|
|
|
|
- onClose() {
|
|
|
|
- this.setData({
|
|
|
|
- show: false
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- //选好日期点击完成后
|
|
|
|
- onConfirm(event) {
|
|
|
|
- const [start, end] = event.detail;
|
|
|
|
- const daysBetween = this.calculateDaysBetween(start, end); // 计算天数差
|
|
|
|
|
|
+ //随轮播图变化而变化
|
|
|
|
+ onRoomChange: function (event) {
|
|
|
|
+ const currentIndex = event.detail.current; // 获取当前索引
|
|
this.setData({
|
|
this.setData({
|
|
- show: false,
|
|
|
|
- start,
|
|
|
|
- end,
|
|
|
|
- decodedDateStartart: `${this.formatDate(start)} `,
|
|
|
|
- decodedDateEnd: `${this.formatDate(end)}`,
|
|
|
|
- daysBetween
|
|
|
|
- });
|
|
|
|
- if (this.data.decodedDateStartart.trim() == this.data.date_start1.trim() && this.data.decodedDateEnd.trim() == this.data.date_end1.trim()) {
|
|
|
|
- this.setData({
|
|
|
|
- istoday: 'true'
|
|
|
|
- })
|
|
|
|
- console.log(this.data.istoday);
|
|
|
|
- } else {
|
|
|
|
- this.setData({
|
|
|
|
- istoday: 'false'
|
|
|
|
- })
|
|
|
|
- console.log(this.data.istoday);
|
|
|
|
- }
|
|
|
|
- this.getroom()
|
|
|
|
- console.log(`入住日期: ${this.data.decodedDateStartart}, 离店日期: ${this.data.decodedDateEnd}, 天数差: ${daysBetween}天`);
|
|
|
|
- },
|
|
|
|
- //拨打电话
|
|
|
|
- phone() {
|
|
|
|
- let phone = this.data.storeList[0].mobile
|
|
|
|
- console.log(phone);
|
|
|
|
- wx.makePhoneCall({
|
|
|
|
- phoneNumber: phone
|
|
|
|
|
|
+ roomIndex: currentIndex + 1
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- callMap() {
|
|
|
|
- if (this.data.storeList[0].location) {
|
|
|
|
- const latitude = this.data.storeList[0].location.latitude
|
|
|
|
- const longitude = this.data.storeList[0].location.longitude
|
|
|
|
- wx.openLocation({
|
|
|
|
- name: this.data.storeList[0].storeName,
|
|
|
|
- latitude,
|
|
|
|
- longitude,
|
|
|
|
- scale: 18
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
})
|
|
})
|