share.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. goodShareImg: ''
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: function (options) {
  13. let type = options.type || '';
  14. if (type == 'commiss'){
  15. this.getCommissShareImage();
  16. }else {
  17. this.getShareImage();
  18. }
  19. },
  20. /**
  21. * 商品列表分享图
  22. */
  23. getShareImage: function () {
  24. wx.showLoading({ title: '获取中' })
  25. var that = this;
  26. var token = wx.getStorageSync('token');
  27. var community_id = wx.getStorageSync('community').communityId;
  28. app.util.request({
  29. url: 'entry/wxapp/user',
  30. data: {
  31. controller: 'user.user_index_shareqrcode',
  32. community_id,
  33. token: token
  34. },
  35. dataType: 'json',
  36. method: 'POST',
  37. success: function (res) {
  38. if (res.data.code == 0) {
  39. let goodShareImg = res.data.image_path;
  40. that.setData({ goodShareImg });
  41. wx.hideLoading();
  42. // var image_path = res.data.image_path;
  43. // wx.getImageInfo({
  44. // src: image_path,
  45. // success: function (res) {
  46. // var real_path = res.path;
  47. // wx.saveImageToPhotosAlbum({
  48. // filePath: real_path,
  49. // success(res) {
  50. // wx.showToast({
  51. // title: '图片保存成功,可以分享了',
  52. // icon: 'none',
  53. // duration: 2000
  54. // })
  55. // that.setData({
  56. // is_share_html: true
  57. // });
  58. // }
  59. // })
  60. // }
  61. // })
  62. }
  63. }
  64. })
  65. },
  66. /**
  67. * 会员分销分享图
  68. */
  69. getCommissShareImage: function () {
  70. wx.showLoading({ title: '获取中' })
  71. var that = this;
  72. var token = wx.getStorageSync('token');
  73. app.util.request({
  74. url: 'entry/wxapp/user',
  75. data: {
  76. controller: 'distribution.get_haibao',
  77. token: token
  78. },
  79. dataType: 'json',
  80. method: 'POST',
  81. success: function (res) {
  82. if (res.data.code == 0) {
  83. let goodShareImg = res.data.commiss_qrcode;
  84. that.setData({ goodShareImg });
  85. wx.hideLoading();
  86. }
  87. }
  88. })
  89. },
  90. //图片点击事件
  91. preImg: function (event) {
  92. var src = event.currentTarget.dataset.src;//获取data-src
  93. var goodShareImg = this.data.goodShareImg;//获取data-list
  94. //图片预览
  95. wx.previewImage({
  96. current: src, // 当前显示图片的http链接
  97. urls: [goodShareImg] // 需要预览的图片http链接列表
  98. })
  99. },
  100. /**
  101. * 生命周期函数--监听页面显示
  102. */
  103. onShow: function () {
  104. }
  105. })