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.getUserInfo( userInfo =>{
  28. this.setData({userInfo})
  29. console.log( "userInfo", userInfo)
  30. // 已经实名认证
  31. if( userInfo.identify ){
  32. this.indexLoad()
  33. }
  34. })
  35. },
  36. onPullDownRefresh() {
  37. if (!this.loading) {
  38. this.indexLoad( this.stopPullDownRefresh )
  39. }
  40. },
  41. stopPullDownRefresh(){
  42. wx.stopPullDownRefresh()
  43. },
  44. indexLoad: function( cb ) {
  45. let _this = this
  46. app.formPost('Exam.index', {}).then(res => {
  47. if (res.code === 200) {
  48. _this.setData({
  49. groups: res.data.groups
  50. });
  51. cb&&cb()
  52. }
  53. })
  54. },
  55. downloadFile: function(){
  56. let url = this.data.info.code_url
  57. util.downloadFile( url, res=>{
  58. this.setData({buyModel:false, code_url:''})
  59. } )
  60. },
  61. gotoHistory: function(){
  62. wx.navigateTo({
  63. url: '/pages/exam/record/index',
  64. })
  65. },
  66. gotoExam:function( e ){
  67. let groupId = e.currentTarget.dataset.id
  68. wx.navigateTo({
  69. url: `/pages/exam/do/index?id=${groupId}`
  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. })