123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- // pages/index/index.js
- const app = getApp()
- const util = require("../../utils/util")
- const urlDef = require("../../utils/urls")
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- array: ['艾克斯郎校区1', '艾克斯郎校区2', '艾克斯郎校区3', '艾克斯郎校区4'],
- index: 0,
- curStu: {},
- classList: [
- { img: '/images/kc.png', title: '今日课程', num: '0', url:"/pages/schedule/schedule" },
- { img: '/images/jtzy.png', title: '今日作业', num: '0' },
- { img: '/images/cq.png', title: '出勤率', num: '0%' },
- ],
- appList: [
- { img: '/images/kb.png', title: '我的课表',url:"/pages/schedule/schedule" },
- { img: '/images/zy.png', title: '提交作业',url:"/pages/task/task" },
- { img: '/images/dp.png', title: '课堂点评' },
- { img: '/images/zj.png', title: '成长足迹' },
- { img: '/images/qj.png', title: '请假',url:"/pages/leave/leave" },
- { img: '/images/bk.png', title: '补课',url:"/pages/lessons/lessons" },
- { img: '/images/jk.png', title: '加课' },
- { img: '/images/dk.png', title: '调课' },
- ],
- bannerList: [],
- userList: [],
- userItems: [],
- orgItems: [],
- },
- //切换身份
- changeStu: function (e) {
- let sid = e.currentTarget.dataset.id;
- this.doChangeUser(sid);
- },
- doChangeUser: function (sid) {
- if (this.data.curStu.studentId == sid) {
- console.log('无须切换')
- return;
- }
- wx.showLoading({
- title: '正在切换用户',
- mask: true
- })
- console.log('切换用户 : ' + sid);
- const urls = urlDef.urls;
- util.apiPost(urls.change_user, { targetId: sid }).then(rs => {
- wx.hideLoading();
- if (rs === 1) {
- console.log('切换成功');
- this.loadIndexData();
- } else {
- wx.showToast({
- title: '切换失败,请稍后重试',
- icon: 'none'
- })
- }
- });
- },
- //切换校区
- bindPickerChange: function (e) {
- let i = e.detail.value;
- if (i == this.data.index) {
- console.log('无须切换...');
- return;
- }
- // 取该校区 第1位学生 作为默认登录用户
- let targetId = this.data.orgItems[i].orgId;
- console.log('切换校区 ' + targetId);
- this.data.userItems.some(u => {
- console.log('用户: ' + JSON.stringify(u));
- if (u.orgId === targetId) {
- this.doChangeUser(u.studentId);
- this.setData({
- index: i
- });
- return true;
- }
- });
- },
- toPage:function(e){
- wx.navigateTo({
- url: e.currentTarget.dataset.url,
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.loadIndexData();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- strLen(s) {
- return (s ? s.length : 0);
- },
- loadIndexData: function () {
- const urls = urlDef.urls;
- //获取登录用户数据, 并加载首页数据
- util.apiPost(urls.get_cur_user, {}).then(rs => {
- // console.log(JSON.stringify(rs));
- let userItems = rs.attr.others;
- let orgItems = [];
- userItems.forEach(u => {
- let exists = false;
- orgItems.some(o => {
- if (o.orgId === u.orgId) {
- exists = true;
- return true;
- }
- });
- if (!exists) {
- orgItems.push({ orgId: u.orgId, orgName: u.orgName });
- }
- if (u.id === rs.id) { // 当前用户
- this.setData({ 'curStu': { studentId: u.studentId, orgId: u.orgId } });
- }
- if (this.strLen(u.imageUrl) === 0) {
- u.imageUrl = '/images/head.png';
- } else {
- u.imageUrl = urls.oss_file + 'image/' + u.imageUrl;
- }
- });
- this.setData({ 'userItems': userItems, 'orgItems': orgItems });
- 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) + '%' });
- })
- });
- }
- })
|