760 lines
19 KiB
JavaScript
760 lines
19 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: 'timestamp',
|
|
list: [{
|
|
name: "最新发布",
|
|
value: 'timestamp'
|
|
},
|
|
{
|
|
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",
|
|
|
|
}
|
|
},
|
|
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
|
|
},
|
|
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
|
|
})
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
|
|
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 that = this;
|
|
var location = [];
|
|
if (options.location) {
|
|
location = options.location.split(',')
|
|
}
|
|
that.data.location.value = location;
|
|
that.data.school.value = options.school || '';
|
|
that.data.moreCondition.data.gender = options.gender || '0';
|
|
that.data.moreCondition.data.leaseterm = options.leaseterm || '0';
|
|
that.data.moreCondition.data.publish = options.publish || 'twomonth';
|
|
|
|
this.setData({
|
|
q: options.q ? options.q : '',
|
|
options: options || {},
|
|
location: that.data.location,
|
|
school: that.data.school,
|
|
moreCondition: that.data.moreCondition
|
|
})
|
|
|
|
setTimeout(function () {
|
|
that.get_config()
|
|
}, 200)
|
|
|
|
},
|
|
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({
|
|
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
|
|
})
|
|
this.getgroupSearch();
|
|
this.get_list();
|
|
this.getAd();
|
|
this.getLocationList();
|
|
|
|
} else {
|
|
setTimeout(function () {
|
|
that.get_config()
|
|
}, 200)
|
|
}
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
let that = this;
|
|
if (!app.globalData.config || !app.globalData.config.lists) {
|
|
return false
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
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()
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
var location = '';
|
|
var title = '寄托香港租房-个人房源';
|
|
if (this.data.location.value.length > 0) {
|
|
location = this.data.location.value.join(',');
|
|
title = '寄托香港租房-' + this.data.location.data[Math.floor(this.data.location.value[0]) + ''] + '个人房源';
|
|
} else if (this.data.school.value) {
|
|
title = '寄托香港租房-' + this.data.school.list[this.data.school.value + ''] + '附近个人房源';
|
|
}
|
|
let path = `/pages/personList/personList?school=${this.data.school.value}&location=${location}`;
|
|
|
|
return {
|
|
path: path,
|
|
title: title,
|
|
success: function (res) {
|
|
miucms.share(app, 'index')
|
|
}
|
|
}
|
|
},
|
|
// 拉去广告
|
|
getAd() {
|
|
let that = this;
|
|
miucms.request(app.globalData.config.special.lists, {}).then(data => {
|
|
|
|
that.setData({
|
|
attachment: data.data
|
|
})
|
|
wx.hideLoading()
|
|
that.getverifiedList()
|
|
}).catch(res => {})
|
|
|
|
},
|
|
getverifiedList() {
|
|
let that = this;
|
|
miucms.request(app.globalData.config.adv.verifiedList, {}).then(data => {
|
|
|
|
that.setData({
|
|
verifiedList: data.data
|
|
})
|
|
}).catch(res => {})
|
|
},
|
|
// 获取地域列表
|
|
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()
|
|
// that.calculateConditionPosition()
|
|
})
|
|
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;
|
|
}
|
|
that.setData({
|
|
loading: true
|
|
})
|
|
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,
|
|
'type': this.data.types.value,
|
|
location: that.data.location.value,
|
|
school: that.data.school.value,
|
|
page: this.data.page,
|
|
})
|
|
var that = this;
|
|
// console.log("sendData", sendData);
|
|
|
|
// miucms.request(app.globalData.config.lists.init, sendData).then(data => {
|
|
miucms.request(`${app.globalData.baseURL}/tenement/housingresources/lists`, sendData).then(data => {
|
|
// console.log(data);
|
|
if (data.code != 200) {
|
|
this.setData({
|
|
loading: false
|
|
})
|
|
return
|
|
}
|
|
data = data.data
|
|
// console.log("data", data);
|
|
|
|
that.data.lists = that.data.lists.concat(data.data)
|
|
that.setData({
|
|
lists: that.data.lists,
|
|
page: data.page * data.limit >= data.count ? 0 : data.page + 1,
|
|
user: data.user,
|
|
loading: false,
|
|
})
|
|
wx.hideLoading()
|
|
|
|
}).catch(res => {
|
|
// console.log("lists", this.data.lists);
|
|
|
|
})
|
|
},
|
|
|
|
// 清空数组
|
|
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.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()
|
|
},
|
|
// 选择热词
|
|
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)
|
|
},
|
|
|
|
|
|
}) |