index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 + '&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. this.loadIndexData();
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function () {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function () {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. },
  190. strLen(s) {
  191. return (s ? s.length : 0)
  192. },
  193. loadVideoInfo: function (videos, personType) {
  194. let urls = urlDef.urls
  195. videos.forEach(v => {
  196. util.apiPost(urls.video_loadInfo + v.videoId).then((rs) => {
  197. v.imgUrl = rs.img
  198. v.playUrl = rs.url
  199. if (personType == 0) {
  200. this.setData({
  201. 'stuShowList': videos
  202. })
  203. }
  204. if (personType == 1) {
  205. this.setData({
  206. 'teaShowList': videos
  207. })
  208. }
  209. });
  210. });
  211. },
  212. queryVideoShow: function (personType) {
  213. const urls = urlDef.urls;
  214. //获取登录用户数据, 并加载首页数据
  215. util.apiPost(urls.person_video_list, {
  216. 'q.orgId': this.data.curStu.orgId,
  217. 'q.doPersonId': this.data.curStu.studentId,
  218. 'q.personType': personType,
  219. 'q.sortBy': 'rand',
  220. 'q.limit4': 'true'
  221. }).then(rs => {
  222. this.loadVideoInfo(rs, personType)
  223. })
  224. },
  225. queryStudentShow: function () {
  226. this.queryVideoShow(0)
  227. },
  228. queryTeacherShow: function () {
  229. this.queryVideoShow(1)
  230. },
  231. loadIndexData: function () {
  232. const urls = urlDef.urls;
  233. //获取登录用户数据, 并加载首页数据
  234. util.apiPost(urls.get_cur_user, {}).then(rs => {
  235. // console.log(JSON.stringify(rs));
  236. let userItems = rs.attr.others
  237. let orgItems = []
  238. let student = {}
  239. userItems.forEach(u => {
  240. let exists = false;
  241. orgItems.some(o => {
  242. if (o.orgId === u.orgId) {
  243. exists = true;
  244. return true;
  245. }
  246. })
  247. if (!exists) {
  248. orgItems.push({
  249. orgId: u.orgId,
  250. orgName: u.orgName
  251. })
  252. }
  253. if (u.id === rs.id) { // 当前用户
  254. const headImg = u.imageUrl ? urls.oss_file + 'image/' + u.imageUrl : '/images/head.png';
  255. student = {
  256. studentId: u.studentId,
  257. orgId: u.orgId,
  258. orgName: u.orgName,
  259. name: u.studentName,
  260. sex: u.sex,
  261. headImg: headImg
  262. }
  263. this.setData({
  264. 'curStu': student
  265. })
  266. // 放入 strong中
  267. wx.setStorageSync('student', student);
  268. }
  269. if (this.strLen(u.imageUrl) === 0) {
  270. u.imageUrl = '/images/head.png'
  271. } else {
  272. u.imageUrl = urls.oss_file + 'image/' + u.imageUrl
  273. }
  274. })
  275. this.setData({
  276. 'userItems': userItems,
  277. 'orgItems': orgItems
  278. })
  279. let personId = rs.attr.personId
  280. let orgId = rs.attr.orgId
  281. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  282. // banner 图片
  283. util.apiPost(urls.get_advert, {
  284. '&q.use': 1,
  285. 'q.orgId': orgId,
  286. 'q.exceptStatus': 2
  287. }).then(r => {
  288. // console.log('banner : ' + JSON.stringify(r));
  289. this.setData({
  290. 'bannerList': r
  291. })
  292. });
  293. // 今日课程
  294. util.apiPost(urls.leave_get_classes_date, {
  295. 'q.studentId': personId,
  296. 'q.attenceDate': today
  297. }).then(r => {
  298. // console.log('今日课程 : ' + JSON.stringify(r));
  299. this.setData({
  300. 'classList[0].num': (r ? r.length : 0)
  301. })
  302. })
  303. // 作业未提交
  304. util.apiPost(urls.my_homework, {
  305. 'q.studentId': personId,
  306. 'q.status': 0
  307. }).then(r => {
  308. // console.log('作业未提交 : ' + JSON.stringify(r));
  309. this.setData({
  310. 'classList[1].num': (r ? r.length : 0)
  311. })
  312. });
  313. // 出勤率
  314. util.apiPost(urls.get_attendance_rate, {
  315. 'q.studentId': personId
  316. }).then(r => {
  317. // console.log('出勤率 : ' + JSON.stringify(r));
  318. let attendRate = 0,
  319. alreadyCount = 0,
  320. shouldCount = 0;
  321. if (r != null) {
  322. r.forEach(it => {
  323. if (it.isAttend === '1') {
  324. alreadyCount = it.num
  325. } else if (it.isAttend === '0') {
  326. shouldCount = it.num
  327. }
  328. });
  329. }
  330. let t = (alreadyCount + shouldCount)
  331. if (t > 0) {
  332. attendRate = alreadyCount * 100 / t
  333. }
  334. this.setData({
  335. 'classList[2].num': attendRate.toFixed(2) + '%'
  336. })
  337. })
  338. this.queryVideoShow(0)
  339. this.queryVideoShow(1)
  340. });
  341. },
  342. doThumbsUp: function (o) {
  343. const urls = urlDef.urls;
  344. let pid = this.data.curStu.studentId;
  345. let pt = o.detail.personType;
  346. let vid = o.detail.videoId;
  347. let entity = {
  348. videoId: vid,
  349. personId: pid,
  350. personType: pt,
  351. actionType: 1
  352. };
  353. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  354. if (pt == 0) {
  355. this.data.stuShowList.map(o => {
  356. if (o.videoId == vid) {
  357. o.goodCount += 1
  358. }
  359. })
  360. this.setData({
  361. 'stuShowList': this.data.stuShowList
  362. })
  363. }
  364. if (pt == 1) {
  365. this.data.teaShowList.map(o => {
  366. if (o.videoId == vid) {
  367. o.goodCount += 1
  368. }
  369. })
  370. this.setData({
  371. 'teaShowList': this.data.teaShowList
  372. })
  373. }
  374. }).catch(e => {
  375. console.log(e);
  376. })
  377. }
  378. })