DESKTOP-RQ919RC\Pc ced718c079 标注,4.4之前
2025-04-16 18:33:36 +08:00

778 lines
21 KiB
JavaScript

// pages/pageIndex/pageIndex.js
var WxParse = require('../../wxParse/wxParse.js');
var app = getApp()
var config = {};
var miucms = require('../../utils/miucms.js');
Page({
/**
* 页面的初始数据
*/
data: {
loding: true,
HKapartment: [],
otherHousing: [],
HKhousing: [],
banner: [],
service: '',
servicename: '',
screen_data: {},
advListHKhousing: {},
advListotherHousing: {},
initState: false,
unreadMessages: 0, // 底部我的图标 未读系统通知数量
areaIndex: 0, //
tabValue: 0,
swiperCurrent: 0, // 新轮播图 滚动的下标
topTitle: "",
areaPopState: false, // 区域找房的弹窗 状态
areaPopId: 0, // 区域 选中
areaPopList: [], // 地区选项选中 数据
getLocationList: [], // 地区选项 配置数据
listData: [], // 列表数据
listPage: 1, // 列表数据 页数
listDataLeft: [], // 列表数据
listDataRight: [], // 列表数据
listType: "", // 推荐列表类型
pagevalue: null, // 推荐列表的 value
showTOTOP: false, // 返回顶部按钮状态
HeadSwiperHeight: 0, // 轮播图的最高度
bgColorObj: app.globalData.bgColorObj,
miniProgram: "",
isMapFindState: false,
updateLoading: false,
isAllLoaded: false,
popwindow: {}, // 弹窗信息
popwindowState: false, // 弹窗状态
popwindowBtnState: true, // 弹窗按钮状态
popwindowBtnAnimationState: false, // 弹窗按钮动画状态
},
/**
* 生命周期函数--监听页面加载
*/
timer: null,
onLoad: function (options) {
// this.getLocationData()
wx.showLoading()
this.get_config()
},
// 获取系统通知数量
getNoticeNumber() {
if (app.globalData.unreadMessagesState) {
this.setData({
unreadMessages: app.globalData.unreadMessages
})
return
}
miucms.count().then(res => {
this.setData({
unreadMessages: res.data.count
})
})
},
get_config() {
var that = this;
this.setData({
screen_data: app.globalData.screen_data,
bottomLift: app.globalData.screen_data.bottomLift,
isMapFindState: app.globalData.isMapFindState,
})
// if (app.globalData.code) {
if (app.globalData.config && app.globalData.config.lists) {
this.getNewInit()
// setTimeout(() => {
// }, 1000)
this.setData({
initState: true,
popwindow: app.globalData.popwindow,
})
setTimeout(() => this.decideYouWantPopup(), 1000)
this.getTopTitle()
let screen_data = this.data.screen_data
this.ratio = screen_data['windowWidth'] / 750
let windowWidth = screen_data['windowWidth']; //获取设备屏幕宽度
let headHeight = (windowWidth / 750) * Number(12)
this.headHeight = headHeight
} else {
setTimeout(function () {
that.get_config()
}, 10)
}
},
getTopTitle() {
miucms.getTopTitle(this, app)
},
// 新初始化数据
getNewInit() {
miucms.wxget(`${app.globalData.baseURL}/tenement/v2/api/home`).then(res => {
let data = res.data
let {
recommendedTab
} = data
let listType = ""
recommendedTab.forEach(el => {
if (el['select']) listType = el['type']
})
data.apartment = data.apartment.slice(0, 5)
this.setData({
...data,
listType,
loding: false
})
this.getNoticeNumber()
this.getListData()
})
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
return {
title: this.data.topTitle
}
},
onShareTimeline() {
return {
title: this.data.topTitle
}
},
onPullDownRefresh: function () {
this.setData({
listDataLeft: [],
listDataRight: [],
listPage: 1,
pagevalue: 0,
})
this.getListDataState = false
this.leftHeight = 0
this.rightHeight = 0
this.dataCount = 0
this.getListData()
wx.stopPullDownRefresh()
},
copy() {
const content = this.data.servicename;
miucms.copy(content).then((res) => {}).catch(err => {})
},
// 关闭广告
closeAd(e) {
let {
position,
world,
id
} = e.detail;
if (world) {
delete this.data.advListotherHousing[position];
this.setData({
advListotherHousing: this.data.advListotherHousing
})
} else {
delete this.data.advListHKhousing[position];
this.setData({
advListHKhousing: this.data.advListHKhousing
})
}
miucms.closeAD(id)
},
// 点击广告
clickAD(e) {
miucms.clickAD(e.detail.id)
},
setValue(e) {
let key = e.currentTarget.dataset.key
let value = e.currentTarget.dataset.value
this.setData({
[key]: value
})
},
// 切换 tab
toggleTab(e) {
let value = e.currentTarget.dataset.value
const combination = this.data.combination
this.setData({
areaIndex: value,
})
const type = combination[value]?.field
// miucms.statistics({
// name: "combination",
// data: {
// type
// }
// })
},
// 公共跳转
publicJumps(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url,
fail: function (err) {
if (err['errMsg'] !== "navigateTo:fail webview count limit exceed") return
wx.redirectTo({
url,
})
}
})
},
// 新 瀑布流 点击事件
handleSwiper(e) {
let {
appid,
url,
statid,
finderusername,
feedid,
type,
advertisingtype,
advtype,
} = e.currentTarget.dataset
let requestUrl = `${app.globalData.baseURL}/tenement/v2/api/ad/click`
miucms.request(requestUrl, {
statid
}).then(res => {})
// 跳转视频号
if ((type == 5) || (type == 'adv' && advtype == "videofeed_5")) {
wx.openChannelsActivity({
finderUserName: finderusername,
feedId: feedid
})
return false
}
// 跳转直播
if ((type == 4) || (type == 'adv' && advtype == "videofeed_4")) {
wx.openChannelsLive({
finderUserName: finderusername
})
return false
}
// 判断跳转小程序
if (appid) {
if (url.charAt(0) !== '/') url = "/" + url
wx.navigateToMiniProgram({
appId: appid,
path: url
})
return false;
}
// 判断是否是h5页面的
if (url && url.indexOf('http') != -1) {
wx.navigateTo({
url: `/pages/webViewwebweb/index?url=${ url }`,
})
return false;
}
if (url) {
if (url.charAt(0) !== '/') url = "/" + url
wx.navigateTo({
url,
})
return false;
}
},
// 新 点击 搜索
search(e) {
let value = e.detail.value
},
// 打开 区域找房 的 弹窗
openAreaPop(e) {
let areaPopId = e.currentTarget.dataset.id
this.setData({
areaPopId,
areaPopList: [],
areaPopState: !this.data.areaPopState
})
if (this.data.getLocationList.length == 0) this.getLocationData()
},
// 获取
getLocationData() {
miucms.request(app.globalData.baseURL + "/tenement/v2/api/home/getLocationData").then(res => {
let data = res.data
let obj = {}
for (const key in data) {
// 判断是否是整数
if ((key ^ 0) == key) {
obj[key] = {}
obj[key]['name'] = data[key]
} else {
if (!obj[key ^ 0]['data']) obj[key ^ 0]['data'] = []
obj[key ^ 0]['data'].push({
key,
name: data[key],
pitch: false,
})
}
}
this.setData({
getLocationList: obj
})
})
},
// 跳转个人列表
skipPersonList(e) {
let {
key,
id
} = e.currentTarget.dataset
wx.navigateTo({
url: `/pages/personList/personList?${key}=${id}`,
})
},
// 处理点击
areaPopItem(e) {
let {
key,
index
} = e.currentTarget.dataset
let areaPopList = this.data.areaPopList
let getLocationList = this.data.getLocationList
let areaPopId = this.data.areaPopId
const indexOf = areaPopList.indexOf(key)
if (indexOf === -1) {
areaPopList.push(key)
getLocationList[areaPopId].data[index].pitch = true
} else {
areaPopList.splice(indexOf, 1)
getLocationList[areaPopId].data[index].pitch = false
}
this.setData({
areaPopList,
getLocationList
})
},
areaPopItemUnlimited(e) {
let {
areapopid
} = e.currentTarget.dataset
let areaPopId = this.data.areaPopId
let getLocationList = this.data.getLocationList
getLocationList[areaPopId].data.forEach(el => {
el.pitch = false
})
this.setData({
getLocationList,
areaPopList: []
})
if (areapopid >= 0) {
this.setData({
areaPopId: areapopid
})
}
},
// 处理区域找房弹窗的确定
handleAreaPopConfirm() {
let areaPopList = this.data.areaPopList
let areaPopId = this.data.areaPopId
if (areaPopList.length == 0) areaPopList = [areaPopId]
wx.navigateTo({
url: `/pages/personList/personList?location=${areaPopList}`,
})
},
// lastClickTime: 0,
// 切换 tab
cutTab(e) {
let {
index,
type
} = e.currentTarget.dataset
if (type == this.data.listType) return // 点击选中 type 时
const currentTime = new Date().getTime();
this.lastClickTime = currentTime
// 修改 tab 列表选中状态
let recommendedTab = this.data.recommendedTab
let pagevalue = ""
recommendedTab.forEach(el => {
el['select'] = false
})
recommendedTab[index]['select'] = true
// 初始化数据
this.setData({
recommendedTab,
listDataLeft: [],
listDataRight: [],
listType: type,
listPage: 1,
pagevalue: 0,
})
this.getListDataState = false
this.top10State = true
this.leftHeight = 0
this.rightHeight = 0
this.dataCount = 0
this.getListData()
// miucms.statistics({
// name: 'recommendedTab',
// data: {
// type
// }
// })
},
dataCount: 0, // 数据的数量
// 获取列表数据
getListData() {
if (this.getListDataState) return
this.getListDataState = true
wx.showLoading({
title: '加载中...',
mask: true
})
// 获取数据
miucms.wxget(app.globalData.baseURL + "/tenement/v2/api/home/recommendList", {
page: this.data.listPage,
limit: 20,
type: this.data.listType,
pagevalue: this.data.pagevalue || 0,
}).then(res => {
if (res.code != 200) return
let data = res.data.data
// 广告数据
let pagevalue = res.data.pagevalue
let recommendedTab = this.data.recommendedTab
this.dataCount = data.length + this.dataCount
this.setData({
listPage: this.data.listPage + 1,
listData: data,
pagevalue,
recommendedTab
})
if (data.length >= 10) this.calculationBefore(data, this.data.listType)
else {
this.listDataIndex = 0
this.calculateProcessingCenter()
}
}).catch(() => {
this.getListDataState = false
}).finally(() => {
wx.hideLoading()
})
},
// 计算 瀑布流
calculationBefore(data = [...data], type) {
// 拿到当前左右两边的数据
// 是先渲染十个数据再 计算
let listDataLeft = this.data.listDataLeft
let listDataRight = this.data.listDataRight
data = data.slice(0, 10)
data.forEach((el, index) => {
if (index % 2 === 0) listDataLeft.push(el)
else listDataRight.push(el)
})
this.setData({
listDataLeft,
listDataRight,
})
this.top10State = true
},
listDataIndex: 10,
leftHeight: 0, // px 单位
rightHeight: 0,
ratio: 0,
pinterestImgLoadIndex: 0, // 加载了建施图
// 计算
calculateProcessingCenter() {
// return
if (!this.getListDataState) return
let ratio = this.ratio
if (!this.ratio) this.ratio = this.data.screen_data['windowWidth'] / 750
let targetData = this.data.listData[this.listDataIndex]
if (!targetData) {
this.getListDataState = false
return
}
let type = targetData['type']
if (type == 'adv') {
this.getPictureHeight(targetData.image).then(res => {
targetData['imageLocal'] = res.path
this.whichSide(res.actual, targetData)
return
})
} else {
let altitude = 0 // rpx
if (type == 'apartment') {
altitude = 205
if (targetData['specifications'].length > 2) altitude += 100
else altitude += 64 * targetData['specifications'].length
} else altitude = 141
altitude = altitude * ratio // 转 px
this.setData({
targetData
})
altitude += (150 / 180 * 317.5 * ratio)
let select = type == 'apartment' ? '#apartment' : '#general'
let query = wx.createSelectorQuery();
query.select(select).boundingClientRect(rect => {
if (!rect) {
this.whichSide(altitude, targetData)
return
}
let height = rect.height;
altitude += height
this.whichSide(altitude, targetData)
}).exec();
}
},
// 判断在哪边的
whichSide(res, targetData) {
if (this.leftHeight <= this.rightHeight) {
this.leftHeight = this.leftHeight + res
this.data.listDataLeft.push(targetData)
} else {
this.rightHeight = this.rightHeight + res
this.data.listDataRight.push(targetData)
}
this.setData({
listDataLeft: this.data.listDataLeft,
listDataRight: this.data.listDataRight
})
if (this.data.listData[this.listDataIndex]) {
this.listDataIndex++
this.calculateProcessingCenter()
}
},
pinterestImgLoadCount: 0,
pinterestImgLoad(e) {
return
this.pinterestImgLoadCount++
if (this.getListDataState) return
this.pinterestImgLoadIndex++
if (this.pinterestImgLoadIndex >= 10 && this.top10State) {
this.top10State = false
this.pinterestImgLoadIndex = 0
this.listDataIndex = 10
let query = wx.createSelectorQuery();
query.select("#pinterest-list-left").boundingClientRect()
query.select("#pinterest-list-right").boundingClientRect()
query.exec(rect => {
if (!rect[0]) {
this.getListDataState = false
wx.hideLoading()
return
}
this.leftHeight = rect[0].height
this.rightHeight = rect[1].height
this.calculateProcessingCenter()
})
}
},
// 获取图片高度
getPictureHeight(src) {
return new Promise((resolve, reject) => {
wx.getImageInfo({
src,
success: res => {
let {
width,
height,
path
} = res
let actual = height / width * 317 * this.ratio
resolve({
actual,
path
})
}
})
})
},
// 上拉到底部
onReachBottom() {
if (this.data.listDataLeft.length + this.data.listDataRight.length != this.dataCount) {
let query = wx.createSelectorQuery();
query.select("#pinterest-list-left").boundingClientRect()
query.select("#pinterest-list-right").boundingClientRect()
query.exec(rect => {
this.leftHeight = rect[0].height
this.rightHeight = rect[1].height
this.listDataIndex = 10
this.calculateProcessingCenter()
})
} else this.getListData()
},
headHeight: 0,
onPageScroll(e) {
if (e.scrollTop > this.headHeight && !this.data.operationsTop) {
this.setData({
operationsTop: true
})
} else if (e.scrollTop <= this.headHeight && 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
})
}
},
goIrentList() {
wx.navigateTo({
url: '/pages/brandApartmentList/brandApartmentList',
})
},
today: null, // 当前日期
// 判断是否要弹窗
decideYouWantPopup() {
// 判断今天是否要自动弹出
this.today = new Date().toDateString(); // 获取当前日期
const lastPopupDate = wx.getStorageSync('lastPopupDate') || ''
const popwindow = this.data.popwindow
// 要弹窗
// if (lastPopupDate !== this.today && this.data.popwindow.status == 1 && this.data.popwindow.isAuto == 1) this.listenWaterfallFlow()
// autowindowtime 为 0 时取消自动弹窗. >0 时为自动弹窗时间 (秒 )
if (lastPopupDate !== this.today && popwindow.autowindowtime > 0) this.listenWaterfallFlow()
},
// 开启监听瀑布流元素是否在 可视窗口上
listenWaterfallFlow() {
const observer = wx.createIntersectionObserver(this, {
thresholds: [0.1] // 设定阈值,表示元素一半进入可视区域时触发
});
observer.relativeToViewport().observe(`#pinterest-list-left`, (res) => {
if (res.intersectionRatio > 0) {
this.timingPopwindow()
observer.disconnect(); // 取消观察
}
});
},
popwindowTiminr: null, // 弹窗定时器
// 定时十秒开启弹窗
timingPopwindow() {
if (this.popwindowTiminr) return
this.popwindowTiminr = setTimeout(() => {
wx.setStorage({
key: 'lastPopupDate',
data: this.today,
});
// 判断是否已经开启 后 开启
if (!this.data.popwindowState) this.openPopwindow()
}, this.data.popwindow.autowindowtime)
},
// 主动开启 弹窗
openInitiativePopwindow() {
this.setData({
['popwindow.text']: "找方同学咨询公寓"
})
this.openPopwindow()
// miucms.statistics({
// name: "popwindow"
// })
},
// 打开弹窗
openPopwindow() {
clearTimeout(this.popwindowTiminr)
this.setData({
popwindowState: true,
popwindowBtnState: false,
popwindowBtnAnimationState: true,
})
},
// 关闭弹窗
closePopwindow() {
this.setData({
popwindowState: false,
popwindowBtnState: true,
})
this.setData({
['popwindow.text']: ""
})
},
})