shareF.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="content">
  3. <image src="http://xxl.liuniu946.com/static/image/share-bg.png" mode="" class="bg"></image>
  4. <view class="">
  5. </view>
  6. <view class="share-user-logo">
  7. <image :src="userlogo" mode=""></image>
  8. </view>
  9. <view class="good">
  10. <image src="http://xxl.liuniu946.com/static/image/good.png" mode=""></image>
  11. </view>
  12. <view class="good-tit">
  13. {{goodname}}
  14. </view>
  15. <!-- #ifdef MP-WEIXIN -->
  16. <button class="share-btn" open-type="share" v-if="couldshare == 1">
  17. 立即分享
  18. </button>
  19. <!-- #endif -->
  20. <!-- #ifdef H5 -->
  21. <button class="share-btn" open-type="share" v-if="couldshare == 1" @click="imgShare = true">
  22. 立即分享
  23. </button>
  24. <!-- #endif -->
  25. <view class="share-btn" v-if="couldshare == 2" @click="getGift">
  26. {{jsspan}}
  27. </view>
  28. <image src="../../static/img/shareimg.png" mode="widthFix" style="position: fixed;top:0;width: 750rpx;"
  29. v-if="imgShare" @click="imgShare = !imgShare">
  30. </image>
  31. </view>
  32. </template>
  33. <script>
  34. // #ifdef H5
  35. import {
  36. weixindata,
  37. shareLoad
  38. } from '@/utils/wxAuthorized';
  39. // #endif
  40. import {
  41. getGift
  42. } from '@/api/shop.js'
  43. export default {
  44. data() {
  45. return {
  46. code: '',
  47. imgShare: false,
  48. userlogo: '',
  49. shareId: '',
  50. nickname: '',
  51. goodimg: '',
  52. couldshare: 0,
  53. jsspan: '立即领取',
  54. goodname: ''
  55. }
  56. },
  57. onLoad(opt) {
  58. this.code = opt.code
  59. this.userlogo = opt.logo
  60. this.shareId = opt.shareid
  61. this.nickname = decodeURI(opt.nickname)
  62. this.couldshare = opt.type
  63. this.goodname = decodeURI(opt.goodname)
  64. // #ifdef MP
  65. if (opt.type == 2) {
  66. if (opt.scene) {
  67. // 存储小程序邀请人
  68. uni.setStorage({
  69. key: 'spread_code',
  70. data: opt.scene
  71. });
  72. }
  73. }
  74. // #endif
  75. // #ifdef H5
  76. this.IndexShare()
  77. // #endif
  78. },
  79. // 分享
  80. onShareAppMessage(options) {
  81. let obj = this
  82. // 设置菜单中的转发按钮触发转发事件时的转发内容
  83. let pages = getCurrentPages(); //获取加载的页面
  84. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  85. let url = currentPage.route; //当前页面url
  86. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  87. // let name = this.goodsObjact.store_name || this.goodsObjact.title;
  88. let shareObj = {
  89. title: obj.nickname + '分享您一张子臣鸭汤兑换券', // 默认是小程序的名称(可以写slogan等)
  90. path: url + '?code=' + obj.code + '&type=2' +
  91. '&logo=' + obj.userlogo +
  92. '&nickname=' + encodeURI(obj.nickname) + '&goodname=' + encodeURI(obj
  93. .goodname), // 默认是当前页面,必须是以‘/’开头的完整路径
  94. imageUrl: 'http://xxl.liuniu946.com/static/image/good.png',
  95. success: function(res) {
  96. console.log(shareObj.path, 'path+++++++++++++++++++');
  97. // 转发成功之后的回调
  98. if (res.errMsg == 'shareAppMessage:ok') {}
  99. },
  100. fail: function() {
  101. // 转发失败之后的回调
  102. if (res.errMsg == 'shareAppMessage:fail cancel') {
  103. // 用户取消转发
  104. } else if (res.errMsg == 'shareAppMessage:fail') {
  105. // 转发失败,其中 detail message 为详细失败信息
  106. }
  107. }
  108. };
  109. return shareObj;
  110. },
  111. methods: {
  112. // #ifdef H5
  113. IndexShare() {
  114. let obj = this;
  115. console.log(obj.Path);
  116. // 保存邀请人
  117. let data = {
  118. link: obj.$store.state.baseURL + '/index/#/pages/shop/shareF?code=' + obj.code + '&type=2' +
  119. '&logo=' + obj.userlogo +
  120. '&nickname=' + encodeURI(obj.nickname) + '&goodname=' + encodeURI(obj.goodname),
  121. title: obj.nickname + '向您分享' + obj.goodname,
  122. desc: '欢迎加入想亮',
  123. imgUrl: 'http://xxl.liuniu946.com/static/image/good.png'
  124. };
  125. console.log(data, '分享数据');
  126. shareLoad(data);
  127. },
  128. // #endif
  129. getGift() {
  130. let obj = this
  131. console.log('ddd')
  132. getGift({
  133. code: obj.code
  134. }).then(res => {
  135. console.log(res)
  136. uni.showToast({
  137. title: '领取成功',
  138. duration: 2000
  139. });
  140. obj.jsspan = '已领取'
  141. setTimeout(() => {
  142. uni.switchTab({
  143. url: '/pages/index/index'
  144. })
  145. }, 1500)
  146. }).catch(err => {
  147. console.log(err)
  148. })
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. page {
  155. background-color: #901b21;
  156. width: 100%;
  157. height: 100%
  158. }
  159. .content {
  160. position: relative;
  161. background-color: #901b21;
  162. min-height: 100%;
  163. .bg {
  164. // position: absolute;
  165. width: 750rpx;
  166. height: 1334rpx;
  167. }
  168. .share-btn {
  169. width: 492rpx;
  170. height: 86rpx;
  171. background-color: #ebd49e;
  172. border-radius: 43rpx;
  173. text-align: center;
  174. line-height: 86rpx;
  175. color: #901b21;
  176. font-weight: bold;
  177. font-size: 36rpx;
  178. position: absolute;
  179. top: 1159rpx;
  180. left: 130rpx;
  181. }
  182. .share-user-logo {
  183. position: absolute;
  184. top: 400rpx;
  185. left: 0;
  186. right: 0;
  187. margin: auto;
  188. width: 118rpx;
  189. height: 118rpx;
  190. border-radius: 50%;
  191. image {
  192. width: 118rpx;
  193. height: 118rpx;
  194. border-radius: 50%;
  195. }
  196. }
  197. .good {
  198. width: 290rpx;
  199. height: 290rpx;
  200. border-radius: 20rpx;
  201. position: absolute;
  202. top: 560rpx;
  203. left: 0;
  204. right: 0;
  205. margin: auto;
  206. image {
  207. width: 290rpx;
  208. height: 290rpx;
  209. border-radius: 20rpx;
  210. }
  211. }
  212. .good-tit {
  213. position: absolute;
  214. font-size: 32rpx;
  215. color: #901b21;
  216. text-align: center;
  217. width: 750rpx;
  218. top: 880rpx;
  219. }
  220. }
  221. </style>