index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/home/index?groupId=${groupId}&answerId=${answerId}`
  67. })
  68. },
  69. gotoCollection(){
  70. wx.navigateTo({
  71. url: '/pages/exam/collection/index',
  72. })
  73. },
  74. doWxPay( data ){
  75. let that = this
  76. wx.requestPayment({
  77. timeStamp: data.timeStamp,
  78. nonceStr: data.nonceStr,
  79. package: data.package,
  80. signType: data.signType,
  81. paySign: data.paySign,
  82. success: function (event) {
  83. wx.showModal({
  84. title: '支付成功',
  85. showCancel: false,
  86. content: '本次共支付费用¥'+(data.fee/100)+'元'+ `\n\n试卷更新可能延迟,请耐心等待`,
  87. success(res) {
  88. that.indexLoad()
  89. }
  90. })
  91. }
  92. })
  93. },
  94. startWxpay(e){
  95. let groupId = +e.currentTarget.dataset.id
  96. let system = this.data.system
  97. app.formPost('User.PayExam', {groupId, system}).then(res => {
  98. if (res.code === 200) {
  99. if( res.data.payType=="free" ){
  100. this.indexLoad()
  101. }else if (res.data.payType=="qrcode"){
  102. this.setData({info: res.data, buyModel:true})
  103. }else{
  104. this.doWxPay( res.data )
  105. }
  106. }
  107. })
  108. },
  109. onShareAppMessage: function(){
  110. },
  111. gotoError: function(){
  112. wx.navigateTo({
  113. url: '/pages/exam/error/index',
  114. })
  115. }
  116. })