// pages/index/index.js const app = getApp() const util = require("../../utils/util") const urlDef = require("../../utils/urls") Page({ /** * 页面的初始数据 */ data: { array: ['艾克斯郎校区1', '艾克斯郎校区2', '艾克斯郎校区3', '艾克斯郎校区4'], objectArray: [ { id: 0, name: '艾克斯郎校区1' }, { id: 1, name: '艾克斯郎校区2' }, { id: 2, name: '艾克斯郎校区3' }, { id: 3, name: '艾克斯郎校区4' } ], index: 0, stuList: [ { id: 0 }, { id: 1 } ], curStu: 0, classList: [ { img: '/images/kc.png', title: '今日课程', num: '1' }, { img: '/images/jtzy.png', title: '今日作业', num: '6' }, { img: '/images/cq.png', title: '出勤率', num: '100%' }, ], appList: [ { img: '/images/kb.png', title: '我的课表' }, { img: '/images/zy.png', title: '提交作业' }, { img: '/images/dp.png', title: '课堂点评' }, { img: '/images/zj.png', title: '成长足迹' }, { img: '/images/qj.png', title: '请假' }, { img: '/images/bk.png', title: '补课' }, { img: '/images/jk.png', title: '加课' }, { img: '/images/dk.png', title: '调课' }, ], bannerList: [], userList: [], }, //切换身份 changeStu: function (e) { let sid = e.currentTarget.dataset.id; console.log('切换用户 : ' + sid); if (this.data.curStu == sid) { return; } this.setData({ curStu: sid }) }, //切换校区 bindPickerChange: function (e) { this.setData({ index: e.detail.value }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.loadIndexData(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, loadIndexData: function () { const urls = urlDef.urls; //获取登录用户数据, 并加载首页数据 util.apiPost(urls.get_cur_user, {}).then(rs => { console.log(JSON.stringify(rs)); let curUser = rs.attr; curUser.studentId = curUser.personId; // 新增studentId属性 let otherUsers = rs.attr.others.filter(o => { return o.studentId != curUser.studentId }); curUser.others = [];// 清除 others 属性 console.log('其他用户 : ' + JSON.stringify(otherUsers)); this.setData({ 'curStu': curUser.studentId }); let userList = [curUser].concat(otherUsers); userList.map(o => { if (o.imageUrl && o.imageUrl.length > 0) { o.imageUrl = urls.oss_file + 'image/'+ o.imageUrl; } else { o.imageUrl = '/images/head.png'; } }) this.setData({ 'userList': userList }); console.log('userList ' + JSON.stringify(this.data.userList)); let personId = rs.attr.personId; let orgId = rs.attr.orgId; let today = util.curTime().substring(0, 10).replace(/\//g, '-'); // banner 图片 util.apiPost(urls.get_advert, { '&q.use': 1, 'q.orgId': orgId, 'q.exceptStatus': 2 }).then(r => { // console.log('banner : ' + JSON.stringify(r)); this.setData({ 'bannerList': r }); }); // 今日课程 util.apiPost(urls.leave_get_classes_date, { 'q.studentId': personId, 'q.attenceDate': today }).then(r => { // console.log('今日课程 : ' + JSON.stringify(r)); this.setData({ 'classList[0].num': (r ? r.length : 0) }); }) // 作业未提交 util.apiPost(urls.my_homework, { 'q.studentId': personId, 'q.status': 0 }).then(r => { // console.log('作业未提交 : ' + JSON.stringify(r)); this.setData({ 'classList[1].num': (r ? r.length : 0) }); }); // 出勤率 util.apiPost(urls.get_attendance_rate, { 'q.studentId': personId }).then(r => { console.log('出勤率 : ' + JSON.stringify(r)); let attendRate = 0, alreadyCount = 0, shouldCount = 0; if (r != null) { r.forEach(it => { if (it.isAttend === '1') { alreadyCount = it.num; } else if (it.isAttend === '0') { shouldCount = it.num; } }); } let t = (alreadyCount + shouldCount); if (t > 0) { attendRate = alreadyCount * 100 / t; } console.log(attendRate) this.setData({ 'classList[2].num': attendRate.toFixed(2) + '%' }); }) }); } })