index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. spinShow: false,
  7. groups: [],
  8. pushPaper: [],
  9. timeLimitPaper: [],
  10. userInfo:{},
  11. taskList: []
  12. },
  13. onLoad: function(){
  14. app.checkLogin( userInfo =>{
  15. this.setData({userInfo})
  16. this.indexLoad()
  17. })
  18. },
  19. onPullDownRefresh() {
  20. if (!this.loading) {
  21. this.indexLoad( this.stopPullDownRefresh )
  22. }
  23. },
  24. stopPullDownRefresh(){
  25. wx.stopPullDownRefresh()
  26. },
  27. showPhone(){
  28. wx.showToast({
  29. title: "手机"+this.data.userInfo.phone,
  30. type:'success',
  31. duration:2*1000
  32. })
  33. },
  34. indexLoad: function( cb ) {
  35. let _this = this
  36. app.formPost('Exam.index', {}).then(res => {
  37. if (res.code === 200) {
  38. _this.setData({
  39. groups: res.data.groups
  40. });
  41. cb&&cb()
  42. }
  43. })
  44. },
  45. getPhoneNumber (e) {
  46. if( e.detail.errMsg =="getPhoneNumber:ok"){
  47. let param = {
  48. "iv": e.detail.iv,
  49. "encryptedData":e.detail.encryptedData,
  50. }
  51. app.formPost( "User.bindphone", param).then( (res)=>{
  52. if( res.code == 200){
  53. this.setData( {userInfo: res.data})
  54. app.setUserInfo( res.data )
  55. this.indexLoad()
  56. }
  57. })
  58. }else{
  59. app.message("绑定失败", 'error')
  60. }
  61. },
  62. gotoHistory: function(){
  63. wx.navigateTo({
  64. url: '/pages/record/index',
  65. })
  66. },
  67. gotoExam:function( e ){
  68. let groupId = e.currentTarget.dataset.id
  69. wx.navigateTo({
  70. url: `/pages/exam/do/index?id=${groupId}`
  71. })
  72. },
  73. doWxPay( data ){
  74. wx.requestPayment({
  75. timeStamp: data.timeStamp,//记住,这边的timeStamp一定要是字符串类型的,不然会报错
  76. nonceStr: data.nonceStr,
  77. package: data.package,
  78. signType: data.signType,
  79. paySign: data.paySign,
  80. success: function (event) {
  81. console.log(event);
  82. wx.showToast({title: '支付成功',icon: 'success', duration: 2000 });
  83. }
  84. })
  85. },
  86. startWxpay(e){
  87. let groupId = +e.currentTarget.dataset.id
  88. app.formPost('User.PayExam', {groupId}).then(res => {
  89. if (res.code === 200) {
  90. this.doWxPay( res.data )
  91. }
  92. })
  93. },
  94. gotoError: function(){
  95. wx.navigateTo({
  96. url: '/pages/exam/error/index',
  97. })
  98. }
  99. })