猎豆优选小程序

shareDetail.vue 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view>
  3. <u-navbar :is-back="true" title="分享" :background="background" title-color="#181818" back-icon-color="#181818" />
  4. <image class="head_bg" src="https://ld.726p.com/ldyx_static/imgs/head_bg.png" mode="widthFix"></image>
  5. <!-- 商品文案 -->
  6. <view class="area_block">
  7. <view class="area_title">商品文案</view>
  8. <textarea class="h_block textare" v-model="share_content" placeholder-style="color:#ccc" placeholder="请输入文案"/>
  9. <view class="h_block">【商品详情】{{posterInfo && posterInfo.url_info && posterInfo.url_info.share_link ? posterInfo.url_info.share_link : '-'}}</view>
  10. </view>
  11. <!-- 图片选择 -->
  12. <view class="area_block area_block_image">
  13. <view class="area_title">图片选择</view>
  14. <scroll-view class="image_blcok" scroll-x="true">
  15. <view class="image_item" v-if="canvasImage" @click="openclickImage(-1)">
  16. <u-icon class="image_select" @tap.stop="selectImg(-1)" name="checkmark-circle-fill" :color="select_share_image_id == -1 ? '#FB3F3C' : '#ccc'" size="40"></u-icon>
  17. <image class="image" :src="canvasImage"></image>
  18. </view>
  19. <view class="image_item" v-if="goodsParams.img" @click="openclickImage(-2)">
  20. <u-icon class="image_select" @tap.stop="selectImg(-2)" name="checkmark-circle-fill" :color="select_share_image_id == -2 ? '#FB3F3C' : '#ccc'" size="40"></u-icon>
  21. <image class="image" :src="goodsParams.img"></image>
  22. </view>
  23. <view class="image_item" v-for="(img,index) in posterInfo.small_images" :key="index" @click="openclickImage(index)">
  24. <u-icon class="image_select" @tap.stop="selectImg(index)" name="checkmark-circle-fill" :color="select_share_image_id == index ? '#FB3F3C' : '#ccc'" size="40"></u-icon>
  25. <image class="image" :src="img"></image>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. <!-- 提示语 -->
  30. <view class="share_hint">提示:点击【分享】将自动复制文案和转发选中图片,请前往对话框进行文字粘贴</view>
  31. <!-- 按钮 -->
  32. <view class="share_button_view">
  33. <button class="share_xcx" open-type="share">分享小程序</button>
  34. <button class="share_hint_img" @click="goShare">分享</button>
  35. </view>
  36. <!-- 海报 -->
  37. <createShareImage :goodsParams="goodsParams" :isDyGoods="true" @getCanvasImage="getCanvasImage"></createShareImage>
  38. </view>
  39. </template>
  40. <script>
  41. import createShareImage from '@/components/createShareImage.vue'
  42. export default {
  43. components:{
  44. createShareImage
  45. },
  46. data() {
  47. return {
  48. background:{
  49. backgroundImage: 'transparent'
  50. },
  51. goods_id: '', // 商品id
  52. goodsParams: {}, // 商品参数(用于获取商品详情的相关参数 前一页面传入)
  53. canvasImage: '', // 二维码图片地址
  54. posterInfo: {}, // 商品分享数据
  55. share_content: '', // 分享文案
  56. select_share_image_id: -3, // 选择图片的ID,什么都没选择为-3,-1为canvas图片,-2是从列表带过来的商品主图,其他图片从0递增
  57. previous_page_options: {}, //上一页传入
  58. shop_type: '', // 商品店铺类型 4京东
  59. }
  60. },
  61. onLoad(options) {
  62. this.previous_page_options = options;
  63. const { img = '', goods_id = '', coupon_price = '', discount_price = '', price = '', is_coupon = '', commission_rate = '', is_high_commission = '', coupon_end_time = '', coupon_start_time = '', title = '' } = options
  64. // 接收前一页面传入的商品参数
  65. this.goods_id = decodeURIComponent(goods_id)
  66. this.goodsParams = {
  67. goods_id: decodeURIComponent(goods_id),
  68. coupon_price: decodeURIComponent(coupon_price),
  69. discount_price: decodeURIComponent(discount_price),
  70. price: decodeURIComponent(price),
  71. is_coupon: decodeURIComponent(is_coupon),
  72. commission_rate: decodeURIComponent(commission_rate),
  73. is_high_commission: decodeURIComponent(is_high_commission),
  74. coupon_end_time: decodeURIComponent(coupon_end_time),
  75. coupon_start_time: decodeURIComponent(coupon_start_time),
  76. img: decodeURIComponent(img),
  77. title: decodeURIComponent(title),
  78. }
  79. this.shop_type = options.shop_type || '' // 商品店铺类型 淘宝、天猫、京东
  80. },
  81. onShareAppMessage(res) {
  82. const title = this.posterInfo.title;
  83. let userInfo = uni.getStorageSync('userInfo') || '';
  84. // 将传入对象转为&连接的字符串
  85. let arr1 = [];
  86. Object.keys(this.previous_page_options).forEach((key)=>{
  87. arr1.push([key,this.previous_page_options[key]].join('='))
  88. })
  89. let str1 = arr1.join('&')
  90. let path = `/pages/subPackages/dy/goodsDetail?invite_code=${userInfo.invite_code}&${str1}`
  91. return {
  92. title: title,
  93. path: path,
  94. imageUrl: this.goodsParams.img ? this.goodsParams.img : this.posterInfo.small_images[0],
  95. desc:'',
  96. content:'',
  97. success(res){
  98. uni.showToast({
  99. title:'分享成功'
  100. })
  101. },
  102. fail(res){
  103. uni.showToast({
  104. title:'分享失败',
  105. icon:'none'
  106. })
  107. }
  108. }
  109. },
  110. methods: {
  111. // 点击查看大图
  112. openclickImage (id) {
  113. let img_url = ''
  114. if(id == -2){
  115. img_url = this.goodsParams.img
  116. } else if(id == -1){
  117. img_url = this.canvasImage;
  118. }else{
  119. img_url = this.posterInfo.small_images[id]
  120. }
  121. var url = img_url;
  122. wx.previewImage({
  123. current: url,
  124. urls: [url],
  125. fail: function () {
  126. console.log('fail')
  127. },
  128. complete: function () {
  129. console.info("点击图片了");
  130. },
  131. })
  132. },
  133. // 图片选择
  134. selectImg(id){
  135. if ( this.select_share_image_id == id ) { // 点击同一个图片,选择取消
  136. this.select_share_image_id = -3
  137. } else {
  138. this.select_share_image_id = id;
  139. }
  140. },
  141. // 去分享
  142. goShare(){
  143. // 下单链接
  144. let placeOrderUrl = this.posterInfo && this.posterInfo.url_info && this.posterInfo.url_info.share_link
  145. // 复制文案
  146. const share_content = `${this.share_content}\n[爱心]下单链接:${placeOrderUrl}`
  147. this.$copyEvent( {text: share_content, toast_title: '文案已复制',cb:()=>{
  148. // 图片分享
  149. if ( this.select_share_image_id == -3 ) return ;
  150. if ( this.select_share_image_id == -2 ) { // 商品主图
  151. wx.downloadFile({
  152. url: this.goodsParams.img,
  153. success: (res) => {
  154. wx.showShareImageMenu({
  155. path: res.tempFilePath
  156. })
  157. }
  158. })
  159. } else if ( this.select_share_image_id == -1 ) { // canvas图片
  160. wx.showShareImageMenu({
  161. path: this.canvasImage
  162. })
  163. } else {
  164. const img_url = this.posterInfo.small_images[this.select_share_image_id];
  165. wx.downloadFile({
  166. url: img_url,
  167. success: (res) => {
  168. wx.showShareImageMenu({
  169. path: res.tempFilePath
  170. })
  171. }
  172. })
  173. }
  174. }} )
  175. },
  176. // 获取二维码图片地址
  177. getCanvasImage({image, posterInfo}){
  178. this.canvasImage = image;
  179. this.posterInfo = posterInfo;
  180. this.share_content = `${posterInfo.title}\n${posterInfo.is_coupon == 1 && posterInfo.coupon_price != 0 ? `【在售】${posterInfo.price}\n【券后价】${posterInfo.discount_price}` : `【在售】${posterInfo.discount_price}`}\n`
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .head_bg{
  187. position: absolute;
  188. top: 0;
  189. left: 0;
  190. width: 100%;
  191. }
  192. .area_block{
  193. width: 702rpx;
  194. height: 594rpx;
  195. background: #FFFFFF;
  196. border-radius: 12rpx;
  197. margin: 18rpx auto 0;
  198. position: relative;
  199. .area_title{
  200. color: #181818;
  201. font-size: 32rpx;
  202. line-height: 106rpx;
  203. border-bottom: 2rpx solid #F9F9FA;
  204. padding-left: 42rpx;
  205. }
  206. .h_block{
  207. width: 662rpx;
  208. background: #F6F6F6;
  209. padding: 26rpx;
  210. color: #181818;
  211. font-size: 28rpx;
  212. line-height: 40rpx;
  213. margin: auto;
  214. box-sizing: border-box;
  215. }
  216. .textare{
  217. margin-top: 26rpx;
  218. margin-bottom: 10rpx;
  219. height: 336rpx;
  220. }
  221. }
  222. .area_block_image{
  223. height: 366rpx;
  224. }
  225. .image_blcok{
  226. white-space: nowrap;
  227. width: 100%;
  228. margin-top: 44rpx;
  229. .image_item{
  230. display: inline-block;
  231. width: 180rpx;
  232. height: 180rpx;
  233. margin-left: 20rpx;
  234. position: relative;
  235. .image_select{
  236. position: absolute;
  237. top: 0rpx;
  238. right: 0rpx;
  239. padding: 10rpx 10rpx 40rpx 40rpx;
  240. }
  241. .image{
  242. width: 100%;
  243. height: 100%;
  244. }
  245. }
  246. }
  247. .share_hint{
  248. width: 654rpx;
  249. height: 68rpx;
  250. font-size: 24rpx;
  251. color: #E55454;
  252. line-height: 34rpx;
  253. margin: 26rpx auto 0;
  254. }
  255. .share_button_view{
  256. width: 628rpx;
  257. height: 84rpx;
  258. background: #FFBB93;
  259. border-radius: 42rpx;
  260. margin: 56rpx auto 0;
  261. display: flex;
  262. align-items: center;
  263. button{
  264. background: transparent;
  265. margin: 0;
  266. width: 50%;
  267. color: #FFFFFF;
  268. font-size: 36rpx;
  269. font-weight: bold;
  270. &::after{
  271. border: none;
  272. }
  273. }
  274. .share_hint_img{
  275. width: 366rpx;
  276. height: 100%;
  277. background: linear-gradient(90deg, #FF9048 0%, #FB3F3C 100%);
  278. border-radius: 42rpx;
  279. }
  280. }
  281. </style>