index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. // pages/index/index.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. quanList: [],
  12. quanTipFlag: false,
  13. isShow: true,
  14. array: ['艾克斯郎校区1', '艾克斯郎校区2', '艾克斯郎校区3', '艾克斯郎校区4'],
  15. index: 0,
  16. curStu: {},
  17. classList: [{
  18. img: '/images/kc.png',
  19. title: '今日课程',
  20. num: '0',
  21. url: "/pages/schedule/schedule"
  22. },
  23. {
  24. img: '/images/jtzy.png',
  25. title: '今日作业',
  26. num: '0',
  27. url: "/pages/task/task"
  28. },
  29. {
  30. img: '/images/cq.png',
  31. title: '出勤率',
  32. num: '0%',
  33. url: "/pages/classTotalList/classTotalList"
  34. },
  35. ],
  36. appList: [{
  37. img: '/images/kb.png',
  38. title: '我的课表',
  39. url: "/pages/schedule/schedule",
  40. },
  41. {
  42. img: '/images/zy.png',
  43. title: '提交作业',
  44. url: "/pages/task/task",
  45. },
  46. {
  47. img: '/images/dp.png',
  48. title: '课堂点评',
  49. url: "/pages/evaluation/evaluation"
  50. },
  51. {
  52. img: '/images/zj.png',
  53. title: '成长足迹',
  54. url: "/pages/growUp/growUp"
  55. },
  56. {
  57. img: '/images/qj.png',
  58. title: '请假',
  59. url: "/pages/leave/leave"
  60. },
  61. {
  62. img: '/images/bk.png',
  63. title: '补课',
  64. url: "/pages/lessons/lessons"
  65. },
  66. {
  67. img: '/images/jk.png',
  68. title: '加课',
  69. url: "/pages/addClass/addClass"
  70. },
  71. {
  72. img: '/images/dk.png',
  73. title: '调课',
  74. url: "/pages/theClasses/theClasses"
  75. },
  76. ],
  77. bannerList: [],
  78. userList: [],
  79. userItems: [],
  80. orgItems: [],
  81. stuShowList: [],
  82. teaShowList: [],
  83. },
  84. queryQuan: function () {
  85. const urls = urlDef.urls;
  86. let stu = wx.getStorageSync('student');
  87. if (stu) {
  88. let params = { 'q.studentId': stu.studentId, 'q.orgId': stu.orgId }
  89. let url = null;
  90. url = urls.coupon_receive_list;
  91. params.pageNum = 9999
  92. util.apiPost(url, params).then(rs => {
  93. let quanList = rs.list
  94. for(var i in quanList){
  95. quanList[i].lastDate = quanList[i].endDate.substring(0,10)
  96. }
  97. this.setData({
  98. quanList
  99. })
  100. if(quanList.length > 0 ) {
  101. const indexQuanTip = wx.getStorageSync('indexQuanTip')
  102. if(indexQuanTip){
  103. this.setData({
  104. quanTipFlag: true
  105. })
  106. wx.setStorageSync('indexQuanTip', false)
  107. }
  108. }
  109. })
  110. }
  111. },
  112. //切换身份
  113. changeStu: function (e) {
  114. let sid = e.currentTarget.dataset.id;
  115. this.doChangeUser(sid);
  116. },
  117. doChangeUser: function (sid) {
  118. if (this.data.curStu.studentId == sid) {
  119. console.log('无须切换')
  120. return;
  121. }
  122. wx.showLoading({
  123. title: '正在切换用户',
  124. mask: true
  125. })
  126. console.log('切换用户 : ' + sid);
  127. const urls = urlDef.urls;
  128. util.apiPost(urls.change_user, {
  129. targetId: sid
  130. }).then(rs => {
  131. wx.hideLoading();
  132. if (rs === 1) {
  133. console.log('切换成功');
  134. this.loadIndexData();
  135. } else {
  136. wx.showToast({
  137. title: '切换失败,请稍后重试',
  138. icon: 'none'
  139. })
  140. }
  141. });
  142. },
  143. //切换校区
  144. bindPickerChange: function (e) {
  145. let i = e.detail.value;
  146. if (i == this.data.index) {
  147. console.log('无须切换...');
  148. return;
  149. }
  150. // 取该校区 第1位学生 作为默认登录用户
  151. let targetId = this.data.orgItems[i].orgId;
  152. console.log('切换校区 ' + targetId);
  153. this.data.userItems.some(u => {
  154. if (u.orgId === targetId) {
  155. this.doChangeUser(u.studentId);
  156. this.setData({
  157. index: i
  158. });
  159. return true;
  160. }
  161. });
  162. },
  163. toPage: function (e) {
  164. if (typeof e.currentTarget.dataset.url == 'undefined') {
  165. return
  166. }
  167. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  168. wx.navigateTo({
  169. url: e.currentTarget.dataset.url + '?beginDate=' + (today.substring(0, 5) + '01-01') + '&endDate=' + today,
  170. })
  171. },
  172. getMoreShow: function (e) {
  173. wx.navigateTo({
  174. url: '/pages/showVideoList/showVideoList?personType=' + e.currentTarget.dataset.type,
  175. })
  176. },
  177. closeTip:function(){
  178. this.setData({
  179. quanTipFlag:false
  180. })
  181. },
  182. toQuan:function(){
  183. wx.navigateTo({
  184. url: '/pages/quan/quan',
  185. })
  186. this.setData({
  187. quanTipFlag:false
  188. })
  189. },
  190. /**
  191. * 生命周期函数--监听页面加载
  192. */
  193. onLoad: function (options) {
  194. this.setData({
  195. isShow: wx.getStorageSync('isShow'),
  196. })
  197. this.localtionMethod()
  198. // this.queryQuan()
  199. },
  200. /**
  201. * 生命周期函数--监听页面初次渲染完成
  202. */
  203. onReady: function () {
  204. },
  205. /**
  206. * 生命周期函数--监听页面显示
  207. */
  208. onShow: function () {
  209. wx.hideHomeButton()
  210. const latlng = wx.getStorageSync('latlng')
  211. if(!latlng){
  212. this.localtionMethod()
  213. }
  214. if(!wx.getStorageSync('openId')){
  215. // wx.redirectTo({
  216. // url: '/pages/login/login',
  217. // })
  218. // return
  219. } else {
  220. this.loadIndexData();
  221. }
  222. },
  223. /**
  224. * 生命周期函数--监听页面隐藏
  225. */
  226. onHide: function () {
  227. },
  228. /**
  229. * 生命周期函数--监听页面卸载
  230. */
  231. onUnload: function () {
  232. },
  233. /**
  234. * 页面相关事件处理函数--监听用户下拉动作
  235. */
  236. onPullDownRefresh: function () {
  237. },
  238. /**
  239. * 页面上拉触底事件的处理函数
  240. */
  241. onReachBottom: function () {
  242. },
  243. /**
  244. * 用户点击右上角分享
  245. */
  246. onShareAppMessage: function () {
  247. },
  248. strLen(s) {
  249. return (s ? s.length : 0)
  250. },
  251. loadVideoInfo: function (videos, personType) {
  252. let urls = urlDef.urls
  253. videos.forEach(v => {
  254. util.apiPost(urls.video_loadInfo + v.videoId).then((rs) => {
  255. v.imgUrl = rs.img
  256. v.playUrl = rs.url
  257. if (personType == 0) {
  258. this.setData({
  259. 'stuShowList': videos
  260. })
  261. }
  262. if (personType == 1) {
  263. this.setData({
  264. 'teaShowList': videos
  265. })
  266. }
  267. });
  268. });
  269. },
  270. queryVideoShow: function (personType) {
  271. const urls = urlDef.urls;
  272. //获取登录用户数据, 并加载首页数据
  273. util.apiPost(urls.person_video_list, {
  274. 'q.orgId': this.data.curStu.orgId,
  275. 'q.doPersonId': this.data.curStu.studentId,
  276. 'q.personType': personType,
  277. 'q.sortBy': 'rand',
  278. 'q.limit4': 'true'
  279. }).then(rs => {
  280. this.loadVideoInfo(rs, personType)
  281. })
  282. },
  283. queryStudentShow: function () {
  284. this.queryVideoShow(0)
  285. },
  286. queryTeacherShow: function () {
  287. this.queryVideoShow(1)
  288. },
  289. loadIndexData: function () {
  290. this.setData({
  291. 'stuShowList': [],
  292. 'teaShowList': [],
  293. })
  294. const urls = urlDef.urls;
  295. //获取登录用户数据, 并加载首页数据
  296. util.apiPost(urls.get_cur_user, {}).then(rs => {
  297. // console.log(JSON.stringify(rs));
  298. let userItems = rs.attr.others
  299. let orgItems = []
  300. let student = {}
  301. userItems.forEach(u => {
  302. let exists = false;
  303. orgItems.some(o => {
  304. if (o.orgId === u.orgId) {
  305. exists = true;
  306. return true;
  307. }
  308. })
  309. if (!exists) {
  310. orgItems.push({
  311. orgId: u.orgId,
  312. orgName: u.orgName
  313. })
  314. }
  315. if (u.studentId === rs.attr.personId) { // 当前用户
  316. const headImg = u.imageUrl ? urls.oss_file + 'image/' + u.imageUrl : '/images/head.png';
  317. student = {
  318. studentId: u.studentId,
  319. orgId: u.orgId,
  320. orgName: u.orgName,
  321. name: u.studentName,
  322. sex: u.sex,
  323. headImg: headImg
  324. }
  325. this.setData({
  326. 'curStu': student
  327. })
  328. // 放入 strong中
  329. const stu = wx.getStorageSync('student')
  330. if(stu && stu.studentId != student.studentId){
  331. wx.setStorageSync('indexQuanTip', true)
  332. }
  333. wx.setStorageSync('student', student);
  334. this.queryQuan()
  335. }
  336. if (this.strLen(u.imageUrl) === 0) {
  337. u.imageUrl = '/images/head.png'
  338. } else {
  339. u.imageUrl = urls.oss_file + 'image/' + u.imageUrl
  340. }
  341. u.headName = u.studentName.substring(u.studentName.length - 1, u.studentName.length)
  342. })
  343. this.setData({
  344. 'userItems': userItems,
  345. 'orgItems': orgItems
  346. })
  347. let personId = rs.attr.personId
  348. let orgId = rs.attr.orgId
  349. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  350. // banner 图片
  351. util.apiPost(urls.get_advert, {
  352. '&q.use': 1,
  353. 'q.orgId': orgId,
  354. 'q.exceptStatus': 2
  355. }).then(r => {
  356. // console.log('banner : ' + JSON.stringify(r));
  357. this.setData({
  358. 'bannerList': r
  359. })
  360. });
  361. // 今日课程
  362. util.apiPost(urls.leave_get_classes_date, {
  363. 'q.studentId': personId,
  364. 'q.attenceDate': today
  365. }).then(r => {
  366. // console.log('今日课程 : ' + JSON.stringify(r));
  367. let courseCount = 0
  368. if (r && r.length > 0) {
  369. courseCount = r[0].total;
  370. }
  371. this.setData({
  372. 'classList[0].num': courseCount
  373. })
  374. })
  375. // 作业未提交
  376. util.apiPost(urls.my_homework, {
  377. 'q.studentId': personId,
  378. 'q.status': 0
  379. }).then(r => {
  380. // console.log('作业未提交 : ' + JSON.stringify(r));
  381. this.setData({
  382. 'classList[1].num': (r ? r.length : 0)
  383. })
  384. });
  385. // 出勤率
  386. util.apiPost(urls.get_attendance_rate, {
  387. 'q.studentId': personId
  388. }).then(r => {
  389. // console.log('出勤率 : ' + JSON.stringify(r));
  390. let attendRate = 0,
  391. alreadyCount = 0,
  392. shouldCount = 0;
  393. if (r != null) {
  394. r.forEach(it => {
  395. if (it.isAttend === '1') {
  396. alreadyCount = it.num
  397. } else if (it.isAttend === '0') {
  398. shouldCount = it.num
  399. }
  400. });
  401. }
  402. let t = (alreadyCount + shouldCount)
  403. if (t > 0) {
  404. attendRate = alreadyCount * 100 / t
  405. }
  406. this.setData({
  407. 'classList[2].num': attendRate.toFixed(2) + '%'
  408. })
  409. })
  410. this.queryVideoShow(0)
  411. this.queryVideoShow(1)
  412. });
  413. },
  414. doThumbsUp: function (o) {
  415. const urls = urlDef.urls;
  416. let pid = this.data.curStu.studentId;
  417. let pt = o.detail.personType;
  418. let vid = o.detail.videoId;
  419. let entity = {
  420. videoId: vid,
  421. personId: pid,
  422. personType: pt,
  423. actionType: 1
  424. };
  425. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  426. if (pt == 0) {
  427. this.data.stuShowList.map(o => {
  428. if (o.videoId == vid) {
  429. o.goodCount += 1
  430. }
  431. })
  432. this.setData({
  433. 'stuShowList': this.data.stuShowList
  434. })
  435. }
  436. if (pt == 1) {
  437. this.data.teaShowList.map(o => {
  438. if (o.videoId == vid) {
  439. o.goodCount += 1
  440. }
  441. })
  442. this.setData({
  443. 'teaShowList': this.data.teaShowList
  444. })
  445. }
  446. }).catch(e => {
  447. console.log(e);
  448. })
  449. },
  450. getMyLocal: function () {
  451. //获取当前定位具体位置名称
  452. var qqmapsdk = new QQMapWX({
  453. key: 'FCLBZ-ZQ2Y3-DC23W-3EXRK-LUKX6-W7F6Z'
  454. });
  455. var that = this
  456. var lat = wx.getStorageSync('latlng').latitude;
  457. var lng = wx.getStorageSync('latlng').longitude;
  458. // 在组件实例进入页面节点树时执行
  459. qqmapsdk.reverseGeocoder({
  460. location: {
  461. latitude: lat,
  462. longitude: lng
  463. },
  464. success: function (res) {
  465. //获取当前地址成功
  466. that.setData({
  467. address: res.result.address,
  468. location: {
  469. latitude: res.result.location.lat,
  470. longitude: res.result.location.lng
  471. }
  472. })
  473. const name = res.result.address_component.city
  474. wx.setStorageSync('wxLocalName', name)
  475. // const locationNavTop = that.selectComponent("#locationNavTop")
  476. // locationNavTop.getAddr()
  477. // that.getLocationList(res.result.address_reference)
  478. },
  479. fail: function (res) {
  480. console.log('获取当前地址失败');
  481. }
  482. });
  483. },
  484. localtionMethod: function () {
  485. const that = this
  486. wx.getLocation({
  487. type: 'wgs84',
  488. success(res) {
  489. // console.log(res)
  490. wx.setStorageSync('latlng', res)
  491. that.getCoder()
  492. that.getMyLocal()
  493. },
  494. fail(res) {
  495. console.log(JSON.stringify(res))
  496. wx.hideLoading({
  497. success: (res) => {
  498. wx.showModal({
  499. title: '提示',
  500. content: "定位失败,请检查手机'位置服务'或GPS功能已开启并授权小程序位置信息",
  501. success(res){
  502. if(res.confirm){
  503. wx.openSetting({
  504. success (res) {
  505. console.log(res.authSetting)
  506. // res.authSetting = {
  507. // "scope.userInfo": true,
  508. // "scope.userLocation": true
  509. // }
  510. }
  511. })
  512. }
  513. }
  514. })
  515. },
  516. })
  517. }
  518. })
  519. },
  520. getCoder:function(){
  521. const lat = wx.getStorageSync('latlng').latitude
  522. const lng = wx.getStorageSync('latlng').longitude
  523. wx.request({
  524. url: 'https://apis.map.qq.com/ws/geocoder/v1/?location='+lat+','+lng+"&key=FCLBZ-ZQ2Y3-DC23W-3EXRK-LUKX6-W7F6Z",
  525. method: 'GET',
  526. success: function( res ) {
  527. let cityCode = res.data.result.ad_info.city_code
  528. let nationCode = res.data.result.ad_info.nation_code
  529. cityCode = cityCode.substring(nationCode.length, cityCode.length)
  530. wx.setStorageSync('adCode', cityCode)
  531. },
  532. fail:function(res){
  533. console.log(res)
  534. }
  535. })
  536. }
  537. })