index.js 9.2 KB

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