737 lines
23 KiB
JavaScript

// pages/restOfWorld/restOfWorld.js
var app = getApp()
var config = {};
var miucms = require('../../utils/miucms.js');
Page({
/**
* 页面的初始数据
*/
data: {
showTOTOP: false,
loading: true,
conditionFixed: false, //筛选条件一列是否固定在顶部
attachment: [],
groupSearch: [], //组合最热
selectGroupIndex: null,
orderby: {
value: 'default',
list: [{
name: "综合",
value: 'default'
}, {
name: "最新发布",
value: 'updatetime'
},
{
name: "热门",
value: 'hotnum'
},
{
name: "价格从低到高",
value: 'rentasc'
},
{
name: "价格从高到低",
value: 'rentdesc'
},
]
},
list: [],
page: 1,
location: {},
types: {
data: [],
value: ''
},
property: {},
cityList: [],
moreCondition: {
show: false,
data: {
gender: "0",
leaseterm: "",
publish: 0,
}
},
city: {
uniqid: "",
name: "",
alias: ''
},
hascondition: true,
langs: {}, // 语言包
isAuthorization: 0,
operationsTop: false,
authenticationPopState: false, // 认证中介 弹窗状态
headerSearchTop: false,
totalSum: 0, // 数据总数
allowsearch: false, // 是否需要筛选
isMapFindState: false,
money: {
rent_min: 0,
rent_max: ''
},
requestData: {}, // 请求参数
QRCodePopState: false, // 二维码弹窗状态
morePage: 1, // 更多的页数
moreList: [], // 更多的数据
popwindowBtnState: true, // 弹窗按钮状态
popwindow: {}, // 弹窗信息
},
headerSearchTopHeight: 10,
onPageScroll(e) {
if (e.scrollTop > this.headerSearchTopHeight && !this.data.headerSearchTop) {
this.setData({
headerSearchTop: true
})
} else if (e.scrollTop <= this.headerSearchTopHeight && this.data.headerSearchTop) {
this.setData({
headerSearchTop: false
})
}
if (e.scrollTop > this.operationsHeight && !this.data.operationsTop) {
this.setData({
operationsTop: true
})
} else if (e.scrollTop <= this.operationsHeight && this.data.operationsTop) {
this.setData({
operationsTop: false
})
}
if (e.scrollTop > 1000 && !this.data.showTOTOP) {
this.setData({
showTOTOP: true
})
} else if (e.scrollTop < 1000 && this.data.showTOTOP) {
this.setData({
showTOTOP: false
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 获取全局筛选的值
let selectionObj = {}
selectionObj = app.globalData.restSelectionObj
var location = [];
const locationArr = miucms.updateProperty('location', options, selectionObj)
if (locationArr) this.data.requestData['location'] = locationArr.split(',')
this.data.location.value = location;
const types = miucms.updateProperty('types', options, selectionObj) || 0
this.data.types.value = types
this.data.requestData['types'] = types
const gender = miucms.updateProperty('gender', options, selectionObj) || 0
this.data.moreCondition.data.gender = gender
this.data.requestData['gender'] = gender
const leaseterm = miucms.updateProperty('leaseterm', options, selectionObj) || 0
this.data.moreCondition.data.leaseterm = leaseterm
this.data.requestData['leaseterm'] = leaseterm
const publish = miucms.updateProperty('publish', options, selectionObj) || 0
this.data.moreCondition.data.publish = publish
this.data.requestData['publish'] = publish
const iselevator = miucms.updateProperty('iselevator', options, selectionObj) || 0
this.data.moreCondition.data.iselevator = iselevator
this.data.requestData['iselevator'] = iselevator
const issunshinearea = miucms.updateProperty('issunshinearea', options, selectionObj) || 0
this.data.moreCondition.data.issunshinearea = issunshinearea
this.data.requestData['issunshinearea'] = issunshinearea
const orderby = miucms.updateProperty('orderby', options, selectionObj) || 'default'
this.data.orderby.value = orderby
this.data.requestData['orderby'] = orderby
const oMoney = miucms.updateProperty('money', options, selectionObj)
if (oMoney) {
let money = oMoney.split('~')
this.data.money.rent_min = money[0];
this.data.money.rent_max = money[1];
this.data.requestData['rent_min'] = money[0];
this.data.requestData['rent_max'] = money[1];
}
this.setData({
location: this.data.location,
moreCondition: this.data.moreCondition,
requestData: this.data.requestData,
orderby: this.data.orderby,
city: {
uniqid: options.cityid || '',
name: options.name || '',
alias: options.alias || ''
},
})
var that = this;
wx.setStorage({
key: 'selectcityData',
data: that.data.city,
})
this.get_config()
this.firstInpage = false;
this.setData({
money: this.data.money,
})
},
firstInpage: true,
onShow() {
var that = this;
if (this.firstInpage) {
return false
}
wx.getStorage({
key: 'selectcityData',
success: function (res) {
if (res.data.uniqid == that.data.city.uniqid) {
return false
}
that.setData({
city: res.data,
selectGroupIndex: null
})
if (res.data && res.data.uniqid && app.globalData.config.lists) {
that.clear_data()
}
},
})
},
onUnload() {
wx.removeStorage({
key: 'selectcityData',
success: function (res) {},
})
wx.removeStorage({
key: 'countryList',
success: function (res) {},
})
},
get_config() {
var that = this;
if (app.globalData.config.lists) {
config = app.globalData.config;
that.data.user = app.globalData.user;
this.setData({
isMapFindState: app.globalData.isMapFindState,
screen_data: app.globalData.screen_data,
leaseterm: that.data.leaseterm,
status: app.globalData.status,
StudentapartmentNew: app.globalData.StudentapartmentNew,
intermediary: app.globalData.user.intermediary,
identity: app.globalData.user.identity || 1,
popwindow: app.globalData.popwindow,
// identity: 1,
})
let screen_data = this.data.screen_data
let windowWidth = screen_data['windowWidth']; //获取设备屏幕宽度
this.headerSearchTopHeight = (windowWidth / 750) * Number(20)
this.get_list();
this.getAd();
this.getLocationList()
// app.globalData['langs'] ? this.data.langs = app.globalData['langs'] : this.getDtailsLangs()
if (app.globalData['langs']) {
this.setData({
langs: app.globalData['langs']
})
} else this.getDtailsLangs()
} else {
setTimeout(function () {
that.get_config()
}, 200)
}
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
if (!app.globalData.config || !app.globalData.config.lists) {
wx.stopPullDownRefresh();
return false
}
this.clear_data()
this.getAd()
wx.stopPullDownRefresh();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (this.data.morePage >= 1) this.getMoreList()
if (!app.globalData.config || !app.globalData.config.lists || this.data.page.next_page < 2 || this.data.page == 0) return false
this.get_list()
},
getTitle(){
let path = `/pages/needHousing/needHousing?name=${this.data.city.name}&cityid=${this.data.city.uniqid}&alias=${this.data.city.alias}`;
var title = app.globalData.topTitle;
if (this.data.city.name) title = app.globalData.topTitle + ' - ' + this.data.city.name
return {
path,
title,
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
const res = this.getTitle()
return {
path: res.path,
title: res.title,
success: function (res) {
miucms.share(app, 'index')
}
}
},
onShareTimeline() {
const res = this.getTitle()
return {
path: res.path,
title: res.title,
}
},
// 拉去广告
getAd() {
let that = this;
miucms.request(app.globalData.config.otherlist.banner, {}).then(data => {
that.setData({
attachment: data.data
})
wx.hideLoading()
}).catch(res => {})
},
// 组合搜索
getgroupSearch() {
return
var that = this;
miucms.request(app.globalData.config.otherlist.groupsearch, {}).then(data => {
this.setData({
groupSearch: data.data
}, function () {
that.calculateConditionPosition()
})
wx.hideLoading()
}).catch(res => {})
},
// 拉取列表
get_list() {
var that = this;
if (this.data.page == 0) return
wx.showLoading({
title: '加载中...',
})
this.setData({
loading: true,
morePage: 1,
moreList: [],
})
let url = `${app.globalData.baseURL}/tenement/v2/api/lists`
let requestData = {
page: this.data.page,
intermediary: 6
}
requestData = Object.assign(requestData, this.data.requestData)
miucms.request(url, requestData).then(data => {
data = data.data
let list = data.data
list.forEach(element => {
if (Array.isArray(element.rent)) element.rent = element.rent.join(' ~ ')
})
this.handleDetailData(list)
let page = data.page * data.limit >= data.count ? 0 : data.page + 1
this.setData({
totalSum: data.count,
loading: false,
page
})
wx.hideLoading()
// 判断是否是最后一页 和是否选中学校和区域 如果都是则 需要请求更多数据
if (this.data.page == 0 && requestData['location'].length != 0) this.getMoreList()
}).catch(res => {}).finally(() => {
wx.hideLoading()
})
let selectionObj = {
...this.data.requestData,
location: this.data.requestData.location && this.data.requestData.location.join(','),
}
if (this.data.requestData['rent_min'] > 0) selectionObj['money'] = `${this.data.requestData['rent_min']}~${this.data.requestData['rent_max']}`
app.globalData.restSelectionObj = selectionObj
},
// 获取地域列表
getLocationList() {
let that = this;
miucms.request(app.globalData.config.otherlist.region, {}).then(data => {
this.data.location.data = data.data.location;
this.data.types.data = data.data['type'];
that.setData({
['gender.list']: data.data.gender,
location: this.data.location,
types: this.data.types,
property: data.data.property,
cityList: data.data.cityList,
allowsearch: data.data.allowsearch
})
wx.setStorage({
key: 'countryList',
data: data.data.cityList,
})
wx.hideLoading()
}).catch(res => {})
},
// 计算筛选条件位置
calculateConditionPosition() {
var that = this;
wx.createIntersectionObserver().relativeToViewport({
top: -20
}).observe('.hot-text-box', res => {
if (res.intersectionRatio > 0) {
that.setData({
conditionFixed: false
})
} else {
that.setData({
conditionFixed: true
})
}
})
},
// 清空数组
clear_data: function () {
this.setData({
page: 1,
list: []
})
this.get_list()
},
// 提交出租方式
submittype(e) {
this.data.types.value = e.detail.data;
this.setData({
types: this.data.types,
selectGroupIndex: null
})
this.clear_data()
},
// 提交排序
submitOrderby(e) {
this.data.orderby.value = e.detail.value;
this.setData({
orderby: this.data.orderby
})
this.clear_data()
},
// 提交更多
myEventSelectSubmit(e) {
this.setData({
moreCondition: {
show: false,
data: e.detail
},
selectGroupIndex: null
})
this.hasMoreCondition()
this.clear_data()
},
// 判断‘更多’是否加粗
hasMoreCondition() {
let hascondition = false;
for (let i in this.data.moreCondition.data) {
if (this.data.moreCondition.data[i] != 0) {
// 存在一个就加粗
hascondition = true;
}
}
this.setData({
hascondition,
})
},
// 选择热词
selectGroup(e) {
let index = e.currentTarget.dataset.index;
let obj = this.data.groupSearch[index].where;
// this.data.location.value = [...obj.location];//区域
this.data.types.value = obj['type']; //出租方式
this.data.orderby.value = obj.orderby; //排序
var isNotID = true,
city = {
uniqid: obj.cityid,
name: '',
"alias": ""
};
this.data.cityList.every(item => {
item.city.every(s => {
if (s.cityid == obj.cityid) {
isNotID = false;
city.name = s.name;
city.alias = item.alias;
}
return isNotID
})
return isNotID
})
this.data.city = city;
this.data.moreCondition.data = {
gender: obj.gender,
leaseterm: obj.leaseterm,
publish: obj.publish,
}
this.setData({
selectGroupIndex: index,
// location: this.data.location,
types: this.data.types,
orderby: this.data.orderby,
moreCondition: this.data.moreCondition,
city
})
this.hasMoreCondition()
this.clear_data()
},
// 点击广告
clickAD(e) {
miucms.clickAD(e.detail.id)
},
// 关闭广告
closeAD(e) {
let index = e.currentTarget.dataset.index;
this.data.list.splice(index, 1)
this.setData({
list: this.data.list
})
miucms.closeAD(e.detail.id)
},
// 获取语言包 保存全局
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(data, dataType = 'list') {
let langs = this.data.langs || {}
if (Object.keys(langs).length == 0) {
setTimeout(() => {
this.handleDetailData(data)
}, 300)
} else {
langs['publishergender'] = {
...langs['gender']
}
data.forEach(element => {
// 某些原因 需要放前面来
// let tabArr = ["gptype", "property", "elevator", "sunshinearea", "gender"]
// if (element['type'] >>> 0 == 2) tabArr = ["gptype", "property", "elevator", "sunshinearea"]
let tabArr = ["gptype", "type", "elevator", "sunshinearea", "gender"]
if (element['type'] >>> 0 == 2) tabArr = ["gptype", "type", "elevator", "sunshinearea"]
let list = ['type', 'rentalduration', 'intermediary', "property", "elevator", "sunshinearea", "gender", "publishergender"]
if (Array.isArray(element['floor'])) list.push('floor') // 判断 楼层是否需要 替换值, 因为在求房源里是多个值
let differentNames = { // 需要替换的 键名
"intermediary": "intermediary_text"
}
list.forEach(elemen => {
if (element[elemen] == -1) {} else if (element[elemen] == 0) element[differentNames[elemen] ? differentNames[elemen] : elemen] = '不限' // 当 值为 [0] 时为不限
else element[differentNames[elemen] ? differentNames[elemen] : elemen] = langs[elemen][element[elemen]]
})
let tabList = []
tabArr.forEach(el => {
if (element[el] && element[el] != -1 && element[el] != '不限' && element[el] != '其他') tabList.push(element[el])
})
element['tabList'] = tabList
let leasetermLangs = langs.leaseterm
element.leaseterm = leasetermLangs[element.leaseterm || 1]
let location = langs.location // 遍历替换区域的值 所有房源
let pendingData = element['location'] || []
let locationList = []
for (const key in location) {
if (pendingData.indexOf(key) != -1) locationList.push(`${location[Math.trunc(key)]} > ${ Math.trunc(key) != key ? location[key] : '不限' }`)
}
element['locationList'] = locationList
})
let list = this.data.list
let moreList = this.data.moreList
if (dataType == 'list') list = list.concat(data)
else moreList = moreList.concat(data)
this.setData({
list,
moreList,
})
}
},
// 跳转求房源发布页面
goAskHousing() {
let user = app.globalData['user']
let miniProgram = app.globalData['miniProgram']
if (user['uid']) {
if (!user['nickname'] || !user['avatar']) {
wx.navigateTo({
url: '/pagesLoginRequired/pages/setAvatarNickname/setAvatarNickname',
})
return
}
if (miniProgram == 'gx') {
wx.navigateToMiniProgram({
appId: "wx9c68fbf7886ea9c4",
path: "/pages/askHousing/askHousing"
})
} else {
wx.navigateTo({
url: '/pages/askHousing/askHousing',
})
}
} else {
this.setData({
isAuthorization: 1
})
}
},
operationsHeight: 0,
// 记录 轮播图的高度 // 随便计算 筛选的高度
// 筛选到顶部的高度
recordSwiperHeight(e) {
let swiperHeight = e.detail
let screen_data = this.data.screen_data
wx.createSelectorQuery().select("#list-operations").boundingClientRect((rect) => {
if (!rect) return
let top = rect.top - screen_data['totalTopHeight']
this.operationsHeight = top
}).exec()
},
// 处理接收 筛选 组件的参数
submitOperations(e) {
let value = e.detail
let requestData = this.data.requestData
requestData = Object.assign(requestData, value)
this.data.requestData = requestData
this.data.page = 1
this.data.list = []
this.get_list()
},
setValue(e) {
let key = e.currentTarget.dataset.key
let value = e.currentTarget.dataset.value
this.setData({
[key]: value
})
},
// 公共跳转
publicJumps(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url,
})
},
publicJumpsSearch() {
wx.navigateTo({
url: "/pages/search/search?isAskingSearch=true",
})
},
consultStateCut() {
this.setData({
QRCodePopState: !this.data.QRCodePopState
})
},
moreLoading: false, // 更多的数据
// 获取更多数据
getMoreList() {
if (this.data.morePage == 0 || this.moreLoading) return
this.moreLoading = true
let requestData = {
page: this.data.morePage,
intermediary: 6
}
requestData = Object.assign(requestData, this.data.requestData)
miucms.request(`${app.globalData.baseURL}/tenement/v2/api/lists/moreRecommendations`, requestData).then(res => {
if (res.code != 200) return
const data = res.data
let list = data.data || []
list.forEach(element => {
if (Array.isArray(element.rent)) element.rent = element.rent.join(' ~ ')
})
this.setData({
morePage: data.page * data.limit >= data.count ? 0 : data.page + 1,
})
this.handleDetailData(list, 'more')
}).finally(() => {
this.moreLoading = false
})
},
// 切换弹窗
openInitiativePopwindow() {
this.setData({
QRCodePopState: !this.data.QRCodePopState
})
},
// 返回是否打开 筛选框
isOpenOperations(e) {
const state = e.detail
this.setData({
popwindowBtnState: !state
})
},
})