index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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. wx.setStorageSync('student', student);
  330. wx.setStorageSync('indexQuanTip', true)
  331. this.queryQuan()
  332. }
  333. if (this.strLen(u.imageUrl) === 0) {
  334. u.imageUrl = '/images/head.png'
  335. } else {
  336. u.imageUrl = urls.oss_file + 'image/' + u.imageUrl
  337. }
  338. u.headName = u.studentName.substring(u.studentName.length - 1, u.studentName.length)
  339. })
  340. this.setData({
  341. 'userItems': userItems,
  342. 'orgItems': orgItems
  343. })
  344. let personId = rs.attr.personId
  345. let orgId = rs.attr.orgId
  346. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  347. // banner 图片
  348. util.apiPost(urls.get_advert, {
  349. '&q.use': 1,
  350. 'q.orgId': orgId,
  351. 'q.exceptStatus': 2
  352. }).then(r => {
  353. // console.log('banner : ' + JSON.stringify(r));
  354. this.setData({
  355. 'bannerList': r
  356. })
  357. });
  358. // 今日课程
  359. util.apiPost(urls.leave_get_classes_date, {
  360. 'q.studentId': personId,
  361. 'q.attenceDate': today
  362. }).then(r => {
  363. // console.log('今日课程 : ' + JSON.stringify(r));
  364. let courseCount = 0
  365. if (r && r.length > 0) {
  366. courseCount = r[0].total;
  367. }
  368. this.setData({
  369. 'classList[0].num': courseCount
  370. })
  371. })
  372. // 作业未提交
  373. util.apiPost(urls.my_homework, {
  374. 'q.studentId': personId,
  375. 'q.status': 0
  376. }).then(r => {
  377. // console.log('作业未提交 : ' + JSON.stringify(r));
  378. this.setData({
  379. 'classList[1].num': (r ? r.length : 0)
  380. })
  381. });
  382. // 出勤率
  383. util.apiPost(urls.get_attendance_rate, {
  384. 'q.studentId': personId
  385. }).then(r => {
  386. // console.log('出勤率 : ' + JSON.stringify(r));
  387. let attendRate = 0,
  388. alreadyCount = 0,
  389. shouldCount = 0;
  390. if (r != null) {
  391. r.forEach(it => {
  392. if (it.isAttend === '1') {
  393. alreadyCount = it.num
  394. } else if (it.isAttend === '0') {
  395. shouldCount = it.num
  396. }
  397. });
  398. }
  399. let t = (alreadyCount + shouldCount)
  400. if (t > 0) {
  401. attendRate = alreadyCount * 100 / t
  402. }
  403. this.setData({
  404. 'classList[2].num': attendRate.toFixed(2) + '%'
  405. })
  406. })
  407. this.queryVideoShow(0)
  408. this.queryVideoShow(1)
  409. });
  410. },
  411. doThumbsUp: function (o) {
  412. const urls = urlDef.urls;
  413. let pid = this.data.curStu.studentId;
  414. let pt = o.detail.personType;
  415. let vid = o.detail.videoId;
  416. let entity = {
  417. videoId: vid,
  418. personId: pid,
  419. personType: pt,
  420. actionType: 1
  421. };
  422. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  423. if (pt == 0) {
  424. this.data.stuShowList.map(o => {
  425. if (o.videoId == vid) {
  426. o.goodCount += 1
  427. }
  428. })
  429. this.setData({
  430. 'stuShowList': this.data.stuShowList
  431. })
  432. }
  433. if (pt == 1) {
  434. this.data.teaShowList.map(o => {
  435. if (o.videoId == vid) {
  436. o.goodCount += 1
  437. }
  438. })
  439. this.setData({
  440. 'teaShowList': this.data.teaShowList
  441. })
  442. }
  443. }).catch(e => {
  444. console.log(e);
  445. })
  446. },
  447. getMyLocal: function () {
  448. //获取当前定位具体位置名称
  449. var qqmapsdk = new QQMapWX({
  450. key: 'FCLBZ-ZQ2Y3-DC23W-3EXRK-LUKX6-W7F6Z'
  451. });
  452. var that = this
  453. var lat = wx.getStorageSync('latlng').latitude;
  454. var lng = wx.getStorageSync('latlng').longitude;
  455. // 在组件实例进入页面节点树时执行
  456. qqmapsdk.reverseGeocoder({
  457. location: {
  458. latitude: lat,
  459. longitude: lng
  460. },
  461. success: function (res) {
  462. //获取当前地址成功
  463. that.setData({
  464. address: res.result.address,
  465. location: {
  466. latitude: res.result.location.lat,
  467. longitude: res.result.location.lng
  468. }
  469. })
  470. const name = res.result.address_component.city
  471. wx.setStorageSync('wxLocalName', name)
  472. // const locationNavTop = that.selectComponent("#locationNavTop")
  473. // locationNavTop.getAddr()
  474. // that.getLocationList(res.result.address_reference)
  475. },
  476. fail: function (res) {
  477. console.log('获取当前地址失败');
  478. }
  479. });
  480. },
  481. localtionMethod: function () {
  482. const that = this
  483. wx.getLocation({
  484. type: 'wgs84',
  485. success(res) {
  486. // console.log(res)
  487. wx.setStorageSync('latlng', res)
  488. that.getCoder()
  489. that.getMyLocal()
  490. },
  491. fail(res) {
  492. console.log(JSON.stringify(res))
  493. wx.hideLoading({
  494. success: (res) => {
  495. wx.showModal({
  496. title: '提示',
  497. content: "定位失败,请检查手机'位置服务'或GPS功能已开启并授权小程序位置信息",
  498. success(res){
  499. if(res.confirm){
  500. wx.openSetting({
  501. success (res) {
  502. console.log(res.authSetting)
  503. // res.authSetting = {
  504. // "scope.userInfo": true,
  505. // "scope.userLocation": true
  506. // }
  507. }
  508. })
  509. }
  510. }
  511. })
  512. },
  513. })
  514. }
  515. })
  516. },
  517. getCoder:function(){
  518. const lat = wx.getStorageSync('latlng').latitude
  519. const lng = wx.getStorageSync('latlng').longitude
  520. wx.request({
  521. url: 'https://apis.map.qq.com/ws/geocoder/v1/?location='+lat+','+lng+"&key=FCLBZ-ZQ2Y3-DC23W-3EXRK-LUKX6-W7F6Z",
  522. method: 'GET',
  523. success: function( res ) {
  524. let cityCode = res.data.result.ad_info.city_code
  525. let nationCode = res.data.result.ad_info.nation_code
  526. cityCode = cityCode.substring(nationCode.length, cityCode.length)
  527. wx.setStorageSync('adCode', cityCode)
  528. },
  529. fail:function(res){
  530. console.log(res)
  531. }
  532. })
  533. }
  534. })