123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //index.js
- //获取应用实例
- const app = getApp()
- Page({
- data: {
- spinShow: false,
- buyModel:false,
- code_url:'',
- info:{},
- system: "",
- groups: [],
- pushPaper: [],
- timeLimitPaper: [],
- userInfo:{},
- taskList: []
- },
- onLoad: function(){
- app.checkLogin( userInfo =>{
- this.setData({userInfo})
- this.indexLoad()
- })
- let that = this
- wx.getSystemInfo({
- success: function(res) {
- that.setData({system: res.system})
- }
- })
- },
- modalConfirm(){
- var imgSrc= this.data.code_url;
- var save = wx.getFileSystemManager();
- var number = Math.random();
- let that = this
- save.writeFile({
- filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
- data: imgSrc,
- encoding: 'base64',
- success: res => {
- wx.saveImageToPhotosAlbum({
- filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
- success: function (res) {
- wx.showToast({
- title: '保存成功',
- })
- that.setData({buyModel:false})
- },
- fail: function (err) {
- that.setData({buyModel:false})
- }
- })
- }, fail: err => {
- that.setData({buyModel:false})
- }
- })
-
- },
- onPullDownRefresh() {
- if (!this.loading) {
- this.indexLoad( this.stopPullDownRefresh )
- }
- },
- stopPullDownRefresh(){
- wx.stopPullDownRefresh()
- },
- showPhone(){
- wx.showToast({
- title: "手机"+this.data.userInfo.phone,
- type:'success',
- duration:2*1000
- })
- },
- indexLoad: function( cb ) {
- let _this = this
- app.formPost('Exam.index', {}).then(res => {
- if (res.code === 200) {
- _this.setData({
- groups: res.data.groups
- });
- cb&&cb()
- }
- })
- },
- getPhoneNumber (e) {
- if( e.detail.errMsg =="getPhoneNumber:ok"){
- let param = {
- "iv": e.detail.iv,
- "encryptedData":e.detail.encryptedData,
- }
- app.formPost( "User.bindphone", param).then( (res)=>{
- if( res.code == 200){
- this.setData( {userInfo: res.data})
- app.setUserInfo( res.data )
- this.indexLoad()
- }
- })
- }else{
- app.message("绑定失败", 'error')
- }
- },
- gotoHistory: function(){
- wx.navigateTo({
- url: '/pages/record/index',
- })
- },
- gotoExam:function( e ){
- let groupId = e.currentTarget.dataset.id
- wx.navigateTo({
- url: `/pages/exam/do/index?id=${groupId}`
- })
- },
- gotoCollectin(){
- wx.navigateTo({
- url: '/pages/exam/index/index',
- })
- },
- doWxPay( data ){
- let that = this
- wx.requestPayment({
- timeStamp: data.timeStamp,
- nonceStr: data.nonceStr,
- package: data.package,
- signType: data.signType,
- paySign: data.paySign,
- success: function (event) {
- wx.showModal({
- title: '支付成功',
- showCancel: false,
- content: '本次共支付费用¥'+(data.fee/100)+'元'+ `\n\n试卷更新可能延迟,请耐心等待`,
- success(res) {
- that.indexLoad()
- }
- })
- }
- })
- },
- startWxpay(e){
- let groupId = +e.currentTarget.dataset.id
- let system = this.data.system
- app.formPost('User.PayExam', {groupId, system}).then(res => {
- if (res.code === 200) {
- if( res.data.payType=="free" ){
- this.indexLoad()
- }else if (res.data.payType=="qrcode"){
- this.setData({info: res.data, buyModel:true})
- }else{
- this.doWxPay( res.data )
- }
- }
- })
- },
- onShareAppMessage: function(){
- },
- gotoError: function(){
- wx.navigateTo({
- url: '/pages/exam/error/index',
- })
- }
- })
|