index.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. // pages/index/index.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. isShow: true,
  11. array: ['艾克斯郎校区1', '艾克斯郎校区2', '艾克斯郎校区3', '艾克斯郎校区4'],
  12. index: 0,
  13. curStu: {},
  14. classList: [{
  15. img: '/images/kc.png',
  16. title: '今日课程',
  17. num: '0',
  18. url: "/pages/schedule/schedule"
  19. },
  20. {
  21. img: '/images/jtzy.png',
  22. title: '今日作业',
  23. num: '0',
  24. url: "/pages/task/task"
  25. },
  26. {
  27. img: '/images/cq.png',
  28. title: '出勤率',
  29. num: '0%',
  30. url: "/pages/classTotalList/classTotalList"
  31. },
  32. ],
  33. appList: [{
  34. img: '/images/kb.png',
  35. title: '我的课表',
  36. url: "/pages/schedule/schedule"
  37. },
  38. {
  39. img: '/images/zy.png',
  40. title: '提交作业',
  41. url: "/pages/task/task"
  42. },
  43. {
  44. img: '/images/dp.png',
  45. title: '课堂点评',
  46. url: "/pages/evaluation/evaluation"
  47. },
  48. {
  49. img: '/images/zj.png',
  50. title: '成长足迹',
  51. url: "/pages/growUp/growUp"
  52. },
  53. {
  54. img: '/images/qj.png',
  55. title: '请假',
  56. url: "/pages/leave/leave"
  57. },
  58. {
  59. img: '/images/bk.png',
  60. title: '补课',
  61. url: "/pages/lessons/lessons"
  62. },
  63. {
  64. img: '/images/jk.png',
  65. title: '加课',
  66. url: "/pages/addClass/addClass"
  67. },
  68. {
  69. img: '/images/dk.png',
  70. title: '调课',
  71. url: "/pages/theClasses/theClasses"
  72. },
  73. ],
  74. bannerList: [],
  75. userList: [],
  76. userItems: [],
  77. orgItems: [],
  78. stuShowList: [],
  79. teaShowList: [],
  80. },
  81. //切换身份
  82. changeStu: function (e) {
  83. let sid = e.currentTarget.dataset.id;
  84. this.doChangeUser(sid);
  85. },
  86. doChangeUser: function (sid) {
  87. if (this.data.curStu.studentId == sid) {
  88. console.log('无须切换')
  89. return;
  90. }
  91. wx.showLoading({
  92. title: '正在切换用户',
  93. mask: true
  94. })
  95. console.log('切换用户 : ' + sid);
  96. const urls = urlDef.urls;
  97. util.apiPost(urls.change_user, {
  98. targetId: sid
  99. }).then(rs => {
  100. wx.hideLoading();
  101. if (rs === 1) {
  102. console.log('切换成功');
  103. this.loadIndexData();
  104. } else {
  105. wx.showToast({
  106. title: '切换失败,请稍后重试',
  107. icon: 'none'
  108. })
  109. }
  110. });
  111. },
  112. //切换校区
  113. bindPickerChange: function (e) {
  114. let i = e.detail.value;
  115. if (i == this.data.index) {
  116. console.log('无须切换...');
  117. return;
  118. }
  119. // 取该校区 第1位学生 作为默认登录用户
  120. let targetId = this.data.orgItems[i].orgId;
  121. console.log('切换校区 ' + targetId);
  122. this.data.userItems.some(u => {
  123. if (u.orgId === targetId) {
  124. this.doChangeUser(u.studentId);
  125. this.setData({
  126. index: i
  127. });
  128. return true;
  129. }
  130. });
  131. },
  132. toPage: function (e) {
  133. if (typeof e.currentTarget.dataset.url == 'undefined') {
  134. return
  135. }
  136. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  137. wx.navigateTo({
  138. url: e.currentTarget.dataset.url + '?beginDate=' + (today.substring(0, 5) + '01-01') + '&endDate=' + today,
  139. })
  140. },
  141. getMoreShow: function (e) {
  142. wx.navigateTo({
  143. url: '/pages/showVideoList/showVideoList?personType=' + e.currentTarget.dataset.type,
  144. })
  145. },
  146. /**
  147. * 生命周期函数--监听页面加载
  148. */
  149. onLoad: function (options) {
  150. this.setData({
  151. isShow: wx.getStorageSync('isShow')
  152. })
  153. },
  154. /**
  155. * 生命周期函数--监听页面初次渲染完成
  156. */
  157. onReady: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面显示
  161. */
  162. onShow: function () {
  163. if(!wx.getStorageSync('openId')){
  164. wx.redirectTo({
  165. url: '/pages/login/login',
  166. })
  167. return
  168. } else {
  169. this.loadIndexData();
  170. }
  171. },
  172. /**
  173. * 生命周期函数--监听页面隐藏
  174. */
  175. onHide: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面卸载
  179. */
  180. onUnload: function () {
  181. },
  182. /**
  183. * 页面相关事件处理函数--监听用户下拉动作
  184. */
  185. onPullDownRefresh: function () {
  186. },
  187. /**
  188. * 页面上拉触底事件的处理函数
  189. */
  190. onReachBottom: function () {
  191. },
  192. /**
  193. * 用户点击右上角分享
  194. */
  195. onShareAppMessage: function () {
  196. },
  197. strLen(s) {
  198. return (s ? s.length : 0)
  199. },
  200. loadVideoInfo: function (videos, personType) {
  201. let urls = urlDef.urls
  202. videos.forEach(v => {
  203. util.apiPost(urls.video_loadInfo + v.videoId).then((rs) => {
  204. v.imgUrl = rs.img
  205. v.playUrl = rs.url
  206. if (personType == 0) {
  207. this.setData({
  208. 'stuShowList': videos
  209. })
  210. }
  211. if (personType == 1) {
  212. this.setData({
  213. 'teaShowList': videos
  214. })
  215. }
  216. });
  217. });
  218. },
  219. queryVideoShow: function (personType) {
  220. const urls = urlDef.urls;
  221. //获取登录用户数据, 并加载首页数据
  222. util.apiPost(urls.person_video_list, {
  223. 'q.orgId': this.data.curStu.orgId,
  224. 'q.doPersonId': this.data.curStu.studentId,
  225. 'q.personType': personType,
  226. 'q.sortBy': 'rand',
  227. 'q.limit4': 'true'
  228. }).then(rs => {
  229. this.loadVideoInfo(rs, personType)
  230. })
  231. },
  232. queryStudentShow: function () {
  233. this.queryVideoShow(0)
  234. },
  235. queryTeacherShow: function () {
  236. this.queryVideoShow(1)
  237. },
  238. loadIndexData: function () {
  239. const urls = urlDef.urls;
  240. //获取登录用户数据, 并加载首页数据
  241. util.apiPost(urls.get_cur_user, {}).then(rs => {
  242. // console.log(JSON.stringify(rs));
  243. let userItems = rs.attr.others
  244. let orgItems = []
  245. let student = {}
  246. userItems.forEach(u => {
  247. let exists = false;
  248. orgItems.some(o => {
  249. if (o.orgId === u.orgId) {
  250. exists = true;
  251. return true;
  252. }
  253. })
  254. if (!exists) {
  255. orgItems.push({
  256. orgId: u.orgId,
  257. orgName: u.orgName
  258. })
  259. }
  260. if (u.id === rs.id) { // 当前用户
  261. const headImg = u.imageUrl ? urls.oss_file + 'image/' + u.imageUrl : '/images/head.png';
  262. student = {
  263. studentId: u.studentId,
  264. orgId: u.orgId,
  265. orgName: u.orgName,
  266. name: u.studentName,
  267. sex: u.sex,
  268. headImg: headImg
  269. }
  270. this.setData({
  271. 'curStu': student
  272. })
  273. // 放入 strong中
  274. wx.setStorageSync('student', student);
  275. }
  276. if (this.strLen(u.imageUrl) === 0) {
  277. u.imageUrl = '/images/head.png'
  278. } else {
  279. u.imageUrl = urls.oss_file + 'image/' + u.imageUrl
  280. }
  281. })
  282. this.setData({
  283. 'userItems': userItems,
  284. 'orgItems': orgItems
  285. })
  286. let personId = rs.attr.personId
  287. let orgId = rs.attr.orgId
  288. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  289. // banner 图片
  290. util.apiPost(urls.get_advert, {
  291. '&q.use': 1,
  292. 'q.orgId': orgId,
  293. 'q.exceptStatus': 2
  294. }).then(r => {
  295. // console.log('banner : ' + JSON.stringify(r));
  296. this.setData({
  297. 'bannerList': r
  298. })
  299. });
  300. // 今日课程
  301. util.apiPost(urls.leave_get_classes_date, {
  302. 'q.studentId': personId,
  303. 'q.attenceDate': today
  304. }).then(r => {
  305. // console.log('今日课程 : ' + JSON.stringify(r));
  306. let courseCount = 0
  307. if (r && r.length > 0) {
  308. courseCount = r[0].total;
  309. }
  310. this.setData({
  311. 'classList[0].num': courseCount
  312. })
  313. })
  314. // 作业未提交
  315. util.apiPost(urls.my_homework, {
  316. 'q.studentId': personId,
  317. 'q.status': 0
  318. }).then(r => {
  319. // console.log('作业未提交 : ' + JSON.stringify(r));
  320. this.setData({
  321. 'classList[1].num': (r ? r.length : 0)
  322. })
  323. });
  324. // 出勤率
  325. util.apiPost(urls.get_attendance_rate, {
  326. 'q.studentId': personId
  327. }).then(r => {
  328. // console.log('出勤率 : ' + JSON.stringify(r));
  329. let attendRate = 0,
  330. alreadyCount = 0,
  331. shouldCount = 0;
  332. if (r != null) {
  333. r.forEach(it => {
  334. if (it.isAttend === '1') {
  335. alreadyCount = it.num
  336. } else if (it.isAttend === '0') {
  337. shouldCount = it.num
  338. }
  339. });
  340. }
  341. let t = (alreadyCount + shouldCount)
  342. if (t > 0) {
  343. attendRate = alreadyCount * 100 / t
  344. }
  345. this.setData({
  346. 'classList[2].num': attendRate.toFixed(2) + '%'
  347. })
  348. })
  349. this.queryVideoShow(0)
  350. this.queryVideoShow(1)
  351. });
  352. },
  353. doThumbsUp: function (o) {
  354. const urls = urlDef.urls;
  355. let pid = this.data.curStu.studentId;
  356. let pt = o.detail.personType;
  357. let vid = o.detail.videoId;
  358. let entity = {
  359. videoId: vid,
  360. personId: pid,
  361. personType: pt,
  362. actionType: 1
  363. };
  364. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  365. if (pt == 0) {
  366. this.data.stuShowList.map(o => {
  367. if (o.videoId == vid) {
  368. o.goodCount += 1
  369. }
  370. })
  371. this.setData({
  372. 'stuShowList': this.data.stuShowList
  373. })
  374. }
  375. if (pt == 1) {
  376. this.data.teaShowList.map(o => {
  377. if (o.videoId == vid) {
  378. o.goodCount += 1
  379. }
  380. })
  381. this.setData({
  382. 'teaShowList': this.data.teaShowList
  383. })
  384. }
  385. }).catch(e => {
  386. console.log(e);
  387. })
  388. }
  389. })