猎豆优选小程序

shareGoodsDetail.vue 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <view class="page-wrap">
  3. <!-- 顶部按钮 -->
  4. <!-- <image :style="{'top': `${statusBarHeight}px`}" class="back-btn" src="https://ld.726p.com/ldyx_static/imgs/btn-back.png" @click="onClickToBack" /> -->
  5. <!-- S 轮播图 -->
  6. <view class="swiper-wrap">
  7. <u-swiper
  8. :list="swiperList"
  9. height="750"
  10. mode="round"
  11. bg-color="transparent"
  12. />
  13. </view>
  14. <view class="commission-price-view" v-if="user_level > 1 && goodsItem.commission_price > 0" @click="onClickCommission">猎豆优选专享,下单或分享可获{{goodsItem.commission_price}}元</view>
  15. <!-- E 轮播图 -->
  16. <!-- S 商品信息 -->
  17. <view class="info-wrap con-block">
  18. <view class="tp-wrap">
  19. <view class="lt-wrap">
  20. <text class="price-title">{{goodsItem.is_coupon == 1 && goodsItem.coupon_price > 0 ? '券后价' : '' }} ¥</text>
  21. <text class="price">{{ goodsItem.discount_price }}</text>
  22. <text class="price-old">¥{{ goodsItem.price }}</text>
  23. </view>
  24. <view class="rt-wrap">
  25. <view class="salesVolume" v-if="goodsItem.volume > 100">
  26. 月销:{{ $NumberHandle({value:goodsItem.volume,comma:true}) }}+
  27. </view>
  28. </view>
  29. </view>
  30. <view class="bm-wrap">
  31. <image class="shop-icon" v-if="goodsItem.shop_type == 0" src="https://ld.726p.com/ldyx_static/imgs/icon-tb.png" />
  32. <image class="shop-icon" v-else-if="goodsItem.shop_type == 1" src="https://ld.726p.com/ldyx_static/imgs/icon-tmall.png" />
  33. {{ goodsItem.title }}
  34. </view>
  35. <view class="quan-block" v-if="goodsItem.is_coupon == 1 && goodsItem.coupon_price > 0" @click="copyTKL">
  36. <view class="quan-info">
  37. <view class="quan-info-1">
  38. 优惠券 ¥<text class="quan-price">{{goodsItem.coupon_price}}</text>
  39. </view>
  40. <view class="quan-time">{{goodsItem.coupon_start_time && goodsItem.coupon_start_time.slice(0,16)}} ~ {{goodsItem.coupon_end_time && goodsItem.coupon_end_time.slice(0,16)}}</view>
  41. </view>
  42. <view class="quan-button">复制淘口令</view>
  43. </view>
  44. </view>
  45. <!-- E 商品信息 -->
  46. <!-- S 店铺信息 -->
  47. <view class="shop-wrap con-block">
  48. <view class="lt-wrap">
  49. <image class="shop-img" :src="goodsItem.shop.pic_path" />
  50. </view>
  51. <view class="rt-wrap">
  52. <view class="tp-wrap">
  53. <text class="shop-name">{{ goodsItem.shop.title }}</text>
  54. <view class="enter-wrap">
  55. </view>
  56. </view>
  57. <view class="point-wrap">
  58. <text>宝贝描述 {{ goodsItem.shop.item_score }}</text>
  59. <text>服务态度 {{ goodsItem.shop.service_score }}</text>
  60. <text>发货速度 {{ goodsItem.shop.delivery_score }}</text>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- E 店铺信息 -->
  65. <!-- S 相关推荐 -->
  66. <view class="recommend-wrap con-block">
  67. <view class="block-title">相关推荐</view>
  68. <view class="goods-list-wrap">
  69. <view v-for="item in recommendList" :key="item.goods_id" class="goods-item-wrap" @click="onClickGoodsItem(item)">
  70. <image class="goods-img" :src="item.img" />
  71. <view v-if="user_level > 1 && item.commission_price > 0" class="goods-commission">预估佣金 ¥{{ item.commission_price }}</view>
  72. <view class="goods-title">{{ item.title }}</view>
  73. <view class="goods-price">
  74. <text class="price">¥{{ item.discount_price }}</text>
  75. <text class="price-old">¥{{ item.price }}</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- E 相关推荐 -->
  81. <!-- S 宝贝详情 -->
  82. <view class="detail-wrap con-block">
  83. <view class="block-title">宝贝详情</view>
  84. <view class="content">
  85. <image class="price-img" src="https://gw.alicdn.com/tfs/TB1k9XsQpXXXXXLXpXXXXXXXXXX-750-368.png" mode="widthFix"/>
  86. </view>
  87. </view>
  88. <!-- E 宝贝详情 -->
  89. <!-- S 猜你喜欢 -->
  90. <view class="guess-wrap con-block">
  91. <view class="block-title">猜你喜欢</view>
  92. <!-- S 双排商品列表 -->
  93. <view class="goods-list-double-wrap">
  94. <block v-for="goodsItem in guessList">
  95. <verticalGood class="verticalGoodItem" v-if="goodsItem" :key="goodsItem.goods_id" :goodsItem="goodsItem" path="goodsItemRecommendAction"></verticalGood>
  96. </block>
  97. </view>
  98. <!-- E 双排商品列表 -->
  99. </view>
  100. <!-- E 猜你喜欢 -->
  101. <!-- 底部按钮 -->
  102. <view class="open-tb-btn-view" :style="{ 'bottom': isIphoneX ? '120rpx' : '100rpx' }">
  103. <image v-if="isIOS" @click="goTb" class="open-tb-btn" src="https://ld.726p.com/ldyx_static/imgs/open-tb-btn.png" mode="widthFix"></image>
  104. <view v-else class="copy-tkl" @click="copyTKL">复制淘口令</view>
  105. </view>
  106. <!-- 回到顶部 -->
  107. <u-back-top :scroll-top="scrollTop"></u-back-top>
  108. </view>
  109. </template>
  110. <script>
  111. const app = getApp()
  112. const $router = app.globalData.$router
  113. import verticalGood from '@/components/verticalGood.vue'
  114. export default {
  115. components:{
  116. verticalGood
  117. },
  118. data() {
  119. return {
  120. isIOS: app.globalData.isIOS,
  121. isIphoneX: app.globalData.isIphoneX,
  122. statusBarHeight: app.globalData.statusBarHeight,
  123. swiperList: [], // 轮播图列表(image指定图片路径,也可以通过name属性自定义)
  124. recommendList: [], // 相关推荐列表
  125. guessList: [], // 猜你喜欢列表
  126. guessListPage: 1,
  127. guessListHasNext: true,
  128. goods_id: '', // 商品id
  129. goodsParams: {}, // 商品参数(用于获取商品详情的相关参数 前一页面传入)
  130. goodsItem: { // 商品详情数据
  131. discount_price: '',
  132. price: '',
  133. volume: '',
  134. title: '',
  135. coupon_price: '',
  136. shop: {
  137. pic_path: '',
  138. title: '',
  139. delivery_score: '',
  140. item_score: '',
  141. service_score: '',
  142. },
  143. },
  144. isLogin: false, // 是否已登录
  145. user_level: uni.getStorageSync('userInfo') ?
  146. uni.getStorageSync('userInfo').user_level : '', // 当前用户等级
  147. scrollTop: 0,
  148. tkl: ''
  149. };
  150. },
  151. onPageScroll(e) {
  152. this.scrollTop = e.scrollTop;
  153. },
  154. onLoad(options) {
  155. const { user_id = '', goods_id = '', coupon_price = '', discount_price = '', price = '', is_coupon = '', commission_rate = '', is_high_commission = '', coupon_end_time = '', coupon_start_time = '' } = options
  156. // 接收前一页面传入的商品参数
  157. this.goods_id = decodeURIComponent(goods_id)
  158. this.goodsParams = {
  159. user_id: decodeURIComponent(user_id),
  160. goods_id: decodeURIComponent(goods_id),
  161. coupon_price: decodeURIComponent(coupon_price),
  162. discount_price: decodeURIComponent(discount_price),
  163. price: decodeURIComponent(price),
  164. is_coupon: decodeURIComponent(is_coupon),
  165. commission_rate: decodeURIComponent(commission_rate),
  166. is_high_commission: decodeURIComponent(is_high_commission),
  167. coupon_end_time: decodeURIComponent(coupon_end_time),
  168. coupon_start_time: decodeURIComponent(coupon_start_time),
  169. }
  170. // 获取商品详情数据
  171. this.handleGetgoodsItem()
  172. // 获取相关推荐列表
  173. this.handleGetRecommendList()
  174. // 获取猜你喜欢列表
  175. this.handleGetGuessList()
  176. // 获取用户登录状态
  177. this.handleGetUserIsLogin()
  178. // 用户浏览信息上报
  179. // this.handleUserReport()
  180. // 商品分享获取数据接口
  181. this.handleGetPosterInfo()
  182. },
  183. // 上滑触底事件
  184. onReachBottom() {
  185. this.handleGetGuessList()
  186. },
  187. methods: {
  188. //去淘宝
  189. goTb(){
  190. let tklCode = this.tkl;
  191. let params = tklCode.split('https://m.tb.cn')[1].split(' ')[0].split('/')[1];
  192. const a = document.createElement('a');
  193. a.style.display = 'none';
  194. // a.href = `https://b.mashort.cn${params}`; // 可唤起
  195. a.href = `https://s.tb.cn/${params}` // 可唤起
  196. document.body.appendChild(a);
  197. a.click();
  198. document.body.removeChild(a);
  199. },
  200. // 用户浏览信息上报
  201. // async handleUserReport() {
  202. // if (!this.isLogin) return false
  203. // const { goods_id, is_coupon, coupon_price, price, discount_price, commission_rate, coupon_end_time, coupon_start_time } = this.goodsParams
  204. // try {
  205. // const url = this.$api.goodsItem_record
  206. // const params = { goods_id, is_coupon, coupon_price, price, discount_price, commission_rate, coupon_end_time, coupon_start_time }
  207. // await this.$postJSON(url, params)
  208. // } catch (error) {
  209. // console.log('error => ', error)
  210. // }
  211. // },
  212. // 获取用户登录状态
  213. handleGetUserIsLogin() {
  214. const userInfo = uni.getStorageSync('userInfo') || ''
  215. const user_id = uni.getStorageSync('user_id') || ''
  216. if (userInfo && user_id) {
  217. this.isLogin = true
  218. } else {
  219. this.isLogin = false
  220. }
  221. },
  222. // 获取猜你喜欢列表
  223. async handleGetGuessList() {
  224. const { guessListPage, guessListHasNext, goods_id } = this
  225. if (!guessListHasNext) return false
  226. try {
  227. uni.showLoading({ title: '加载中...', mask: true })
  228. const url = this.$api.goods_recommendlist
  229. const params = { page: guessListPage, goods_id, user_id: this.goodsParams.user_id }
  230. const { data: res = {} } = await this.$postJSON(url, params)
  231. if (res && res.errno == 0 && Array.isArray(res.rst.data)) {
  232. this.guessListHasNext = res.rst.pageInfo.hasNext
  233. this.guessListHasNext && this.guessListPage++
  234. this.guessList = [...this.guessList, ...res.rst.data]
  235. } else {
  236. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  237. }
  238. } catch (error) {
  239. console.log('error => ', error)
  240. } finally {
  241. uni.hideLoading()
  242. }
  243. },
  244. // 获取相关推荐列表
  245. async handleGetRecommendList() {
  246. try {
  247. uni.showLoading({ title: '加载中...', mask: true })
  248. const url = this.$api.goods_recommendtop
  249. const params = { goods_id: this.goods_id ,user_id: this.goodsParams.user_id}
  250. const { data: res = {} } = await this.$postJSON(url, params)
  251. if (res && res.errno == 0 && Array.isArray(res.rst.data)) {
  252. this.recommendList = [...res.rst.data]
  253. } else {
  254. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  255. }
  256. } catch (error) {
  257. console.log('error => ', error)
  258. } finally {
  259. uni.hideLoading()
  260. }
  261. },
  262. // 获取商品详情数据
  263. async handleGetgoodsItem() {
  264. const { user_id, goods_id, coupon_price, discount_price, price, is_coupon, commission_rate } = this.goodsParams
  265. try {
  266. uni.showLoading({ title: '加载中...', mask: true })
  267. const url = this.$api.goods_detail
  268. const params = { goods_id, coupon_price, discount_price, price, is_coupon, commission_rate ,user_id}
  269. const { data: res = {} } = await this.$postJSON(url, params)
  270. if (res && res.errno == 0 && res.rst.data) {
  271. this.goodsItem = { ...res.rst.data }
  272. this.swiperList = res.rst.data.small_img.map(item => ({
  273. image: item
  274. }))
  275. } else {
  276. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  277. }
  278. } catch (error) {
  279. console.log('error => ', error)
  280. } finally {
  281. uni.hideLoading()
  282. }
  283. },
  284. // 监听点击"返回"
  285. onClickToBack() {
  286. uni.navigateBack()
  287. },
  288. // 监听跳转详情
  289. onClickGoodsItem(goodsItem) {
  290. try{ app.categoryNew_countBuy({type:0,path:'goodsItemTopRecommendAction'}) }catch(e){} ; // 数据上报
  291. const { img = '', goods_id = '', coupon_price = '', discount_price = '', price = '', is_coupon = '', commission_rate = '', is_high_commission = '', coupon_end_time = '', coupon_start_time = '' } = goodsItem
  292. const pages = getCurrentPages()
  293. const currentPageLength = pages.length
  294. // 微信小程序 页面栈限制 最多10页
  295. if (currentPageLength < 10) {
  296. uni.navigateTo({
  297. url: `/pages/subPackages/home/goodsDetail?img=${encodeURIComponent(img)}&goods_id=${encodeURIComponent(goods_id)}&coupon_price=${encodeURIComponent(coupon_price)}&discount_price=${encodeURIComponent(discount_price)}&price=${encodeURIComponent(price)}&is_coupon=${encodeURIComponent(is_coupon)}&commission_rate=${encodeURIComponent(commission_rate)}&is_high_commission=${encodeURIComponent(is_high_commission)}&coupon_end_time=${encodeURIComponent(coupon_end_time)}&coupon_start_time=${encodeURIComponent(coupon_start_time)}`
  298. })
  299. } else {
  300. uni.redirectTo({
  301. url: `/pages/subPackages/home/goodsDetail?img=${encodeURIComponent(img)}&goods_id=${encodeURIComponent(goods_id)}&coupon_price=${encodeURIComponent(coupon_price)}&discount_price=${encodeURIComponent(discount_price)}&price=${encodeURIComponent(price)}&is_coupon=${encodeURIComponent(is_coupon)}&commission_rate=${encodeURIComponent(commission_rate)}&is_high_commission=${encodeURIComponent(is_high_commission)}&coupon_end_time=${encodeURIComponent(coupon_end_time)}&coupon_start_time=${encodeURIComponent(coupon_start_time)}`
  302. })
  303. }
  304. },
  305. // 监听点击收藏
  306. onClickSetFavorites() {
  307. if (!this.isLogin) { // 未登录 => 去登录
  308. $router.navigateTo({
  309. url: '/pages/subPackages/login/loginPhone'
  310. })
  311. } else {
  312. this.handleSetFavorites()
  313. }
  314. },
  315. async handleSetFavorites() {
  316. const { user_id, goods_id, is_coupon, discount_price, price, coupon_price, commission_rate, coupon_end_time, coupon_start_time } = this.goodsParams
  317. try {
  318. uni.showLoading({ title: '加载中...', mask: true })
  319. const url = this.$api.goodsItem_addFavorites
  320. const params = { goods_id, is_coupon, discount_price, price, coupon_price, commission_rate, coupon_end_time, coupon_start_time, user_id }
  321. const { data: res } = await this.$postJSON(url, params)
  322. if (res && res.errno == 0) {
  323. // 设置成功 => 更新状态
  324. this.handleGetgoodsItem()
  325. } else {
  326. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  327. }
  328. } catch (error) {
  329. console.log('error => ', error)
  330. } finally {
  331. uni.hideLoading()
  332. }
  333. },
  334. // 监听点击“反佣金”
  335. onClickCommission() {
  336. $router.navigateTo({
  337. url: `/pages/subPackages/my/tqjs`
  338. })
  339. },
  340. copyTKL(){
  341. this.$copyEvent( {text: this.tkl} )
  342. },
  343. // 获取分享商品海报的参数信息
  344. async handleGetPosterInfo() {
  345. const { goods_id, is_coupon, user_id} = this.goodsParams
  346. try {
  347. const url = this.$api.goodsItem_getTKL;
  348. const params = { goods_id, is_coupon, user_id }
  349. const { data: res } = await this.$postJSON(url, params)
  350. if (res && res.errno == 0 && res.rst.data) {
  351. this.tkl = res.rst.data;
  352. } else {
  353. }
  354. } catch (error) {
  355. }
  356. },
  357. },
  358. }
  359. </script>
  360. <style lang="scss" scoped>
  361. @import '@/static/style/goodsDetail.scss';
  362. .open-tb-btn-view{
  363. width: 360rpx;
  364. position: fixed;
  365. left: 0;
  366. right: 0;
  367. bottom: 100rpx;
  368. margin: auto;
  369. }
  370. .open-tb-btn{
  371. width: 100%;
  372. height: 100%;
  373. }
  374. .copy-tkl{
  375. background: #fb5b05;
  376. line-height: 80rpx;
  377. text-align: center;
  378. border-radius: 80rpx;
  379. font-size: 32rpx;
  380. color: #ffffff;
  381. font-weight: bold;
  382. }
  383. </style>