index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. this.setData({
  240. 'stuShowList': [],
  241. 'teaShowList': [],
  242. })
  243. const urls = urlDef.urls;
  244. //获取登录用户数据, 并加载首页数据
  245. util.apiPost(urls.get_cur_user, {}).then(rs => {
  246. // console.log(JSON.stringify(rs));
  247. let userItems = rs.attr.others
  248. let orgItems = []
  249. let student = {}
  250. userItems.forEach(u => {
  251. let exists = false;
  252. orgItems.some(o => {
  253. if (o.orgId === u.orgId) {
  254. exists = true;
  255. return true;
  256. }
  257. })
  258. if (!exists) {
  259. orgItems.push({
  260. orgId: u.orgId,
  261. orgName: u.orgName
  262. })
  263. }
  264. if (u.studentId === rs.attr.personId) { // 当前用户
  265. const headImg = u.imageUrl ? urls.oss_file + 'image/' + u.imageUrl : '/images/head.png';
  266. student = {
  267. studentId: u.studentId,
  268. orgId: u.orgId,
  269. orgName: u.orgName,
  270. name: u.studentName,
  271. sex: u.sex,
  272. headImg: headImg
  273. }
  274. this.setData({
  275. 'curStu': student
  276. })
  277. // 放入 strong中
  278. wx.setStorageSync('student', student);
  279. }
  280. if (this.strLen(u.imageUrl) === 0) {
  281. u.imageUrl = '/images/head.png'
  282. } else {
  283. u.imageUrl = urls.oss_file + 'image/' + u.imageUrl
  284. }
  285. })
  286. this.setData({
  287. 'userItems': userItems,
  288. 'orgItems': orgItems
  289. })
  290. let personId = rs.attr.personId
  291. let orgId = rs.attr.orgId
  292. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  293. // banner 图片
  294. util.apiPost(urls.get_advert, {
  295. '&q.use': 1,
  296. 'q.orgId': orgId,
  297. 'q.exceptStatus': 2
  298. }).then(r => {
  299. // console.log('banner : ' + JSON.stringify(r));
  300. this.setData({
  301. 'bannerList': r
  302. })
  303. });
  304. // 今日课程
  305. util.apiPost(urls.leave_get_classes_date, {
  306. 'q.studentId': personId,
  307. 'q.attenceDate': today
  308. }).then(r => {
  309. // console.log('今日课程 : ' + JSON.stringify(r));
  310. let courseCount = 0
  311. if (r && r.length > 0) {
  312. courseCount = r[0].total;
  313. }
  314. this.setData({
  315. 'classList[0].num': courseCount
  316. })
  317. })
  318. // 作业未提交
  319. util.apiPost(urls.my_homework, {
  320. 'q.studentId': personId,
  321. 'q.status': 0
  322. }).then(r => {
  323. // console.log('作业未提交 : ' + JSON.stringify(r));
  324. this.setData({
  325. 'classList[1].num': (r ? r.length : 0)
  326. })
  327. });
  328. // 出勤率
  329. util.apiPost(urls.get_attendance_rate, {
  330. 'q.studentId': personId
  331. }).then(r => {
  332. // console.log('出勤率 : ' + JSON.stringify(r));
  333. let attendRate = 0,
  334. alreadyCount = 0,
  335. shouldCount = 0;
  336. if (r != null) {
  337. r.forEach(it => {
  338. if (it.isAttend === '1') {
  339. alreadyCount = it.num
  340. } else if (it.isAttend === '0') {
  341. shouldCount = it.num
  342. }
  343. });
  344. }
  345. let t = (alreadyCount + shouldCount)
  346. if (t > 0) {
  347. attendRate = alreadyCount * 100 / t
  348. }
  349. this.setData({
  350. 'classList[2].num': attendRate.toFixed(2) + '%'
  351. })
  352. })
  353. this.queryVideoShow(0)
  354. this.queryVideoShow(1)
  355. });
  356. },
  357. doThumbsUp: function (o) {
  358. const urls = urlDef.urls;
  359. let pid = this.data.curStu.studentId;
  360. let pt = o.detail.personType;
  361. let vid = o.detail.videoId;
  362. let entity = {
  363. videoId: vid,
  364. personId: pid,
  365. personType: pt,
  366. actionType: 1
  367. };
  368. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  369. if (pt == 0) {
  370. this.data.stuShowList.map(o => {
  371. if (o.videoId == vid) {
  372. o.goodCount += 1
  373. }
  374. })
  375. this.setData({
  376. 'stuShowList': this.data.stuShowList
  377. })
  378. }
  379. if (pt == 1) {
  380. this.data.teaShowList.map(o => {
  381. if (o.videoId == vid) {
  382. o.goodCount += 1
  383. }
  384. })
  385. this.setData({
  386. 'teaShowList': this.data.teaShowList
  387. })
  388. }
  389. }).catch(e => {
  390. console.log(e);
  391. })
  392. }
  393. })