goodsPoster.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl:'',
  9. ads:'',
  10. goodsId:''
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. wx.showLoading({
  17. title: '生成中',
  18. })
  19. this.setData({
  20. goodsId:options.goodsId
  21. });
  22. util.request(api.QrGoodsCodeCreate, {goodsId:this.data.goodsId
  23. }).then(res=>{
  24. wx.hideLoading();
  25. this.setData({
  26. imgUrl:res.data.imgUrl,
  27. ads:res.data.ads
  28. })
  29. });
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady: function () {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow: function () {
  40. },
  41. copyText(){
  42. wx.setClipboardData({
  43. data: this.data.ads,
  44. success: function (res) {
  45. wx.showToast({
  46. title: '文案复制成功',
  47. icon: 'success',
  48. duration: 2000
  49. });
  50. }
  51. })
  52. },
  53. goSaveQrcode:function(){//保存二维码图片
  54. let that=this;
  55. wx.showLoading({
  56. title: '保存中',
  57. });
  58. wx.downloadFile({
  59. url: that.data.imgUrl,
  60. success:function(res){
  61. wx.hideLoading();
  62. if(res.statusCode===200){
  63. let img=res.tempFilePath;
  64. wx.saveImageToPhotosAlbum({
  65. filePath: img,
  66. success(res){
  67. wx.showToast({
  68. title: '保存成功'
  69. })
  70. },
  71. })
  72. }
  73. },
  74. fail(res){
  75. wx.hideLoading();
  76. util.showErrorToast('图片保存失败 请重试');
  77. }
  78. })
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. onShareAppMessage: function () {
  104. }
  105. })