664 lines
20 KiB
JavaScript
664 lines
20 KiB
JavaScript
// pages/show/show.js
|
|
var app = getApp()
|
|
var miucms = require('../../utils/miucms.js');
|
|
var config = {};
|
|
var screenWidth = 288;
|
|
var center_position = 144;
|
|
var avatar_height = 40;
|
|
var screenWidth2 = 288;
|
|
var center_position2 = 144;
|
|
var save = false;
|
|
var today = new Date();
|
|
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: {
|
|
isloding: true,
|
|
showTOTOP: false,
|
|
tid: '',
|
|
uniqid: '0W4XS5SrvSHD',
|
|
token: '',
|
|
imgUrls: [],
|
|
page: {
|
|
next_page: 1
|
|
},
|
|
listPage: 1,
|
|
data: [],
|
|
contact: {},
|
|
loading: false,
|
|
info: {
|
|
// subject: `寄托港校租房-学生公寓`
|
|
subject: `${app.globalData.topTitle}-学生公寓`
|
|
},
|
|
listTab: {},
|
|
brands: {
|
|
list: [],
|
|
value: '',
|
|
obj: {}
|
|
},
|
|
roomlistings: {
|
|
list: [],
|
|
value: '',
|
|
obj: {}
|
|
},
|
|
roomtype: {
|
|
list: [],
|
|
value: '',
|
|
obj: {}
|
|
},
|
|
money: {
|
|
rent_min: 0,
|
|
rent_max: ''
|
|
},
|
|
screen_data: {},
|
|
schoolList: [],
|
|
school: '',
|
|
schoolObj: {},
|
|
schoolSidObj: {},
|
|
irenCouponReceive: null,
|
|
irentCouponBig: false,
|
|
hideCoupon: false,
|
|
initState: false,
|
|
topTitle: "",
|
|
consultState: false, // 咨询弹窗状态
|
|
schoolScrollLeft: 100,
|
|
QRCodePopState: false, // 二维码弹窗状态
|
|
popwindow: {}, // 弹窗信息
|
|
popwindowBtnState: true, // 弹窗按钮状态
|
|
scrollView: "",
|
|
|
|
},
|
|
|
|
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
|
|
})
|
|
}
|
|
clearTimeout(this.timer)
|
|
if (!this.data.irentCouponBig && this.data.irenCouponReceive) {
|
|
// 显示在侧边栏
|
|
this.setData({
|
|
hideCoupon: true
|
|
})
|
|
}
|
|
this.timer = setTimeout(() => {
|
|
this.setData({
|
|
hideCoupon: false
|
|
})
|
|
}, 3000)
|
|
},
|
|
timer: null,
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
console.log("options", options);
|
|
wx.showLoading()
|
|
// 获取全局筛选的值
|
|
let brandSelectionObj = app.globalData.brandSelectionObj
|
|
|
|
wx.getSystemInfo({
|
|
success: function (res) {
|
|
windowWidth = res.windowWidth
|
|
}
|
|
})
|
|
|
|
// brandSelectionObj['school'] = 6
|
|
|
|
// this.data.roomtype.value = options.roomtype || '';
|
|
// this.data.roomlistings.value = options.roomlistings || '';
|
|
// this.data.brands.value = options.brands || '';
|
|
|
|
this.data.school = miucms.updateProperty('school', options, brandSelectionObj) || ''
|
|
this.data.roomtype.value = miucms.updateProperty('roomtype', options, brandSelectionObj) || ''
|
|
this.data.roomlistings.value = miucms.updateProperty('roomlistings', options, brandSelectionObj) || ''
|
|
this.data.brands.value = miucms.updateProperty('brands', options, brandSelectionObj) || ''
|
|
|
|
const oMoney = miucms.updateProperty('money', options, brandSelectionObj)
|
|
if (oMoney) {
|
|
let money = oMoney.split('~')
|
|
this.data.money.rent_min = money[0];
|
|
this.data.money.rent_max = money[1];
|
|
}
|
|
|
|
this.setData({
|
|
isMapFindState: app.globalData.isMapFindState,
|
|
irentCouponBig: app.globalData.irentCouponBig,
|
|
options: options || {},
|
|
school: this.data.school || '',
|
|
roomlistings: this.data.roomlistings,
|
|
roomtype: this.data.roomtype,
|
|
money: this.data.money,
|
|
brands: this.data.brands,
|
|
// topTitle: app.globalData.topTitle
|
|
})
|
|
this.getTopTitle()
|
|
screenWidth = wx.getSystemInfoSync().screenWidth;
|
|
center_position = screenWidth / 2;
|
|
this.setData({
|
|
screenWidth: screenWidth,
|
|
})
|
|
this.attachedIn()
|
|
this.get_config()
|
|
},
|
|
|
|
getTopTitle() {
|
|
miucms.getTopTitle(this, app)
|
|
this.setData({
|
|
[`info.subject`]: `${app.globalData.topTitle}-学生公寓`
|
|
})
|
|
wx.setNavigationBarTitle({
|
|
title: this.data.miniProgram == 'xg' ? '寄托香港租房' : '寄托港校租房'
|
|
});
|
|
},
|
|
attachedIn() {
|
|
if (app.globalData.screen_data.totalTopHeight > 30) {
|
|
this.data.screen_data = app.globalData.screen_data;
|
|
this.setData({
|
|
screen_data: app.globalData.screen_data
|
|
})
|
|
} else {
|
|
try {
|
|
app.computeNavigateBarHeight();
|
|
} catch (e) {
|
|
// 获取系统信息失败
|
|
this.setData({
|
|
screen_data: {
|
|
windowHeight: 812,
|
|
totalTopHeight: 68,
|
|
statusBarHeight: 20,
|
|
titleBarHeight: 48,
|
|
titleWidth: 87
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
},
|
|
get_config() {
|
|
var that = this;
|
|
if (app.globalData.config.lists) {
|
|
config = app.globalData.config;
|
|
that.setData({
|
|
user: app.globalData.user,
|
|
status: app.globalData.status,
|
|
listTab: app.globalData.listTab,
|
|
wechat: app.globalData.wechat,
|
|
initState: true,
|
|
miniProgram: app.globalData.miniProgram,
|
|
popwindow: app.globalData.popwindow,
|
|
})
|
|
|
|
let screen_data = this.data.screen_data
|
|
let windowWidth = screen_data['windowWidth']; //获取设备屏幕宽度
|
|
this.headerSearchTopHeight = (windowWidth / 750) * Number(20)
|
|
|
|
this.getfilterConditions();
|
|
this.getList()
|
|
this.get_content();
|
|
|
|
} else {
|
|
setTimeout(function () {
|
|
that.get_config()
|
|
}, 200)
|
|
}
|
|
},
|
|
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
this.data.school = ''
|
|
this.data.brands.value = ''
|
|
this.data.roomlistings.value = ''
|
|
this.data.roomtype.value = ''
|
|
this.setData({
|
|
listPage: 1,
|
|
page: {
|
|
next_page: 1
|
|
},
|
|
school: '',
|
|
brands: this.data.brands,
|
|
roomlistings: this.data.roomlistings,
|
|
roomtype: this.data.roomtype,
|
|
money: {
|
|
rent_min: 0,
|
|
rent_max: ''
|
|
},
|
|
data: []
|
|
})
|
|
|
|
const listOperations = this.selectComponent('#list-operations-components')
|
|
const conditionObj = listOperations.data.conditionObj || {}
|
|
for (const key in conditionObj) {
|
|
if (conditionObj[key]?.valueText) conditionObj[key].valueText = ''
|
|
}
|
|
listOperations.setData({
|
|
conditionObj
|
|
})
|
|
this.getList()
|
|
wx.stopPullDownRefresh();
|
|
},
|
|
onReachBottom() {
|
|
// 加载下一页
|
|
if (!this.data.page.next_page) return false
|
|
if (this.data.listPage == 0) return false
|
|
this.getList()
|
|
},
|
|
|
|
getTitle() {
|
|
let path = `/pages/brandApartmentList/brandApartmentList?school=${this.data.school}&brands=${this.data.brands.value}&roomtype=${this.data.roomtype.value}&roomlistings=${this.data.roomlistings.value}&money=${this.data.money.rent_min}~${this.data.money.rent_max}`;
|
|
let title = this.data.school ? `${ this.data.topTitle }-${this.data.schoolObj[this.data.school]}附近公寓` : this.data.info.subject;
|
|
// let imageUrl = this.data.info.share_img
|
|
|
|
return {
|
|
path,
|
|
title,
|
|
// imageUrl,
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function (res) {
|
|
// 来自页面内转发按钮
|
|
if (res.from === 'button') var types = res.from === 'button' ? 'share_btn' : 'show';
|
|
let ress = this.getTitle()
|
|
console.log("res", ress);
|
|
return {
|
|
title: ress.title,
|
|
// imageUrl: ress.imageUrl,
|
|
path: ress.path,
|
|
success: function (res) {
|
|
miucms.share(app, types)
|
|
},
|
|
}
|
|
|
|
},
|
|
|
|
onShareTimeline() {
|
|
let res = this.getTitle()
|
|
return {
|
|
title: res.title,
|
|
// imageUrl: res.imageUrl,
|
|
path: res.path,
|
|
}
|
|
},
|
|
// 获取筛选条件
|
|
getfilterConditions() {
|
|
let that = this;
|
|
var sendData = Object.assign({}, this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
})
|
|
miucms.request(app.globalData.config.studentapartment.filterConditions, {}).then(data => {
|
|
wx.hideLoading()
|
|
if (data.extraparam) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: data.message,
|
|
})
|
|
} else {
|
|
data.data.brand.forEach(item => {
|
|
item.value = item.id;
|
|
that.data.brands.obj[item.id] = item.name;
|
|
})
|
|
that.data.brands.list = [{
|
|
value: '',
|
|
name: '全部品牌'
|
|
}, ...data.data.brand];
|
|
|
|
data.data.roomtype.forEach(item => {
|
|
item.value = item.id;
|
|
that.data.roomtype.obj[item.id] = item.name;
|
|
})
|
|
that.data.roomtype.list = [{
|
|
value: '',
|
|
name: '全部房型'
|
|
}, ...data.data.roomtype];
|
|
|
|
data.data.roomlistings.forEach(item => {
|
|
item.value = item.id;
|
|
that.data.roomlistings.obj[item.id] = item.name;
|
|
})
|
|
that.data.roomlistings.list = [{
|
|
value: '',
|
|
name: '全部楼型'
|
|
}, ...data.data.roomlistings];
|
|
|
|
|
|
let schoolObj = {}
|
|
let schoolSidObj = {}
|
|
data.data.school.forEach(item => {
|
|
schoolObj[item.id] = item.name
|
|
schoolSidObj[item.id] = item.sid
|
|
})
|
|
|
|
that.setData({
|
|
schoolObj,
|
|
schoolSidObj,
|
|
schoolList: data.data.school,
|
|
brands: that.data.brands,
|
|
roomtype: that.data.roomtype,
|
|
roomlistings: that.data.roomlistings
|
|
})
|
|
|
|
// 公寓列表 学校筛选的获取对应位置。并计算是否横向滚动
|
|
wx.nextTick(() => {
|
|
let index = this.data.school || 0
|
|
if (index == 0) return
|
|
|
|
this.setData({
|
|
scrollView: `item${ index }`
|
|
})
|
|
return
|
|
wx.createSelectorQuery().select('#annex-school').boundingClientRect((parentRect) => {
|
|
wx.createSelectorQuery().select(`.annex-school-item.item${index}`).boundingClientRect((childRect) => {
|
|
console.log("childRect", childRect);
|
|
const distance = childRect.left - parentRect.left - parentRect.width + childRect.width + 10
|
|
if (distance <= 0) return
|
|
this.setData({
|
|
schoolScrollLeft: distance
|
|
})
|
|
}).exec();
|
|
}).exec();
|
|
})
|
|
}
|
|
}).catch(res => {})
|
|
},
|
|
get_content: function () {
|
|
let that = this;
|
|
var sendData = Object.assign({}, this.data.options, {
|
|
session: wx.getStorageSync('session'),
|
|
})
|
|
miucms.request(app.globalData.config.studentapartment.slide, {}).then(data => {
|
|
wx.hideLoading()
|
|
if (data.extraparam) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: data.message,
|
|
})
|
|
} else {
|
|
that.setData({
|
|
imgUrls: data.data
|
|
})
|
|
}
|
|
}).catch(res => {})
|
|
|
|
},
|
|
// 获取列表
|
|
getList: function () {
|
|
let that = this;
|
|
if (this.data.page.next_page === 0 || this.data.loading || this.data.listPage == 0) return false
|
|
|
|
this.setData({
|
|
loading: true
|
|
})
|
|
|
|
let listPage = this.data.listPage
|
|
let url = `${app.globalData.baseURL}/tenement/v2/api/apartment`
|
|
|
|
miucms.request(url, {
|
|
page: listPage,
|
|
school: this.data.school,
|
|
brand: this.data.brands.value,
|
|
roomlistings: this.data.roomlistings.value,
|
|
roomtype: this.data.roomtype.value,
|
|
rent_min: this.data.money.rent_min,
|
|
rent_max: this.data.money.rent_max
|
|
}).then(data => {
|
|
if (data.code != 200) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: data.message,
|
|
})
|
|
} else {
|
|
data = data.data
|
|
this.data.data = this.data.data.concat(data.data)
|
|
this.setData({
|
|
data: this.data.data,
|
|
listPage: data.page * data.limit >= data.count ? 0 : listPage + 1,
|
|
contact: data.contact,
|
|
loading: false,
|
|
irenCouponReceive: data.irenCouponReceive
|
|
})
|
|
}
|
|
wx.hideLoading()
|
|
}).catch(res => {})
|
|
|
|
// 将筛选写入全局
|
|
let brandSelectionObj = {
|
|
school: this.data.school,
|
|
brands: this.data.brands.value,
|
|
roomlistings: this.data.roomlistings.value,
|
|
roomtype: this.data.roomtype.value,
|
|
}
|
|
if (this.data.money.rent_min) brandSelectionObj['money'] = `${this.data.money.rent_min}~${this.data.money.rent_max}`
|
|
app.globalData.brandSelectionObj = brandSelectionObj
|
|
},
|
|
copy(e) {
|
|
const content = e.currentTarget.dataset.content;
|
|
miucms.copy(content).then((res) => {})
|
|
},
|
|
// 租金条件筛选提交
|
|
submitMoney(e) {
|
|
this.data.money = Object.assign({}, e.detail);
|
|
this.setData({
|
|
selectGroupIndex: null,
|
|
money: this.data.money
|
|
})
|
|
this.clear_data()
|
|
},
|
|
// 选择品牌
|
|
submitBrands(e) {
|
|
this.data.brands.value = e.detail.value || e.currentTarget.dataset.value;
|
|
this.setData({
|
|
brands: this.data.brands
|
|
})
|
|
this.clear_data()
|
|
},
|
|
// 选择房型
|
|
submitRoomtype(e) {
|
|
this.data.roomtype.value = e.detail.value || e.currentTarget.dataset.value;
|
|
|
|
this.setData({
|
|
roomtype: this.data.roomtype
|
|
})
|
|
this.clear_data()
|
|
},
|
|
// 选择楼型
|
|
submitRoomlistings(e) {
|
|
this.data.roomlistings.value = e.detail.value || e.currentTarget.dataset.value
|
|
this.setData({
|
|
roomlistings: this.data.roomlistings
|
|
})
|
|
this.clear_data()
|
|
},
|
|
clear_data() {
|
|
this.setData({
|
|
listPage: 1,
|
|
page: {
|
|
next_page: 1
|
|
},
|
|
data: []
|
|
})
|
|
wx.pageScrollTo({
|
|
scrollTop: 0,
|
|
duration: 200,
|
|
})
|
|
this.getList()
|
|
},
|
|
// 点击选择学校
|
|
chooseSchool(e) {
|
|
this.setData({
|
|
school: e.currentTarget.dataset.id
|
|
})
|
|
this.clear_data()
|
|
},
|
|
// 前往对方小程序
|
|
tominiProgram(e) {
|
|
let {
|
|
path,
|
|
appId
|
|
} = this.data.irenCouponReceive;
|
|
let that = this;
|
|
wx.navigateToMiniProgram({
|
|
appId,
|
|
path,
|
|
success(res) {
|
|
|
|
},
|
|
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;
|
|
|
|
},
|
|
|
|
// 点击复制列表的 疑问微信号
|
|
copyWechat() {
|
|
let value = this.data.contact.wechat
|
|
miucms.copy(value)
|
|
},
|
|
|
|
// 处理 列表 事件
|
|
submitOperations(e) {
|
|
let type = e.detail.type
|
|
if (type == 'brand') this.submitBrands(e)
|
|
if (type == 'rent') this.submitMoney(e)
|
|
if (type == 'house') this.submitRoomtype(e)
|
|
if (type == 'floor') this.submitRoomlistings(e)
|
|
},
|
|
|
|
// 记录 轮播图的高度 // 随便计算 筛选的高度
|
|
// 筛选到顶部的高度
|
|
recordSwiperHeight(e) {
|
|
let swiperHeight = e.detail
|
|
let screen_data = this.data.screen_data
|
|
wx.createSelectorQuery().select("#annex-school").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,
|
|
})
|
|
},
|
|
|
|
consultStateCut() {
|
|
this.setData({
|
|
QRCodePopState: !this.data.QRCodePopState
|
|
})
|
|
// this.setData({
|
|
// consultState: !this.data.consultState
|
|
// })
|
|
},
|
|
|
|
toTop() {
|
|
wx.pageScrollTo({
|
|
scrollTop: 0,
|
|
})
|
|
},
|
|
|
|
// 点击收藏
|
|
bindCollect(e) {
|
|
let index = e.currentTarget.dataset.index
|
|
const target = this.data.data[index]
|
|
|
|
const baseURL = app.globalData.baseURL
|
|
wx.showLoading()
|
|
miucms.request(baseURL + '/tenement/v2/api/user/apartmentCollection', {
|
|
token: target.token
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
let data = res.data
|
|
target['iscollect'] = data.status
|
|
target['collectnum'] = data.count
|
|
|
|
this.data.data[index] = target
|
|
this.setData({
|
|
data: this.data.data
|
|
})
|
|
|
|
wx.hideLoading()
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: res.message,
|
|
})
|
|
})
|
|
},
|
|
|
|
// 切换弹窗
|
|
openInitiativePopwindow() {
|
|
this.setData({
|
|
QRCodePopState: !this.data.QRCodePopState
|
|
})
|
|
},
|
|
|
|
// 返回是否打开 筛选框
|
|
isOpenOperations(e) {
|
|
const state = e.detail
|
|
this.setData({
|
|
popwindowBtnState: !state
|
|
})
|
|
},
|
|
}) |