// 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()