123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- // pages/receipt/receipt.js
- const app = getApp();
- const api = require('../../api/api');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- navbarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '收款码', //导航栏 中间的标题,
- capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
- },
- userinfo: wx.getStorageSync('userinfo'),
- modalType: false, //弹框默认不显示
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- downloadImg() {
- wx.showLoading({
- title: '加载中...'
- });
- //wx.downloadFile方法:下载文件资源到本地
- wx.downloadFile({
- url: this.data.userinfo.collection_code, //图片地址
- success: function (res) {
- //wx.saveImageToPhotosAlbum方法:保存图片到系统相册
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath, //图片文件路径
- success: function (data) {
- wx.hideLoading(); //隐藏 loading 提示框
- wx.showModal({
- title: '提示',
- content: '保存成功',
- modalType: false,
- })
- },
- // 接口调用失败的回调函数
- fail: function (err) {
- if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
- wx.showModal({
- title: '提示',
- content: '需要您授权保存相册',
- modalType: false,
- success: modalSuccess => {
- wx.openSetting({
- success(settingdata) {
- console.log("settingdata", settingdata)
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
- wx.showModal({
- title: '提示',
- content: '获取权限成功,再次点击图片即可保存',
- modalType: false,
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '获取权限失败,将无法保存到相册哦~',
- modalType: false,
- })
- }
- },
- fail(failData) {
- console.log("failData", failData)
- },
- complete(finishData) {
- console.log("finishData", finishData)
- }
- })
- }
- })
- }
- },
- complete(res) {
- wx.hideLoading(); //隐藏 loading 提示框
- }
- })
- }
- })
- }
- })
|