|
@@ -9,34 +9,12 @@ 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,
|
|
|
+ curStu: {},
|
|
|
classList: [
|
|
|
- { img: '/images/kc.png', title: '今日课程', num: '1' },
|
|
|
- { img: '/images/jtzy.png', title: '今日作业', num: '6' },
|
|
|
- { img: '/images/cq.png', title: '出勤率', num: '100%' },
|
|
|
+ { img: '/images/kc.png', title: '今日课程', num: '0' },
|
|
|
+ { img: '/images/jtzy.png', title: '今日作业', num: '0' },
|
|
|
+ { img: '/images/cq.png', title: '出勤率', num: '0%' },
|
|
|
],
|
|
|
appList: [
|
|
|
{ img: '/images/kb.png', title: '我的课表' },
|
|
@@ -50,25 +28,61 @@ Page({
|
|
|
],
|
|
|
bannerList: [],
|
|
|
userList: [],
|
|
|
+ userItems: [],
|
|
|
+ orgItems: [],
|
|
|
},
|
|
|
|
|
|
//切换身份
|
|
|
changeStu: function (e) {
|
|
|
let sid = e.currentTarget.dataset.id;
|
|
|
- console.log('切换用户 : ' + sid);
|
|
|
- if (this.data.curStu == sid) {
|
|
|
+ this.doChangeUser(sid);
|
|
|
+ },
|
|
|
+ doChangeUser: function (sid) {
|
|
|
+ if (this.data.curStu.studentId == sid) {
|
|
|
+ console.log('无须切换')
|
|
|
return;
|
|
|
}
|
|
|
- this.setData({
|
|
|
- curStu: sid
|
|
|
+ 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) {
|
|
|
- this.setData({
|
|
|
- index: e.detail.value
|
|
|
- })
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -126,33 +140,40 @@ Page({
|
|
|
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 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;
|
|
|
+ // 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 {
|
|
|
- o.imageUrl = '/images/head.png';
|
|
|
+ u.imageUrl = urls.oss_file + 'image/' + u.imageUrl;
|
|
|
}
|
|
|
- })
|
|
|
- this.setData({ 'userList': userList });
|
|
|
+ });
|
|
|
+
|
|
|
+ this.setData({ 'userItems': userItems, 'orgItems': orgItems });
|
|
|
|
|
|
|
|
|
- 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, '-');
|