myClass.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. showMore: false, //更多
  6. showzs: false,
  7. show: false,
  8. sessionKey: "",
  9. notice: "暂无未读通知",
  10. classInfo: {},
  11. kcArr: [],
  12. sfmArr: [],
  13. studentName: "",
  14. status: '', //状态
  15. myCanvasId: 0,
  16. byzsbj: "../../images/zsbj.jpg",
  17. IngCourseArr: [] //如果有正在进行的课就存一下
  18. },
  19. // 更多
  20. listToggle: function () {
  21. this.setData({
  22. showMore: !this.data.showMore
  23. })
  24. },
  25. hidePopup() {
  26. this.setData({
  27. show: false
  28. });
  29. let sessionKey = "";
  30. wx.checkSession({
  31. success: () => {
  32. sessionKey = wx.getStorageSync('sessionKey');
  33. wx.request({
  34. url: app.globalData.publicUrl + '/wx/student/verification',
  35. method: "post",
  36. data: {
  37. sessionKey: sessionKey
  38. },
  39. success: function (res) {
  40. console.log(res, "我成功了")
  41. }
  42. })
  43. },
  44. fail() {
  45. console.log("我没有缓存并去登录请求")
  46. wx.login({
  47. success(res) {
  48. console.log(res);
  49. let code = res.code
  50. wx.request({
  51. url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
  52. method: "get",
  53. data: {
  54. code
  55. },
  56. success: function (res) {
  57. sessionKey = res.data.sessionKey;
  58. wx.setStorageSync('sessionKey', res.data.sessionKey);
  59. wx.request({
  60. url: app.globalData.publicUrl + '/wx/student/verification',
  61. method: "post",
  62. data: {
  63. sessionKey: sessionKey
  64. },
  65. success: function (res) {
  66. console.log(res, "我成功了")
  67. }
  68. })
  69. }
  70. })
  71. }
  72. })
  73. }
  74. })
  75. },
  76. myactiveMore() {
  77. wx.navigateTo({
  78. url: '../myActive/myActive'
  79. })
  80. },
  81. // 随堂考试
  82. // gokhAnswer() {
  83. // wx.navigateTo({
  84. // url: '../answerAfterclass/answerAfterclass'
  85. // })
  86. // },
  87. gokhAnswer(e) {
  88. let isStudyDone = e.currentTarget.dataset.item.isStudyDone
  89. let isExam = e.currentTarget.dataset.item.isExam
  90. if (isStudyDone != 1) {
  91. wx.showModal({
  92. showCancel: false,
  93. content: "您的学习课程还未完成哦,请先完成学习任务后再来考试吧!"
  94. })
  95. return false
  96. } else {
  97. if (isExam == 0) {
  98. wx.request({
  99. url: app.globalData.publicUrl + '/wx/exam/examList',
  100. method: "post",
  101. data: {
  102. sessionKey: this.data.sessionKey,
  103. courseId: e.currentTarget.dataset.item.courseid,
  104. clasId: this.data.classInfo.id
  105. },
  106. success: (res) => {
  107. if (res.data.code == 0) {
  108. console.log(res.data);
  109. //let answersId = res.data.list[0].answersId ;
  110. if (res.data.list[0]) {
  111. if (res.data.list[0].answersId) {
  112. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
  113. } else {
  114. console.log('777777');
  115. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
  116. }
  117. }
  118. }
  119. }
  120. })
  121. } else {
  122. wx.showModal({
  123. showCancel: false,
  124. content: "您已经考完试了!"
  125. })
  126. }
  127. }
  128. // console.log(e.currentTarget.dataset.courseid, "00");
  129. },
  130. //我的班级去评价
  131. gopjClass(e) {
  132. console.log(e.currentTarget.dataset.item, "8888")
  133. let isStudyDone = e.currentTarget.dataset.item.isStudyDone
  134. let isFeedback = e.currentTarget.dataset.item.isFeedback
  135. if (isStudyDone != 1) {
  136. wx.showModal({
  137. showCancel: false,
  138. content: "您的学习课程还未完成哦,请先完成学习任务后再来评价吧!"
  139. })
  140. return false
  141. } else {
  142. if (isFeedback == 0) {
  143. wx.request({
  144. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  145. method: "post",
  146. data: {
  147. sessionKey: this.data.sessionKey,
  148. questSub: '3',
  149. courseId: e.currentTarget.dataset.courseid,
  150. clasId: this.data.classInfo.id
  151. },
  152. success: (res) => {
  153. if (res.data.code == 0) {
  154. console.log(res.data);
  155. //let answersId = res.data.list[0].answersId ;
  156. if (res.data.list[0]) {
  157. if (res.data.list[0].answersId) {
  158. if (res.data.list[0].status == '1') {
  159. wx.navigateTo({
  160. url: '/pages/evaluationCourseDetail/evaluationCourseDetail?answersId=' + res.data.list[0].answersId,
  161. })
  162. } else {
  163. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'evaluationCourse');
  164. }
  165. } else {
  166. console.log('777777');
  167. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'evaluationCourse');
  168. }
  169. }
  170. }
  171. }
  172. })
  173. } else {
  174. wx.showModal({
  175. showCancel: false,
  176. content: "您已经评价过了!"
  177. })
  178. }
  179. }
  180. },
  181. goMyPoints() {
  182. // wx.showModal({
  183. // showCancel: false,
  184. // content: "敬请期待",
  185. // success(res) {}
  186. // })
  187. wx.navigateTo({
  188. url: '../myPoints/myPoints'
  189. })
  190. },
  191. goactiveDetails() {
  192. wx.navigateTo({
  193. url: '../myactiveDetails/myactiveDetails'
  194. })
  195. },
  196. lq() {
  197. wx.showLoading({
  198. mask: true,
  199. title: '加载中',
  200. })
  201. this.setData({
  202. myCanvasId: this.data.myCanvasId + 1
  203. })
  204. console.log(this.data.myCanvasId)
  205. let str = this.data.studentName + "同志于" + this.data.classInfo.beginDate + " 至 " + this.data.classInfo.endDate + "参加学习完成规定培训内容,准予结业,特发此证。"
  206. let strArr = [];
  207. //每15个字截取一下
  208. // let n = 15;
  209. // for (let i = 0, l = str.length; i < l / n; i++) {
  210. // let a = str.slice(n * i, n * (i + 1));
  211. // strArr.push(a);
  212. // }
  213. let a = str.slice(0, 18);
  214. let b = str.slice(16, 36);
  215. let c = str.slice(36, 56);
  216. strArr.push(a, b, c);
  217. console.log(strArr, "我是截取之后的")
  218. const ctx = wx.createCanvasContext(this.data.myCanvasId);
  219. ctx.drawImage(this.data.byzsbj, 0, 0, 300, 415); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
  220. ctx.setFillStyle("#000");
  221. ctx.setFontSize(16); //字大小
  222. ctx.setTextAlign('left'); //是否居中显示,参考点画布中线
  223. let leftPositionAarr = [60, 30, 30, 30]
  224. for (let i = 0; i < strArr.length; i++) {
  225. console.log(i);
  226. ctx.fillText(strArr[i], leftPositionAarr[i], 160 + i * 30);
  227. }
  228. // ctx.fillText(str, 150, 160); //150:canvas画布宽300,取1/2,中间,280:纵向位置
  229. ctx.draw();
  230. wx.hideLoading();
  231. this.setData({
  232. showzs: true
  233. });
  234. wx.request({
  235. url: app.globalData.publicUrl + '/wx/student/wxGraduation',
  236. method: "post",
  237. data: {
  238. sessionKey: this.data.sessionKey
  239. },
  240. success: (res) => {
  241. console.log(res.data, "领取结业证提交")
  242. }
  243. })
  244. },
  245. saveZs() {
  246. wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片
  247. canvasId: this.data.myCanvasId,
  248. success(res) {
  249. console.log(res)
  250. wx.authorize({ //向用户发起授权请求
  251. scope: 'scope.writePhotosAlbum', //保存相册授权
  252. success: () => {
  253. wx.saveImageToPhotosAlbum({ //保存图片到系统相册
  254. filePath: res.tempFilePath,
  255. success: () => {
  256. wx.showToast({
  257. title: '图片保存成功'
  258. })
  259. }
  260. })
  261. }
  262. })
  263. }
  264. })
  265. },
  266. onClose1() {
  267. this.setData({
  268. showzs: false
  269. });
  270. },
  271. // 期末考试
  272. goQmks() {
  273. this.getgoQmks();
  274. },
  275. // 期末考试接口 、、、、、、
  276. getgoQmks() {
  277. console.log(this.data.sessionKey);
  278. console.log(this.data.classInfo.id);
  279. wx.request({
  280. url: app.globalData.publicUrl + '/wx/exam/examList',
  281. method: "post",
  282. data: {
  283. sessionKey: this.data.sessionKey,
  284. clasId: this.data.classInfo.id
  285. },
  286. success: (res) => {
  287. if (res.data.code == 0) {
  288. console.log(res.data);
  289. //let answersId = res.data.list[0].answersId ;
  290. console.log(res.data.list.length);
  291. if (res.data.list[0]) {
  292. if (res.data.list[0].answersId) {
  293. if (res.data.list[0].status == '1') {
  294. wx.navigateTo({
  295. url: '/pages/grade/grade?answersId=' + res.data.list[0].answersId,
  296. })
  297. } else {
  298. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
  299. }
  300. } else {
  301. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
  302. }
  303. }
  304. }
  305. }
  306. })
  307. },
  308. // 学员登记表的
  309. goWrite() {
  310. // wx.showModal({
  311. // showCancel: false,
  312. // content: "敬请期待",
  313. // success(res) {}
  314. // })
  315. //this.getBanner();
  316. wx.navigateTo({
  317. url: '../studentRegistration/studentRegistration'
  318. })
  319. },
  320. // 学员登记表 、、、、、、
  321. getBanner() {
  322. console.log(this.data.sessionKey);
  323. wx.request({
  324. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  325. method: "post",
  326. data: {
  327. sessionKey: this.data.sessionKey,
  328. questSub: '0'
  329. },
  330. success: (res) => {
  331. if (res.data.code == 0) {
  332. console.log(res.data);
  333. //let answersId = res.data.list[0].answersId ;
  334. console.log(res.data.list.length);
  335. if (res.data.list[0]) {
  336. if (res.data.list[0].answersId) {
  337. if (res.data.list[0].status) {
  338. wx.navigateTo({
  339. url: '/pages/studentRegistrationDeyail/studentRegistrationDeyail?answersId=' + res.data.list[0].answersId,
  340. })
  341. } else {
  342. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'studentRegistration');
  343. }
  344. } else {
  345. console.log('777777');
  346. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'studentRegistration');
  347. }
  348. }
  349. }
  350. }
  351. })
  352. },
  353. // 综合反馈表 、、、、、、
  354. getBanner1() {
  355. console.log(this.data.sessionKey, "dayin");
  356. console.log(this.data.classInfo.id);
  357. wx.request({
  358. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  359. method: "post",
  360. data: {
  361. sessionKey: this.data.sessionKey,
  362. questSub: '1',
  363. clasId: this.data.classInfo.id
  364. },
  365. success: (res) => {
  366. if (res.data.code == 0) {
  367. console.log(res.data, "zonghe");
  368. //let answersId = res.data.list[0].answersId ;
  369. console.log(res.data.list.length);
  370. if (res.data.list[0]) {
  371. if (res.data.list[0].answersId) {
  372. if (res.data.list[0].status == '1') {
  373. wx.navigateTo({
  374. url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId,
  375. })
  376. } else {
  377. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'feedBack');
  378. }
  379. } else {
  380. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack');
  381. }
  382. }
  383. }
  384. }
  385. })
  386. },
  387. toPath(id, paperId, answersId, address, status) {
  388. wx.navigateTo({
  389. url: '/pages/' + address + '/' + address + '?id=' + id + '&paperId=' + paperId + '&answersId=' + answersId + '&status=' + status,
  390. })
  391. },
  392. beginKao(id, paperId, sessionKey, address) {
  393. console.log(paperId, "8888888");
  394. wx.request({
  395. url: app.globalData.publicUrl + '/wx/exam/begin',
  396. method: "post",
  397. data: {
  398. sessionKey: sessionKey,
  399. id: id,
  400. paperId: paperId
  401. },
  402. success: (res) => {
  403. console.log(res);
  404. if (res.data.code == 0) {
  405. console.log(res, "为我么我们微妙"); // 提交答案是后
  406. this.setData({
  407. status: res.data.status
  408. })
  409. this.toPath(id, paperId, res.data.answersId, address, );
  410. }
  411. }
  412. })
  413. },
  414. goWrite2() {
  415. // wx.showModal({
  416. // showCancel: false,
  417. // content: "敬请期待",
  418. // success(res) {}
  419. // })
  420. // wx.navigateTo({
  421. // url: '../feedBack/feedBack'
  422. // })
  423. this.getBanner1();
  424. },
  425. // 跳转直播点播页面
  426. goStudy(e) {
  427. let id = e.currentTarget.dataset.item.id //此课程的id
  428. console.log(id)
  429. console.log(this.data.IngCourseArr, "我是筛选的列表")
  430. if (this.data.IngCourseArr.length == 0) {
  431. if (e.currentTarget.dataset.item.isLive == 1) {
  432. if (e.currentTarget.dataset.item.isActive == 1) {
  433. wx.navigateTo({
  434. url: '../zbDetails/zbDetails?id=' + id
  435. })
  436. } else {
  437. wx.showModal({
  438. showCancel: false,
  439. content: "直播还未开始哦"
  440. })
  441. return false;
  442. }
  443. } else {
  444. wx.navigateTo({
  445. url: '../dbDetails/dbDetails?id=' + id
  446. })
  447. }
  448. } else {
  449. if (id == this.data.IngCourseArr.id) {
  450. if (e.currentTarget.dataset.item.isLive == 1) {
  451. if (e.currentTarget.dataset.item.isActive == 1) {
  452. wx.navigateTo({
  453. url: '../zbDetails/zbDetails?id=' + id
  454. })
  455. } else {
  456. wx.showModal({
  457. showCancel: false,
  458. content: "直播还未开始哦"
  459. })
  460. return false;
  461. }
  462. } else {
  463. wx.navigateTo({
  464. url: '../dbDetails/dbDetails?id=' + id
  465. })
  466. }
  467. } else {
  468. wx.showModal({
  469. showCancel: false,
  470. content: "您有未完成的学习课程,请先完成学习任务后再进行其他课程学习!"
  471. })
  472. }
  473. }
  474. },
  475. // 查询我是否有班&&班级名字
  476. isClass(sessionKey) {
  477. // let _this = this;
  478. wx.request({
  479. url: app.globalData.publicUrl + '/wx/student/selMyClas',
  480. method: "post",
  481. data: {
  482. sessionKey: sessionKey
  483. },
  484. success: (res) => {
  485. console.log(res.data.code, "我是返回是否有班级")
  486. if (res.data.code == 0) {
  487. this.setData({
  488. classInfo: res.data.data
  489. })
  490. this.isAgree(sessionKey);
  491. } else {
  492. wx.showModal({
  493. content: "您当前还没有开放的班级!",
  494. showCancel: false,
  495. success(res) {
  496. if (res.confirm) {
  497. wx.switchTab({
  498. url: '../index/index'
  499. })
  500. }
  501. }
  502. })
  503. return false;
  504. }
  505. }
  506. })
  507. },
  508. // 协议是否已同意
  509. isAgree(sessionKey) {
  510. // let _this = this;
  511. wx.request({
  512. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  513. method: "post",
  514. data: {
  515. sessionKey: sessionKey
  516. },
  517. success: (res) => {
  518. console.log(res, "查询学员信息")
  519. if (res.data.code == 0 && res.data.data) {
  520. if (res.data.data.agreement == 0) {
  521. this.setData({
  522. studentName: res.data.data.studentName,
  523. show: false
  524. });
  525. } else {
  526. this.setData({
  527. studentName: res.data.data.studentName,
  528. show: true
  529. });
  530. }
  531. }
  532. }
  533. })
  534. },
  535. // 我的通知
  536. getMynotice(sessionKey) {
  537. // let _this = this;
  538. wx.request({
  539. url: app.globalData.publicUrl + '/wx/eduNoticeSee/list',
  540. method: "post",
  541. data: {
  542. sessionKey: sessionKey,
  543. isSee: 1,
  544. isNotice: 0
  545. },
  546. success: (res) => {
  547. console.log(res, "333333333")
  548. if (res.data.code == 0) {
  549. if (res.data.list && res.data.list.length !== 0)
  550. this.setData({
  551. notice: res.data.list[0].noticeContent
  552. });
  553. }
  554. }
  555. })
  556. },
  557. gomyNotice() {
  558. // if (this.data.notice !== "暂无未读通知") {
  559. wx.navigateTo({
  560. url: '../myNotice/myNotice'
  561. })
  562. // }
  563. },
  564. // // 我的课程
  565. getMycourse(sessionKey) {
  566. // let _this = this;
  567. wx.request({
  568. url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
  569. method: "post",
  570. data: {
  571. sessionKey: sessionKey
  572. },
  573. success: (res) => {
  574. console.log(res, "kckckc")
  575. this.setData({
  576. kcArr: res.data.list
  577. });
  578. for (let i = 0; i < res.data.list.length; i++) {
  579. if (res.data.list[i].isStudyDone == 0) {
  580. this.setData({
  581. IngCourseArr: res.data.list[i]
  582. })
  583. }
  584. }
  585. let result = [];
  586. if (res.data.list)
  587. for (let i = 0; i < res.data.list.length; i++) {
  588. result.push({
  589. courseTime: res.data.list[i].courseTime
  590. });
  591. }
  592. const timesArr = result.map((item) => {
  593. return item.courseTime;
  594. });
  595. let sfmArr = [];
  596. for (let i = 0; i < timesArr.length; i++) {
  597. let value = timesArr[i];
  598. const resultValue = this.handler(value);
  599. sfmArr.push({
  600. courseTime: resultValue
  601. })
  602. this.setData({
  603. sfmArr: sfmArr
  604. })
  605. }
  606. }
  607. })
  608. },
  609. handler(value) {
  610. //换算为秒 进制1000
  611. const second = Math.floor(value / 1000); //判断是否够1秒
  612. if (second < 1) {
  613. return "0秒";
  614. }
  615. const secondValue = second % 60; // 秒
  616. const minutes = Math.floor(second / 60); //判断是否够1分钟
  617. if (minutes < 1) {
  618. return `${secondValue}秒`;
  619. }
  620. const minutesValue = minutes % 60; //分
  621. const hours = Math.floor(minutes / 60); //判断是否够1小时
  622. if (hours < 1) {
  623. return `${minutesValue}分${secondValue}秒`;
  624. }
  625. const hoursValue = hours % 60; //小时
  626. return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  627. },
  628. async onShow() {
  629. const sessionKey = await tools.checkSessionAndLogin();
  630. console.log(sessionKey, "000000");
  631. //const sessionKey = 'BqQROCKCxn7R2NXdQLud9Q==';
  632. this.setData({
  633. sessionKey: sessionKey
  634. })
  635. this.isClass(sessionKey);
  636. this.getMycourse(sessionKey);
  637. this.getMynotice(sessionKey);
  638. }
  639. })