index.js 9.1 KB

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