index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. var imgSrc= this.data.code_url;
  31. var save = wx.getFileSystemManager();
  32. var number = Math.random();
  33. let that = this
  34. save.writeFile({
  35. filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  36. data: imgSrc,
  37. encoding: 'base64',
  38. success: res => {
  39. wx.saveImageToPhotosAlbum({
  40. filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  41. success: function (res) {
  42. wx.showToast({
  43. title: '保存成功',
  44. })
  45. that.setData({buyModel:false})
  46. },
  47. fail: function (err) {
  48. that.setData({buyModel:false})
  49. }
  50. })
  51. }, fail: err => {
  52. that.setData({buyModel:false})
  53. }
  54. })
  55. },
  56. onPullDownRefresh() {
  57. if (!this.loading) {
  58. this.indexLoad( this.stopPullDownRefresh )
  59. }
  60. },
  61. stopPullDownRefresh(){
  62. wx.stopPullDownRefresh()
  63. },
  64. showPhone(){
  65. wx.showToast({
  66. title: "手机"+this.data.userInfo.phone,
  67. type:'success',
  68. duration:2*1000
  69. })
  70. },
  71. indexLoad: function( cb ) {
  72. let _this = this
  73. app.formPost('Exam.index', {}).then(res => {
  74. if (res.code === 200) {
  75. _this.setData({
  76. groups: res.data.groups
  77. });
  78. cb&&cb()
  79. }
  80. })
  81. },
  82. getPhoneNumber (e) {
  83. if( e.detail.errMsg =="getPhoneNumber:ok"){
  84. let param = {
  85. "iv": e.detail.iv,
  86. "encryptedData":e.detail.encryptedData,
  87. }
  88. app.formPost( "User.bindphone", param).then( (res)=>{
  89. if( res.code == 200){
  90. this.setData( {userInfo: res.data})
  91. app.setUserInfo( res.data )
  92. this.indexLoad()
  93. }
  94. })
  95. }else{
  96. app.message("绑定失败", 'error')
  97. }
  98. },
  99. gotoHistory: function(){
  100. wx.navigateTo({
  101. url: '/pages/record/index',
  102. })
  103. },
  104. gotoExam:function( e ){
  105. let groupId = e.currentTarget.dataset.id
  106. wx.navigateTo({
  107. url: `/pages/exam/do/index?id=${groupId}`
  108. })
  109. },
  110. gotoCollectin(){
  111. wx.navigateTo({
  112. url: '/pages/exam/index/index',
  113. })
  114. },
  115. doWxPay( data ){
  116. let that = this
  117. wx.requestPayment({
  118. timeStamp: data.timeStamp,
  119. nonceStr: data.nonceStr,
  120. package: data.package,
  121. signType: data.signType,
  122. paySign: data.paySign,
  123. success: function (event) {
  124. wx.showModal({
  125. title: '支付成功',
  126. showCancel: false,
  127. content: '本次共支付费用¥'+(data.fee/100)+'元'+ `\n\n试卷更新可能延迟,请耐心等待`,
  128. success(res) {
  129. that.indexLoad()
  130. }
  131. })
  132. }
  133. })
  134. },
  135. startWxpay(e){
  136. let groupId = +e.currentTarget.dataset.id
  137. let system = this.data.system
  138. app.formPost('User.PayExam', {groupId, system}).then(res => {
  139. if (res.code === 200) {
  140. if( res.data.payType=="free" ){
  141. this.indexLoad()
  142. }else if (res.data.payType=="qrcode"){
  143. this.setData({info: res.data, buyModel:true})
  144. }else{
  145. this.doWxPay( res.data )
  146. }
  147. }
  148. })
  149. },
  150. onShareAppMessage: function(){
  151. },
  152. gotoError: function(){
  153. wx.navigateTo({
  154. url: '/pages/exam/error/index',
  155. })
  156. }
  157. })