index.js 9.2 KB

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