index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. userInfo:{},
  12. from:0,
  13. size: 10,
  14. type: '',
  15. courseList: []
  16. },
  17. onLoad: function( options ){
  18. let type= options.type||''
  19. this.setData({type})
  20. let that = this
  21. wx.getSystemInfo({
  22. success: function(res) {
  23. that.setData({system: res.system})
  24. }
  25. })
  26. wx.setNavigationBarTitle({
  27. title: type+'-课程购买'
  28. })
  29. },
  30. gotoCourse( e ){
  31. let courseId = e.currentTarget.dataset.id;
  32. wx.navigateTo({
  33. url: `/pages/study/course/index?courseId=${courseId}`,
  34. })
  35. },
  36. onShow: function () {
  37. app.checkLogin( userInfo =>{
  38. this.setData({userInfo, from:0})
  39. this.indexLoad()
  40. })
  41. },
  42. onPullDownRefresh() {
  43. if (!this.loading) {
  44. this.setData({from:0, courseList:[]})
  45. this.indexLoad( this.stopPullDownRefresh )
  46. }
  47. },
  48. onReachBottom() {
  49. if (!this.loading && this.data.from > -1) {
  50. this.indexLoad( )
  51. }
  52. },
  53. stopPullDownRefresh(){
  54. wx.stopPullDownRefresh()
  55. },
  56. indexLoad: function( cb ) {
  57. let param ={
  58. from: this.data.from,
  59. size: this.data.size,
  60. type: this.data.type,
  61. }
  62. let courseList = this.data.courseList;
  63. app.formPost('Study.getWxCourseMarket', param).then(res => {
  64. if (res.code === 200) {
  65. if( param.from == 0){
  66. courseList = [];
  67. }
  68. this.setData({
  69. from: res.data.from,
  70. courseList: courseList.concat(res.data.list),
  71. });
  72. cb&&cb()
  73. }
  74. })
  75. },
  76. downloadFile: function(){
  77. let url = this.data.info.code_url
  78. util.downloadFile( url, res=>{
  79. this.setData({buyModel:false, code_url:''})
  80. } )
  81. },
  82. doWxPay( data ){
  83. let that = this
  84. wx.requestPayment({
  85. timeStamp: data.timeStamp,
  86. nonceStr: data.nonceStr,
  87. package: data.package,
  88. signType: data.signType,
  89. paySign: data.paySign,
  90. success: function (event) {
  91. wx.showModal({
  92. title: '支付成功',
  93. showCancel: false,
  94. content: '本次共支付费用¥'+(data.fee/100)+'元'+ `\n\n试卷更新可能延迟,请耐心等待`,
  95. success(res) {
  96. that.indexLoad()
  97. }
  98. })
  99. }
  100. })
  101. },
  102. startWxpay(e){
  103. let courseId = +e.currentTarget.dataset.id
  104. let system = this.data.system
  105. app.formPost('User.PayCourse', {courseId, system}).then(res => {
  106. if (res.code === 200) {
  107. if( res.data.payType=="free" ){
  108. this.indexLoad()
  109. }else if (res.data.payType=="qrcode"){
  110. this.setData({info: res.data, buyModel:true})
  111. }else{
  112. this.doWxPay( res.data )
  113. }
  114. }
  115. })
  116. },
  117. onShareAppMessage: function(){
  118. },
  119. gotoError: function(){
  120. wx.navigateTo({
  121. url: '/pages/exam/error/index',
  122. })
  123. }
  124. })