680 lines
20 KiB
JavaScript

// pages/show/show.js
var app = getApp()
var miucms = require('../../utils/miucms.js');
const util = require('../../utils/util.js');
var config = {};
var screenWidth = 288;
var center_position = 144;
var avatar_height = 40;
var screenWidth2 = 288;
var center_position2 = 144;
var save = false;
var today = new Date();
var time_now = today.getFullYear() + '.' + (today.getMonth() > 8 ? (today.getMonth() + 1) : '0' + (today.getMonth() + 1)) + '.' + (today.getDate() > 9 ? today.getDate() : '0' + today.getDate());
var windowWidth = 0;
Page({
/**
* 页面的初始数据
*/
data: {
isloding: true,
tid: '',
uniqid: '',
token: '',
indicatorDots: true,
autoplay: true,
interval: 3000,
duration: 500,
circular: true,
current: 0,
coordinate: [],
brand: '',
consumption: '',
introduction: '',
life: '',
message: '',
traffic: '',
screen_data: {},
swiperHeight: 0,
markers: [],
attachment: [],
show_share_box: false,
share: false,
options: {},
isUserAuthorization: 0,
isAuthorization: 0,
showSchool: false,
showFooter: true, //底部栏
listTab: {},
q: '',
companyid: '',
withSameBrand: [],
irenCouponReceive: null,
irentCouponBig: true,
hideCoupon: false,
customerservice: null,
serviceWindowState: false,
serviceWindowList: [], // 客服弹出列表数据
tips: "", //客服弹窗提示语
facilitiesKeyValue: {
public: "公共",
kitchen: "餐厨",
lavatory: "洗手间",
},
bottomLift: 0,
operationsTop: false,
isShowVideo: true, // 是否显示 视频
},
timer: null,
headHeight: 0,
onPageScroll(e) {
if (e.scrollTop > this.headHeight && !this.data.operationsTop) {
this.setData({
operationsTop: true
})
} else if (e.scrollTop <= this.headHeight && this.data.operationsTop) {
this.setData({
operationsTop: false
})
}
clearTimeout(this.timer)
if (!this.data.irentCouponBig && this.data.irenCouponReceive) {
// 显示在侧边栏
this.setData({
hideCoupon: true
})
}
this.timer = setTimeout(() => {
this.setData({
hideCoupon: false
})
}, 3000)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (options.q) {
let decodedUrl = options.q;
while (decodedUrl !== decodeURIComponent(decodedUrl)) {
decodedUrl = decodeURIComponent(decodedUrl);
}
options.q = decodedUrl
}
console.log("options.q", options.q);
wx.getSystemInfo({
success: function (res) {
windowWidth = res.windowWidth
}
})
screenWidth = wx.getSystemInfoSync().screenWidth;
center_position = screenWidth / 2;
this.setData({
uniqid: options.uniqid || '',
source: options.source ? options.source : '',
options: options || {},
screenWidth: screenWidth,
q: options.q ? options.q : '',
irentCouponBig: app.globalData.irentCouponBig
})
wx.showLoading()
this.get_config()
},
onShow() {
if (wx.getEnterOptionsSync().query && wx.getEnterOptionsSync().query.scancode_time && app.globalData.scancode_time != wx.getEnterOptionsSync().query.scancode_time) {
app.globalData.scancode_time = wx.getEnterOptionsSync().query.scancode_time;
this.setData({
options: wx.getEnterOptionsSync().query,
q: wx.getEnterOptionsSync().query.q
})
this.get_config()
}
},
get_config() {
var that = this;
if (app.globalData.config.lists) {
config = app.globalData.config;
that.setData({
user: app.globalData.user,
listTab: app.globalData.listTab,
screen_data: app.globalData.screen_data,
bottomLift: app.globalData.screen_data.bottomLift,
isShowVideo: app.globalData.isShowVideo,
})
this.get_content();
let screen_data = this.data.screen_data
let windowWidth = screen_data['windowWidth']; //获取设备屏幕宽度
let headHeight = (windowWidth / 750) * Number(70)
this.headHeight = headHeight
} else {
setTimeout(function () {
that.get_config()
}, 200)
}
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function (res) {
// 来自页面内转发按钮
if (res.from === 'button') var types = res.from === 'button' ? 'share_btn' : 'show';
// let that = this;
// var title = that.data.data.title;
// if (that.data.data.isquarantine) title = this.data.listTab.quarantineLists + '-' + that.data.data.title
let title = `中国香港 > ${ this.data.data.address }`
return {
title,
// imageUrl: that.data.data.thumbnail,
success: function (res) {
miucms.share(app, types)
},
}
},
onShareTimeline() {
// let that = this;
// var title = that.data.data.title;
// if (that.data.data.isquarantine) title = this.data.listTab.quarantineLists + '-' + that.data.data.title
let title = `中国香港 > ${ this.data.data.address }`
return {
title,
// imageUrl: that.data.data.thumbnail,
}
},
get_content: function () {
console.log("get_content");
let that = this;
var sendData = Object.assign({}, this.data.options, {
session: wx.getStorageSync('session'),
uniqid: that.data.uniqid,
// tid: that.data.tid,
// source: that.data.source,
// q: that.data.q
})
console.log("sendData", sendData);
let url = `${app.globalData.baseURL}/tenement/v2/api/apartment/details`
// url = app.globalData.config.studentapartment.details
miucms.wxget(url, sendData).then(data => {
wx.hideLoading()
if (data.code != 200) {
wx.showModal({
title: '提示',
content: data.message,
success(res) {
this.backOrIndex()
}
})
} else {
data = data.data
let info = data.info
if (!this.data.isShowVideo) {
info.videos = []
const roomList = data.roomList || []
roomList.forEach(element => {
element.videos = []
})
}
let coordinate = info.coordinate
this.data.coordinate = coordinate.split(',').map(item => {
return item * 1
});
let image = [...info.attachment]
let attachment = [];
if (info.live && info.live.length > 0) {
info.live.map(item => {
item['islive'] = 1;
attachment.push(item)
})
}
if (info.videos && info.videos.length > 0) {
info.videos.map(item => {
item['isvideo'] = 1
attachment.push(item)
})
}
info.attachment.map(item => {
attachment.push({
type: "image",
image: item
})
})
that.setData({
withsameapartments: data.withsameapartments,
token: data.token,
booking: data.booking,
roomList: data.roomList,
company: data.company,
irenCouponReceive: data.irenCouponReceive,
// companyid: data.data.companyid,
// uniqid: data.data.uniqid,
isAuthorization: data.code == 401 ? 1 : 0,
data: info,
attachment,
image,
video: info.videos,
live: info.live,
coordinate: that.data.coordinate,
brand: info.brand,
consumption: info.consumption,
introduction: info.introduction,
life: info.life,
message: info.message,
traffic: info.traffic,
markers: [{
id: 1,
latitude: that.data.coordinate[0],
longitude: that.data.coordinate[1],
width: 30,
height: 50
}],
customerservice: info.customerservice,
isloding: false
})
if (data.withsameapartments > 0) this.getList()
// this.handleSwiperInit()
}
}).catch(res => {
wx.hideLoading()
that.setData({
isloding: false,
})
wx.showModal({
title: '提示',
content: res.message || '抱歉,网络出错。请稍后重试~',
success(res) {
miucms.backOrIndex()
}
})
})
},
getList() {
let that = this;
var sendData = Object.assign({}, this.data.options, {
companyid: this.data.companyid,
token: this.data.token
})
let url = `${app.globalData.baseURL}/tenement/v2/api/apartment`
miucms.request(url, sendData).then(data => {
wx.hideLoading()
if (data.code != 200) {
wx.showModal({
title: '提示',
content: data.message,
})
} else {
this.setData({
withSameBrand: data.data.data
})
}
}).catch(res => {
wx.hideLoading()
this.setData({
isloding: false
})
wx.showModal({
title: '提示',
content: res.message || '抱歉,网络出错。请稍后重试~',
})
})
},
to_map: function (e) {
var that = this;
if (that.data.coordinate.length < 2) {
wx.showModal({
title: '提示',
content: '没有找到坐标',
})
return false
}
var latitude = that.data.coordinate[0];
var longitude = that.data.coordinate[1];
wx.openLocation({
latitude: latitude,
longitude: longitude,
scale: 24,
name: that.data.data.title,
address: that.data.data.address
})
},
navigategoBack() {
var pages = getCurrentPages();
if (pages.length == 1) {
wx.reLaunch({
url: `/pages/brandApartmentList/brandApartmentList`
});
} else {
wx.navigateBack({
changed: true
}); //返回上一页
}
},
send_form_id(e) {
if (this.data.booking && this.data.booking.button == '优惠预定') this.tominiProgram();
else {
this.send_form_idd(e)
return
}
wx.request({
url: app.globalData.config.FormidInsert,
data: {
session: wx.getStorageSync('session'),
formid: e.detail.formId,
statid: this.data.data.statid
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: app.globalData.header,
success: function (res) {}
})
},
// 弹出预登记
send_form_idd(e) {
if (this.data.serviceWindowList.length == 0) {
let url = `${app.globalData.baseURL}/tenement/v2/api/apartment/customerservice`
miucms.wxget(url, {
token: this.data.token,
customerservice: this.data.customerservice
}).then(res => {
if (res.code == 200) {
let serviceWindowList = this.data.serviceWindowList.concat(res.data.customerservicelist)
this.setData({
serviceWindowList,
tips: res.data.tips
})
if (serviceWindowList.length > 0) {
this.setData({
serviceWindowState: !this.data.serviceWindowState
})
} else {
let url = this.data.customerservice ? '/' + this.data.booking.path + '&customerservice=' + this.data.customerservice : '/' + this.data.booking.path;
wx.navigateTo({
url: url,
})
}
}
})
} else {
this.setData({
serviceWindowState: !this.data.serviceWindowState
})
}
// 应该是数据统计 开始
wx.request({
url: app.globalData.config.FormidInsert,
data: {
session: wx.getStorageSync('session'),
formid: e.detail.formId,
statid: this.data.data.statid
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: app.globalData.header,
success: function (res) {}
})
// 应该是数据统计 结束
},
share_pic: function () {
let that = this;
if (!this.data.data.poster) {
wx.showToast({
title: '暂无分享图片~',
icon: 'none'
})
return false
}
// 有圖片,去到分享頁面
this.setData({
share: true,
show_naviagate: true
})
wx.setStorage({
key: 'share_info',
data: {
pic: [],
text: that.data.data.poster
},
})
},
close_share: function () {
this.setData({
share: false,
show_share_box: false
})
},
to_share() {
wx.navigateTo({
url: '/pages/share/share',
})
},
toindex: function () {
wx.reLaunch({
url: '/pages/index/index',
})
},
// 如果用户已经同意授权。则开始获取数据
islogin(obj) {
if (!obj.detail.ispageinlogin) {
wx.showLoading({
title: '加载中',
})
this.get_content();
}
},
// 点击去举报
toReport() {
if (this.data.isAuthorization == 1) {
this.setData({
isUserAuthorization: 1
})
return false
}
let that = this;
wx.navigateTo({
url: `/pages/report/report?id=${this.data.data.uniqid}&types=apartment`,
})
},
showSchoolAlert(e) {
this.setData({
showSchool: e.currentTarget.dataset.show == 1 ? true : false
})
},
// 开始播放视频,隐藏底部栏
playVideo() {
this.setData({
showFooter: false
})
},
// 关闭视频,显示底部栏
closeVideo() {
this.setData({
showFooter: true
})
},
// 前往对方小程序
tominiProgram(e) {
let types = e && e.currentTarget.dataset.types || '';
let {
path,
appId
} = types ? this.data.irenCouponReceive : this.data.booking;
let that = this;
wx.navigateToMiniProgram({
appId,
path,
complete(res) {
let isOpen = res.errMsg == 'navigateToMiniProgram:ok' ? true : false;
that.stat(isOpen, types)
}
})
},
// 统计点击
stat(isOpen, types) {
if (types) {
if (this.data.irenCouponReceive.stat === null) return false
} else {
if (this.data.booking.stat === null) return false
}
let stat = types ? this.data.irenCouponReceive.stat : this.data.booking.stat;
miucms.request(app.globalData.config.studentapartment.stat, {
stat,
isOpen
}).then(res => {}).catch(res => {})
},
// 放大,缩小现金券
showIrentCoupon() {
this.setData({
irentCouponBig: !this.data.irentCouponBig,
hideCoupon: false
})
if (!this.data.irentCouponBig) app.globalData.irentCouponBig = false;
},
// 切换客服弹窗状态
bindServiceWindow() {
this.setData({
serviceWindowState: !this.data.serviceWindowState
})
},
serviceWindow() {
return false
},
// 跳转同品牌列表
goDualBrand() {
wx.pageScrollTo({
offsetTop: -200,
selector: "#dual-brand"
})
},
// 处理房间类型
mediaItem(e) {
let index = e.currentTarget.dataset.index
let current = e.currentTarget.dataset.current
let roomList = this.data.roomList
let targetData = roomList[index]
let videos = roomList[index].videos || []
let images = roomList[index].images || []
videos.forEach(element => {
element['isvideo'] = 1
element['video'] = element['videourl']
element['imageurl'] = element['imageurl']
element['url'] = element['videourl']
element['type'] = "video"
element['poster'] = element['imageurl']
})
images.forEach(element => {
element['type'] = "image"
element['image'] = element['imageurl']
element['url'] = element['imageurl']
})
let attachment = [...targetData['videos'], ...targetData['images']]
console.log("attachment", attachment);
// wx.previewMedia({
// sources: attachment,
// current
// })
wx.setStorageSync('sourcesList', attachment);
wx.navigateTo({
url: '/pages/video_show/video_show?current=' + current
})
},
// 公共跳转
publicJumps(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url,
fail: function (err) {
if (err['errMsg'] !== "navigateTo:fail webview count limit exceed") return
wx.redirectTo({
url,
})
}
})
},
copy(e) {
let value = e.currentTarget.dataset.value
miucms.copy(value)
},
// 点击收藏
bindCollect(e) {
const index = e.currentTarget.dataset.index
let target = {}
let token = this.data.token
if (index != undefined) {
target = this.data.withSameBrand[index]
token = target['token'] || ''
}
const baseURL = app.globalData.baseURL
wx.showLoading()
miucms.request(baseURL + '/tenement/v2/api/user/apartmentCollection', {
token
}).then(res => {
if (res.code != 200) return
let data = res.data
if (index != undefined) {
target['iscollect'] = data.status
target['collectnum'] = data.count
this.data.withSameBrand[index] = target
this.setData({
withSameBrand: this.data.withSameBrand
})
} else {
this.setData({
'data.iscollect': data.status,
'data.collectnum': data.count,
})
}
wx.hideLoading()
wx.showToast({
icon: "none",
title: res.message,
})
})
},
})