You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
9.0 KiB

5 years ago
// pages/info/hotelProductInfo/index.js
import util from "../../../utils/util"
import commonApi from "../../../utils/https/common"
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
5 years ago
invoiceModes:{
1:"如需发票,请向酒店前台索取",
2:"美团开具发票",
3:"第三方开具发票"
},
showInfoFlag:false,
5 years ago
listimgs:[],
startDate:"",//入住时间
endDate:"",//离店时间
startDateText:"",//入住时间转文字
endDateText:"",//离店时间转文字
days:1,//住店的日期总数
today:"",//今天,也就是入住可以选择的日期
tomorrow:"",//离店最早可以选择的日期
sceneInfo:null,
ask:[],
isLike:0,
commentTotal:0,
comment:[],
products:[],
5 years ago
isTest:true,
activeSkuIndex:-1,
skuList:[],
roomInfo:null
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
id:options.id
})
commonApi._post("pbservice/Other/getClientConfig",{
unique_key:"wechatxcx"
}).then(res=>{
let data = JSON.parse(res.data);
this.setData({
isTest:data.isTest
})
})
// 先初始化日期
let today = new Date(),tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
this.setData({
today:util.formatDate(today),
startDate:util.formatDate(today),
endDate:util.formatDate(tomorrow),
startDateText:util.dateToText(today),
endDateText:util.dateToText(tomorrow),
tomorrow:util.formatDate(tomorrow)
})
this.getDetail()
5 years ago
// this.getProduct()
},
BroswerRecord:function(){
setTimeout(()=>{
if(app.globalData.uuid){
commonApi._post('browse/browse_record',{
type:"scene",
title:this.data.sceneInfo.title,
drive:"mini",
source_id:this.data.sceneInfo.id,
url:"/pages/info/hotelProductInfo/index?id="+this.data.sceneInfo.id,
uuid:app.globalData.uuid
}).then(res=>{
})
}
else {
this.BroswerRecord();
}
},500)
5 years ago
},
getProduct:function(){
5 years ago
commonApi._post(this.data.sceneInfo.third_supplier_type=='mt'?"scene/get_mt_hotel_real_rooms_list":"scene/get_hotel_sku_list",{
5 years ago
start_time:this.data.startDate,
end_time:this.data.endDate,
scene_id:this.data.id
}).then(res=>{
res.data.map(item=>{
item.display_tags = (item.display_tags?item.display_tags.split(","):[]).splice(0,2)
})
this.setData({
products:res.data
})
})
},
5 years ago
// 获取产品下面的规格列表
getSkuList:function(e){
if(e.currentTarget.dataset.index==this.data.activeSkuIndex){
this.setData({
activeSkuIndex:-1
})
return;
}
this.setData({
activeSkuIndex:e.currentTarget.dataset.index,
skuList:[]
})
commonApi._post('scene/get_mt_hotel_real_rooms_sku_list',{
start_date:this.data.startDate,
end_date:this.data.endDate,
real_room_id:e.currentTarget.dataset.id
}).then(res=>{
this.setData({
skuList:res.data
})
})
},
5 years ago
order:function(e){
let item = e.currentTarget.dataset.item;
item.startDate = this.data.startDate;
item.endDate = this.data.endDate;
item.startDateText = this.data.startDateText;
item.endDateText = this.data.endDateText;
item.startDay = this.getDay(item.startDate);
item.endDay = this.getDay(item.endDate);
item.days = this.data.days;
app.globalData.product = item;
app.globalData.couponInfo = null;
wx.navigateTo({
url: '/pages/order/hotel/index',
})
},
5 years ago
orderMt:function(e){
let item = e.currentTarget.dataset.item,product = e.currentTarget.dataset.product;
item.startDate = this.data.startDate;
item.endDate = this.data.endDate;
item.startDateText = this.data.startDateText;
item.endDateText = this.data.endDateText;
item.startDay = this.getDay(item.startDate);
item.endDay = this.getDay(item.endDate);
item.days = this.data.days;
item.id = item.sku_id;
// item.product_id = product.real_room_id;
item.sku_name = product.room_name;
item.sku_model={};
item.sku_model.area = product.useable_area+"m²";
item.sku_model.bed_type = item.bed_type;
item.sku_model.breakfast=item.breakfast;
item.sku_model.max_room_num = item.max_room_num;
console.log(item);
app.globalData.product = item;
// return;
app.globalData.couponInfo = null;
wx.navigateTo({
url: '/pages/order/hotel/index',
})
},
5 years ago
getDay:function(date){
let d = new Date(date.replace(/-/g,'/')).getDay();
let days = ["日","一","二","三","四","五","六"];
return days[d];
},
getDetail:function(){
// 获取详情
commonApi._post("scene/detail",{
id:this.data.id
}).then(res=>{
if(!res.data) {
util.back();
return;
}
// res.data.listimg = res.data.listimg?res.data.listimg.split(","):[];
res.data.display_tags = (res.data.display_tags?res.data.display_tags.split(","):[]).splice(0,2);
this.setData({
sceneInfo:res.data
})
5 years ago
this.BroswerRecord();
this.getProduct()
5 years ago
})
// 获取问大家
commonApi._post("ask/getQuestionList",{
scene_id:this.data.id,
page_no:1,
page_num:3
}).then(res=>{
console.log(res)
this.setData({
ask:res.data.rows
})
})
// 获取是否喜欢
commonApi.user_post("scene/is_scene_collection",{
scene_id:this.data.id
}).then(res=>{
this.setData({
isLike:res.data
})
})
// 获取评价列表
commonApi.user_post("scene/get_comment",{
scene_id:this.data.id
}).then(res=>{
res.data.list.map(item=>{
item.rate = Number(item.rate)
})
this.setData({
comment:res.data.list,
commentTotal:res.data.total
})
})
},
like:function(){
let id = this.data.id,isLike = this.data.isLike;
commonApi.user_post(isLike!=1?"scene/scene_collection":"scene/scene_cancel_collection",{
scene_id:id
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '操作成功',
})
this.setData({
isLike:isLike==1?0:1
})
}
})
},
gotoLocation:function(){
let info = this.data.sceneInfo;
wx.openLocation({
latitude: Number(info.lat),
longitude: Number(info.lon),
})
},
changeInDate:function(e){
console.log(e)
let date = new Date(e.detail.value.replace(/-/g,'/'));
let tomorrow = new Date(date.getTime() + 24 * 60 * 60 * 1000);
this.setData({
startDate:util.formatDate(date),
startDateText:util.dateToText(date),
tomorrow:util.formatDate(tomorrow)
})
// 如果开始日期要比结束日期晚的话 那么结束日期自动变成开始日期的下一天
let endDate = new Date(this.data.endDate.replace(/-/g,'/'));
5 years ago
if(endDate.getTime()<=date.getTime()){
5 years ago
this.setData({
endDate:util.formatDate(tomorrow),
endDateText:util.dateToText(tomorrow)
})
}
this.calcDays();
},
changeLeaveDate:function(e){
let date = new Date(e.detail.value.replace(/-/g,'/'));
5 years ago
console.log(date)
5 years ago
this.setData({
endDate:util.formatDate(date),
endDateText:util.dateToText(date)
})
this.calcDays();
},
calcDays:function(){
let endDate = this.data.endDate.replace(/-/g,'/'),startDate = this.data.startDate.replace(/-/g,'/');
endDate = new Date(endDate).getTime();
startDate = new Date(startDate).getTime();
let days = Math.round((endDate - startDate) / (1000 * 24 * 60 * 60))
this.setData({
5 years ago
days:days,
activeSkuIndex:-1,
skuList:[]
})
// this.getProduct()
},
showRoomInfo:function(e){
let product = e.currentTarget.dataset.info,sku = e.currentTarget.dataset.sku;
this.setData({
showInfoFlag:true
// roomInfo:
})
commonApi.user_post("product/getMtRoomSkuInfo",{
real_room_id:product.real_room_id,
sku_id:sku.sku_id,
start_date: this.data.startDate,
end_date: this.data.endDate
}).then(res=>{
this.setData({
roomInfo:{
sku:sku,
skuInfo:res.data,
productInfo:product
}
})
})
},
hideRoomInfo:function(){
this.setData({
showInfoFlag:false,
roomInfo:null
5 years ago
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})