648 lines
17 KiB
JavaScript
648 lines
17 KiB
JavaScript
// pages/projectSchoolHomepage/projectSchoolHomepage.js
|
|
var miucms = require('../../utils/miucms.js');
|
|
const util = require('../../utils/util.js')
|
|
const common = require('../../utils/commonMethod')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
informationState: false, // 授权后可能需要弹出完成信息框 个人背景那些
|
|
islogin: false,
|
|
isloginBtnState: false,
|
|
|
|
current: 0,
|
|
territoryState: "", // 学科领域弹窗状态
|
|
|
|
// selectType: "", // '' subject school
|
|
id: 0,
|
|
|
|
briefShow: false, // 学校简介显示状态
|
|
|
|
selectState: false, // 排序选项 弹窗显示
|
|
|
|
screenkey: "all", // all subject school
|
|
|
|
screen: {
|
|
name: "",
|
|
key: "all", // all subject school
|
|
pitch: "all",
|
|
},
|
|
|
|
bezier: {},
|
|
|
|
hotList: [],
|
|
|
|
list: [],
|
|
page: 1,
|
|
count: 0,
|
|
|
|
briefHeight: 0, // 简介高度
|
|
|
|
contrastcount: 0,
|
|
|
|
discipline: [],
|
|
universitydepartment: [],
|
|
|
|
sortObj: {
|
|
0: "排名由高到低",
|
|
1: "学费由低到高",
|
|
2: "学费由高到低",
|
|
},
|
|
|
|
sortIndex: 0, // 排名由高到低 0 学费由低到高 1 学费由高到低 2
|
|
|
|
isInitFinish: false,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
rpx525: 262,
|
|
rpx15: 15,
|
|
windowWidth: 375,
|
|
options: {},
|
|
onLoad(options) {
|
|
this.rpx525 = util.rpxTopx(525)
|
|
this.options = options
|
|
// this.data.id = options.id
|
|
this.rpx15 = util.rpxTopx(15)
|
|
|
|
miucms.pageStart(app).then(() => {
|
|
const screen_data = app.globalData.screen_data
|
|
this.windowWidth = screen_data.windowWidth
|
|
this.windowHeight = screen_data.windowHeight || 812
|
|
|
|
this.setData({
|
|
islogin: app.globalData.user.uid > 0 ? true : false,
|
|
id: options.id
|
|
})
|
|
|
|
common.xgBasicData(this, app).then(data => {
|
|
this.setData({
|
|
contrastcount: data.contrastcount || 0,
|
|
})
|
|
})
|
|
|
|
this.getinit()
|
|
this.getProjectData()
|
|
})
|
|
},
|
|
|
|
getinit() {
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
})
|
|
util.wxget("/api/project.university/getInfo", {
|
|
id: this.data.id,
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
let hotList = data.hot_projects || []
|
|
hotList.forEach(element => {
|
|
element['random'] = app.randomString(6)
|
|
})
|
|
|
|
// 将一维数组转换成二维数组,每两个元素为一组
|
|
let twoDimensionalArray = [];
|
|
for (let i = 0; i < hotList.length; i += 2) {
|
|
twoDimensionalArray.push(hotList.slice(i, i + 2));
|
|
}
|
|
this.setData({
|
|
info: data.info,
|
|
hotList: twoDimensionalArray,
|
|
discipline: data.discipline,
|
|
universitydepartment: data.universitydepartment || [],
|
|
isInitFinish: true,
|
|
})
|
|
|
|
if (!this.indexSidebar) this.indexSidebar = this.selectComponent('#index-sidebar')
|
|
|
|
|
|
wx.nextTick(() => this.getBriefHeight())
|
|
}).finally(() => {
|
|
wx.hideLoading()
|
|
})
|
|
},
|
|
|
|
// 获取项目列表
|
|
loading: false,
|
|
listAll: [], // 所有的数据
|
|
screenList: [], // 当前筛选所有数据
|
|
|
|
getProjectData() {
|
|
const screen = this.data.screen
|
|
if (this.data.page == 0 || this.loading) return
|
|
this.loading = true
|
|
|
|
util.wxget("/api/project.lists", {
|
|
limit: 2000,
|
|
page: this.data.page,
|
|
sid: this.data.id,
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
|
|
let list = data.data || []
|
|
const date = new Date()
|
|
const month = date.getMonth() + 1
|
|
const year = date.getFullYear()
|
|
|
|
list.forEach(element => {
|
|
const semester = element.semester || {}
|
|
if (month > semester.month && year + 1 <= semester.year) element['semesterState'] = true
|
|
element['tuition_fee_text'] = common.formatNumberWithSpaces(element.tuition_fee)
|
|
element['random'] = app.randomString(6)
|
|
element['rankk'] = this.convertRankToRankText(element.rank)
|
|
})
|
|
|
|
this.listAll = list
|
|
this.screenList = list
|
|
this.setData({
|
|
count: data.count,
|
|
})
|
|
this.screenData()
|
|
}).finally(() => {
|
|
this.loading = false
|
|
})
|
|
},
|
|
|
|
convertRankToRankText(rank) {
|
|
if (!rank) return 0
|
|
if (rank.indexOf('-')) {
|
|
const range = rank.split('-');
|
|
const start = parseInt(range[0]) * 1;
|
|
const end = parseInt(range[1]) * 1;
|
|
return start || end || 0
|
|
} else return rank
|
|
},
|
|
|
|
// 在 screenList 数据截取要显示的数据
|
|
calculateShowList() {
|
|
const limit = 20
|
|
let screenList = this.screenList
|
|
let page = this.data.page
|
|
if (page == 0) return
|
|
const startIndex = (page - 1) * limit;
|
|
const endIndex = startIndex + limit;
|
|
let list = screenList.slice(startIndex, endIndex);
|
|
|
|
this.setData({
|
|
list: this.data.list.concat(list),
|
|
page: endIndex >= screenList.length ? 0 : page + 1,
|
|
})
|
|
},
|
|
|
|
// 筛选数据
|
|
screenData() {
|
|
const sort = this.data.sortIndex
|
|
let screen = this.data.screen
|
|
const disciplineid = screen['disciplineid']
|
|
const university = screen['university']
|
|
let listAll = this.listAll
|
|
|
|
screen['pitch'] = screen.key
|
|
|
|
let screenList = this.screenList
|
|
|
|
let list = []
|
|
if (disciplineid > 0) screenList = listAll.filter(item => item.disciplineid === disciplineid);
|
|
else if (university) screenList = listAll.filter(item => item.department === university);
|
|
else screenList = this.listAll
|
|
|
|
if (sort == 0) {
|
|
screenList.sort((a, b) => {
|
|
// a 排在后面
|
|
if (a.rankk == 0) return 1;
|
|
// b 排在后面
|
|
if (b.rankk == 0) return -1;
|
|
|
|
return a.rankk - b.rankk
|
|
});
|
|
} else if (sort == 1) {
|
|
// 按学费由低到高排序
|
|
screenList.sort((a, b) => {
|
|
if (a.tuition_fee == null) return 1;
|
|
if (b.tuition_fee == null) return -1;
|
|
return a.tuition_fee - b.tuition_fee
|
|
});
|
|
} else if (sort == 2) {
|
|
// 按学费由高到低排序
|
|
screenList.sort((a, b) => {
|
|
if (a.tuition_fee == null) return 1;
|
|
if (b.tuition_fee == null) return -1;
|
|
return b.tuition_fee - a.tuition_fee
|
|
});
|
|
}
|
|
|
|
this.screenList = screenList
|
|
|
|
this.setData({
|
|
screen,
|
|
list: [],
|
|
page: 1,
|
|
count: this.screenList.length,
|
|
})
|
|
|
|
this.calculateShowList()
|
|
},
|
|
|
|
// 选中 排序
|
|
screenIncident(e) {
|
|
const sort = e.currentTarget.dataset.sort
|
|
|
|
this.setData({
|
|
list: [],
|
|
page: 1,
|
|
sortIndex: sort,
|
|
selectState: false,
|
|
})
|
|
|
|
this.screenData()
|
|
},
|
|
|
|
// 获取简介的高度
|
|
getBriefHeight() {
|
|
const query = wx.createSelectorQuery();
|
|
query.select('#rich-text').boundingClientRect((rect) => {
|
|
let briefHeight = null
|
|
if (rect && rect.height) briefHeight = rect.height
|
|
|
|
this.setData({
|
|
briefHeight
|
|
})
|
|
}).exec();
|
|
},
|
|
|
|
// 切换简介显示
|
|
cutBriefShow() {
|
|
this.setData({
|
|
briefShow: !this.data.briefShow
|
|
})
|
|
},
|
|
|
|
// 计算当前所处的页面索引
|
|
hotscroll(e) {
|
|
if (Math.random() > 0.7) return; // 30% 的概率
|
|
const scrollLeft = e.detail.scrollLeft + this.rpx525 / 2
|
|
const current = Math.floor(scrollLeft / this.rpx525);
|
|
if (this.data.current == current) return;
|
|
if (current > this.data.hotList.length - 1) return
|
|
this.setData({
|
|
current
|
|
});
|
|
},
|
|
|
|
// 点击显示 筛选条件框
|
|
cutCondition() {
|
|
this.setData({
|
|
selectState: !this.data.selectState
|
|
})
|
|
},
|
|
|
|
// 物品的点击事件
|
|
handleClick(e) {
|
|
if (!this.data.islogin) {
|
|
this.openLoginBtnState()
|
|
return
|
|
}
|
|
const index = e.currentTarget.dataset.index
|
|
const i = e.currentTarget.dataset.i
|
|
const type = e.currentTarget.dataset.type
|
|
const status = e.currentTarget.dataset.status || 0
|
|
const id = e.currentTarget.dataset.id
|
|
const random = e.currentTarget.dataset.random
|
|
|
|
if (status == 1) return
|
|
|
|
const query = this.createSelectorQuery();
|
|
query.select('#add' + random).boundingClientRect();
|
|
// if (status == 1) return
|
|
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"
|
|
if (status == 1) url = "/api/project.contrast/delete"
|
|
|
|
util.wxpost(url, {
|
|
projectid: id
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
if (type === 'hot') {
|
|
const hotList = this.data.hotList
|
|
if (hotList[index][i]['contraststatus'] == null) hotList[index][i]['contraststatus'] = {}
|
|
hotList[index][i]['contraststatus'] = {
|
|
status: 1,
|
|
ismanage: 1,
|
|
}
|
|
this.setData({
|
|
hotList,
|
|
})
|
|
}
|
|
|
|
if (type === 'list') {
|
|
const list = this.data.list
|
|
if (list[index]['contraststatus'] == null) list[index]['contraststatus'] = {}
|
|
|
|
list[index]['contraststatus'] = {
|
|
status: 1,
|
|
ismanage: 1,
|
|
}
|
|
|
|
this.setData({
|
|
list,
|
|
})
|
|
}
|
|
|
|
this.setData({
|
|
contrastcount: data.count,
|
|
})
|
|
|
|
app.globalData.basicData['contrastcount'] = data.count
|
|
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: res.message,
|
|
})
|
|
})
|
|
},
|
|
|
|
// 打开筛选选择框
|
|
openselect() {
|
|
let screen = this.data.screen
|
|
screen['state'] = true
|
|
this.setData({
|
|
screen,
|
|
})
|
|
},
|
|
|
|
// 关闭筛选选择框
|
|
closeselect(e) {
|
|
const disciplineid = e.detail?.disciplineid || ''
|
|
const university = e.detail?.university || ''
|
|
const label = e.detail?.label || ''
|
|
|
|
let screen = this.data.screen
|
|
screen['state'] = false
|
|
|
|
// 没有选择
|
|
if (disciplineid == "" && university == "") {
|
|
screen['key'] = screen['pitch']
|
|
this.setData({
|
|
screen,
|
|
})
|
|
} else {
|
|
screen['disciplineid'] = disciplineid
|
|
screen['name'] = label || university
|
|
screen['university'] = university
|
|
|
|
this.setData({
|
|
screen,
|
|
list: [],
|
|
page: 1,
|
|
}, () => {
|
|
this.screenData()
|
|
})
|
|
}
|
|
},
|
|
|
|
// 点击选择 中间 的 筛选
|
|
selectScreen(e) {
|
|
const type = e.currentTarget.dataset.type
|
|
let screen = this.data.screen
|
|
|
|
screen['key'] = type
|
|
if (type == 'all') {
|
|
screen['disciplineid'] = ''
|
|
screen['universityid'] = ''
|
|
screen['list'] = []
|
|
this.setData({
|
|
screen,
|
|
list: [],
|
|
page: 1,
|
|
sortIndex: 0,
|
|
})
|
|
this.screenData()
|
|
return
|
|
}
|
|
|
|
if (type == 'subject') {
|
|
screen['list'] = this.data.discipline
|
|
screen['universityid'] = ''
|
|
} else if (type == 'school') {
|
|
screen['disciplineid'] = ''
|
|
screen['list'] = this.data.universitydepartment
|
|
}
|
|
|
|
screen['state'] = true
|
|
|
|
this.setData({
|
|
screen,
|
|
sortIndex: 1,
|
|
})
|
|
},
|
|
|
|
// 打开 授权按钮
|
|
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,
|
|
page: 1,
|
|
list: [],
|
|
})
|
|
this.onLoad(this.options)
|
|
},
|
|
|
|
// 子组件传值 修改 完善信息组件的状态
|
|
revampInformationState() {
|
|
this.setData({
|
|
informationState: false
|
|
})
|
|
},
|
|
|
|
// 点击跳转详情
|
|
goDetails(e) {
|
|
const uniqid = e.currentTarget.dataset.uniqid
|
|
common.goPage(`/pages/projectDetails/projectDetails?uniqid=${ uniqid }`)
|
|
},
|
|
|
|
closeMoreSelect() {
|
|
const list = this.data.list
|
|
list.forEach(element => {
|
|
element['moreState'] = false
|
|
})
|
|
this.setData({
|
|
list,
|
|
})
|
|
},
|
|
|
|
openMoreSelect(e) {
|
|
const index = e.currentTarget.dataset.index || 0
|
|
const list = this.data.list
|
|
list.forEach(element => {
|
|
element['moreState'] = false
|
|
})
|
|
list[index]['moreState'] = !list[index]['moreState']
|
|
this.setData({
|
|
list,
|
|
})
|
|
},
|
|
|
|
addProject(e) {
|
|
const index = e.currentTarget.dataset.index
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
let url = "/api/project.contrast/add"
|
|
|
|
util.wxpost(url, {
|
|
projectid: id
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
|
|
const list = this.data.list
|
|
|
|
if (list[index]['contraststatus'] == null) list[index]['contraststatus'] = {}
|
|
|
|
list[index]['contraststatus'] = {
|
|
status: 1,
|
|
ismanage: 1,
|
|
}
|
|
|
|
this.setData({
|
|
list,
|
|
contrastcount: data.count,
|
|
})
|
|
|
|
app.globalData.basicData['contrastcount'] = data.count
|
|
|
|
common.toast(res.message)
|
|
})
|
|
},
|
|
|
|
// 点击 跳转 公共方法
|
|
goPage(e) {
|
|
const url = e.currentTarget.dataset.url
|
|
common.goPage(url)
|
|
},
|
|
|
|
indexSidebar: null,
|
|
windowHeight: 812,
|
|
onPageScroll(e) {
|
|
const scrollTop = e.scrollTop
|
|
|
|
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()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
wx.stopPullDownRefresh()
|
|
|
|
this.setData({
|
|
info: {},
|
|
hotList: [],
|
|
page: 1,
|
|
list: [],
|
|
})
|
|
|
|
this.getinit()
|
|
this.getProjectData()
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
this.calculateShowList()
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
},
|
|
onShareTimeline() {
|
|
util.statistics({
|
|
name: "share-timeline"
|
|
})
|
|
|
|
return {
|
|
title: "【寄托港校项目库】- " + this.data.info.name,
|
|
}
|
|
},
|
|
}) |