637 lines
17 KiB
JavaScript
637 lines
17 KiB
JavaScript
// pages/projectList/projectList.js
|
|
var miucms = require('../../utils/miucms.js');
|
|
const util = require('../../utils/util.js')
|
|
const common = require('../../utils/commonMethod')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
isFirstPattern: true,
|
|
classify: "school", // school subject
|
|
screenState: false, // 选择框的状态
|
|
territoryState: false, // 专业弹窗
|
|
|
|
comprehensive: {
|
|
organizationKey: "",
|
|
organization: [],
|
|
yearKey: "",
|
|
year: [],
|
|
obj: {},
|
|
list: [],
|
|
total: 0,
|
|
only: 0,
|
|
page: 1,
|
|
},
|
|
|
|
discipline: {
|
|
organizationKey: "",
|
|
organization: [],
|
|
yearKey: "",
|
|
year: [],
|
|
majorKey: "",
|
|
obj: {},
|
|
list: [],
|
|
total: 0,
|
|
only: 0,
|
|
page: 1,
|
|
},
|
|
|
|
university: [],
|
|
universityArr: [],
|
|
isInitFinish: false,
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
rpx219: 0,
|
|
onLoad(options) {
|
|
this.rpx219 = util.rpxTopx(219)
|
|
|
|
miucms.pageStart(app).then(() => {
|
|
const screen_data = app.globalData.screen_data
|
|
this.windowHeight = screen_data.windowHeight || 812
|
|
|
|
common.xgBasicData(this, app).then(data => {
|
|
let universityArr = []
|
|
const university = JSON.parse(JSON.stringify(data.university || {}))
|
|
university.forEach(element => {
|
|
universityArr.push(element.value)
|
|
})
|
|
this.setData({
|
|
university: data.university,
|
|
universityArr,
|
|
})
|
|
this.getRankings()
|
|
})
|
|
})
|
|
},
|
|
|
|
// 获取 综合排名 数据
|
|
getSynthesizeData() {
|
|
let comprehensive = this.data.comprehensive
|
|
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
})
|
|
|
|
util.wxget("/api/project.rankings/comprehensive", {
|
|
token: comprehensive['token'],
|
|
ishongkong: comprehensive['only'] || 0,
|
|
limit: 2000,
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
let data = res.data
|
|
let list = data.data || []
|
|
const universityArr = this.data.universityArr
|
|
// 遍历去掉非香港院校
|
|
list.forEach(element => {
|
|
if (!universityArr.includes(element.sid)) element.sid = 0
|
|
});
|
|
comprehensive['total'] = data.count
|
|
comprehensive['allList'] = list
|
|
comprehensive['list'] = []
|
|
comprehensive['page'] = 1
|
|
|
|
comprehensive['organizeText'] = comprehensive['organizationKey']
|
|
comprehensive['yearText'] = comprehensive['yearKey']
|
|
|
|
this.setData({
|
|
comprehensive,
|
|
screenState: false,
|
|
})
|
|
|
|
this.renderComprehensiveList()
|
|
}).finally(() => wx.hideLoading())
|
|
},
|
|
|
|
// 渲染 综合排名 limit: 20
|
|
renderComprehensiveList() {
|
|
const limit = 20
|
|
let comprehensive = this.data.comprehensive
|
|
let page = comprehensive['page']
|
|
if (page == 0) return
|
|
|
|
const allList = comprehensive['allList']
|
|
const target = allList.slice((page - 1) * limit, page * limit)
|
|
comprehensive['list'] = comprehensive.list.concat(target)
|
|
comprehensive['page'] = target.length < limit ? 0 : page + 1
|
|
this.setData({
|
|
comprehensive
|
|
})
|
|
},
|
|
|
|
// 获取 专业排名 数据
|
|
getMajorData() {
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
})
|
|
let discipline = this.data.discipline
|
|
// console.log("discipline", discipline);
|
|
|
|
util.wxget("/api/project.rankings/discipline", {
|
|
token: discipline['token'],
|
|
ishongkong: discipline['only'] || 0,
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
let data = res.data
|
|
discipline['total'] = data.count
|
|
discipline['allList'] = data.data
|
|
discipline['list'] = []
|
|
discipline['page'] = 1
|
|
|
|
discipline['organizeText'] = discipline['organizationKey']
|
|
discipline['yearText'] = discipline['yearKey']
|
|
discipline['majorText'] = discipline['majorKey']
|
|
|
|
this.setData({
|
|
discipline,
|
|
screenState: false,
|
|
})
|
|
this.renderDisciplineList()
|
|
}).finally(() => wx.hideLoading())
|
|
},
|
|
|
|
// 渲染 专业排名 limit: 20
|
|
renderDisciplineList() {
|
|
const limit = 20
|
|
let discipline = this.data.discipline
|
|
let page = discipline['page']
|
|
if (page == 0) return
|
|
|
|
const allList = discipline['allList']
|
|
const target = allList.slice((page - 1) * limit, page * limit)
|
|
discipline['list'] = discipline.list.concat(target)
|
|
discipline['page'] = target.length < limit ? 0 : page + 1
|
|
|
|
this.setData({
|
|
discipline,
|
|
})
|
|
},
|
|
|
|
// 获取 配置信息
|
|
getRankings() {
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
})
|
|
util.wxget("/api/project.rankings", {}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
|
|
const comprehensive = data.comprehensive
|
|
let comprehensiveTarget = this.data.comprehensive
|
|
let organizationSet = [...this.objectOne(comprehensive)]
|
|
comprehensiveTarget['organization'] = organizationSet
|
|
comprehensiveTarget['organizationKey'] = organizationSet[0]
|
|
|
|
let yearsSet = [...this.collectYears(comprehensive)]
|
|
yearsSet.sort((a, b) => b - a);
|
|
|
|
// console.log("yearsSet", yearsSet);
|
|
// comprehensiveTarget['year'] = yearsSet
|
|
comprehensiveTarget['yearKey'] = yearsSet[0]
|
|
comprehensiveTarget['obj'] = comprehensive
|
|
|
|
this.checkComprehensiveYear()
|
|
|
|
const discipline = data.discipline
|
|
let disciplineTarget = this.data.discipline
|
|
|
|
const dOrganization = [...this.objectOne(discipline)]
|
|
const [dOrganizationKey, dOrganizationValue] = Object.entries(discipline)[0]
|
|
disciplineTarget['organization'] = dOrganization
|
|
disciplineTarget['organizationKey'] = dOrganizationKey
|
|
disciplineTarget['majorKey'] = Object.entries(dOrganizationValue)[0][0]
|
|
const dYear = [...this.collectYears(discipline)]
|
|
dYear.sort((a, b) => b - a);
|
|
|
|
// disciplineTarget['year'] = dYear
|
|
disciplineTarget['yearKey'] = dYear[0]
|
|
disciplineTarget['obj'] = discipline
|
|
|
|
this.checkDisciplineYear()
|
|
|
|
this.setData({
|
|
comprehensive: comprehensiveTarget,
|
|
discipline: disciplineTarget,
|
|
isInitFinish: true,
|
|
})
|
|
|
|
if (!this.indexSidebar) this.indexSidebar = this.selectComponent('#index-sidebar')
|
|
|
|
this.haveComprehensive()
|
|
|
|
if (!this.indexSidebar) this.indexSidebar = this.selectComponent('#index-sidebar')
|
|
|
|
}).finally(() => wx.hideLoading())
|
|
},
|
|
|
|
// 计算出对象所有 一级 key
|
|
objectOne(obj) {
|
|
let arr = []
|
|
for (const key in obj) {
|
|
arr.push(key)
|
|
}
|
|
return arr
|
|
},
|
|
|
|
// 计算出 对象 所有 二级 key 不重复
|
|
collectYears(obj, arr = new Set()) {
|
|
for (let key in obj) {
|
|
if (obj.hasOwnProperty(key)) {
|
|
if (!isNaN(key) && key.length === 4) {
|
|
arr.add(key);
|
|
}
|
|
|
|
const value = obj[key];
|
|
if (typeof value === 'object' && value !== null) {
|
|
this.collectYears(value, arr);
|
|
}
|
|
}
|
|
}
|
|
return [...arr];
|
|
},
|
|
|
|
// 切换查看类型
|
|
cutClassify(e) {
|
|
const classify = e.currentTarget.dataset.type
|
|
if (classify == this.data.classify) return
|
|
|
|
|
|
let discipline = this.data.discipline
|
|
// 切换 专业排名时 判断 是否需要 显示选择
|
|
if (classify == 'subject' && discipline.list.length == 0) {
|
|
this.haveDiscipline()
|
|
}
|
|
|
|
this.setData({
|
|
classify,
|
|
})
|
|
},
|
|
|
|
indexSidebar: null,
|
|
windowHeight: 812,
|
|
onPageScroll(e) {
|
|
const scrollTop = e.scrollTop
|
|
|
|
let isFirstPattern = true
|
|
if (scrollTop > this.rpx219) 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()
|
|
},
|
|
|
|
// 切换仅显示香港
|
|
cutOnlyXg() {
|
|
const classify = this.data.classify
|
|
if (classify == 'school') {
|
|
let comprehensive = this.data.comprehensive
|
|
comprehensive['only'] = comprehensive['only'] == 1 ? 0 : 1
|
|
|
|
comprehensive['list'] = []
|
|
this.setData({
|
|
comprehensive,
|
|
})
|
|
|
|
this.getSynthesizeData()
|
|
} else {
|
|
let discipline = this.data.discipline
|
|
discipline['only'] = discipline['only'] == 1 ? 0 : 1
|
|
discipline['list'] = []
|
|
this.setData({
|
|
discipline,
|
|
})
|
|
this.getMajorData()
|
|
}
|
|
},
|
|
|
|
// 选择机构 - 综合
|
|
selectOrganicComprehensive(e) {
|
|
let key = e.currentTarget.dataset.key
|
|
|
|
// const key = e.currentTarget.dataset.key
|
|
let comprehensive = this.data.comprehensive
|
|
comprehensive['organizationKey'] = key
|
|
this.setData({
|
|
comprehensive,
|
|
})
|
|
this.checkComprehensiveYear()
|
|
},
|
|
|
|
// 判断是否存在值 综合 检查 年份
|
|
checkComprehensiveYear() {
|
|
const comprehensive = this.data.comprehensive
|
|
const obj = comprehensive.obj
|
|
const target = obj[comprehensive.organizationKey]
|
|
|
|
let year = this.objectOne(target) || []
|
|
|
|
year.sort((a, b) => b - a);
|
|
|
|
if (!year.includes(comprehensive.yearKey)) comprehensive.yearKey = year[0]
|
|
|
|
// if (year.length == 1) comprehensive.yearKey = year[0]
|
|
|
|
comprehensive['year'] = year
|
|
this.setData({
|
|
comprehensive
|
|
})
|
|
},
|
|
|
|
// 选择年份 - 综合
|
|
selectYearComprehensive(e) {
|
|
const key = e.currentTarget.dataset.key
|
|
let comprehensive = this.data.comprehensive
|
|
comprehensive['yearKey'] = key
|
|
this.setData({
|
|
comprehensive,
|
|
})
|
|
},
|
|
|
|
// 选择机构 - 专业
|
|
selectOrganicMajor(e) {
|
|
const key = e.currentTarget.dataset.key
|
|
let discipline = this.data.discipline
|
|
discipline['organizationKey'] = key
|
|
discipline['majorKey'] = ""
|
|
|
|
this.setData({
|
|
discipline
|
|
})
|
|
|
|
// this.checkDisciplineYear()
|
|
this.selectFirstMajorInRanking()
|
|
},
|
|
|
|
// 选中专业排名后 默认选择 第一个专业
|
|
selectFirstMajorInRanking() {
|
|
let discipline = this.data.discipline
|
|
const organizationKey = discipline.organizationKey
|
|
|
|
const obj = discipline.obj
|
|
|
|
let majorsList = {}
|
|
majorsList = obj[organizationKey]
|
|
|
|
// console.log(Object.keys(majorsList)[0]);
|
|
|
|
const majorKey = Object.keys(majorsList)[0] || ''
|
|
// console.log("majorsList", majorsList[majorKey]);
|
|
const yearObj = majorsList[majorKey]
|
|
const yearList = Object.keys(yearObj)
|
|
yearList.sort((a, b) => b - a);
|
|
// console.log("yearList", yearList);
|
|
|
|
discipline['majorKey'] = majorKey
|
|
discipline['year'] = yearList
|
|
discipline['yearKey'] = yearList[0]
|
|
this.setData({
|
|
discipline,
|
|
})
|
|
},
|
|
|
|
// 判断是否存在值 专业 检查 年份
|
|
checkDisciplineYear() {
|
|
const discipline = this.data.discipline
|
|
const obj = discipline.obj
|
|
const target = obj[discipline.organizationKey]
|
|
|
|
let year = this.collectYears(target) || []
|
|
year.sort((a, b) => b - a);
|
|
if (!year.includes(discipline.yearKey)) discipline.yearKey = year[0]
|
|
discipline['year'] = year
|
|
|
|
// if (year.length == 1) discipline.yearKey = year[0]
|
|
|
|
this.setData({
|
|
discipline
|
|
})
|
|
},
|
|
|
|
// 选择年份 - 综合
|
|
selectYearDiscipline(e) {
|
|
const key = e.currentTarget.dataset.key
|
|
let discipline = this.data.discipline
|
|
discipline['yearKey'] = key
|
|
this.setData({
|
|
discipline,
|
|
})
|
|
},
|
|
|
|
// 打开专业弹窗
|
|
opneMajorPop() {
|
|
let discipline = this.data.discipline
|
|
|
|
const organizationKey = discipline.organizationKey
|
|
const yearKey = discipline.yearKey
|
|
|
|
// discipline['yearKey'] = ""
|
|
|
|
const obj = discipline.obj
|
|
if (!organizationKey) {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: '请先选择评榜机构',
|
|
})
|
|
return
|
|
}
|
|
let majorsList = {}
|
|
// 没有 选择年份的情况下
|
|
majorsList = obj[organizationKey]
|
|
|
|
this.setData({
|
|
majorsList,
|
|
territoryState: true,
|
|
screenState: false,
|
|
})
|
|
},
|
|
|
|
// 关闭 专业选择
|
|
closeselect(e) {
|
|
const yearList = e.detail?.yearList || []
|
|
|
|
yearList.sort((a, b) => b - a);
|
|
|
|
const key = e.detail?.key || ''
|
|
|
|
if (!key) {
|
|
this.setData({
|
|
territoryState: false,
|
|
screenState: true,
|
|
})
|
|
}
|
|
|
|
let discipline = this.data.discipline
|
|
|
|
discipline['majorKey'] = key
|
|
discipline['year'] = yearList
|
|
if (!yearList.includes(discipline.yearKey)) discipline.yearKey = ""
|
|
|
|
discipline.yearKey = yearList[0]
|
|
|
|
this.setData({
|
|
territoryState: false,
|
|
screenState: true,
|
|
discipline,
|
|
})
|
|
},
|
|
|
|
// 选好了 综合
|
|
haveComprehensive() {
|
|
let comprehensive = this.data.comprehensive
|
|
const organizationKey = comprehensive['organizationKey']
|
|
const yearKey = comprehensive['yearKey']
|
|
|
|
if (!organizationKey) this.selectionPrompt("请选择评榜机构")
|
|
if (!yearKey) this.selectionPrompt("请选择年份")
|
|
|
|
if (!organizationKey || !yearKey) return
|
|
|
|
const obj = comprehensive['obj']
|
|
|
|
const organizationValue = obj[organizationKey]
|
|
const token = organizationValue[yearKey]
|
|
comprehensive['token'] = token
|
|
|
|
this.setData({
|
|
comprehensive
|
|
})
|
|
|
|
this.getSynthesizeData()
|
|
|
|
},
|
|
|
|
// 选好了 专业
|
|
haveDiscipline() {
|
|
let discipline = this.data.discipline
|
|
const organizationKey = discipline['organizationKey']
|
|
const majorKey = discipline['majorKey']
|
|
const yearKey = discipline['yearKey']
|
|
|
|
if (!organizationKey) this.selectionPrompt("请选择评榜机构")
|
|
if (!majorKey) this.selectionPrompt("请选择专业")
|
|
if (!yearKey) this.selectionPrompt("请选择年份")
|
|
if (!organizationKey || !majorKey || !yearKey) return
|
|
|
|
const obj = discipline['obj']
|
|
|
|
const organizationValue = obj[organizationKey]
|
|
const majorValue = organizationValue[majorKey]
|
|
const token = majorValue[yearKey]
|
|
discipline['token'] = token
|
|
this.setData({
|
|
discipline
|
|
})
|
|
|
|
this.getMajorData()
|
|
},
|
|
|
|
//选择提示
|
|
selectionPrompt(title) {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title,
|
|
})
|
|
},
|
|
|
|
// 跳转学校主页
|
|
goSchoolHomepage(e) {
|
|
const sid = e.currentTarget.dataset.sid
|
|
wx.navigateTo({
|
|
url: '/pages/projectSchoolHomepage/projectSchoolHomepage?id=' + sid,
|
|
})
|
|
},
|
|
|
|
// 点击
|
|
cutScreenState() {
|
|
this.setData({
|
|
screenState: !this.data.screenState,
|
|
})
|
|
},
|
|
|
|
goDetails(e) {
|
|
return
|
|
const id = e.currentTarget.dataset.id
|
|
common.goPage(`/pages/projectDetails/projectDetails?id=${id}`)
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
wx.stopPullDownRefresh()
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
if (this.data.classify == 'school') this.renderComprehensiveList()
|
|
if (this.data.classify == 'subject') this.renderDisciplineList()
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
},
|
|
onShareTimeline() {
|
|
util.statistics({
|
|
name: "share-timeline"
|
|
})
|
|
return {
|
|
title: "【寄托港校项目库】- 榜单",
|
|
}
|
|
},
|
|
}) |