index.js 2.6 KB

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