123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- const app = getApp();
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- user_id:{
- type: String|Number,
- value: false,
- },
- },
- /**
- * 组件的初始数据
- */
- data: {
- imgCode:'',
- minute:300,
- timer:1,
- timeMsg:'',
- isIOS:app.data.isIOS,
- writePhotosFlag:-1,
- token:''
- },
- pageLifetimes: {
- show: function(options) {
- this.getSet()
- },
- hide: function() {
- // 页面被隐藏
- clearInterval(this.data.timer)
- },
- },
- lifetimes: {
- attached: function() {
- // 在组件实例进入页面节点树时执行
- this.getToken()
- this.getSet()
- }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- getSet(){
- var _this = this;
- wx.getSetting({
- success(res) {
- if(res.authSetting['scope.writePhotosAlbum'] == false){
- _this.setData({writePhotosFlag:false})
- }
- if(res.authSetting['scope.writePhotosAlbum'] == true){
- _this.setData({writePhotosFlag:true})
- }
- }
- })
- },
- CountDown() {//倒计时
- var maxtime = this.data.minute
- var minutes = '', seconds = ''
- this.setData({timeMsg:''})
- var timer = setInterval(()=>{
- if (maxtime >= 0) {
- minutes = Math.floor(maxtime / 60)<10?('0'+Math.floor(maxtime / 60)):Math.floor(maxtime / 60);
- seconds = Math.floor(maxtime % 60)<10?('0'+Math.floor(maxtime % 60)):Math.floor(maxtime % 60);
- this.setData({timeMsg: minutes + ":" + seconds + "后失效"});
- --maxtime;
- } else{
- this.setData({timeMsg:'已失效,请重新刷新'})
- clearInterval(this.data.timer);
- }
- },1000)
- this.setData({timer:timer})
- },
- getToken(){
- wx.showLoading({
- title: '加载中',
- })
- app.func.req('/api/sphClaim/getToken', 'get', {}, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- this.setData({
- token:res.rst.token
- })
- wx.setStorageSync('claim_token', res.rst.token)
- this.getEvm()
- }else{
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
-
- },
- getEvm(){
- this.setData({
- imgCode:app.data.rootDocment+'/api/sphClaim/getQRcode?token='+this.data.token,
- })
- this.CountDown()
- },
- downLoadImgEvent(){
- if(!this.data.writePhotosFlag){
- wx.openSetting()
- return
- }
- var _this = this;
- wx.getSetting({
- success(res) {
- if (!res.authSetting['scope.writePhotosAlbum']) {
- _this.setData({writePhotosFlag:false})
- wx.authorize({
- scope:'scope.writePhotosAlbum',
- success() {//授权成功
- _this.setData({writePhotosFlag:true})
- _this.downloadImg()
- },
- fail:function(err){
- _this.setData({writePhotosFlag:false})
- }
- })
- }else{//已经授权
- _this.setData({writePhotosFlag:true})
- _this.downloadImg()
- }
- }
- })
- },
- downloadImg(){
- var imgSrc = this.data.imgCode
- wx.downloadFile({
- url: imgSrc,
- success: function (res) {
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function (data) {
- wx.showToast({
- title: '保存成功',
- icon: 'success',
- duration: 2000
- })
- },
- fail: function (err) {
- },
- complete(res){
- }
- })
- }
- })
- },
- claimResetList(){
- this.triggerEvent('claimResetList')
- },
- cancelTask(){
- this.triggerEvent('closeClaimMask')
- },
- }
- })
|