myMission.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. const app = require('../../utils/util.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. showewm: false,
  8. showzs: false,
  9. kcArr: [],
  10. ewmurl: '',
  11. sfmArr: [],
  12. className: '',
  13. istask1: false,
  14. istask2: false,
  15. istask3: false,
  16. istask4: false,
  17. istask5: false
  18. },
  19. selectBtn0() {
  20. this.setData({
  21. select: 0
  22. });
  23. },
  24. selectBtn1() {
  25. this.setData({
  26. select: 1
  27. });
  28. },
  29. gokhAnswer() {
  30. wx.navigateTo({
  31. url: '../answerAfterclass/answerAfterclass'
  32. })
  33. },
  34. gopjClass() {
  35. wx.navigateTo({
  36. url: '../evaluationCourse/evaluationCourse'
  37. })
  38. },
  39. startAnswer() {
  40. wx.navigateTo({
  41. url: '/pages/answerAfterclass/answerAfterclass',
  42. })
  43. },
  44. goWrite() {
  45. // wx.showModal({
  46. // showCancel: false,
  47. // content: "敬请期待",
  48. // success(res) {}
  49. // })
  50. wx.navigateTo({
  51. url: '../studentRegistration/studentRegistration'
  52. })
  53. },
  54. goWrite2() {
  55. // wx.showModal({
  56. // showCancel: false,
  57. // content: "敬请期待",
  58. // success(res) {}
  59. // })
  60. wx.navigateTo({
  61. url: '../feedBack/feedBack'
  62. })
  63. },
  64. lq() {
  65. // wx.showModal({
  66. // showCancel: false,
  67. // content: "此功能暂时还未开放哦",
  68. // success(res) {}
  69. // })
  70. this.setData({
  71. showzs: true
  72. });
  73. },
  74. // 跳转直播点播页面
  75. goStudy(e) {
  76. let id = e.currentTarget.dataset.item.id
  77. if (e.currentTarget.dataset.item.isLive == 1) {
  78. if (e.currentTarget.dataset.item.isActive == 1) {
  79. wx.navigateTo({
  80. url: '../zbDetails/zbDetails?id=' + id
  81. })
  82. } else {
  83. wx.showModal({
  84. showCancel: false,
  85. content: "直播还未开始哦",
  86. success(res) {}
  87. })
  88. }
  89. } else {
  90. wx.navigateTo({
  91. url: '../dbDetails/dbDetails?id=' + id
  92. })
  93. }
  94. },
  95. getMycourse(sessionKey) {
  96. var _this = this;
  97. wx.request({
  98. url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
  99. method: "post",
  100. data: {
  101. sessionKey: sessionKey
  102. },
  103. success: function (res) {
  104. if (res.data.code == 0 && res.data.list.length !== 0) {
  105. _this.setData({
  106. kcArr: res.data.list,
  107. istask3: res.data.allDone
  108. });
  109. let result = [];
  110. if (res.data.list)
  111. for (var i = 0; i < res.data.list.length; i++) {
  112. result.push({
  113. courseTime: res.data.list[i].courseTime
  114. });
  115. }
  116. const timesArr = result.map((item) => {
  117. return item.courseTime;
  118. });
  119. let sfmArr = [];
  120. for (let i = 0; i < timesArr.length; i++) {
  121. let value = timesArr[i];
  122. const resultValue = _this.handler(value);
  123. sfmArr.push({
  124. courseTime: resultValue
  125. })
  126. _this.setData({
  127. sfmArr: sfmArr
  128. })
  129. }
  130. }
  131. }
  132. })
  133. },
  134. handler(value) {
  135. //换算为秒 进制1000
  136. const second = Math.floor(value / 1000); //判断是否够1秒
  137. if (second < 1) {
  138. return "0秒";
  139. }
  140. const secondValue = second % 60; // 秒
  141. const minutes = Math.floor(second / 60); //判断是否够1分钟
  142. if (minutes < 1) {
  143. return `${secondValue}秒`;
  144. }
  145. const minutesValue = minutes % 60; //分
  146. const hours = Math.floor(minutes / 60); //判断是否够1小时
  147. if (hours < 1) {
  148. return `${minutesValue}分${secondValue}秒`;
  149. }
  150. const hoursValue = hours % 60; //小时
  151. return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  152. },
  153. // 学员身份认证 检查第一个任务
  154. checkTaskList(sessionKey) {
  155. var _this = this;
  156. wx.request({
  157. url: app.globalData.publicUrl2 + '/wx/student/selStudentSessionKey',
  158. method: "post",
  159. data: {
  160. sessionKey: sessionKey
  161. },
  162. success: function (res) {
  163. console.log(res.data, "wwwwww")
  164. if (res.data.code == 0) {
  165. if (res.data.data.remark == 1) {
  166. _this.setData({
  167. istask1: true
  168. })
  169. }
  170. }
  171. }
  172. })
  173. },
  174. // 查询我是否有班&&班级名字
  175. isClass(sessionKey) {
  176. var _this = this;
  177. wx.request({
  178. url: app.globalData.publicUrl2 + '/wx/student/selMyClas',
  179. method: "post",
  180. data: {
  181. sessionKey: sessionKey
  182. },
  183. success: function (res) {
  184. console.log(res, "我是返回是否班级")
  185. if (res.data.code == 0) {
  186. if (res.data.data !== null || res.data.data !== "") {
  187. _this.setData({
  188. className: res.data.data.clasName
  189. })
  190. } else {
  191. wx.showModal({
  192. content: "您当前还没有开放的班级!",
  193. showCancel: false,
  194. success(res) {
  195. if (res.confirm) {
  196. wx.switchTab({
  197. url: '../index/index'
  198. })
  199. }
  200. }
  201. })
  202. return false;
  203. }
  204. } else {
  205. wx.showModal({
  206. content: "您当前还没有开放的班级!",
  207. showCancel: false,
  208. success(res) {
  209. if (res.confirm) {
  210. wx.switchTab({
  211. url: '../index/index'
  212. })
  213. }
  214. }
  215. })
  216. return false;
  217. }
  218. }
  219. })
  220. },
  221. // 记录二维码已经点击
  222. ewmClick(sessionKey) {
  223. let _this = this;
  224. wx.request({
  225. url: app.globalData.publicUrl2 + '/wx/student/wxGroup',
  226. method: "post",
  227. data: {
  228. sessionKey: sessionKey
  229. },
  230. success: function (res) {
  231. console.log(res)
  232. _this.setData({
  233. showewm: true,
  234. istask1: true
  235. })
  236. }
  237. })
  238. },
  239. ewmGet(sessionKey) {
  240. let _this = this;
  241. wx.request({
  242. url: app.globalData.publicUrl2 + '/wx/student/selAllClas',
  243. method: "post",
  244. data: {
  245. sessionKey: sessionKey
  246. },
  247. success: function (res) {
  248. console.log(res.data.data, "22222222")
  249. var filterArr = res.data.data.claList.filter(o => o.isActive == 5)
  250. console.log(filterArr, "111111111111")
  251. if (filterArr.length !== 0) {
  252. _this.setData({
  253. ewmurl: filterArr[0].codeImg
  254. })
  255. }
  256. }
  257. })
  258. },
  259. showEwm() {
  260. var sessionKey = "";
  261. var _this = this;
  262. wx.checkSession({
  263. success: () => {
  264. console.log("我有缓存")
  265. sessionKey = wx.getStorageSync('sessionKey');
  266. // console.log(sessionKey)
  267. _this.ewmClick(sessionKey)
  268. _this.ewmGet(sessionKey)
  269. },
  270. fail() {
  271. console.log("我没有缓存并去登录请求")
  272. wx.login({
  273. success(res) {
  274. console.log(res);
  275. var code = res.code
  276. wx.request({
  277. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  278. method: "get",
  279. data: {
  280. code
  281. },
  282. success: function (res) {
  283. sessionKey = res.data.sessionKey;
  284. wx.setStorageSync('sessionKey', res.data.sessionKey);
  285. _this.ewmClick(sessionKey)
  286. _this.ewmGet(sessionKey)
  287. }
  288. })
  289. }
  290. })
  291. }
  292. })
  293. },
  294. onShow() {
  295. var _this = this;
  296. wx.checkSession({
  297. success: () => {
  298. console.log("我有缓存")
  299. var sessionKey = wx.getStorageSync('sessionKey');
  300. console.log(sessionKey, "我有缓存")
  301. if (sessionKey == "") {
  302. wx.login({
  303. success(res) {
  304. console.log(res);
  305. var code = res.code
  306. wx.request({
  307. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  308. method: "get",
  309. data: {
  310. code
  311. },
  312. success: function (res) {
  313. sessionKey = res.data.sessionKey;
  314. wx.setStorageSync('sessionKey', res.data.sessionKey);
  315. _this.checkTaskList(sessionKey)
  316. _this.isClass(sessionKey);
  317. _this.getMycourse(sessionKey);
  318. }
  319. })
  320. }
  321. })
  322. } else {
  323. _this.checkTaskList(sessionKey)
  324. _this.isClass(sessionKey);
  325. _this.getMycourse(sessionKey);
  326. }
  327. },
  328. fail() {
  329. console.log("我没有缓存并去登录请求")
  330. wx.login({
  331. success(res) {
  332. console.log(res);
  333. var code = res.code
  334. wx.request({
  335. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  336. method: "get",
  337. data: {
  338. code
  339. },
  340. success: function (res) {
  341. wx.setStorageSync('sessionKey', res.data.sessionKey);
  342. var sessionKey = res.data.sessionKey;
  343. _this.checkTaskList(sessionKey)
  344. _this.isClass(sessionKey);
  345. _this.getMycourse(sessionKey);
  346. }
  347. })
  348. }
  349. })
  350. }
  351. })
  352. },
  353. onClose() {
  354. wx.hideLoading()
  355. this.setData({
  356. showewm: false
  357. });
  358. },
  359. onClose1() {
  360. this.setData({
  361. showzs: false
  362. });
  363. },
  364. /**
  365. * 生命周期函数--监听页面初次渲染完成
  366. */
  367. saveImg() {
  368. let _this = this;
  369. console.log(_this.data.ewmurl)
  370. wx.getSetting({
  371. success(res) {
  372. if (!res.authSetting['scope.writePhotosAlbum']) {
  373. wx.authorize({
  374. scope: 'scope.writePhotosAlbum',
  375. success() {
  376. console.log(res, "我点击同意啦")
  377. wx.showLoading({
  378. title: '保存中...'
  379. })
  380. var imgSrc = _this.data.ewmurl;
  381. wx.downloadFile({
  382. url: imgSrc,
  383. success: function (res) {
  384. console.log(res, '我下载完成啦');
  385. //图片保存到本地
  386. wx.saveImageToPhotosAlbum({
  387. filePath: res.tempFilePath,
  388. success: function (data) {
  389. console.log(data, '我保存成功啦')
  390. wx.hideLoading();
  391. wx.showToast({
  392. title: '保存成功',
  393. icon: 'success',
  394. duration: 2000
  395. })
  396. },
  397. fail: function (err) {
  398. console.log(err, '我保存失败啦')
  399. wx.hideLoading();
  400. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  401. console.log("当初用户拒绝,再次发起授权")
  402. wx.openSetting({
  403. success(settingdata) {
  404. console.log(settingdata)
  405. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  406. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  407. } else {
  408. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  409. }
  410. }
  411. })
  412. }
  413. },
  414. complete(res) {
  415. console.log(res);
  416. }
  417. })
  418. }
  419. })
  420. console.log('授权成功')
  421. }
  422. })
  423. } else {
  424. var imgSrc = _this.data.ewmurl
  425. wx.downloadFile({
  426. url: imgSrc,
  427. success: function (res) {
  428. console.log(res, '我下载完成啦');
  429. wx.hideLoading();
  430. //图片保存到本地
  431. wx.saveImageToPhotosAlbum({
  432. filePath: res.tempFilePath,
  433. success: function (data) {
  434. console.log(data, '我保存成功啦')
  435. wx.hideLoading();
  436. wx.showToast({
  437. title: '保存成功',
  438. icon: 'success',
  439. duration: 2000
  440. })
  441. },
  442. fail: function (err) {
  443. console.log(err, '我保存失败啦')
  444. wx.hideLoading();
  445. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  446. console.log("当初用户拒绝,再次发起授权")
  447. wx.openSetting({
  448. success(settingdata) {
  449. console.log(settingdata)
  450. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  451. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  452. } else {
  453. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  454. }
  455. }
  456. })
  457. }
  458. },
  459. complete(res) {
  460. console.log(res);
  461. }
  462. })
  463. }
  464. })
  465. }
  466. }
  467. })
  468. },
  469. onReady: function () {
  470. },
  471. /**
  472. * 生命周期函数--监听页面显示
  473. */
  474. // onShow: function () {
  475. // },
  476. /**
  477. * 生命周期函数--监听页面隐藏
  478. */
  479. onHide: function () {
  480. },
  481. /**
  482. * 生命周期函数--监听页面卸载
  483. */
  484. onUnload: function () {
  485. },
  486. /**
  487. * 页面相关事件处理函数--监听用户下拉动作
  488. */
  489. onPullDownRefresh: function () {
  490. },
  491. /**
  492. * 页面上拉触底事件的处理函数
  493. */
  494. onReachBottom: function () {
  495. },
  496. /**
  497. * 用户点击右上角分享
  498. */
  499. onShareAppMessage: function () {
  500. }
  501. })