index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. },
  18. onLoad: function(){
  19. let that = this
  20. wx.getSystemInfo({
  21. success: function(res) {
  22. that.setData({system: res.system})
  23. }
  24. })
  25. },
  26. onShow: function(){
  27. app.checkLogin( userInfo =>{
  28. this.setData({userInfo})
  29. // 已经实名认证
  30. this.indexLoad()
  31. })
  32. },
  33. onPullDownRefresh() {
  34. if (!this.loading) {
  35. this.indexLoad( this.stopPullDownRefresh )
  36. }
  37. },
  38. stopPullDownRefresh(){
  39. wx.stopPullDownRefresh()
  40. },
  41. indexLoad: function( cb ) {
  42. let _this = this
  43. app.formPost('Exam.index', {}).then(res => {
  44. if (res.code === 200) {
  45. _this.setData({
  46. groups: res.data.groups
  47. });
  48. cb&&cb()
  49. }
  50. })
  51. },
  52. downloadFile: function(){
  53. let url = this.data.info.code_url
  54. util.downloadFile( url, res=>{
  55. this.setData({buyModel:false, code_url:''})
  56. } )
  57. },
  58. gotoHistory: function(){
  59. wx.navigateTo({
  60. url: '/pages/exam/record/index',
  61. })
  62. },
  63. gotoExam:function( e ){
  64. let {groupId, answerId} = e.currentTarget.dataset.item
  65. // wx.navigateTo({
  66. // url: `/pages/exam/do/index?id=${groupId}`
  67. // })
  68. wx.navigateTo({
  69. url: `/pages/exam/group/group?groupId=${groupId}&answerId=${answerId}`
  70. })
  71. },
  72. gotoCollection(){
  73. wx.navigateTo({
  74. url: '/pages/exam/collection/index',
  75. })
  76. },
  77. doWxPay( data ){
  78. let that = this
  79. wx.requestPayment({
  80. timeStamp: data.timeStamp,
  81. nonceStr: data.nonceStr,
  82. package: data.package,
  83. signType: data.signType,
  84. paySign: data.paySign,
  85. success: function (event) {
  86. wx.showModal({
  87. title: '支付成功',
  88. showCancel: false,
  89. content: '本次共支付费用¥'+(data.fee/100)+'元'+ `\n\n试卷更新可能延迟,请耐心等待`,
  90. success(res) {
  91. that.indexLoad()
  92. }
  93. })
  94. }
  95. })
  96. },
  97. startWxpay(e){
  98. let groupId = +e.currentTarget.dataset.id
  99. let system = this.data.system
  100. app.formPost('User.PayExam', {groupId, system}).then(res => {
  101. if (res.code === 200) {
  102. if( res.data.payType=="free" ){
  103. this.indexLoad()
  104. }else if (res.data.payType=="qrcode"){
  105. this.setData({info: res.data, buyModel:true})
  106. }else{
  107. this.doWxPay( res.data )
  108. }
  109. }
  110. })
  111. },
  112. onShareAppMessage: function(){
  113. },
  114. gotoError: function(){
  115. wx.navigateTo({
  116. url: '/pages/exam/error/index',
  117. })
  118. }
  119. })