min-project/pages/projectComparison/projectComparison.js
2024-12-12 12:14:09 +08:00

358 lines
9.9 KiB
JavaScript

// pages/projectComparison/projectComparison.js
var miucms = require('../../utils/miucms.js');
let app = getApp()
const util = require('../../utils/util')
const common = require('../../utils/commonMethod')
Page({
/**
* 页面的初始数据
*/
data: {
projectState: "", // 项目弹窗的状态 '' replace add
screen_data: {},
totalTopHeight: 86,
islogin: false,
briefness: false, // 是否开启头部的简单模式
isquick: false, // 快速保存按钮显示
list: [],
projectList: [],
projectPage: 1,
stateObj: {
0: "待定",
1: "主申",
2: "冲刺",
3: "保底",
},
showObj: {},
loading: true,
isInitFinish: false,
},
/**
* 生命周期函数--监听页面加载
*/
ids: [],
onLoad(options) {
this.ids = options.ids.split(",") || [];
miucms.pageStart(app).then(() => {
const screen_data = app.globalData.screen_data
this.setData({
screen_data,
totalTopHeight: screen_data.totalTopHeight,
islogin: app.globalData.user.uid > 0 ? true : false,
isInitFinish: true,
})
if (!this.indexSidebar) this.indexSidebar = this.selectComponent('#index-sidebar')
common.xgBasicData(this, app).then(data => {
let obj = {}
const discipline = JSON.parse(JSON.stringify(data.discipline))
discipline.forEach(element => {
obj[element.value] = element.label
})
this.setData({
disciplineObj: obj,
})
this.initData()
})
})
},
initData() {
wx.showLoading({
title: '加载中...',
})
this.setData({
loading: true,
})
util.wxpost("/api/project.contrast", {
projectid: this.ids,
}).then(res => {
if (res.code != 200) return
const data = res.data
const list = data.data || []
let allArr = []
list.forEach(element => allArr.push(common.decodeKey(element)))
const obj = this.data.disciplineObj
// console.log("discipline", obj);
Promise.allSettled(allArr).then(res => {
console.log("res", res);
let list = []
res.forEach(element => list.push(element.status === "fulfilled" ? element.value : {}));
list.forEach(element => {
element['tuition_fee_text'] = common.formatNumberWithSpaces(element['tuition_fee'] || '')
element['admission_deposit_text'] = common.formatNumberWithSpaces(element['admission_deposit'] || '')
if (element.language_of_instruction) {
let strOutput = element.language_of_instruction.join(',');
element['language_of_instruction_text'] = strOutput
}
if (Array.isArray(element.english_proficiency)) {
const english = element.english_proficiency
let text = ""
english.forEach(element => {
text += `${element.name_zh}(${element.name_en}) ${element.total}分以上 \n`
})
element['english_proficiency_text'] = text
}
if (element.scholarship) element['scholarshipText'] = this.JudgmentScholarshipText(element.scholarship)
element['disciplinename'] = obj[element.disciplineid] || ''
})
console.log("list", list[0].disciplineid);
this.setData({
isquick: data.isquick,
list,
}, () => wx.nextTick(() => this.getAllItemHeight()))
}).catch(err => {
common.toast("出错了,请联系管理员。")
})
}).finally(() => {
wx.hideLoading()
this.setData({
loading: false,
})
})
},
// 判断奖学金文案
JudgmentScholarshipText(obj) {
let text = ""
if (obj.local && obj.nonlocal) text = '均有'
else if (!obj.local && !obj.nonlocal) text = '均无'
else if (obj.local && !obj.nonlocal) text = '非本地学生无'
else if (!obj.local && obj.nonlocal) text = '非本地学生有'
return text
},
getAllItemHeight() {
this.createSelectorQuery().selectAll(".lump .block").boundingClientRect(data => {
let showObj = {}
data.forEach(element => {
const type = element.dataset?.type
if (type != undefined && element.height > 200) {
showObj[type] = {
show: true,
unfold: true,
}
}
})
this.setData({
showObj
})
}).exec();
},
selectIndex: null, // 选中要替换或增加的 下标
// 点击 顶部的 增加 或者 替换 项目
handleProject(e) {
const type = e.currentTarget.dataset.type
const index = e.currentTarget.dataset.index
this.selectIndex = index
this.setData({
projectState: type,
projectList: [],
projectPage: 1,
})
this.getListData()
},
// 点击 关闭 项目弹窗
closeProject() {
this.setData({
projectState: ""
})
},
// 点击 选择项目
selectProject(e) {
const index = e.currentTarget.dataset.index
const type = this.data.projectState
const projectList = this.data.projectList
const target = projectList[index]
// 替换
if (type == 'replace') this.ids[this.selectIndex] = `${target.projectid}`
else this.ids.push(`${target.projectid}`) // 增加
this.initData()
this.setData({
projectState: "",
})
},
// 点击 删除项目
deleteProject(e) {
const index = e.currentTarget.dataset.index || 0
wx.showModal({
title: "确认删除?",
success: res => {
if (!res.confirm) return
this.ids.splice(index, 1); // 从指定下标删除一个元素
const list = this.data.list
list.splice(index, 1); // 从指定下标删除一个元素
this.setData({
list,
})
}
})
},
// 获取项目列表数据
loading: false,
getListData() {
if (this.data.projectPage == 0 || this.loading) return
this.loading = true
wx.showLoading({
title: '加载中...',
})
util.wxpost("/api/project.user", {
limit: 2000,
}).then(res => {
if (res.code != 200) return
const data = res.data
let list = data.data || []
const ids = this.ids
list = list.filter(obj => obj.status === 1 && !ids.includes(`${obj.projectid}`));
this.setData({
projectList: list,
projectPage: data.count > data.limit * data.page ? this.data.projectPage + 1 : 0,
})
}).finally(() => {
wx.hideLoading()
this.loading = false
})
},
// 点击保存
save() {
util.wxpost("/api/project.contrast/addQuick", {
projectid: this.ids
}).then(res => {
common.toast(res.message)
this.setData({
isquick: true,
})
app.globalData['isquickState'] = true
})
},
cutShow(e) {
const type = e.currentTarget.dataset.type
let showObj = this.data.showObj
showObj[type]['show'] = !showObj[type]['show']
this.setData({
showObj,
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
wx.stopPullDownRefresh()
this.initData()
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
// onShareAppMessage() {
// return {
// title: "【寄托港校项目库】 - 项目对比",
// }
// },
// onShareTimeline() {
// util.statistics({
// name: "share-timeline"
// })
// return {
// title: "【寄托港校项目库】 - 项目对比",
// }
// },
indexSidebar: null,
windowHeight: 812,
onPageScroll(e) {
const scrollTop = e.scrollTop
let briefness = true
if (scrollTop < 10) briefness = false
// 如果和 data 值 是一样的则 return
if (this.data.briefness == briefness) return
this.setData({
briefness
})
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()
},
})