index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. spinShow: false,
  7. buyModel:false,
  8. code_url:'',
  9. info:{},
  10. system: "",
  11. groups: [],
  12. pushPaper: [],
  13. timeLimitPaper: [],
  14. userInfo:{},
  15. taskList: []
  16. },
  17. onLoad: function(){
  18. app.checkLogin( userInfo =>{
  19. this.setData({userInfo})
  20. this.indexLoad()
  21. })
  22. let that = this
  23. wx.getSystemInfo({
  24. success: function(res) {
  25. that.setData({system: res.system})
  26. }
  27. })
  28. },
  29. modalConfirm(){
  30. this.setData({buyModel:false})
  31. },
  32. onPullDownRefresh() {
  33. if (!this.loading) {
  34. this.indexLoad( this.stopPullDownRefresh )
  35. }
  36. },
  37. stopPullDownRefresh(){
  38. wx.stopPullDownRefresh()
  39. },
  40. showPhone(){
  41. wx.showToast({
  42. title: "手机"+this.data.userInfo.phone,
  43. type:'success',
  44. duration:2*1000
  45. })
  46. },
  47. indexLoad: function( cb ) {
  48. let _this = this
  49. app.formPost('Exam.index', {}).then(res => {
  50. if (res.code === 200) {
  51. _this.setData({
  52. groups: res.data.groups
  53. });
  54. cb&&cb()
  55. }
  56. })
  57. },
  58. getPhoneNumber (e) {
  59. if( e.detail.errMsg =="getPhoneNumber:ok"){
  60. let param = {
  61. "iv": e.detail.iv,
  62. "encryptedData":e.detail.encryptedData,
  63. }
  64. app.formPost( "User.bindphone", param).then( (res)=>{
  65. if( res.code == 200){
  66. this.setData( {userInfo: res.data})
  67. app.setUserInfo( res.data )
  68. this.indexLoad()
  69. }
  70. })
  71. }else{
  72. app.message("绑定失败", 'error')
  73. }
  74. },
  75. gotoHistory: function(){
  76. wx.navigateTo({
  77. url: '/pages/record/index',
  78. })
  79. },
  80. gotoExam:function( e ){
  81. let groupId = e.currentTarget.dataset.id
  82. wx.navigateTo({
  83. url: `/pages/exam/do/index?id=${groupId}`
  84. })
  85. },
  86. gotoCollectin(){
  87. wx.navigateTo({
  88. url: '/pages/exam/index/index',
  89. })
  90. },
  91. doWxPay( data ){
  92. let that = this
  93. wx.requestPayment({
  94. timeStamp: data.timeStamp,
  95. nonceStr: data.nonceStr,
  96. package: data.package,
  97. signType: data.signType,
  98. paySign: data.paySign,
  99. success: function (event) {
  100. wx.showModal({
  101. title: '支付成功',
  102. showCancel: false,
  103. content: '本次共支付费用¥'+(data.fee/100)+'元'+ `\n\n试卷更新可能延迟,请耐心等待`,
  104. success(res) {
  105. that.indexLoad()
  106. }
  107. })
  108. }
  109. })
  110. },
  111. startWxpay(e){
  112. let groupId = +e.currentTarget.dataset.id
  113. let system = this.data.system
  114. app.formPost('User.PayExam', {groupId, system}).then(res => {
  115. if (res.code === 200) {
  116. if( res.data.payType=="free" ){
  117. this.indexLoad()
  118. }else if (res.data.payType=="qrcode"){
  119. this.setData({info: res.data, buyModel:true})
  120. }else{
  121. this.doWxPay( res.data )
  122. }
  123. }
  124. })
  125. },
  126. onShareAppMessage: function(){
  127. },
  128. gotoError: function(){
  129. wx.navigateTo({
  130. url: '/pages/exam/error/index',
  131. })
  132. }
  133. })