700 lines
19 KiB
JavaScript
700 lines
19 KiB
JavaScript
// pages/projectLibrary/projectLibrary.js
|
||
var miucms = require('../../utils/miucms.js');
|
||
let app = getApp()
|
||
const util = require('../../utils/util')
|
||
const common = require('../../utils/commonMethod')
|
||
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
totalTopHeight: null,
|
||
isFirstPattern: true, // 是否是首屏模式
|
||
classify: "school", // school subject
|
||
current: 0,
|
||
|
||
discipline: [], // 学科
|
||
university: [], // 学校
|
||
|
||
bezier: {},
|
||
|
||
page: 1,
|
||
list: [],
|
||
listLeft: [],
|
||
listRight: [],
|
||
|
||
fateProject: [], // 缘分项目
|
||
admissionList: [], // 招生官项目
|
||
contrastcount: 0, // 项目对比 数量
|
||
|
||
|
||
informationState: false, // 授权后可能需要弹出完成信息框 个人背景那些
|
||
islogin: false,
|
||
isloginBtnState: false,
|
||
|
||
isInitFinish: false,
|
||
user: {},
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
headHeight: 0, // 头部高度
|
||
rpx15: 15,
|
||
searchBoxTop: 0,
|
||
options: {},
|
||
onLoad(options) {
|
||
this.options = options
|
||
miucms.pageStart(app).then(() => {
|
||
const screen_data = app.globalData.screen_data
|
||
const totalTopHeight = screen_data.totalTopHeight || 0
|
||
|
||
this.searchBoxTop = util.rpxTopx(313.5) + totalTopHeight
|
||
|
||
this.headHeight = util.rpxTopx(313.5)
|
||
this.rpx15 = util.rpxTopx(15)
|
||
|
||
this.setData({
|
||
islogin: app.globalData.user.uid > 0 ? true : false,
|
||
user: app.globalData.user,
|
||
totalTopHeight,
|
||
isInitFinish: true,
|
||
bottomLift: screen_data.bottomLift,
|
||
|
||
})
|
||
|
||
this.windowHeight = screen_data.windowHeight || 812
|
||
|
||
common.xgBasicData(this, app, true).then(data => {
|
||
this.setData({
|
||
contrastcount: data.contrastcount || 0,
|
||
university: data.university,
|
||
discipline: data.discipline,
|
||
})
|
||
})
|
||
|
||
this.getFate()
|
||
this.getAdmission()
|
||
this.addRandom()
|
||
this.getProjectData()
|
||
|
||
const fateProject = (this.data.fateProject || []).map(element => ({
|
||
...element,
|
||
random: app.randomString(6)
|
||
}));
|
||
|
||
this.setData({
|
||
fateProject,
|
||
})
|
||
})
|
||
},
|
||
|
||
addRandom() {
|
||
let list = this.data.list || []
|
||
list.forEach(element => {
|
||
element['random'] = app.randomString(6)
|
||
})
|
||
|
||
this.setData({
|
||
list
|
||
})
|
||
},
|
||
|
||
leftheight: 0,
|
||
rightheight: 0,
|
||
// 处理瀑布流
|
||
handleLazyLoading(list) {
|
||
this.getHeightState = true
|
||
const length = list.length
|
||
const eighty = Math.floor(length * 0.8)
|
||
let left = []
|
||
let right = []
|
||
|
||
// 变量决定第一个元素是放入 left 还是 right
|
||
const startWithLeft = this.leftheight <= this.rightheight; // 如果为 true,第一个元素放入 left,否则放入 right
|
||
const pointList = list.slice(0, eighty)
|
||
pointList.forEach((element, index) => {
|
||
if ((index % 2 === 0 && startWithLeft) || (index % 2 !== 0 && !startWithLeft)) left.push(element);
|
||
else right.push(element);
|
||
})
|
||
|
||
this.setData({
|
||
listLeft: this.data.listLeft.concat(left),
|
||
listRight: this.data.listRight.concat(right),
|
||
})
|
||
|
||
this.getHeight(list, eighty)
|
||
|
||
},
|
||
|
||
queryLeft: null,
|
||
getHeightState: false, // 瀑布流计算中
|
||
// 获取高度
|
||
getHeight(list, index) {
|
||
if (!list[index]) {
|
||
this.getHeightState = false
|
||
return
|
||
}
|
||
this.createSelectorQuery().select(".waterfall .waterfall-left").boundingClientRect(res => {
|
||
this.leftheight = res.height
|
||
|
||
this.createSelectorQuery().select(".waterfall .waterfall-right").boundingClientRect(res => {
|
||
this.rightheight = res.height
|
||
if (this.leftheight <= this.rightheight) {
|
||
this.data.listLeft.push(list[index])
|
||
this.setData({
|
||
listLeft: this.data.listLeft
|
||
})
|
||
} else {
|
||
this.data.listRight.push(list[index])
|
||
|
||
this.setData({
|
||
listRight: this.data.listRight
|
||
})
|
||
}
|
||
|
||
wx.nextTick(() => {
|
||
this.getHeight(list, index + 1)
|
||
})
|
||
}).exec();
|
||
}).exec();
|
||
},
|
||
|
||
|
||
|
||
// 获取今日缘分
|
||
getFate() {
|
||
wx.showLoading({
|
||
title: '加载中...',
|
||
})
|
||
util.wxget("/api/project.home/todayFateProject").then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data || []
|
||
data.forEach(element => {
|
||
element['random'] = app.randomString(6)
|
||
})
|
||
this.setData({
|
||
fateProject: data,
|
||
})
|
||
}).finally(() => {
|
||
wx.hideLoading()
|
||
})
|
||
},
|
||
|
||
// 获取 招生官项目
|
||
getAdmission() {
|
||
util.wxget("/api/project.lists", {
|
||
limit: 20,
|
||
page: 1,
|
||
admissionsproject: 1,
|
||
}).then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data
|
||
const list = data.data || []
|
||
|
||
const admissionList = (list || []).map(element => ({
|
||
...element,
|
||
random: app.randomString(6)
|
||
}));
|
||
|
||
const chunkArray = (array, size) => {
|
||
const result = [];
|
||
for (let i = 0; i < array.length; i += size) {
|
||
result.push(array.slice(i, i + size));
|
||
}
|
||
return result;
|
||
};
|
||
|
||
const groupedAdmissionList = chunkArray(admissionList, 4);
|
||
|
||
this.setData({
|
||
admissionList: groupedAdmissionList,
|
||
})
|
||
})
|
||
|
||
},
|
||
|
||
// 获取项目数据
|
||
getProjectData() {
|
||
if (this.data.page == 0) return
|
||
wx.showLoading({
|
||
title: '加载中...',
|
||
})
|
||
util.wxget("/api/project.lists", {
|
||
limit: 20,
|
||
page: this.data.page,
|
||
}).then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data
|
||
|
||
const date = new Date()
|
||
const month = date.getMonth() + 1
|
||
const year = date.getFullYear()
|
||
|
||
let list = data.data || []
|
||
list = (list).map(element => ({
|
||
...element,
|
||
random: app.randomString(6),
|
||
semesterState: month > element.semester.month && year + 1 <= element.semester.year,
|
||
}));
|
||
|
||
this.setData({
|
||
list: this.data.list.concat(list),
|
||
page: data.count > data.limit * data.page ? this.data.page + 1 : 0,
|
||
})
|
||
|
||
this.handleLazyLoading(list)
|
||
|
||
if (!this.indexSidebar) this.indexSidebar = this.selectComponent('#index-sidebar')
|
||
|
||
}).finally(() => {
|
||
wx.hideLoading()
|
||
})
|
||
},
|
||
|
||
// 物品的点击事件
|
||
handleClick(e) {
|
||
if (!this.data.islogin) {
|
||
this.openLoginBtnState()
|
||
return
|
||
}
|
||
const id = e.currentTarget.dataset.id
|
||
const index = e.currentTarget.dataset.index || 0
|
||
const i = e.currentTarget.dataset.i || 0
|
||
const status = e.currentTarget.dataset.status || 0
|
||
const type = e.currentTarget.dataset.type
|
||
const random = e.currentTarget.dataset.random
|
||
const query = this.createSelectorQuery();
|
||
if (status == 1) return
|
||
|
||
console.log("random", random);
|
||
|
||
query.select('#add' + random).boundingClientRect();
|
||
if (status == 0) {
|
||
this.setData({
|
||
bezier: {},
|
||
})
|
||
query.exec((res) => {
|
||
const data = res[0]
|
||
//定义手指点击位置
|
||
this.setData({
|
||
bezier: {
|
||
x: data.left + data.width / 2 - this.rpx15,
|
||
y: data.top + data.height / 2 - this.rpx15,
|
||
},
|
||
})
|
||
});
|
||
}
|
||
|
||
let url = "/api/project.contrast/add"
|
||
|
||
util.wxpost(url, {
|
||
projectid: id
|
||
}).then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data
|
||
if (type === 'admission') {
|
||
const admissionList = this.data.admissionList
|
||
if (admissionList[index][i]['contraststatus'] == null) admissionList[index][i]['contraststatus'] = {}
|
||
admissionList[index][i]['contraststatus'] = {
|
||
status: 1,
|
||
ismanage: 1,
|
||
}
|
||
this.setData({
|
||
admissionList,
|
||
})
|
||
}
|
||
|
||
console.log("type", type);
|
||
if (type === 'left') {
|
||
const listLeft = this.data.listLeft
|
||
if (listLeft[index]['contraststatus'] == null) listLeft[index]['contraststatus'] = {}
|
||
listLeft[index]['contraststatus'] = {
|
||
status: 1,
|
||
ismanage: 1,
|
||
}
|
||
console.log("listLeft", listLeft, index, "index");
|
||
this.setData({
|
||
listLeft,
|
||
})
|
||
}
|
||
|
||
if (type === 'right') {
|
||
const listRight = this.data.listRight
|
||
if (listRight[index]['contraststatus'] == null) listRight[index]['contraststatus'] = {}
|
||
listRight[index]['contraststatus'] = {
|
||
status: 1,
|
||
ismanage: 1,
|
||
}
|
||
this.setData({
|
||
listRight,
|
||
})
|
||
}
|
||
|
||
if (type == 'fate') {
|
||
let fateProject = this.data.fateProject
|
||
fateProject[index]['state'] = 1
|
||
this.setData({
|
||
fateProject,
|
||
})
|
||
}
|
||
|
||
this.setData({
|
||
contrastcount: data.count,
|
||
})
|
||
|
||
app.globalData.basicData['contrastcount'] = data.count
|
||
|
||
common.toast(res.message)
|
||
})
|
||
},
|
||
|
||
// 切换查看类型
|
||
cutClassify(e) {
|
||
const classify = e.currentTarget.dataset.type
|
||
if (classify == this.data.classify) return
|
||
|
||
this.setData({
|
||
classify
|
||
})
|
||
},
|
||
|
||
swiperchange(e) {
|
||
this.setData({
|
||
current: e.detail.current,
|
||
})
|
||
this.closeMoreSelectAll('admission')
|
||
},
|
||
|
||
// 点击跳转 招生官频道
|
||
goAdmission() {
|
||
wx.navigateToMiniProgram({
|
||
appId: "wxa9296b07391c2bc7",
|
||
path: "/pages/admissionList/admissionList"
|
||
})
|
||
// common.goPage("/pages/admissionList/admissionList")
|
||
},
|
||
|
||
// 点击 查看 学校
|
||
goClassifyValue(e) {
|
||
const classify = this.data.classify
|
||
const value = e.currentTarget.dataset.value
|
||
const name = e.currentTarget.dataset.label
|
||
|
||
let url = ""
|
||
if (classify == 'school') url = `/pages/projectSchoolHomepage/projectSchoolHomepage?id=${value}`
|
||
else url = `/pages/projectSubjectList/projectSubjectList?id=${value}`
|
||
|
||
common.goPage(url)
|
||
},
|
||
|
||
// 点击项目详情
|
||
goDetails(e) {
|
||
const uniqid = e.currentTarget.dataset.uniqid
|
||
const pageUrl = e.currentTarget.dataset.url
|
||
|
||
let url = `/pages/projectDetails/projectDetails?uniqid=${uniqid}`
|
||
|
||
common.goPage(url)
|
||
},
|
||
|
||
// 点击跳转群主
|
||
jumpGroup() {
|
||
// const url = "https://form.gter.net/D8i0iS5uXCWG#/qr"
|
||
// common.goPage(`/pages/webview/webview?url=${url}`)
|
||
this.indexSidebar.setData({
|
||
groupState: true,
|
||
})
|
||
util.statistics({
|
||
name: "side-group"
|
||
})
|
||
},
|
||
|
||
indexSidebar: null,
|
||
windowHeight: 812,
|
||
onPageScroll(e) {
|
||
const scrollTop = e.scrollTop
|
||
|
||
let isFirstPattern = true
|
||
if (scrollTop > this.headHeight) isFirstPattern = false
|
||
|
||
if (this.data.isFirstPattern != isFirstPattern) {
|
||
this.setData({
|
||
isFirstPattern
|
||
})
|
||
}
|
||
|
||
|
||
|
||
let sidebarState = this.indexSidebar.data.sidebarState
|
||
if (scrollTop > this.windowHeight * 3 && sidebarState !== 3) sidebarState = 3
|
||
|
||
if (scrollTop < this.windowHeight * 3 && sidebarState == 3) sidebarState = 2
|
||
|
||
// 同一搜集 修改的 sidebarState
|
||
if (sidebarState !== this.indexSidebar.data.sidebarState) {
|
||
this.indexSidebar.setData({
|
||
sidebarState
|
||
})
|
||
}
|
||
|
||
this.indexSidebar.openSidebarTwoHide()
|
||
|
||
},
|
||
|
||
goPage(e) {
|
||
const url = e.currentTarget.dataset.url
|
||
common.goPage(url)
|
||
},
|
||
|
||
openMoreSelect(e) {
|
||
const index = e.currentTarget.dataset.index || 0
|
||
const i = e.currentTarget.dataset.i || 0
|
||
const type = e.currentTarget.dataset.type
|
||
if (type == 'admission') {
|
||
const admissionList = this.data.admissionList
|
||
admissionList.forEach(element => {
|
||
console.log("element", element);
|
||
element.forEach(ele => {
|
||
ele['moreState'] = false
|
||
})
|
||
})
|
||
|
||
admissionList[index][i]['moreState'] = true
|
||
|
||
this.setData({
|
||
admissionList,
|
||
})
|
||
}
|
||
|
||
if (type == 'left') {
|
||
let listLeft = this.data.listLeft
|
||
listLeft.forEach(element => {
|
||
element['moreState'] = false
|
||
})
|
||
|
||
listLeft[index]['moreState'] = true
|
||
|
||
this.setData({
|
||
listLeft,
|
||
})
|
||
}
|
||
|
||
if (type == 'right') {
|
||
let listRight = this.data.listRight
|
||
listRight.forEach(element => {
|
||
element['moreState'] = false
|
||
})
|
||
|
||
listRight[index]['moreState'] = true
|
||
|
||
this.setData({
|
||
listRight,
|
||
})
|
||
}
|
||
},
|
||
|
||
closeMoreSelect(e) {
|
||
const type = e.currentTarget.dataset.type
|
||
this.closeMoreSelectAll(type)
|
||
},
|
||
|
||
// 关闭所有 状态 选择 弹出框
|
||
closeMoreSelectAll(type) {
|
||
if (type == 'admission') {
|
||
const admissionList = this.data.admissionList
|
||
admissionList.forEach(element => {
|
||
console.log("element", element);
|
||
element.forEach(ele => {
|
||
ele['moreState'] = false
|
||
})
|
||
})
|
||
|
||
this.setData({
|
||
admissionList,
|
||
})
|
||
}
|
||
|
||
if (type == 'left') {
|
||
let listLeft = this.data.listLeft
|
||
listLeft.forEach(element => {
|
||
element['moreState'] = false
|
||
})
|
||
|
||
this.setData({
|
||
listLeft,
|
||
})
|
||
}
|
||
|
||
if (type == 'right') {
|
||
let listRight = this.data.listRight
|
||
listRight.forEach(element => {
|
||
element['moreState'] = false
|
||
})
|
||
|
||
this.setData({
|
||
listRight,
|
||
})
|
||
}
|
||
|
||
},
|
||
|
||
addProject(e) {
|
||
const index = e.currentTarget.dataset.index
|
||
const i = e.currentTarget.dataset.i
|
||
const id = e.currentTarget.dataset.id
|
||
|
||
const type = e.currentTarget.dataset.type
|
||
|
||
util.wxpost("/api/project.contrast/add", {
|
||
projectid: id
|
||
}).then(res => {
|
||
if (res.code != 200) return
|
||
const data = res.data
|
||
|
||
if (type == 'admission') {
|
||
let list = this.data.admissionList
|
||
if (list[index][i]['contraststatus'] == null) list[index][i]['contraststatus'] = {}
|
||
|
||
list[index][i]['contraststatus'] = {
|
||
status: 1,
|
||
ismanage: 1,
|
||
}
|
||
this.setData({
|
||
admissionList: list,
|
||
})
|
||
}
|
||
|
||
if (type == 'left') {
|
||
let list = this.data.listLeft
|
||
if (list[index]['contraststatus'] == null) list[index]['contraststatus'] = {}
|
||
|
||
list[index]['contraststatus'] = {
|
||
status: 1,
|
||
ismanage: 1,
|
||
}
|
||
this.setData({
|
||
listLeft: list,
|
||
})
|
||
}
|
||
|
||
if (type == 'right') {
|
||
let list = this.data.listRight
|
||
if (list[index]['contraststatus'] == null) list[index]['contraststatus'] = {}
|
||
|
||
list[index]['contraststatus'] = {
|
||
status: 1,
|
||
ismanage: 1,
|
||
}
|
||
this.setData({
|
||
listRight: list,
|
||
})
|
||
}
|
||
|
||
this.setData({
|
||
contrastcount: data.count,
|
||
})
|
||
|
||
app.globalData.basicData['contrastcount'] = data.count
|
||
|
||
common.toast(res.message)
|
||
})
|
||
},
|
||
|
||
// 打开 授权按钮
|
||
openLoginBtnState() {
|
||
this.setData({
|
||
isloginBtnState: true,
|
||
})
|
||
},
|
||
|
||
// 关闭授权登录事件
|
||
popClose() {
|
||
this.setData({
|
||
isloginBtnState: !this.data.isloginBtnState
|
||
})
|
||
},
|
||
|
||
userClickLogin(e) {
|
||
let data = e.detail.data
|
||
this.setData({
|
||
islogin: true,
|
||
isloginBtnState: false,
|
||
informationState: data.regdatastep == 'success' ? false : true,
|
||
})
|
||
this.onLoad(this.options)
|
||
},
|
||
|
||
// 子组件传值 修改 完善信息组件的状态
|
||
revampInformationState() {
|
||
this.setData({
|
||
informationState: false
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
if (app.globalData.basicDataState) {
|
||
this.setData({
|
||
contrastcount: app.globalData.basicData['contrastcount'],
|
||
})
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
wx.stopPullDownRefresh()
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
if (!this.getHeightState) this.getProjectData()
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
return {
|
||
title: "聚焦港校项目,助你迈向国际名校之路!",
|
||
}
|
||
},
|
||
|
||
onShareTimeline() {
|
||
util.statistics({
|
||
name: "share-timeline"
|
||
})
|
||
return {
|
||
title: "聚焦港校项目,助你迈向国际名校之路!",
|
||
}
|
||
},
|
||
}) |