515 lines
13 KiB
JavaScript
515 lines
13 KiB
JavaScript
// pages/subjectList/subjectList.js
|
|
var miucms = require('../../utils/miucms.js');
|
|
let app = getApp()
|
|
const util = require('../../utils/util')
|
|
const common = require('../../utils/commonMethod')
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
|
|
informationState: false, // 授权后可能需要弹出完成信息框 个人背景那些
|
|
islogin: false,
|
|
isloginBtnState: false,
|
|
|
|
contentHeight: 0,
|
|
sortState: false, // 排序显示状态
|
|
|
|
university: [],
|
|
sid: "", // 选中学校的值
|
|
|
|
discipline: {},
|
|
id: "",
|
|
|
|
list: [],
|
|
count: 0,
|
|
page: 1,
|
|
contrastcount: 0,
|
|
|
|
bezier: {},
|
|
|
|
sortObj: {
|
|
0: "排名由高到低",
|
|
1: "学费由低到高",
|
|
2: "学费由高到低",
|
|
},
|
|
|
|
sortIndex: 1,
|
|
|
|
territoryState: false,
|
|
isInitFinish: false,
|
|
user: {},
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
options: {},
|
|
rpx15: 15,
|
|
onLoad(options) {
|
|
this.options = options
|
|
miucms.pageStart(app).then(() => {
|
|
const screen_data = app.globalData.screen_data
|
|
const totalTopHeight = screen_data.totalTopHeight || 0
|
|
this.rpx15 = util.rpxTopx(15)
|
|
this.setData({
|
|
sid: options.sid || "",
|
|
islogin: app.globalData.user.uid > 0 ? true : false,
|
|
totalTopHeight,
|
|
isInitFinish: true,
|
|
bottomLift: screen_data.bottomLift,
|
|
contentHeight: totalTopHeight + util.rpxTopx(96),
|
|
id: options.id,
|
|
user: app.globalData.user,
|
|
})
|
|
|
|
if (!this.indexSidebar) this.indexSidebar = this.selectComponent('#index-sidebar')
|
|
|
|
this.windowHeight = screen_data.windowHeight || 812
|
|
|
|
common.xgBasicData(this, app).then(data => {
|
|
let university = JSON.parse(JSON.stringify(data.university)) || []
|
|
university.unshift({
|
|
label: "全部",
|
|
value: ""
|
|
})
|
|
const discipline = data.discipline || []
|
|
let obj = {}
|
|
discipline.forEach(element => {
|
|
obj[element.value] = element
|
|
})
|
|
this.setData({
|
|
contrastcount: data.contrastcount,
|
|
discipline: obj,
|
|
university,
|
|
})
|
|
})
|
|
this.getData()
|
|
})
|
|
},
|
|
|
|
// 获取数据
|
|
loading: false,
|
|
listAll: [], // 所有的数据
|
|
screenList: [], // 当前筛选所有数据
|
|
getData() {
|
|
if (this.data.page == 0 || this.loading) return
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
})
|
|
this.loading = true
|
|
|
|
util.wxget("https://api.gter.net/v1/program/getList", {
|
|
limit: 2000,
|
|
disciplineid: this.data.id,
|
|
sid: this.data.sid,
|
|
page: this.data.page,
|
|
}).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 = (list).map(element => ({
|
|
tuition_fee_text: common.formatNumberWithSpaces(element.tuition_fee),
|
|
...element,
|
|
rankk: convertRankToRankText(element.rank),
|
|
random: app.randomString(6),
|
|
// semesterState: month > element.semester.month && year + 1 <= element.semester.year,
|
|
semesterState: (year < element.semester.year) || (year === element.semester.year && month < element.semester.month)
|
|
}));
|
|
|
|
function 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 || 0
|
|
}
|
|
|
|
this.listAll = list
|
|
this.screenList = list
|
|
|
|
this.setData({
|
|
territoryState: false,
|
|
count: data.count,
|
|
})
|
|
|
|
this.screenData()
|
|
}).finally(() => {
|
|
wx.hideLoading()
|
|
this.loading = false
|
|
})
|
|
},
|
|
|
|
// 在 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 screenList = this.screenList
|
|
|
|
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({
|
|
list: [],
|
|
page: 1,
|
|
count: this.screenList.length,
|
|
})
|
|
|
|
this.calculateShowList()
|
|
},
|
|
|
|
cutSortState() {
|
|
this.setData({
|
|
sortState: !this.data.sortState
|
|
})
|
|
},
|
|
|
|
scrolltolower(e) {
|
|
const direction = e.detail.direction
|
|
if (direction != 'bottom') return
|
|
this.calculateShowList()
|
|
},
|
|
|
|
// 切换 学校
|
|
cutSchool(e) {
|
|
const sid = e.currentTarget.dataset.sid
|
|
this.setData({
|
|
sid,
|
|
page: 1,
|
|
list: [],
|
|
})
|
|
this.getData()
|
|
},
|
|
|
|
goPage(e) {
|
|
const url = e.currentTarget.dataset.url
|
|
common.goPage(url)
|
|
},
|
|
|
|
// 物品的点击事件
|
|
handleClick(e) {
|
|
if (!this.data.islogin) {
|
|
this.openLoginBtnState()
|
|
return
|
|
}
|
|
const index = e.currentTarget.dataset.index
|
|
const status = e.currentTarget.dataset.status || 0
|
|
const id = e.currentTarget.dataset.id
|
|
const random = e.currentTarget.dataset.random
|
|
|
|
const query = this.createSelectorQuery();
|
|
query.select('#add' + random).boundingClientRect();
|
|
|
|
// if (status == 0) {
|
|
this.setData({
|
|
bezier: {},
|
|
})
|
|
query.exec((res) => {
|
|
const data = res[0]
|
|
// console.log("data", data);
|
|
this.setData({
|
|
bezier: {
|
|
x: data.left + data.width / 2 - this.rpx15,
|
|
y: data.top + data.height / 2 - this.rpx15,
|
|
}
|
|
})
|
|
});
|
|
// }
|
|
|
|
let url = "https://api.gter.net/v1/program/addContrast"
|
|
if (status == 1) url = "https://api.gter.net/v1/program/deleteContrast"
|
|
|
|
util.wxpost(url, {
|
|
projectid: id
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
|
|
const list = this.data.list
|
|
list[index]['contraststatus'] = {
|
|
ismanage: 1,
|
|
status: 1,
|
|
}
|
|
|
|
this.setData({
|
|
list,
|
|
contrastcount: data.count,
|
|
})
|
|
|
|
app.globalData.basicData['contrastcount'] = data.count
|
|
|
|
common.toast(res.message)
|
|
})
|
|
},
|
|
|
|
// 选中 排序
|
|
screenIncident(e) {
|
|
const sort = e.currentTarget.dataset.sort
|
|
|
|
this.setData({
|
|
list: [],
|
|
page: 1,
|
|
sortIndex: sort,
|
|
sortState: false,
|
|
})
|
|
|
|
this.screenData()
|
|
},
|
|
|
|
openTerritory() {
|
|
this.setData({
|
|
territoryState: true,
|
|
})
|
|
},
|
|
|
|
closeselect(e) {
|
|
const id = e.detail?.university
|
|
if (!id) {
|
|
this.setData({
|
|
territoryState: false,
|
|
})
|
|
|
|
return
|
|
}
|
|
this.setData({
|
|
id,
|
|
list: [],
|
|
page: 1,
|
|
})
|
|
|
|
this.getData()
|
|
},
|
|
|
|
openMoreSelect(e) {
|
|
const index = e.currentTarget.dataset.index || 0
|
|
|
|
let list = this.data.list
|
|
list.forEach(element => {
|
|
element['moreState'] = false
|
|
})
|
|
|
|
list[index]['moreState'] = true
|
|
|
|
this.setData({
|
|
list,
|
|
})
|
|
},
|
|
|
|
closeMoreSelect(e) {
|
|
const list = this.data.list
|
|
list.forEach(element => {
|
|
element['moreState'] = false
|
|
})
|
|
|
|
this.setData({
|
|
list,
|
|
})
|
|
},
|
|
|
|
addProject(e) {
|
|
const index = e.currentTarget.dataset.index
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
util.wxpost("https://api.gter.net/v1/program/addContrast", {
|
|
projectid: id
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
|
|
let 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)
|
|
})
|
|
},
|
|
|
|
|
|
// 打开 授权按钮
|
|
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
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
wx.stopPullDownRefresh()
|
|
|
|
this.setData({
|
|
page: 1,
|
|
list: [],
|
|
})
|
|
|
|
this.getData()
|
|
|
|
},
|
|
|
|
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()
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
this.calculateShowList()
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
return {
|
|
title: "【寄托港校项目库】 - 学科",
|
|
path: `/pages/projectSubjectList/projectSubjectList?id=${ this.data.id }&sid=${ this.data.sid }`
|
|
}
|
|
},
|
|
|
|
onShareTimeline() {
|
|
return {
|
|
title: "【寄托港校项目库】 - 学科",
|
|
path: `/pages/projectSubjectList/projectSubjectList?id=${ this.data.id }&sid=${ this.data.sid }`,
|
|
}
|
|
},
|
|
}) |