// pages/show/show.js
var app = getApp()
var miucms = require('../../utils/miucms.js');
var config = {};
var WxParse = require('../../wxParse/wxParse.js');
var screenWidth = 288;
var avatar_height = 40;
var screenWidth2 = 288;
var center_position = 144;
var center_position2 = 144;
var save = false;
var today = new Date();
var timer = null;
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: {
loding: true,
tid: '',
uniqid: '',
token: '',
info: {},
thread: {},
isfav: false,
isself: '',
canvas1: 230,
canvas11: 0,
poster: '',
share_img: "",
show_share_box: false,
qrcode: 'https://api.gter.net/avatar/MyTnU9xKN9jCce4KMXDCQOyTNzEyODg4/=api',
show_naviagate: false,
user: {},
screenWidth: 0,
share_info: {},
share: false,
source: '',
q: '',
image_height: [],
show_btn: 'show', //显示在线留言按钮
options: {},
publisheridentity: {
1: '中介',
2: '非中介',
3: '房东',
4: '有房招室友',
5: '其他'
},
isAuthorization: 0,
isUserAuthorization: 0,
showSchool: false, //是否显示房源距离学校弹窗
adv: {},
irenCouponReceive: null,
irentCouponBig: true,
hideCoupon: false,
adsTop: [],
adsposOption: 2, // 0 为普通随时广告 1 为幻灯片轮播广告 2 为无
imgheights: [],
current: 0,
QRCodeState: false, // 微信二维码的状态
isMessage: 0, // 发送系统通知的状态
groupid: 0, // 用户等级
contactInformationState: false, // 认证房源的联系方式弹窗状态
academyState: false, // 认证房源的房源距离院校弹窗状态
listingcount: 0, // 房东一共有几个房源
elseResourceData: [], // 其他房源数据
unitTop: 0, // 租金预算的高度
bottomUnitState: false, // 底部租金 预算显示状态
service: "",
servicename: "", // 求房源的基本数据 键值对
basicRequirementsList: {
"property": "房屋类型",
"floor": "所在楼层",
"elevator": "电梯",
"sunshinearea": "晾晒区",
"acreage": "面积",
"gender": "同住人性别要求",
"publishergender": "发布者性别"
},
basicRequirementsObj: {},
langs: {}, // 语言包
nearbylistings: { // 附近房源的数据
list: [],
page: 1,
pagevalue: 0
},
listDataLeft: [],
listDataRight: [],
contactValue: [],
contactObj: {
wechat: "微信号",
wechatdata: "微信",
whatsapp: "WhatsApp",
tel: "电话号码"
},
operationsTop: false, // 操作栏 是否在顶部
attestationElseResource: [], // 发布者其他房源
bgColorObj: app.globalData.bgColorObj,
wechat: {},
annexSchoolOmit: [], // 附近院校 前面 7个 或者 6个的
annexSchoolList: [], // 附近院校数据
academyPitchIndex: 0, // 附近学校距离选中院校 下标
targetAcademyPitch: [], // 附近学校距离选中院校 数据
specialSchoolDistance: null, // 特殊的 用户带有school参数 则需要特殊显示 学校距离
isShowVideo: true, // 是否显示 视频
showTab: "",
},
to_share() {
wx.navigateTo({
url: '/pages/share/share',
})
},
headHeight: 0,
timer: null,
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)
if (Math.random() > 0.5) return
let scrollTop = e.scrollTop
// 判断 在求房源情况下 底部预算 是否 展示
// if (this.data.info.intermediary == 6) this.judgeBottomUnitState(scrollTop)
this.judgeBottomUnitState(scrollTop)
},
onLoad: function (options) {
wx.showLoading()
wx.getSystemInfo({
success: function (res) {
windowWidth = res.windowWidth
}
})
this.setData({
tid: options.tid || '',
uniqid: options.uniqid || '',
source: options.source ? options.source : '',
q: options.q ? options.q : '',
show_btn: options.show_btn ? options.show_btn : 'show',
options: options || {},
irentCouponBig: app.globalData.irentCouponBig,
['info.cityid']: options.cityid,
isShowVideo: app.globalData.isShowVideo,
})
screenWidth = wx.getSystemInfoSync().screenWidth;
center_position = screenWidth / 2;
this.setData({
screenWidth: screenWidth,
})
this.get_config()
app.globalData['langs'] ? this.data.langs = app.globalData['langs'] : this.getDtailsLangs()
},
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()
}
},
onUnload() {
clearTimeout(timer)
},
// 如果用户已经同意授权。则开始获取数据
islogin(obj) {
if (!obj.detail.ispageinlogin) {
wx.showLoading({
title: '加载中',
})
this.get_content();
}
},
get_config() {
if (app.globalData.config.lists) {
config = app.globalData.config;
let screen_data = app.globalData.screen_data
this.setData({
user: app.globalData.user,
bottomLift: app.globalData.screen_data.bottomLift,
screen_data,
wechat: app.globalData.wechat,
})
let windowWidth = screen_data['windowWidth']; //获取设备屏幕宽度
let headHeight = (windowWidth / 750) * Number(165)
this.headHeight = headHeight
this.get_content();
} else {
timer = setTimeout(() => {
this.get_config()
}, 200)
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function (res) {
// 来自页面内转发按钮
if (res.from === 'button') var types = res.from === 'button' ? 'share_btn' : 'show';
let that = this;
// console.log("res", that.data.info.share_img);
const info = this.data.info
// let title = `中国香港 > ${ info.locationList[0].head } > ${ info.locationList[0].end }`
// if (info.address) title += ' > ' + info.address
let title = '香港租房 | ' + that.data.info.subject
let imageUrl = ""
if (info['intermediary'] == 6) title = "香港租房 | 共5000+实时香港房源,甄选优质学生公寓"
else imageUrl = that.data.info.share_img
return {
title,
imageUrl: this.data.shareImage,
success: function (res) {
miucms.share(app, types)
},
}
},
onShareTimeline() {
// let title = `中国香港 > ${ info.locationList[0].head } > ${ info.locationList[0].end }`
// if (info.address) title += ' > ' + info.address
let title = that.data.info.subject
let imageUrl = ""
if (info['intermediary'] == 6) title = "香港租房 | 共5000+实时香港房源,甄选优质学生公寓"
else imageUrl = that.data.info.share_img
return {
// title: this.data.info.subject,
title,
imageUrl: this.data.shareImage,
}
},
get_content: function () {
let that = this;
var sendData = Object.assign({}, this.data.options, {
session: wx.getStorageSync('session'),
tid: that.data.tid,
uniqid: that.data.uniqid,
source: that.data.source,
q: that.data.q
})
miucms.request(`${app.globalData.baseURL}/tenement/v2/api/details`, sendData).then(data => {
wx.hideLoading()
if (data.code != 200) {
wx.showModal({
title: '提示',
content: data.message,
showCancel: false,
success() {
wx.reLaunch({
url: '/pages/index/index',
})
}
})
} else {
data = data.data
let info = data.info
if (!this.data.isShowVideo) info.video = null
let arr = ["wechat", "wechatdata", "whatsapp", "tel"]
let contactValue = []
let contactObj = this.data.contactObj
arr.forEach(element => {
if (typeof info[element] == "object" && info[element] && info[element]['aid'] != 0) {
contactValue.push({
key: element,
value: info[element],
name: contactObj[element],
})
} else if (typeof info[element] == "string" && info[element]) {
contactValue.push({
key: element,
value: info[element],
name: contactObj[element],
})
}
})
let updatetime = data.info['updatetime'] || ''
updatetime = updatetime.replaceAll("-", "/") // 替换格式 部分 iOS 系统不支持
data.info['updatetimeText'] = miucms.getTimeAgo(updatetime)
let showTab = "person"
if (data.info.intermediary == 1) showTab = "agent"
if (data.info.intermediary == 6) showTab = "need"
that.setData({
showTab,
contactValue,
irentCouponBig: app.globalData.irentCouponBig || true,
info: data.info,
contrastInfo: {
...data.info
},
contacts: data.contacts,
isintermediary: data.isintermediary,
share_info: data.share,
thread: data.thread,
uniqid: data.uniqid,
token: data.token,
isMessage: data.isMessage,
isfav: data.isfav,
isself: data.isself,
isAuthorization: data.code == 401 ? 1 : 0,
adv: data.adv,
irenCouponReceive: data.irenCouponReceive,
groupid: data.groupid,
listingcount: data.listingcount,
landlordcertification: data.landlordcertification,
langs: this.data.langs,
service: data.service,
servicename: data.servicename,
verifiedlistingcount: data.verifiedlistingcount,
intermediarylistingcount: data.intermediarylistingcount,
loding: false
})
if (data.info && data.info.introduction && data.info.introduction.length > 0 && data.info.introduction != ' ') {
WxParse.wxParse('info.introduction', 'html', '
' + data.info.introduction + '
', that, 0);
}
if (data.info && data.info.message && data.info.message.length > 0 && data.info.message != ' ') WxParse.wxParse('info.message', 'html', '' + data.info.message + '
', that, 0);
// 认证房东 和 listingcount (他的房源数量) >1 时加载其他房源接口
if (data.groupid == 19 && data.listingcount > 1) this.getElseResource()
// if (data.info.verified == 1 && data.listingcount > 1) this.getElseResource()
// 判断是否需要请求顶部广告
if (data.ads && data.ads.bannertop) this.requestTopAds(data.ads.bannertop)
// 判断是否是求房源 如果是需要获取租金位置
this.getRentalLocation()
this.handleDetailData()
if (data.info.intermediary != 6) {
// setInterval(() => {
this.drawPoster()
// }, 1000);
}
// 判断是否需要获取附近房源
if (data.info.latitude && data.info.verified == 0 && data.info.intermediary != 6 && data.isintermediary != 1) this.getNearbListings()
else this.nearbListingsState = true // 阻止上拉底部加载的
// 获取其他认证房源
if (data.verifiedlistingcount > 1 || (data.intermediarylistingcount > 1 && data.isintermediary == 1)) this.getAttestationElseResource()
}
}).catch(res => {
wx.hideLoading()
wx.showModal({
title: '提示',
content: res.message || '抱歉,网络出错。请稍后重试~',
})
})
},
drawPoster() {
let obj = {}
const info = this.data.info
const image = info.picturegroup || []
const isintermediary = this.data.isintermediary || 0 // 是否是认证中介
let title = `${ info.gptype }·${ info.type }·HK$${ info.rent }`
obj['bj'] = info.image || image?.[0]?.thumbnail || ''
obj['title'] = title
if (isintermediary == 1) obj['type'] = 2 // 认证中介
else if (info.intermediary == 1) obj['type'] = 3 // 普通中介
else if (info.intermediary == 3 && info.verified == 0) obj['type'] = 4 // 普通个人房源
else if (info.intermediary == 3 && info.verified == 1) obj['type'] = 5 // 认证个人房源
else if (info.intermediary == 4) obj['type'] = 6 // 招室友
else if (info.intermediary == 5) obj['type'] = 7 // 其他
let res = null
if (obj['bj']) res = miucms.generatePoster(obj)
else {
obj['position'] = `香港 > ${ info.locationList[0].head } > ${ info.locationList[0].end }`
obj['typeText'] = `${ info.gptype } · ${ info.type }`
obj['price'] = info.rent
res = miucms.generatePosterNoImage(obj)
}
res.then(res => {
this.setData({
shareImage: res
})
})
},
// 获取语言包 保存全局
getDtailsLangs() {
miucms.request(`${app.globalData.baseURL}/tenement/v2/api/details/langs`).then(res => {
if (res.code != 200) return
let data = res.data
this.setData({
langs: data
})
app.globalData['langs'] = data
})
},
// 专门梳理v4出现的 语音包 及 不同房源值的处理
handleDetailData() {
let langs = this.data.langs || {}
if (Object.keys(langs).length == 0) setTimeout(() => this.handleDetailData(), 300)
else {
let info = this.data.info
// 判断是否是求房源的区间 面积 和 价格
let judgeArr = ['acreage', 'rent']
judgeArr.forEach(element => {
if (Array.isArray(info[element])) info[element] = info[element][0] + ' ~ ' + info[element][1]
})
// 这个是将 详情键 替换语言包里的值
let list = ['type', 'rentalduration', 'intermediary']
// if (Array.isArray(info['floor'])) list.push('floor') // 判断 楼层是否需要 替换值, 因为在求房源里是多个值
let differentNames = { // 需要替换的 键名
"intermediary": "intermediary_text"
}
list.forEach(element => {
if (info[element] == 0) info[differentNames[element] ? differentNames[element] : element] = '不限' // 当 值为 [0] 时为不限
else info[differentNames[element] ? differentNames[element] : element] = langs[element][info[element]]
})
let location = langs.location // 遍历替换区域的值 所有房源
let pendingData = info['location'] || ''
let locationList = []
if (Array.isArray(pendingData)) {
for (const key in location) {
if (pendingData.indexOf(key) != -1) {
locationList.push({
head: location[Math.trunc(key)],
end: Math.trunc(key) != key ? location[key] : '不限',
})
}
}
} else {
locationList.push({
head: location[Math.trunc(pendingData)],
end: Math.trunc(pendingData) != pendingData ? location[pendingData] : '不限',
})
}
info['locationList'] = locationList
let basicRequirementsList = this.data.basicRequirementsList
if (info['intermediary'] != 6) {
basicRequirementsList['gender'] = "性别要求"
delete basicRequirementsList['publishergender']
delete basicRequirementsList['elevator']
}
if (info['intermediary'] == 6 && this.data.contrastInfo['type'] >>> 0 == 2) delete basicRequirementsList['gender']
let obj = []
for (const key in basicRequirementsList) {
let langsKey = langs[key]
if (key == "publishergender") langsKey = langs["gender"]
let value
if (Array.isArray(info[key])) {
value = ""
info[key].forEach((element, index) => {
if (langsKey[element]) value += langsKey[element] + (index != info[key].length - 1 ? ' / ' : '')
})
if (!value) value = "不限"
} else {
if (key == 'acreage' && info[key]) value = `${info[key]} 平方呎`
else if (key != 'floor' && info[key] != undefined && langsKey != undefined) value = langsKey[info[key]]
else if (key == 'floor' && langs["elevator"][info["elevator"]] && langs["elevator"][info["elevator"]] != "不限") value = [info[key], langs["elevator"][info["elevator"]]]
else value = info[key]
}
obj.push({
name: basicRequirementsList[key],
value
})
}
this.setData({
info,
basicRequirementsObj: obj
})
}
},
copy: function (e) {
var that = this;
let num = that.data.info[e.currentTarget.dataset.num] + '';
let hint = e.currentTarget.dataset.hint
wx.setClipboardData({
data: num,
success: function (res) {
wx.getClipboardData({
success: function (res) {
wx.showToast({
title: hint || '复制成功!',
})
},
fail(err) {
wx.showModal({
title: '提示',
content: err,
})
},
})
},
fail(res) {
wx.showModal({
title: '提示',
content: err,
})
}
})
},
// 拨打电话
call_us: function () {
var that = this;
wx.makePhoneCall({
phoneNumber: that.data.info.tel
})
},
add_to_fav: function () {
if (!app.globalData.config || !app.globalData.config.collection) return false
if (this.data.isAuthorization == 1) {
this.setData({
isUserAuthorization: 1
})
return false
}
let that = this;
miucms.request(app.globalData.config.collection.operation, {
token: that.data.token,
uniqid: that.data.uniqid
}).then(data => {
wx.showToast({
title: data.message,
icon: 'none'
})
if (data.extraparam && data.extraparam.mode == 'right') {
// 成功
that.data.info.count_fav = data.data.count;
that.data.isfav = data.data.status == 1 ? true : false;
that.setData({
info: that.data.info,
isfav: that.data.isfav
})
}
}).catch(res => {})
},
share_pic: function () {
let that = this;
if (this.data.isAuthorization == 1) {
this.setData({
isUserAuthorization: 1
})
return false
}
// 有圖片,去到分享頁面
this.setData({
share: true,
show_naviagate: true
})
wx.setStorage({
key: 'share_info',
data: that.data.share_info,
})
},
close_share: function () {
this.setData({
share: false,
show_share_box: false
})
},
downloadFile: function () {
let that = this;
wx.downloadFile({
url: that.data.share_info.text, //仅为示例,并非真实的资源
success: function (res) {
// 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
if (res.statusCode === 200) {
that.data.share_info.text = res.tempFilePath
that.setData({
share_info: that.data.share_info
})
}
}
})
},
save_pic: function () {
let that = this;
if (that.data.share_info.text && that.data.share_info.text.length == 0) {
setTimeout(function () {
that.save_pic()
}, 800)
return false;
}
if (!save) {
wx.saveImageToPhotosAlbum({
filePath: that.data.share_info.text,
success: function (res) {
save = true;
that.setData({
show_share_box: true
})
},
complete: function (res) {
console.log(res)
}
})
} else {
that.setData({
show_share_box: true
})
}
},
toindex: function () {
wx.reLaunch({
url: '/pages/index/index',
})
},
get_user_info: function (e) {
let that = this;
miucms.initial('https://api.gter.net/XiaoappHK:Index.init.json', app)
setTimeout(function () {
that.get_config()
}, 300)
},
preview_img: function (e) {
let index = e.currentTarget.dataset.index;
let that = this;
wx.previewImage({
current: that.data.info.images[index], // 当前显示图片的http链接
urls: that.data.info.images // 需要预览的图片http链接列表
})
},
imageLoad: function (e) {
let originalWidth = e.detail.width;
let originalHeight = e.detail.height;
let index = e.currentTarget.dataset.index;
this.data.image_height[index] = originalHeight * (windowWidth - 40) / originalWidth
this.setData({
image_height: this.data.image_height
})
},
// 在线留言(联系方式)
to_message: function () {
wx.pageScrollTo({
selector: '#relation',
offsetTop: -(app.globalData.screen_data.windowHeight * 0.3)
})
},
send_form_id: function (e) {
wx.request({
url: app.globalData.config.FormidInsert,
data: {
session: wx.getStorageSync('session'),
formid: e.detail.formId
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: app.globalData.header,
success: function (res) {
var data = app.return_data(res);
}
})
},
wxParseTagATap: function (e) {
var url = e.currentTarget.dataset.src;
wx.navigateTo({
url: url,
})
},
show_video: function (e) {
const video = this.data.info.video || []
const images = this.data.info.images || []
let sources = []
video.forEach(element => {
sources.push({
url: element['url'],
poster: element['image'],
type: "video"
})
})
images.forEach(element => {
sources.push({
url: element,
type: "image"
})
})
const current = e.currentTarget.dataset.current;
// console.log("current", current);
// var image = e.currentTarget.dataset.image;
// console.log("sources", sources);
// return
// wx.previewMedia({
// sources,
// current: 0,
// })
wx.setStorageSync('sourcesList', sources);
wx.navigateTo({
url: '/pages/video_show/video_show?current=' + current
})
},
showSchoolAlert(e) {
this.setData({
showSchool: e.currentTarget.dataset.show == 1 ? true : false
})
},
// 去地图
to_map: function (e) {
if (this.data.QRCodeState) return
var latitude = Number(e.currentTarget.dataset.latitude);
var longitude = Number(e.currentTarget.dataset.longitude);
if (latitude == '') return false
var address = e.currentTarget.dataset.address;
wx.openLocation({
latitude: latitude,
longitude: longitude,
scale: 14,
name: this.data.info.address,
address: address
})
},
// 点击去举报
toReport() {
if (this.data.isAuthorization == 1) {
this.setData({
isUserAuthorization: 1
})
return false
}
let that = this;
wx.navigateTo({
url: `/pages/report/report?id=${this.data.info.uniqid}&types=housing`,
})
},
// 点击广告
clickAD(e) {
miucms.clickAD(e.detail.id)
},
// 关闭广告
closeAD(e) {
this.setData({
adv: null
})
miucms.closeAD(e.detail.id)
},
copyWebsite() {
wx.setClipboardData({
data: 'http://ad@gter.net/',
success: function (res) {
wx.getClipboardData({
success: function (res) {
wx.showToast({
title: '复制成功!',
})
},
fail(err) {
wx.showModal({
title: '提示',
content: err,
})
},
})
},
fail(res) {
wx.showModal({
title: '提示',
content: err,
})
}
})
},
// 前往对方小程序
tominiProgram(e) {
let {
path,
appId
} = this.data.irenCouponReceive;
let that = this;
wx.navigateToMiniProgram({
appId,
path,
complete(res) {
let isOpen = res.errMsg == 'navigateToMiniProgram:ok' ? true : false;
that.stat(isOpen)
}
})
},
// 统计点击
stat(isOpen) {
if (this.data.irenCouponReceive.stat === null) return false
miucms.request(app.globalData.config.studentapartment.stat, {
stat: this.data.irenCouponReceive.stat,
isOpen
}).then(res => {}).catch(res => {})
},
// 放大,缩小现金券
showIrentCoupon() {
this.setData({
irentCouponBig: !this.data.irentCouponBig,
hideCoupon: false
})
if (!this.data.irentCouponBig) app.globalData.irentCouponBig = false;
},
imageLoaded(e) {
let imgwidth = e.detail.width,
imgheight = e.detail.height,
ratio = imgwidth / imgheight;
let viewHeight = 750 / ratio;
imgheight = viewHeight;
let imgheights = this.data.imgheights;
imgheights[e.target.dataset.index] = imgheight;
this.setData({
imgheights: imgheights
})
},
onSlideChangeEnd(e) {
this.setData({
current: e.detail.current
})
},
// 请求顶部广告
requestTopAds(id) {
let that = this
miucms.request(app.globalData.baseURL + "/tenement/ads", {
id
}).then(res => {
if (res.code != 200) return
let data = res.data
let adsTop = []
if (data.adspos.option == 1) adsTop.push(data.data[0])
else if (data.adspos.option == 0) adsTop = data.data
that.setData({
adsTop,
adsposOption: data.adspos.option
})
})
},
// 点击统计顶部广告
statisticsTopAds(e) {
let id = e.currentTarget.dataset.id
miucms.request(app.globalData.baseURL + "/peer/ads/details", {
id
}).then(res => {
if (res.code != 200) return
if (res.data.url.indexOf("page") != -1) { // pages/ad/ad?uniqid=W0uGvPWiSCeS
wx.navigateTo({
url: "/" + res.data.url,
})
} else {
wx.navigateTo({
url: `/pages/webViewwebweb/index?url=${res.data.url}`,
})
}
})
},
// 点击打开二维码
openQRCode() {
this.setData({
QRCodeState: !this.data.QRCodeState
})
},
goIsMessage() {
wx.navigateTo({
url: `/pages/circularize/circularize?uniqid=${this.data.options.uniqid}`,
})
},
// 获取其他房源数据
getElseResource() {
miucms.request(`${app.globalData.baseURL}/tenement/housingresources/otherhousinginTA`, {
token: this.data.token,
}).then(res => {
if (res.code == 200) {
let elseResourceData = res.data.data
this.handleElseData(elseResourceData)
} else {
wx.showModal({
title: '提示',
content: res.message
})
}
})
},
// 专门梳理v4出现的 语音包 及 不同房源值的处理
handleElseData(data) {
let langs = this.data.langs || {}
if (Object.keys(langs).length == 0) {
setTimeout(() => {
this.handleDetailData()
}, 300)
} else {
let datadata = []
if (!Array.isArray(data)) {
for (const key in data) {
datadata.push(data[key])
}
data = datadata
}
data.forEach(ele => {
// 这个是将 详情键 替换语言包里的值
let list = ['type', 'rentalduration', 'intermediary', "property", "elevator", "sunshinearea", "gender"]
if (Array.isArray(ele['floor'])) list.push('floor') // 判断 楼层是否需要 替换值, 因为在求房源里是多个值
let differentNames = { // 需要替换的 键名
"intermediary": "intermediary_text"
}
list.forEach(element => {
if (ele[element] == -1) {} else if (ele[element] == 0) ele[differentNames[element] ? differentNames[element] : element] = '不限' // 当 值为 [0] 时为不限
else ele[differentNames[element] ? differentNames[element] : element] = langs[element][ele[element]]
})
let tabArr = ["gptype", "property", "elevator", "sunshinearea", "gender"]
let tabList = []
tabArr.forEach(el => {
if (ele[el] && ele[el] != -1) tabList.push(ele[el])
})
ele['tabList'] = tabList
let location = langs.location // 遍历替换区域的值 所有房源
let pendingData = ele['location']
ele['location'] = `${location[Math.trunc(pendingData)]} > ${location[pendingData]}`
})
this.setData({
attestationElseResource: data,
})
}
},
// 专门取反的函数
negation(e) {
let key = e.currentTarget.dataset.key
this.setData({
[key]: !this.data[key]
})
},
// 滚动到其他
goScrollToEles() {
if (this.listingcount <= 1) return
wx.pageScrollTo({
selector: ".container >>> #else",
offsetTop: 100
})
},
locationmove() {
return
},
// 点击 认证房东 跳转到认证介绍
goApprove() {
let url = this.data.landlordcertification
wx.navigateTo({
url: `/pages/webViewwebweb/index?url=${this.data.landlordcertification}`,
})
},
// 点击复制的公共方法
publicCopy(e) {
let value = e.currentTarget.dataset.value
if (typeof value === 'number') value = value + ''
miucms.copy(value)
},
// 获取租金位置 滑动到顶部显示 底部用
getRentalLocation() {
let that = this
const query = wx.createSelectorQuery()
query.select("#unit").boundingClientRect()
query.exec(function (res) {
if (!res) that.getRentalLocation()
if (res[0] == null) return
let unitTop = res[0].top
that.setData({
unitTop
})
})
},
// 判断 在求房源情况下 底部预算 是否 展示
judgeBottomUnitState(scrollTop) {
let bottomUnitState = false
if (scrollTop > this.data.unitTop) bottomUnitState = true
if (bottomUnitState == this.data.bottomUnitState) return
this.setData({
bottomUnitState
})
},
// 点击复制微信号
copyy() {
const content = this.data.servicename;
if (!content) return
miucms.copy(content).then((res) => {}).catch(err => {})
},
// 获取附近房源
nearbListingsState: false,
getNearbListings() {
if (this.nearbListingsState) return
this.nearbListingsState = true
wx.showLoading({
title: '加载中...',
})
let nearbylistings = this.data.nearbylistings
miucms.wxget(app.globalData.baseURL + "/tenement/v2/api/home/recommendList", {
page: nearbylistings['page'],
limit: 20,
type: "nearby",
pagevalue: nearbylistings['pagevalue'] || 0,
token: this.data.token,
}).then(res => {
if (res.code != 200) return
let data = res.data
nearbylistings['page'] = nearbylistings['page'] + 1
nearbylistings['list'] = data.data
nearbylistings['pagevalue'] = data.pagevalue
this.setData({
nearbylistings: Object.assign(this.data.nearbylistings, nearbylistings)
})
this.calculationBefore(data.data)
}).catch(() => {
this.nearbListingsState = false
}).finally(() => {
wx.hideLoading()
})
},
calculationBefore(data = [...data]) {
let listDataLeft = this.data.listDataLeft || []
let listDataRight = this.data.listDataRight || []
data = data.slice(0, 10)
data.forEach((el, index) => {
if (index % 2 === 0) listDataLeft.push(el)
else listDataRight.push(el)
})
this.data.listDataLeft = listDataLeft
this.data.listDataRight = listDataRight
this.setData({
listDataLeft,
listDataRight,
})
this.top10State = true
},
listDataIndex: 0,
leftHeight: 0, // px 单位
rightHeight: 0,
ratio: 0,
pinterestImgLoadIndex: 0, // 加载了建施图
// 计算
calculateProcessingCenter() {
if (!this.ratio) this.ratio = this.data.screen_data['windowWidth'] / 750 || 0.5
let ratio = this.ratio
let targetData = this.data.nearbylistings.list[this.listDataIndex]
if (!targetData) {
this.nearbListingsState = false
return
}
let type = targetData['type']
if (type == 'adv') {
this.getPictureHeight(targetData.image).then(res => {
targetData['imageLocal'] = res.path
this.whichSide(res.actual, targetData)
return
})
} else {
let altitude = 0 // rpx
if (type == 'apartment') {
altitude = 205
if (targetData['specifications'].length > 2) altitude += 100
else altitude += 64 * targetData['specifications'].length
} else altitude = 141
altitude = altitude * ratio // 转 px
this.setData({
targetData
})
altitude += (150 / 180 * 337.5 * ratio)
let select = type == 'apartment' ? '#apartment' : '#general'
let query = wx.createSelectorQuery();
query.select(select).boundingClientRect(rect => {
if (!rect) {
this.whichSide(altitude, targetData)
return
}
let height = rect.height;
altitude += height
this.whichSide(altitude, targetData)
}).exec();
}
},
// 判断在哪边的
whichSide(res, targetData) {
if (this.leftHeight <= this.rightHeight) {
this.leftHeight = this.leftHeight + res
this.data.listDataLeft.push(targetData)
} else {
this.rightHeight = this.rightHeight + res
this.data.listDataRight.push(targetData)
}
this.setData({
listDataLeft: this.data.listDataLeft,
listDataRight: this.data.listDataRight
})
if (this.data.nearbylistings.list[this.listDataIndex]) {
this.listDataIndex++
this.calculateProcessingCenter()
}
},
pinterestImgLoad(e) {
this.pinterestImgLoadIndex++
if (this.pinterestImgLoadIndex >= 10 && this.top10State) {
this.top10State = false
this.pinterestImgLoadIndex = 0
this.listDataIndex = 10
let query = wx.createSelectorQuery();
query.select("#pinterest-list-left").boundingClientRect()
query.select("#pinterest-list-right").boundingClientRect()
query.exec(rect => {
if (!rect[0]) {
this.nearbListingsState = false
return
}
this.leftHeight = rect[0].height
this.rightHeight = rect[1].height
this.calculateProcessingCenter()
})
}
},
// 获取图片高度
getPictureHeight(src) {
return new Promise((resolve, reject) => {
wx.getImageInfo({
src,
success: res => {
let {
width,
height,
path
} = res
let actual = height / width * 337 * this.ratio
resolve({
actual,
path
})
}
})
})
},
// 获取
getAttestationElseResource() {
miucms.request(`${app.globalData.baseURL}/tenement/v2/api/lists/publisherList`, {
token: this.data.token,
}).then(res => {
if (res.code != 200) return
let attestationElseResource = res.data
this.handleElseData(attestationElseResource)
})
},
// 上拉到底部
onReachBottom() {
this.getNearbListings()
},
// 点击展示名片
showBusinessCard() {
let businesscard = this.data.contacts['businesscard'] || []
let data = []
businesscard.forEach(element => {
data.push(element['image'])
})
wx.previewImage({
current: data[0], // 当前显示图片的http链接
urls: data // 需要预览的图片http链接列表
})
},
// 公共跳转
publicJumps(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url,
fail: function (err) {
if (err['errMsg'] == "navigateTo:fail webview count limit exceed") {
wx.redirectTo({
url,
})
}
}
})
},
})