myMission.js 13 KB

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