index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //index.js
  2. const util = require("../../utils/util")
  3. //获取应用实例
  4. const app = getApp()
  5. Page({
  6. data: {
  7. spinShow: false,
  8. buyModel:false,
  9. code_url:'',
  10. info:{},
  11. system: "",
  12. groups: [],
  13. pushPaper: [],
  14. timeLimitPaper: [],
  15. userInfo:{},
  16. taskList: [],
  17. departments:[]
  18. },
  19. onLoad: function(){
  20. let that = this
  21. wx.getSystemInfo({
  22. success: function(res) {
  23. that.setData({system: res.system})
  24. }
  25. })
  26. app.getDepartments( departments=>{
  27. this.setData({departments})
  28. })
  29. },
  30. onShow: function(){
  31. app.getUserInfo( userInfo =>{
  32. this.setData({userInfo})
  33. // 已经实名认证
  34. if( userInfo.identify ){
  35. this.indexLoad()
  36. }
  37. })
  38. },
  39. onPullDownRefresh() {
  40. if (!this.loading) {
  41. this.indexLoad( this.stopPullDownRefresh )
  42. }
  43. },
  44. stopPullDownRefresh(){
  45. wx.stopPullDownRefresh()
  46. },
  47. indexLoad: function( cb ) {
  48. let _this = this
  49. app.formPost('Exam.index', {}).then(res => {
  50. if (res.code === 200) {
  51. _this.setData({
  52. groups: res.data.groups
  53. });
  54. cb&&cb()
  55. }
  56. })
  57. },
  58. downloadFile: function(){
  59. let url = this.data.info.code_url
  60. util.downloadFile( url, res=>{
  61. this.setData({buyModel:false, code_url:''})
  62. } )
  63. },
  64. gotoHistory: function(){
  65. wx.navigateTo({
  66. url: '/pages/exam/record/index',
  67. })
  68. },
  69. gotoExam:function( e ){
  70. let groupId = e.currentTarget.dataset.id
  71. wx.navigateTo({
  72. url: `/pages/exam/do/index?id=${groupId}`
  73. })
  74. },
  75. gotoCollection(){
  76. wx.navigateTo({
  77. url: '/pages/exam/collection/index',
  78. })
  79. },
  80. onShareAppMessage: function(){
  81. },
  82. gotoError: function(){
  83. wx.navigateTo({
  84. url: '/pages/exam/error/index',
  85. })
  86. }
  87. })