myClass.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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. notice: "暂无未读通知",
  9. classInfo: {}, //班级信息
  10. kcArr: [], //课程列表
  11. sfmArr: [], //换算时分秒数组
  12. studentName: "", //学生明字
  13. status: '', //状态
  14. myCanvasId: 0, //画布id
  15. byzsbj: "../../images/zsbj.jpg", //结业证背景 用于合成图片
  16. IngCourseArr: [], //如果有正在进行的课就存一下
  17. istask: false, //判断班级群是否添加
  18. istask1: false, //学员登记表是否完成
  19. istask2: false, //课程是否完成
  20. istask3: false, //期末考试是否完成
  21. istask4: false, //综合反馈是否完成
  22. },
  23. // 查询我是否认证
  24. isRz(sessionKey) {
  25. wx.request({
  26. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  27. method: "post",
  28. data: {
  29. sessionKey: sessionKey
  30. },
  31. success: (res) => {
  32. if (res.data.code == 0) {
  33. if (res.data.data !== null || res.data.data !== "") {
  34. this.isClass(sessionKey)
  35. } else {
  36. wx.showModal({
  37. content: "您还没有进行身份认证哦",
  38. showCancel: false,
  39. success(res) {
  40. if (res.confirm) {
  41. wx.redirectTo({
  42. url: '../Identity/Identity'
  43. })
  44. }
  45. }
  46. })
  47. }
  48. } else {
  49. wx.showModal({
  50. content: "您还没有进行身份认证哦",
  51. showCancel: false,
  52. success(res) {
  53. if (res.confirm) {
  54. wx.redirectTo({
  55. url: '../Identity/Identity'
  56. })
  57. }
  58. }
  59. })
  60. }
  61. }
  62. })
  63. },
  64. // 查询我是否有班&&班级名字
  65. isClass(sessionKey) {
  66. wx.request({
  67. url: app.globalData.publicUrl + '/wx/student/selMyClas',
  68. method: "post",
  69. data: {
  70. sessionKey: sessionKey
  71. },
  72. success: (res) => {
  73. if (res.data.code == 0) {
  74. this.setData({
  75. classInfo: res.data.data
  76. })
  77. this.checkTaskList4(sessionKey, res.data.data.id);
  78. this.checkTaskList(sessionKey);
  79. this.checkTaskList3(sessionKey, res.data.data.id);
  80. this.isAgree(sessionKey);
  81. } else {
  82. wx.showModal({
  83. content: "您当前还没有正在开放的班级!",
  84. showCancel: false,
  85. success(res) {
  86. if (res.confirm) {
  87. wx.switchTab({
  88. url: '../index/index'
  89. })
  90. }
  91. }
  92. })
  93. return false;
  94. }
  95. }
  96. })
  97. },
  98. // 协议是否已同意
  99. isAgree(sessionKey) {
  100. // let _this = this;
  101. wx.request({
  102. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  103. method: "post",
  104. data: {
  105. sessionKey: sessionKey
  106. },
  107. success: (res) => {
  108. if (res.data.code == 0 && res.data.data) {
  109. if (res.data.data.agreement == 0) {
  110. this.setData({
  111. studentName: res.data.data.studentName,
  112. show: false
  113. });
  114. } else {
  115. this.setData({
  116. studentName: res.data.data.studentName,
  117. show: true
  118. });
  119. }
  120. }
  121. }
  122. })
  123. },
  124. // 点击同意协议 并且记一下
  125. hidePopup() {
  126. this.setData({
  127. show: false
  128. });
  129. let sessionKey = "";
  130. wx.checkSession({
  131. success: () => {
  132. sessionKey = wx.getStorageSync('sessionKey');
  133. wx.request({
  134. url: app.globalData.publicUrl + '/wx/student/verification',
  135. method: "post",
  136. data: {
  137. sessionKey: sessionKey
  138. },
  139. success: function (res) {
  140. console.log(res, "我成功了")
  141. }
  142. })
  143. },
  144. fail() {
  145. wx.login({
  146. success(res) {
  147. let code = res.code
  148. wx.request({
  149. url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
  150. method: "get",
  151. data: {
  152. code
  153. },
  154. success: function (res) {
  155. sessionKey = res.data.sessionKey;
  156. wx.setStorageSync('sessionKey', res.data.sessionKey);
  157. wx.request({
  158. url: app.globalData.publicUrl + '/wx/student/verification',
  159. method: "post",
  160. data: {
  161. sessionKey: sessionKey
  162. },
  163. success: function (res) {
  164. console.log(res, "我成功了")
  165. }
  166. })
  167. }
  168. })
  169. }
  170. })
  171. }
  172. })
  173. },
  174. // 检查班级群是否加了
  175. checkTaskList(sessionKey) {
  176. wx.request({
  177. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  178. method: "post",
  179. data: {
  180. sessionKey: sessionKey
  181. },
  182. success: (res) => {
  183. if (res.data.code == 0) {
  184. if (res.data.data.joinClas == 0) {
  185. this.setData({
  186. istask: true
  187. })
  188. }
  189. this.setData({
  190. studentName: res.data.data.studentName,
  191. })
  192. }
  193. }
  194. })
  195. },
  196. // 学员登记任务check
  197. checkTaskList1(sessionKey) {
  198. wx.request({
  199. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  200. method: "post",
  201. data: {
  202. sessionKey: sessionKey
  203. },
  204. success: (res) => {
  205. if (res.data.code == 0 && res.data.data.register == 0) {
  206. this.setData({
  207. istask1: true
  208. })
  209. }
  210. }
  211. })
  212. },
  213. // 期末考试任务检查
  214. checkTaskList3(sessionKey, id) {
  215. wx.request({
  216. url: app.globalData.publicUrl + '/wx/exam/clasExamstatus',
  217. method: "post",
  218. data: {
  219. sessionKey: sessionKey,
  220. clasId: id
  221. },
  222. success: (res) => {
  223. if (res.data.code == 0 && res.data.status == 1) {
  224. this.setData({
  225. istask3: true
  226. })
  227. }
  228. }
  229. })
  230. },
  231. // 综合反馈任务check
  232. checkTaskList4(sessionKey, id) {
  233. wx.request({
  234. url: app.globalData.publicUrl + '/wx/exam/status',
  235. method: "post",
  236. data: {
  237. sessionKey: sessionKey,
  238. clasId: id
  239. },
  240. success: (res) => {
  241. if (res.data.code == 0 && res.data.status == 1) {
  242. this.setData({
  243. istask4: true
  244. })
  245. }
  246. }
  247. })
  248. },
  249. // 页面上显示的我的未读通知
  250. getMynotice(sessionKey) {
  251. // let _this = this;
  252. wx.request({
  253. url: app.globalData.publicUrl + '/wx/eduNoticeSee/list',
  254. method: "post",
  255. data: {
  256. sessionKey: sessionKey,
  257. isSee: 1,
  258. isNotice: 0
  259. },
  260. success: (res) => {
  261. if (res.data.code == 0) {
  262. if (res.data.list && res.data.list.length !== 0)
  263. this.setData({
  264. notice: res.data.list[0].noticeContent
  265. });
  266. }
  267. }
  268. })
  269. },
  270. // 跳转通知页
  271. gomyNotice() {
  272. // if (this.data.notice !== "暂无未读通知") {
  273. wx.navigateTo({
  274. url: '../myNotice/myNotice'
  275. })
  276. // }
  277. },
  278. // 学员登记表
  279. goWrite() {
  280. if (!this.data.istask) {
  281. wx.showModal({
  282. showCancel: false,
  283. content: "请先去扫描二维码加入班级群吧",
  284. success(res) {
  285. if (res.confirm) {
  286. wx.switchTab({
  287. url: '../myMission/myMission'
  288. })
  289. }
  290. }
  291. })
  292. return false
  293. }
  294. wx.navigateTo({
  295. url: '../studentRegistration/studentRegistration'
  296. })
  297. },
  298. // 学院介绍
  299. toAdd1() {
  300. wx.navigateTo({
  301. url: '../schoolIntrouce/schoolIntrouce'
  302. })
  303. },
  304. // 学员名单
  305. toAdd2() {
  306. wx.navigateTo({
  307. url: '../studentList/studentList?id=' + this.data.classInfo.id
  308. })
  309. },
  310. // 项目组名单
  311. toAdd3() {
  312. wx.navigateTo({
  313. url: '../groupsList/groupsList'
  314. })
  315. },
  316. // 我的课程
  317. getMycourse(sessionKey) {
  318. // let _this = this;
  319. wx.request({
  320. url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
  321. method: "post",
  322. data: {
  323. sessionKey: sessionKey
  324. },
  325. success: (res) => {
  326. this.setData({
  327. kcArr: res.data.list,
  328. istask2: res.data.allDone
  329. });
  330. for (let i = 0; i < res.data.list.length; i++) {
  331. if (res.data.list[i].isStudyDone == 0) {
  332. this.setData({
  333. IngCourseArr: res.data.list[i]
  334. })
  335. }
  336. }
  337. let result = [];
  338. if (res.data.list)
  339. for (let i = 0; i < res.data.list.length; i++) {
  340. result.push({
  341. courseTime: res.data.list[i].courseTime
  342. });
  343. }
  344. const timesArr = result.map((item) => {
  345. return item.courseTime;
  346. });
  347. let sfmArr = [];
  348. for (let i = 0; i < timesArr.length; i++) {
  349. let value = timesArr[i];
  350. const resultValue = this.handler(value);
  351. sfmArr.push({
  352. courseTime: resultValue
  353. })
  354. this.setData({
  355. sfmArr: sfmArr
  356. })
  357. }
  358. }
  359. })
  360. },
  361. // 时间换算
  362. handler(value) {
  363. //换算为秒 进制1000
  364. const second = Math.floor(value / 1000); //判断是否够1秒
  365. if (second < 1) {
  366. return "0秒";
  367. }
  368. const secondValue = second % 60; // 秒
  369. const minutes = Math.floor(second / 60); //判断是否够1分钟
  370. if (minutes < 1) {
  371. return `${secondValue}秒`;
  372. }
  373. const minutesValue = minutes % 60; //分
  374. const hours = Math.floor(minutes / 60); //判断是否够1小时
  375. if (hours < 1) {
  376. return `${minutesValue}分${secondValue}秒`;
  377. }
  378. const hoursValue = hours % 60; //小时
  379. return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  380. },
  381. // 查看更多列表展开
  382. listToggle: function () {
  383. this.setData({
  384. showMore: !this.data.showMore
  385. })
  386. },
  387. // 去学习
  388. goStudy(e) {
  389. if (!this.data.istask) {
  390. wx.showModal({
  391. showCancel: false,
  392. content: "请先去扫描二维码加入班级群吧",
  393. success(res) {
  394. if (res.confirm) {
  395. wx.switchTab({
  396. url: '../myMission/myMission'
  397. })
  398. }
  399. }
  400. })
  401. return false
  402. }
  403. if (!this.data.istask1) {
  404. wx.showModal({
  405. showCancel: false,
  406. content: "请先填写学员登记表再来学习哦!"
  407. })
  408. return false
  409. }
  410. let id = e.currentTarget.dataset.item.id //此课程的id
  411. if (this.data.IngCourseArr.length == 0) {
  412. if (e.currentTarget.dataset.item.isLive == 1) {
  413. if (e.currentTarget.dataset.item.isActive == 1) {
  414. wx.navigateTo({
  415. url: '../zbDetails/zbDetails?id=' + id
  416. })
  417. } else {
  418. wx.showModal({
  419. showCancel: false,
  420. content: "直播还未开始哦"
  421. })
  422. return false;
  423. }
  424. } else {
  425. wx.navigateTo({
  426. url: '../dbDetails/dbDetails?id=' + id
  427. })
  428. }
  429. } else {
  430. if (e.currentTarget.dataset.item.isLive == 1) {
  431. if (e.currentTarget.dataset.item.isActive == 1) {
  432. wx.navigateTo({
  433. url: '../zbDetails/zbDetails?id=' + id
  434. })
  435. } else {
  436. wx.showModal({
  437. showCancel: false,
  438. content: "直播还未开始哦"
  439. })
  440. return false;
  441. }
  442. } else {
  443. if (id == this.data.IngCourseArr.id) {
  444. wx.navigateTo({
  445. url: '../dbDetails/dbDetails?id=' + id
  446. })
  447. } else {
  448. wx.showModal({
  449. showCancel: false,
  450. content: "您的" + this.data.IngCourseArr.courseName + "课还未学完,快去学习吧"
  451. })
  452. }
  453. }
  454. }
  455. },
  456. // 去考试
  457. gokhAnswer(e) {
  458. if (!this.data.istask) {
  459. wx.showModal({
  460. showCancel: false,
  461. content: "请先去扫描二维码加入班级群吧",
  462. success(res) {
  463. if (res.confirm) {
  464. wx.switchTab({
  465. url: '../myMission/myMission'
  466. })
  467. }
  468. }
  469. })
  470. return false
  471. }
  472. if (!this.data.istask1) {
  473. wx.showModal({
  474. showCancel: false,
  475. content: "请先填写学员登记表再来学习哦!"
  476. })
  477. return false
  478. }
  479. let isStudyDone = e.currentTarget.dataset.item.isStudyDone
  480. if (isStudyDone != 1) {
  481. wx.showModal({
  482. showCancel: false,
  483. content: "您的学习课程还未完成哦,请先完成再来考试吧!"
  484. })
  485. return false
  486. } else {
  487. wx.request({
  488. url: app.globalData.publicUrl + '/wx/exam/examList',
  489. method: "post",
  490. data: {
  491. sessionKey: this.data.sessionKey,
  492. courseId: e.currentTarget.dataset.item.id,
  493. clasId: this.data.classInfo.id
  494. },
  495. success: (res) => {
  496. if (res.data.code == 0) {
  497. if (res.data.list.length == 0) {
  498. wx.showModal({
  499. showCancel: false,
  500. content: '老师还未出考试题哦'
  501. })
  502. } else {
  503. if (res.data.list[0]) {
  504. if (res.data.list[0].answersId) {
  505. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
  506. } else {
  507. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
  508. }
  509. }
  510. }
  511. }
  512. }
  513. })
  514. }
  515. },
  516. //去评价
  517. gopjClass(e) {
  518. if (!this.data.istask) {
  519. wx.showModal({
  520. showCancel: false,
  521. content: "请先去扫描二维码加入班级群吧",
  522. success(res) {
  523. if (res.confirm) {
  524. wx.switchTab({
  525. url: '../myMission/myMission'
  526. })
  527. }
  528. }
  529. })
  530. return false
  531. }
  532. if (!this.data.istask1) {
  533. wx.showModal({
  534. showCancel: false,
  535. content: "请先填写学员登记表再来学习哦!"
  536. })
  537. return false
  538. }
  539. let isStudyDone = e.currentTarget.dataset.item.isStudyDone
  540. if (isStudyDone != 1) {
  541. wx.showModal({
  542. showCancel: false,
  543. content: "您的学习课程还未完成哦,请先完成再来评价吧!"
  544. })
  545. return false
  546. } else {
  547. wx.request({
  548. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  549. method: "post",
  550. data: {
  551. sessionKey: this.data.sessionKey,
  552. // questSub: '3',
  553. courseId: e.currentTarget.dataset.item.id,
  554. clasId: this.data.classInfo.id
  555. },
  556. success: (res) => {
  557. if (res.data.code == 0) {
  558. if (res.data.list.length == 0) {
  559. wx.showModal({
  560. showCancel: false,
  561. content: '老师还未出评价模板哦'
  562. })
  563. } else {
  564. if (res.data.list[0]) {
  565. if (res.data.list[0].answersId) {
  566. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'evaluationCourse');
  567. } else {
  568. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'evaluationCourse');
  569. }
  570. }
  571. }
  572. }
  573. }
  574. })
  575. }
  576. },
  577. // 查看详情成绩
  578. gockcj(e) {
  579. if (e.currentTarget.dataset.item.isExamId) {
  580. wx.request({
  581. url: app.globalData.publicUrl + '/wx/answer/detail',
  582. method: "post",
  583. data: {
  584. answersId: e.currentTarget.dataset.item.isExamId
  585. },
  586. success: (res) => {
  587. console.log(res.data.list[0].answerScore)
  588. if (res.data.list[0].answerScore < 0 && (res.data.list[0].answerScore == null || res.data.list[0].answerScore == "")) {
  589. wx.showModal({
  590. showCancel: false,
  591. content: '当前老师批阅中,请耐心等待'
  592. })
  593. } else {
  594. wx.navigateTo({
  595. url: '/pages/grade/grade?answersId=' + e.currentTarget.dataset.item.isExamId,
  596. })
  597. }
  598. }
  599. })
  600. }
  601. },
  602. // 查看详情评价
  603. gockpj(e) {
  604. wx.navigateTo({
  605. url: '/pages/evaluationCourseDetail/evaluationCourseDetail?answersId=' + e.currentTarget.dataset.item.isFeedbackId,
  606. })
  607. },
  608. // 期末考试
  609. goQmks() {
  610. if (!this.data.istask) {
  611. wx.showModal({
  612. showCancel: false,
  613. content: "请先去扫描二维码加入班级群吧",
  614. success(res) {
  615. if (res.confirm) {
  616. wx.switchTab({
  617. url: '../myMission/myMission'
  618. })
  619. }
  620. }
  621. })
  622. return false
  623. }
  624. if (!this.data.istask2) {
  625. wx.showModal({
  626. showCancel: false,
  627. content: "您的课程任务还未全部完成哦!请先去完成再来期末考试吧!"
  628. })
  629. return false
  630. }
  631. wx.request({
  632. url: app.globalData.publicUrl + '/wx/exam/examList',
  633. method: "post",
  634. data: {
  635. sessionKey: this.data.sessionKey,
  636. clasId: this.data.classInfo.id
  637. },
  638. success: (res) => {
  639. if (res.data.code == 0) {
  640. if (res.data.list.length == 0) {
  641. wx.showModal({
  642. showCancel: false,
  643. content: '期末考试还未开始哦!'
  644. })
  645. } else {
  646. if (res.data.list[0].answersId) {
  647. if (res.data.list[0].status == '1') {
  648. wx.request({
  649. url: app.globalData.publicUrl + '/wx/answer/detail',
  650. method: "post",
  651. data: {
  652. answersId: res.data.list[0].answersId
  653. },
  654. success: (res1) => {
  655. if (res1.data.list[0].answerScore) {
  656. wx.navigateTo({
  657. url: '/pages/grade/grade?answersId=' + res.data.list[0].answersId,
  658. })
  659. } else {
  660. wx.showModal({
  661. showCancel: false,
  662. content: '当前老师批阅中,请耐心等待'
  663. })
  664. }
  665. }
  666. })
  667. } else {
  668. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
  669. }
  670. } else {
  671. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
  672. }
  673. }
  674. }
  675. }
  676. })
  677. },
  678. // 综合反馈表
  679. goWrite2() {
  680. if (this.data.istask4) {
  681. wx.request({
  682. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  683. method: "post",
  684. data: {
  685. sessionKey: this.data.sessionKey,
  686. questSub: '1',
  687. clasId: this.data.classInfo.id
  688. },
  689. success: (res) => {
  690. if (res.data.code == 0) {
  691. if (res.data.list[0]) {
  692. if (res.data.list[0].answersId) {
  693. wx.navigateTo({
  694. url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId,
  695. })
  696. } else {
  697. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack');
  698. }
  699. }
  700. }
  701. }
  702. })
  703. } else {
  704. wx.request({
  705. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  706. method: "post",
  707. data: {
  708. sessionKey: this.data.sessionKey,
  709. questSub: '1',
  710. clasId: this.data.classInfo.id
  711. },
  712. success: (res) => {
  713. if (res.data.code == 0) {
  714. if (res.data.list.length == 0) {
  715. wx.showModal({
  716. showCancel: false,
  717. content: '当前综合反馈还不可以填写哦!'
  718. })
  719. } else {
  720. if (res.data.list[0].answersId) {
  721. if (res.data.list[0].status == '1') {
  722. wx.navigateTo({
  723. url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId,
  724. })
  725. } else {
  726. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'feedBack');
  727. }
  728. } else {
  729. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack');
  730. }
  731. }
  732. }
  733. }
  734. })
  735. }
  736. },
  737. // 我的积分
  738. goMyPoints() {
  739. wx.navigateTo({
  740. url: '../myPoints/myPoints'
  741. })
  742. },
  743. // 领取结业证
  744. lq() {
  745. if (!this.data.istask) {
  746. wx.showModal({
  747. showCancel: false,
  748. content: "请先去扫描二维码加入班级群吧",
  749. success(res) {
  750. if (res.confirm) {
  751. wx.switchTab({
  752. url: '../myMission/myMission'
  753. })
  754. }
  755. }
  756. })
  757. return false
  758. }
  759. if (!this.data.istask3) {
  760. wx.showModal({
  761. showCancel: false,
  762. content: "您的期末考试还未完成哦!"
  763. })
  764. return false
  765. }
  766. wx.showLoading({
  767. mask: true,
  768. title: '加载中',
  769. })
  770. this.setData({
  771. myCanvasId: this.data.myCanvasId + 1
  772. })
  773. let str = this.data.studentName + "同志于" + this.data.classInfo.beginDate + " 至 " + this.data.classInfo.endDate + "参加学习完成规定培训内容,准予结业,特发此证。"
  774. let strArr = [];
  775. let a = str.slice(0, 16);
  776. let b = str.slice(16, 36);
  777. let c = str.slice(36, 56);
  778. strArr.push(a, b, c);
  779. const ctx = wx.createCanvasContext(this.data.myCanvasId);
  780. ctx.drawImage(this.data.byzsbj, 0, 0, 300, 415); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
  781. ctx.setFillStyle("#000");
  782. ctx.setFontSize(16); //字大小
  783. ctx.setTextAlign('left'); //是否居中显示,参考点画布中线
  784. let leftPositionAarr = [60, 30, 30, 30]
  785. for (let i = 0; i < strArr.length; i++) {
  786. ctx.fillText(strArr[i], leftPositionAarr[i], 160 + i * 30);
  787. }
  788. // ctx.fillText(str, 150, 160); //150:canvas画布宽300,取1/2,中间,280:纵向位置
  789. ctx.draw();
  790. wx.hideLoading();
  791. this.setData({
  792. showzs: true
  793. });
  794. wx.request({
  795. url: app.globalData.publicUrl + '/wx/student/wxGraduation',
  796. method: "post",
  797. data: {
  798. sessionKey: this.data.sessionKey
  799. },
  800. success: (res) => {
  801. console.log(res.data, "领取结业证提交")
  802. }
  803. })
  804. },
  805. // 存储结业证
  806. saveZs() {
  807. wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片
  808. canvasId: this.data.myCanvasId,
  809. success(res) {
  810. wx.authorize({ //向用户发起授权请求
  811. scope: 'scope.writePhotosAlbum', //保存相册授权
  812. success: () => {
  813. wx.saveImageToPhotosAlbum({ //保存图片到系统相册
  814. filePath: res.tempFilePath,
  815. success: () => {
  816. wx.showToast({
  817. title: '图片保存成功'
  818. })
  819. }
  820. })
  821. }
  822. })
  823. }
  824. })
  825. },
  826. // 证书隐藏
  827. onClose1() {
  828. this.setData({
  829. showzs: false
  830. });
  831. },
  832. toPath(id, paperId, answersId, address, status) {
  833. wx.navigateTo({
  834. url: '/pages/' + address + '/' + address + '?id=' + id + '&paperId=' + paperId + '&answersId=' + answersId + '&status=' + status,
  835. })
  836. },
  837. beginKao(id, paperId, sessionKey, address) {
  838. wx.request({
  839. url: app.globalData.publicUrl + '/wx/exam/begin',
  840. method: "post",
  841. data: {
  842. sessionKey: sessionKey,
  843. id: id,
  844. paperId: paperId
  845. },
  846. success: (res) => {
  847. if (res.data.code == 0) {
  848. this.setData({
  849. status: res.data.status
  850. })
  851. this.toPath(id, paperId, res.data.answersId, address);
  852. }
  853. }
  854. })
  855. },
  856. async onShow() {
  857. const sessionKey = await tools.checkSessionAndLogin();
  858. this.setData({
  859. sessionKey
  860. });
  861. this.isRz(sessionKey)
  862. this.getMycourse(sessionKey);
  863. this.getMynotice(sessionKey);
  864. this.checkTaskList1(sessionKey);
  865. }
  866. })