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.

246 lines
6.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: {
listimgs:[],
startDate:"",//入住时间
endDate:"",//离店时间
startDateText:"",//入住时间转文字
endDateText:"",//离店时间转文字
days:1,//住店的日期总数
today:"",//今天,也就是入住可以选择的日期
tomorrow:"",//离店最早可以选择的日期
sceneInfo:null,
ask:[],
isLike:0,
commentTotal:0,
comment:[],
products:[],
isTest:true
},
/**
* 生命周期函数--监听页面加载
*/
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()
this.getProduct()
},
getProduct:function(){
commonApi._post("scene/get_hotel_sku_list",{
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
})
console.log(res)
})
},
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',
})
},
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
})
})
// 获取问大家
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,'/'));
if(endDate.getTime()<date.getTime()){
this.setData({
endDate:util.formatDate(tomorrow),
endDateText:util.dateToText(tomorrow)
})
}
this.calcDays();
},
changeLeaveDate:function(e){
let date = new Date(e.detail.value.replace(/-/g,'/'));
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({
days:days
})
this.getProduct()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})