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