share-popup.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view>
  3. <component-popup :propShow="popup_status" propPosition="bottom" @onclose="popup_close_event">
  4. <view class="share-popup bg-white">
  5. <view class="close fr oh">
  6. <view class="fr" @tap.stop="popup_close_event">
  7. <icon type="clear" size="20"></icon>
  8. </view>
  9. </view>
  10. <view class="share-popup-content">
  11. <!-- #ifdef H5 -->
  12. <view class="share-items oh cp" @tap="share_h5_event">
  13. <image :src="common_static_url+'share-user-icon.png'" mode="scaleToFill"></image>
  14. <text class="cr-gray text-size-xs single-text">点击复制地址分享给好友、群聊</text>
  15. </view>
  16. <!-- #endif -->
  17. <!-- #ifdef MP-ALIPAY -->
  18. <view class="share-items oh cp" @tap="share_base_event">
  19. <image :src="common_static_url+'share-user-icon.png'" mode="scaleToFill"></image>
  20. <text class="cr-gray text-size-xs single-text">一键分享给好友、群聊</text>
  21. </view>
  22. <!-- #endif -->
  23. <!-- #ifdef MP-WEIXIN || MP-BAIDU || MP-QQ || MP-TOUTIAO || MP-KUAISHOU -->
  24. <view class="share-items oh cp">
  25. <button class="dis-block br-0 ht-auto" type="default" size="mini" open-type="share" hover-class="none" @tap="popup_close_event">
  26. <image :src="common_static_url+'share-user-icon.png'" mode="scaleToFill"></image>
  27. <text class="cr-gray text-size-xs single-text">一键分享给好友、群聊</text>
  28. </button>
  29. </view>
  30. <!-- #endif -->
  31. <view v-if="is_goods_poster == 1 && (goods_id || 0) != 0" class="share-items oh cp" @tap="poster_event">
  32. <image :src="common_static_url+'share-friend-icon.png'" mode="scaleToFill"></image>
  33. <text class="cr-gray text-size-xs single-text">生成海报,分享到朋友圈、好友及群聊</text>
  34. </view>
  35. </view>
  36. </view>
  37. </component-popup>
  38. </view>
  39. </template>
  40. <script>
  41. const app = getApp();
  42. var common_static_url = app.globalData.get_static_url('common');
  43. import componentPopup from "../../components/popup/popup";
  44. export default {
  45. data() {
  46. return {
  47. common_static_url: common_static_url,
  48. popup_status: false,
  49. is_goods_poster: 0,
  50. goods_id: 0
  51. };
  52. },
  53. components: {
  54. componentPopup
  55. },
  56. created: function() {},
  57. methods: {
  58. // 初始配置
  59. init(config = {}) {
  60. if(!app.globalData.is_single_page_check()) {
  61. return false;
  62. }
  63. this.setData({
  64. popup_status: config.status == undefined ? true : config.status,
  65. is_goods_poster: config.is_goods_poster || 0,
  66. goods_id: config.goods_id || 0
  67. });
  68. },
  69. // 弹层关闭
  70. popup_close_event(e) {
  71. this.setData({
  72. popup_status: false
  73. });
  74. },
  75. // h5分享
  76. share_h5_event() {
  77. app.globalData.text_copy_event(app.globalData.get_page_url());
  78. },
  79. // 基础分享事件
  80. share_base_event() {
  81. this.setData({
  82. popup_status: false
  83. });
  84. uni.pageScrollTo({
  85. scrollTop: 0,
  86. duration: 300,
  87. complete: res => {
  88. setTimeout(function() {
  89. uni.showShareMenu();
  90. }, 500);
  91. }
  92. });
  93. },
  94. // 商品海报分享
  95. poster_event() {
  96. var user = app.globalData.get_user_info(this, 'poster_event');
  97. if (user != false) {
  98. // 用户未绑定用户则转到登录页面
  99. if (app.globalData.user_is_need_login(user)) {
  100. uni.navigateTo({
  101. url: "/pages/login/login?event_callback=poster_event"
  102. });
  103. return false;
  104. } else {
  105. uni.showLoading({
  106. title: '生成中...'
  107. });
  108. uni.request({
  109. url: app.globalData.get_request_url('goodsposter', 'distribution', 'distribution'),
  110. method: 'POST',
  111. data: {goods_id: this.goods_id},
  112. dataType: 'json',
  113. success: res => {
  114. uni.hideLoading();
  115. if (res.data.code == 0) {
  116. uni.previewImage({
  117. current: res.data.data,
  118. urls: [res.data.data]
  119. });
  120. } else {
  121. if (app.globalData.is_login_check(res.data, this, 'poster_event')) {
  122. app.globalData.showToast(res.data.msg);
  123. }
  124. }
  125. },
  126. fail: () => {
  127. uni.hideLoading();
  128. app.globalData.showToast('服务器请求出错');
  129. }
  130. });
  131. }
  132. }
  133. }
  134. }
  135. };
  136. </script>
  137. <style>
  138. .share-popup {
  139. padding: 20rpx 10rpx 0 10rpx;
  140. position: relative;
  141. }
  142. .share-popup .close {
  143. position: absolute;
  144. top: 20rpx;
  145. right: 20rpx;
  146. z-index: 2;
  147. }
  148. .share-popup-content {
  149. padding: 0 20rpx;
  150. margin-top: 40rpx;
  151. text-align: left;
  152. }
  153. .share-popup-content .share-items {
  154. padding: 30rpx 0;
  155. height: 85rpx;
  156. }
  157. .share-popup-content .share-items:not(:first-child) {
  158. border-top: 1px solid #f0f0f0;
  159. }
  160. .share-popup-content .share-items button {
  161. background: transparent;
  162. padding: 0;
  163. width: 100%;
  164. text-align: left;
  165. margin: 0;
  166. }
  167. .share-popup-content .share-items image {
  168. width: 80rpx;
  169. height: 80rpx;
  170. vertical-align: middle;
  171. margin-right: 20rpx;
  172. }
  173. .share-popup-content .share-items .single-text {
  174. width: calc(100% - 100rpx);
  175. line-height: 85rpx;
  176. }
  177. </style>