2023-04-17 16:14:18 +08:00

382 lines
8.8 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: 'timestamp',
list: [
{ name: "最新发布", value: 'timestamp' },
{ name: "热门", value: 'hotnum' },
{ name: "价格从低到高", value: 'rentasc' },
{ name: "价格从高到低", value: 'rentdesc' },
]
},
list:[],
page:{
next_page:1
},
location:{},
types:{
data:[],
value:''
},
property:{},
cityList:[],
moreCondition: {
show: false,
data: {
gender: "0",
leaseterm: "",
publish: "twomonth",
}
},
city:{
uniqid:"",
name:"",
alias:''
},
hascondition:true,
},
onPageScroll(e) {
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) {
console.log(options)
this.setData({
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;
},
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;
// console.log('get_configget_configget_configget_config');
if (app.globalData.config.lists) {
config = app.globalData.config;
that.data.user = app.globalData.user;
this.setData({
screen_data: app.globalData.screen_data,
leaseterm: that.data.leaseterm,
status: app.globalData.status,
StudentapartmentNew: app.globalData.StudentapartmentNew
})
this.getgroupSearch();
this.get_list();
this.getAd();
this.getLocationList()
} else {
setTimeout(function () {
that.get_config()
}, 200)
}
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
if (!app.globalData.config || !app.globalData.config.lists) {
// console.log('还没拿到数据呢。。。。。。。。')
wx.stopPullDownRefresh();
return false
}
this.clear_data()
this.getAd()
this.getgroupSearch();
wx.stopPullDownRefresh();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (!app.globalData.config || !app.globalData.config.lists || this.data.page.next_page<2) {
return false
}
this.get_list()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
let path = `/pages/restOfWorld/restOfWorld?name=${this.data.city.name}&cityid=${this.data.city.uniqid}&alias=${this.data.city.alias}`;
var title = '寄托香港租房';
if(this.data.city.name){
title = '寄托香港租房 - ' + this.data.city.name
}
return {
path:path,
title: title,
success:function(res){
miucms.share(app, 'index')
}
}
},
// 拉去广告
getAd() {
let that = this;
miucms.request(app.globalData.config.otherlist.banner, {}).then(data => {
that.setData({
attachment: data.data
})
wx.hideLoading()
}).catch(res => { })
},
// 组合搜索
getgroupSearch() {
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;
this.setData({
loading:true
})
miucms.request(app.globalData.config.otherlist.init, Object.assign({}, this.data.moreCondition.data,{
page:this.data.page.next_page,
'type':this.data.types.value*1,
orderby: this.data.orderby.value,
cityid:this.data.city.uniqid
})).then(data => {
that.setData({
list: that.data.list.concat(data.data),
loading:false,
page:data.page
})
wx.hideLoading()
}).catch(res => { })
},
// 获取地域列表
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({
location: this.data.location,
types: this.data.types,
property: data.data.property,
cityList: data.data.cityList
})
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 => {
console.log(res.intersectionRatio)
if (res.intersectionRatio > 0) {
that.setData({
conditionFixed: false
})
} else {
that.setData({
conditionFixed: true
})
}
})
},
// 清空数组
clear_data: function () {
this.setData({
page: {
next_page: 1
},
list: []
})
this.get_list()
},
// 提交出租方式
submittype(e) {
console.log(e.detail)
this.data.types.value = e.detail.data;
this.setData({
types: this.data.types,
selectGroupIndex: null
})
this.clear_data()
},
// 提交排序
submitOrderby(e) {
console.log(e.detail)
this.data.orderby.value = e.detail.value;
this.setData({
orderby: this.data.orderby
})
this.clear_data()
},
// 提交更多
myEventSelectSubmit(e) {
console.log(e.detail)
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.money.rent_min = obj.rent_min;
// this.data.money.rent_max = obj.rent_max;//租金
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,
// money: this.data.money,
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)
}
})