2025-04-18 19:03:57 +08:00

981 lines
30 KiB
JavaScript

// pages/search/search.js
var app = getApp()
var config = {};
var miucms = require('../../utils/miucms.js');
var WxParse = require('../../wxParse/wxParse.js');
Page({
/**
* 页面的初始数据
*/
data: {
isloding: true,
showTOTOP: false,
multiple: false,
types: 1,
keyword: '',
types: {
value: '',
data: null
}, //6.24删除
location: {
value: [],
data: null
},
leaseterm: {
title: 'leaseterm',
value: '0',
name: '租期不限',
show: false,
list: {
'0': '租期不限',
'1': "长租",
"2": "短租"
},
showTips: 'leaseterm'
},
orderby: {
value: 'default',
list: [{
name: "综合",
value: 'default'
}, {
name: "最新发布",
value: 'updatetime'
},
{
name: "热门",
value: 'hotnum'
},
{
name: "价格从低到高",
value: 'rentasc'
},
{
name: "价格从高到低",
value: 'rentdesc'
},
]
},
shared_page: {
next_page: 1
},
shared_list: [],
entire_list: [],
entire_page: {
next_page: 1
},
loading: false,
status: 0,
q: '',
user: {
newpm: null
},
options: {},
screen_data: {
totalTopHeight: null
},
money: {
rent_min: 0,
rent_max: ''
},
moreCondition: {
show: false,
data: {
gender: "0",
leaseterm: "0",
// publish: "twomonth",
publish: "0",
}
},
lists: [],
page: {
next_page: 1
},
toTopShow: false, //是否显示totop
StudentapartmentNew: null, //是否顯示new
attachment: [],
hascondition: true, //是否有筛选条件
conditionFixed: false, //筛选条件一列是否固定在顶部
conditionBox: [{
name: 'area',
title: '区域'
},
{
name: 'type',
title: '出租方式'
},
{
name: 'money',
title: '租金'
},
],
groupSearch: [], //组合最热
selectGroupIndex: null,
property: {},
school: {
list: {},
value: ''
},
verifiedList: [],
listTab: {},
initState: false,
langs: {}, // 语言包数据
operationsTop: false, // 操作栏 是否在顶部
totalSum: 0, // 数据总数
isMapFindState: false,
morePage: 1, // 更多的页数
moreList: [], // 更多的数据
isShowVideo: true, // 是否显示 视频
},
headerSearchTopHeight: 10,
operationsHeight: 297,
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
})
}
},
/**
* 生命周期函数--监听页面加载
*/
change_data: function (str, index) {
miucms.change_data(this, str)
},
html2wxml: function (str, index, that) {
miucms.html2wxml(str, index, this)
},
onLoad: function (options) {
wx.showLoading({
title: '加载中',
})
// 获取全局筛选的值
let selectionObj = {}
selectionObj = app.globalData.intermediarySelectionObj
// else selectionObj = app.globalData.personSelectionObj
let that = this;
var location = [];
const locationArr = miucms.updateProperty('location', options, selectionObj)
if (locationArr) location = locationArr.split(',')
this.data.location.value = location;
this.data.school.value = miucms.updateProperty('school', options, selectionObj)
this.data.types.value = miucms.updateProperty('types', options, selectionObj)
this.data.moreCondition.data.gender = miucms.updateProperty('gender', options, selectionObj)
this.data.moreCondition.data.leaseterm = miucms.updateProperty('leaseterm', options, selectionObj)
this.data.moreCondition.data.publish = miucms.updateProperty('publish', options, selectionObj)
this.data.moreCondition.data.isverified = miucms.updateProperty('isverified', options, selectionObj)
this.data.moreCondition.data.iselevator = miucms.updateProperty('iselevator', options, selectionObj)
this.data.moreCondition.data.issunshinearea = miucms.updateProperty('issunshinearea', options, selectionObj)
const orderby = miucms.updateProperty('orderby', options, selectionObj)
if (orderby) this.data.orderby.value = 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.setData({
q: options.q ? options.q : '',
intermediary: 1,
options: options || {},
location: this.data.location,
school: this.data.school,
types: this.data.types,
moreCondition: this.data.moreCondition,
orderby: that.data.orderby,
})
this.getTopTitle()
setTimeout(function () {
that.get_config()
that.setData({
money: that.data.money,
})
}, 200)
},
getTopTitle() {
miucms.getTopTitle(this, app)
wx.setNavigationBarTitle({
title: this.data.miniProgram == 'xg' ? '寄托香港租房' : '寄托港校租房'
});
},
get_config() {
var that = this;
if (app.globalData.config && 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,
listTab: app.globalData.listTab,
initState: true,
isloding: false,
langs: app.globalData.langs,
isShowVideo: app.globalData.isShowVideo,
})
app.globalData['langs'] ? '' : this.getDtailsLangs()
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();
} else {
setTimeout(function () {
that.get_config()
}, 200)
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if (!app.globalData.config || !app.globalData.config.lists) return false
},
// 获取语言包 保存全局
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 {
if (!data) return
data.forEach(ele => {
if (ele['distance']) ele['distance'] = Math.round(ele['distance'] * 10) / 10
// 这个是将 详情键 替换语言包里的值
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 tabArr = ["gptype", "type", "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]}`
})
let lists = this.data.lists
let moreList = this.data.moreList
if (dataType == 'list') lists = lists.concat(data)
else moreList = moreList.concat(data)
this.setData({
lists,
moreList,
})
}
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
if (!app.globalData.config || !app.globalData.config.lists) {
wx.stopPullDownRefresh();
return false
}
this.setData({
page: 1,
lists: []
})
this.getAd()
this.getgroupSearch();
this.get_list();
wx.stopPullDownRefresh();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (!app.globalData.config || !app.globalData.config.lists) return false
this.get_list()
if (this.data.morePage >= 1) this.getMoreList()
},
getTitle() {
var location = '';
var title = this.data.topTitle + '-个人房源';
if (this.data.location.value.length > 0) {
location = this.data.location.value.join(',');
title = this.data.topTitle + '-' + this.data.location.data[Math.floor(this.data.location.value[0]) + ''] + '个人房源';
} else if (this.data.school.value) {
title = this.data.topTitle + '-' + this.data.school.list[this.data.school.value + ''] + '附近个人房源';
}
let path = `/pages/personList/personList?school=${this.data.school.value}&location=${location}`;
return {
title,
path,
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
let res = this.getTitle()
return {
path: res.path,
title: res.title,
success: function (res) {
miucms.share(app, 'index')
}
}
},
onShareTimeline() {
let res = this.getTitle()
return {
path: res.path,
title: res.title,
}
},
// 拉去广告
getAd() {
let url = app.globalData.config.studentapartment.quarantineBanner
miucms.request(url, {}).then(data => {
// data.data[0].image = "https://app.gter.net/image/miniApp/HKRenting/md5__a65c6e69fa6d5cad6ee45aeaf147028f.svg"
this.setData({
attachment: data.data
})
wx.hideLoading()
})
},
getverifiedList() {
miucms.request(app.globalData.config.adv.verifiedList, {}).then(data => {
this.setData({
verifiedList: data.data
})
})
},
// 获取地域列表
getLocationList() {
let that = this;
miucms.request(app.globalData.config.lists.region, {}).then(data => {
this.data.location.data = data.data.location;
this.data.types.data = data.data['type'];
this.data.school.list = data.data.school
that.setData({
location: that.data.location,
types: that.data.types,
property: data.data.property,
school: that.data.school
})
wx.hideLoading()
}).catch(res => {})
},
getgroupSearch() {
var that = this;
miucms.request(app.globalData.config.lists.groupsearch, {}).then(data => {
this.setData({
groupSearch: data.data
}, function () {
that.caclulatesearchIndex()
})
wx.hideLoading()
}).catch(res => {})
},
// 是否选中关键词
caclulatesearchIndex() {
let groupSearch = this.data.groupSearch;
let that = this;
let searchindex = null;
for (let i = 0; i < groupSearch.length; i++) {
let ishere = true;
for (let j in groupSearch[i].where) {
let moreCondition = ['gender', 'leaseterm', 'publish'];
let money = ['rent_min', 'rent_max'];
if (moreCondition.indexOf(j) > -1) {
if (j != 'publish') {
if (groupSearch[i].where[j] * 1 != that.data.moreCondition.data[j] * 1) {
ishere = false;
break;
}
} else {
if (groupSearch[i].where[j] != that.data.moreCondition.data[j]) {
ishere = false;
break;
}
}
} else if (money.indexOf(j) > -1) {
if (groupSearch[i].where[j] != that.data.money[j]) {
ishere = false;
break;
}
} else if (j == 'location') {
if (groupSearch[i].where[j].sort().toString() != that.data[j].value.sort().toString()) {
ishere = false;
break;
}
} else if (j == 'type') {
if (groupSearch[i].where[j] != that.data['types'].value) {
ishere = false;
break;
}
} else {
if (groupSearch[i].where[j] != that.data[j].value) {
ishere = false;
break;
}
}
}
if (ishere) {
searchindex = i;
this.setData({
selectGroupIndex: searchindex
})
break;
}
}
},
// 获取列表
get_list: function () {
var that = this;
if (this.data.page == 0 || this.data.loading) return false;
this.setData({
loading: true,
morePage: 1,
moreList: [],
})
this.caclulatesearchIndex()
var sendData = Object.assign({}, this.data.options, this.data.moreCondition.data, this.data.money, {
session: wx.getStorageSync('session'),
orderby: this.data.orderby.value,
types: this.data.types.value,
location: that.data.location.value,
school: that.data.school.value,
page: this.data.page,
intermediary: 1
})
var that = this;
let url = `/tenement/v2/api/lists`
miucms.request(`${app.globalData.baseURL}${url}`, sendData).then(data => {
if (data.code != 200) {
this.setData({
loading: false
})
return
}
data = data.data
this.handleDetailData(data.data)
that.setData({
totalSum: data.count,
// lists: that.data.lists,
page: data.page * data.limit >= data.count ? 0 : data.page + 1,
user: data.user,
loading: false,
})
wx.hideLoading()
// 判断是否是最后一页 和是否选中学校和区域 如果都是则 需要请求更多数据
if (this.data.page == 0 && (sendData['school'] || sendData['location'].length != 0)) this.getMoreList()
}).catch(res => {
wx.hideLoading()
this.setData({
loading: false,
})
})
let selectionObj = {
orderby: this.data.orderby.value,
types: this.data.types.value,
location: this.data.location.value.join(','),
school: this.data.school.value,
intermediary: 1,
...this.data.moreCondition.data,
}
if (this.data.money.rent_min) selectionObj['money'] = `${this.data.money.rent_min}~${this.data.money.rent_max}`
app.globalData.intermediarySelectionObj = selectionObj
},
// 清空数组
clear_data: function () {
this.setData({
page: 1,
lists: []
})
this.get_list()
},
setSelectData(title) {
switch (title) {
case 'location':
this.setData({
location: this.data.location
})
break;
case 'orderby':
this.setData({
orderby: this.data.orderby
})
break;
case 'gender':
this.setData({
gender: this.data.gender
})
break;
case 'leaseterm':
this.setData({
leaseterm: this.data.leaseterm
})
break;
case 'typesObj':
this.setData({
typesObj: this.data.typesObj
})
}
},
select_value: function (e) {
var that = this;
let change = true;
let title = e.currentTarget.dataset.title;
let value = e.currentTarget.dataset.value;
let name = e.currentTarget.dataset.name;
if (that.data[title].value == value) {
change = false
} else {
that.data[title].value = value;
that.data[title].name = name;
}
that.data[title].show = false;
that.setSelectData(title)
wx.setStorage({
key: 'select_info_' + title,
data: {
name: name,
value: value
},
})
if (change) {
this.clear_data()
}
},
select_options2_value: function (e) {
var that = this;
let change = true;
let name = e.currentTarget.dataset.name;
let value = e.currentTarget.dataset.value;
let tab = e.currentTarget.dataset.tab;
let title = e.currentTarget.dataset.title;
if (tab == 'level1') {
this.data.location.level1_value = value;
this.data.location.level1_name = name;
this.data.location.tab = 'level2';
if (value == 0) {
this.data.location.show = false;
this.data.location.level1_value = value;
if (this.data.location.level2_value == 0) {
change = false
}
this.data.location.level2_value = '0';
this.data.location.level2_name = '';
this.data.location.tab = 'level1';
wx.setStorage({
key: 'select_info_location',
data: {
name1: name,
value1: value,
name2: '',
value2: 0
},
})
} else {
if (this.data.location.level1_value == value) {
change = false
}
wx.setStorage({
key: 'select_info_location',
data: {
name1: name,
value1: value,
name2: '',
value2: 0
},
})
}
} else {
if (this.data.location.level2_value == value) {
change = false
}
this.data.location.level2_value = value;
this.data.location.level2_name = name;
this.data.location.show = false;
// this.data.info[title].tab = 'level1';
}
that.setData({
location: that.data.location
})
},
change_select_tab: function (e) {
return false;
let tab = e.currentTarget.dataset.tab;
let title = e.currentTarget.dataset.title;
this.data.location.tab = tab;
if (tab == 'level2' && this.data.location.level1_value == '') {
this.data.location.level1_value = '1';
this.data.location.level1_name = this.data.location.level1['1'];
}
this.setData({
location: this.data.location
})
},
close_box: function (e) {
let title = e.currentTarget.dataset.title;
this.data.location.show = false;
this.setData({
location: this.data.location
})
},
close_alert: function (e) {
var box = e.currentTarget.dataset.box;
this.data[box].show = false;
this.setSelectData(box)
},
send_form_id: function (e) {
return false;
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,
})
},
// 更改選項
changeConditons: function (e) {
let value = e.currentTarget.dataset.tab;
if (value == 'price') {
value = this.data.condition == 'rentasc' ? 'rentdesc' : 'rentasc'
}
this.setData({
condition: value,
})
this.clear_data()
},
// 显示更多选项
showMoreCondition(e) {
this.data.moreCondition.show = e.currentTarget.dataset.show;
this.setData({
moreCondition: this.data.moreCondition
})
},
// 关闭更多选项
myEventcloseMoreCondition() {
this.data.moreCondition.show = false;
this.setData({
moreCondition: this.data.moreCondition
})
},
myEventSelectArea(a) {
// 显示二级菜单
var title = 'location';
this.data[title].show = true;
this.setSelectData(title)
var that = this;
let change = true;
let name = a.detail.name;
let value = a.detail.value;
let tab = 'level1';
// let title = e.currentTarget.dataset.title;
if (tab == 'level1') {
this.data.location.level1_value = value;
this.data.location.level1_name = name;
this.data.location.tab = 'level2';
if (this.data.location.level1_value == value) {
change = false
}
}
that.setData({
location: that.data.location
})
},
// 提交更多
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,
})
},
// 租金条件筛选提交
submitMoney(e) {
this.data.money = Object.assign({}, e.detail);
this.setData({
selectGroupIndex: null,
money: this.data.money
})
this.clear_data()
},
// 提交区域
submitarea(e) {
let {
school,
location
} = e.detail;
this.data.school.value = school;
this.data.location.value = location;
this.setData({
location: this.data.location,
school: this.data.school,
selectGroupIndex: null
})
this.clear_data()
},
// 提交出租方式
submittype(e) {
this.data.types.value = e.detail.types
this.setData({
types: this.data.types,
selectGroupIndex: null
})
this.clear_data()
},
// 提交排序
submitOrderby(e) {
this.data.orderby.value = e.detail.orderby;
this.setData({
orderby: this.data.orderby
})
this.clear_data()
},
// 选择热词
selectGroup(e) {
let index = e.currentTarget.dataset.index;
let obj = this.data.groupSearch[index].where;
this.data.school.value = obj.school || ''; //学校
this.data.location.value = Array.isArray(obj.location) ? [...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; //排序
this.data.moreCondition.data = {
gender: obj.gender,
leaseterm: obj.leaseterm,
publish: obj.publish,
}
this.setData({
selectGroupIndex: index,
school: this.data.school,
location: this.data.location,
types: this.data.types,
money: this.data.money,
orderby: this.data.orderby,
moreCondition: this.data.moreCondition
})
this.hasMoreCondition()
this.clear_data()
},
// 点击广告
clickAD(e) {
miucms.clickAD(e.detail.id)
},
// 关闭广告
closeAD(e) {
let index = e.currentTarget.dataset.index;
this.data.lists.splice(index, 1)
this.setData({
lists: this.data.lists
})
miucms.closeAD(e.detail.id)
},
// 新筛选 的 整合中转
submitOperations(e) {
let {
type
} = e.detail
if (type == "rent") this.submitMoney(e)
if (type == "orderby") this.submitOrderby(e)
if (type == "types") this.submittype(e)
if (type == "moreCondition") this.myEventSelectSubmit(e)
if (type == "school") this.submitarea(e)
},
// 记录 轮播图的高度 // 随便计算 筛选的高度
// 筛选到顶部的高度
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()
},
// 公共跳转
publicJumps(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url,
})
},
moreLoading: false, // 更多的数据
// 获取更多数据
getMoreList() {
if (this.data.morePage == 0 || this.moreLoading) return
this.moreLoading = true
var sendData = Object.assign({}, this.data.options, this.data.moreCondition.data, this.data.money, {
session: wx.getStorageSync('session'),
orderby: this.data.orderby.value,
types: this.data.types.value,
location: this.data.location.value,
school: this.data.school.value,
page: this.data.morePage,
intermediary: this.data.intermediary
})
miucms.request(`${app.globalData.baseURL}/tenement/v2/api/lists/moreRecommendations`, sendData).then(res => {
if (res.code != 200) return
const data = res.data
this.setData({
morePage: data.page * data.limit >= data.count ? 0 : data.page + 1,
})
this.handleDetailData(data.data, 'more')
}).finally(() => {
this.moreLoading = false
})
},
})