index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const app = getApp()
  2. Page({
  3. data: {
  4. spinShow: false,
  5. buyModel:false,
  6. code_url:'',
  7. info:{},
  8. system: "",
  9. groups: [],
  10. pushPaper: [],
  11. timeLimitPaper: [],
  12. userInfo:{},
  13. from:0,
  14. size: 10,
  15. type:'岗前培训',
  16. courseList: []
  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. gotoCourse( e ){
  27. let courseId = e.currentTarget.dataset.id;
  28. wx.navigateTo({
  29. url: `/pages/study/course/index?courseId=${courseId}`,
  30. })
  31. },
  32. onShow: function () {
  33. app.checkLogin( userInfo =>{
  34. this.setData({userInfo, from:0})
  35. this.indexLoad()
  36. })
  37. },
  38. onPullDownRefresh() {
  39. if (!this.loading) {
  40. this.indexLoad( this.stopPullDownRefresh )
  41. }
  42. },
  43. stopPullDownRefresh(){
  44. wx.stopPullDownRefresh()
  45. },
  46. indexLoad: function( cb ) {
  47. let param ={
  48. from: this.data.from,
  49. size: this.data.size,
  50. type:this.data.type,
  51. }
  52. app.formPost('Study.GetWxCourseList', param).then(res => {
  53. if (res.code === 200) {
  54. this.setData({
  55. from: res.data.from,
  56. courseList: res.data.list,
  57. });
  58. cb&&cb()
  59. }
  60. })
  61. },
  62. gotoExam:function( e ){
  63. let groupId = e.currentTarget.dataset.id
  64. wx.navigateTo({
  65. url: `/pages/exam/do/index?id=${groupId}`
  66. })
  67. },
  68. doWxPay( data ){
  69. let that = this
  70. wx.requestPayment({
  71. timeStamp: data.timeStamp,
  72. nonceStr: data.nonceStr,
  73. package: data.package,
  74. signType: data.signType,
  75. paySign: data.paySign,
  76. success: function (event) {
  77. wx.showModal({
  78. title: '支付成功',
  79. showCancel: false,
  80. content: '本次共支付费用¥'+(data.fee/100)+'元'+ `\n\n试卷更新可能延迟,请耐心等待`,
  81. success(res) {
  82. that.indexLoad()
  83. }
  84. })
  85. }
  86. })
  87. },
  88. startWxpay(e){
  89. let groupId = +e.currentTarget.dataset.id
  90. let system = this.data.system
  91. app.formPost('User.PayExam', {groupId, system}).then(res => {
  92. if (res.code === 200) {
  93. if( res.data.payType=="free" ){
  94. this.indexLoad()
  95. }else if (res.data.payType=="qrcode"){
  96. this.setData({info: res.data, buyModel:true})
  97. }else{
  98. this.doWxPay( res.data )
  99. }
  100. }
  101. })
  102. }
  103. })