receipt.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // pages/receipt/receipt.js
  2. const app = getApp();
  3. const api = require('../../api/api');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. navbarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '收款码', //导航栏 中间的标题,
  12. capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
  13. },
  14. userinfo: wx.getStorageSync('userinfo'),
  15. modalType: false, //弹框默认不显示
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady: function () {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面隐藏
  34. */
  35. onHide: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面卸载
  39. */
  40. onUnload: function () {
  41. },
  42. /**
  43. * 页面相关事件处理函数--监听用户下拉动作
  44. */
  45. onPullDownRefresh: function () {
  46. },
  47. /**
  48. * 页面上拉触底事件的处理函数
  49. */
  50. onReachBottom: function () {
  51. },
  52. /**
  53. * 用户点击右上角分享
  54. */
  55. onShareAppMessage: function () {
  56. },
  57. downloadImg() {
  58. wx.showLoading({
  59. title: '加载中...'
  60. });
  61. //wx.downloadFile方法:下载文件资源到本地
  62. wx.downloadFile({
  63. url: this.data.userinfo.collection_code, //图片地址
  64. success: function (res) {
  65. //wx.saveImageToPhotosAlbum方法:保存图片到系统相册
  66. wx.saveImageToPhotosAlbum({
  67. filePath: res.tempFilePath, //图片文件路径
  68. success: function (data) {
  69. wx.hideLoading(); //隐藏 loading 提示框
  70. wx.showModal({
  71. title: '提示',
  72. content: '保存成功',
  73. modalType: false,
  74. })
  75. },
  76. // 接口调用失败的回调函数
  77. fail: function (err) {
  78. if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
  79. wx.showModal({
  80. title: '提示',
  81. content: '需要您授权保存相册',
  82. modalType: false,
  83. success: modalSuccess => {
  84. wx.openSetting({
  85. success(settingdata) {
  86. console.log("settingdata", settingdata)
  87. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  88. wx.showModal({
  89. title: '提示',
  90. content: '获取权限成功,再次点击图片即可保存',
  91. modalType: false,
  92. })
  93. } else {
  94. wx.showModal({
  95. title: '提示',
  96. content: '获取权限失败,将无法保存到相册哦~',
  97. modalType: false,
  98. })
  99. }
  100. },
  101. fail(failData) {
  102. console.log("failData", failData)
  103. },
  104. complete(finishData) {
  105. console.log("finishData", finishData)
  106. }
  107. })
  108. }
  109. })
  110. }
  111. },
  112. complete(res) {
  113. wx.hideLoading(); //隐藏 loading 提示框
  114. }
  115. })
  116. }
  117. })
  118. }
  119. })