海南旅游项目 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
11 KiB

  1. <template>
  2. <view>
  3. <skeleton :loading="skeletonLoading" :row="12" :showAvatar="false" :showTitle="true">
  4. <block v-if="isRight(goods_detail)">
  5. <!-- 商品图片轮播 -->
  6. <swiper :current="current" :indicator-dots="goods_detail.product.pictures.length > 1 ? true : false" :circular="true" class="swiper-box" indicator-active-color="#1998FE">
  7. <swiper-item v-for="(item, index) in goods_detail.product.pictures" :key="index">
  8. <image mode="aspectFill" :src="item" style="width: 100%; height: 100%;" @click="lookImg(index)"></image>
  9. </swiper-item>
  10. </swiper>
  11. <!-- 商品主要信息 -->
  12. <view class="head-info">
  13. <view class="lf-font-32 lf-color-333 lf-font-bold">{{ goods_detail.product.title }}</view>
  14. <view class="lf-row-between lf-font-24 lf-m-t-30 lf-p-b-20">
  15. <view class="lf-flex price">
  16. <lf-price :price="goods_detail.price"></lf-price>
  17. <view class="lf-m-l-20">¥{{ goods_detail.original_price }}</view>
  18. <view v-if="goods_detail.cost">{{ goods_detail.cost }}</view>
  19. </view>
  20. <view class="lf-font-24 lf-text-right">
  21. <view class="lf-color-gray">已售 {{ goods_detail.sale }}</view>
  22. <view class="lf-color-gray">库存 {{ goods_detail.product.stock }}</view>
  23. <!-- <view class="lf-color-primary">{{ goods_detail.specs[0].stock_text }}</view> -->
  24. </view>
  25. </view>
  26. <view class="label-box" v-if="goods_detail.coupon && goods_detail.coupon.length">
  27. <view class="label-item" v-for="(item, index) in goods_detail.coupon" :key="index">{{ item.tag }}</view>
  28. </view>
  29. </view>
  30. <!-- 地址信息 -->
  31. <!-- <view class="address-box">
  32. <view class="lf-font-32 lf-font-bold">适用门店</view>
  33. <view class="lf-m-t-20 lf-row-between">
  34. <view class="lf-flex">
  35. <image mode="aspectFill" class="lf-fle shop-img" :src="goods_detail.store.cover" v-if="goods_detail.store.cover"></image>
  36. <image mode="aspectFill" class="lf-fle shop-img" src="../../static/center/shop-logo.png" v-else></image>
  37. <view class="lf-font-32 lf-m-l-20 lf-line-1" style="max-width: 512rpx;">{{ goods_detail.store.name }}</view>
  38. </view>
  39. <view @click="makePhoneCall(goods_detail.store.tel)">
  40. <text class="lf-iconfont lf-icon-dianhua lf-font-40" style="color: #3A62FF;"></text>
  41. </view>
  42. </view>
  43. <view class="lf-flex lf-m-t-20" @click="openMap">
  44. <view style="width: 60rpx; height: 60rpx;" class="lf-row-center">
  45. <text class="lf-iconfont lf-icon-dizhi lf-font-40" style="color: #555555;"></text>
  46. </view>
  47. <view class="lf-m-l-20 lf-font-28" style="color: #555555;">{{ goods_detail.store.address }}</view>
  48. </view>
  49. </view> -->
  50. <!-- 商品详情 -->
  51. <view class="goods-detail">
  52. <view class="lf-font-32 lf-font-bold lf-m-b-20">旅游须知</view>
  53. <rich-text :nodes="formatRichText(goods_detail.product.know)"></rich-text>
  54. <!-- <image class="goods-img" :src="item" v-for="(item, index) in goods_detail.content" :key="index" v-if="goods_detail.content_type == 'img'"></image> -->
  55. </view>
  56. <!-- 修饰专用 -->
  57. <view class="extra"></view>
  58. <!-- 吸底操作按钮 -->
  59. <view class="lf-row-between fixed-bottom">
  60. <view class="lf-flex lf-p-t-10 lf-p-b-10">
  61. <view class="lf-flex-column lf-row-center icon-item" @click="$url('/pages/index/index', {type: 'switch'})">
  62. <image class="icon-img" src="../../static/tabbar/home.png"></image>
  63. <view class="lf-m-t-1">首页</view>
  64. </view>
  65. <button class="lf-flex-column lf-row-center icon-item" open-type="contact">
  66. <image class="icon-img" src="../../static/center/service.png"></image>
  67. <view class="lf-m-t-1">客服</view>
  68. </button>
  69. <view class="lf-flex-column lf-row-center icon-item" @click="switchCollect">
  70. <image class="icon-img" src="../../static/center/collect-active.png" v-if="is_collect"></image>
  71. <image class="icon-img" src="../../static/center/collect.png" v-else></image>
  72. <view class="lf-m-t-1">{{ is_collect ? '已收藏' : '收藏' }}</view>
  73. </view>
  74. <button class="lf-flex-column lf-row-center icon-item" open-type="share">
  75. <image class="icon-img" src="../../static/center/share.png"></image>
  76. <view class="lf-m-t-1">分享</view>
  77. </button>
  78. </view>
  79. <button class="btn" @click="toAddOrder">立即购买</button>
  80. </view>
  81. <!-- 回到顶部 -->
  82. <!-- <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}" :icon-style="{color: '#ffffff'}"></u-back-top> -->
  83. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
  84. </block>
  85. </skeleton>
  86. </view>
  87. </template>
  88. <script>
  89. export default {
  90. data(){
  91. return {
  92. current: 0, // 轮播下标
  93. goods_id: 0,
  94. goods_detail: {},
  95. is_collect: false, // 1为当前收藏商品了,0为否
  96. skeletonLoading: true
  97. }
  98. },
  99. onLoad(options){
  100. this.goods_id = options.goods_id;
  101. console.log('商品',this.goods_id)
  102. this.getGoodsDetail();
  103. },
  104. computed: {
  105. isRight() {
  106. return function(val) {
  107. return this.$shared.isRight(val);
  108. }
  109. }
  110. },
  111. methods: {
  112. getGoodsDetail(){
  113. this.$http(this.API.API_ADVICEDETAILS, {id: this.goods_id}).then(res => {
  114. this.skeletonLoading = false;
  115. this.goods_detail = res.data;
  116. this.is_collect = Boolean(res.data.is_collect) || false;
  117. }).catch(err => {
  118. this.skeletonLoading = false;
  119. setTimeout(() => {
  120. this.$toBack();
  121. }, 1000);
  122. })
  123. },
  124. // 切换商品收藏
  125. switchCollect(){
  126. let userInfo = uni.getStorageSync('userinfo') || {};
  127. if(!userInfo.id || !userInfo.nickname || !userInfo.avatar){
  128. this.$url('/pages/login/index?type=userinfo');
  129. return;
  130. }
  131. if(this.is_collect) {
  132. this.$http(this.API.API_DELCOLLECT, {agent_product_id:this.goods_id}).then(res => {
  133. this.$msg('取消收藏成功!')
  134. this.is_collect = false
  135. console.log(res)
  136. })
  137. }else {
  138. this.$http(this.API.API_ADDCOLLECT, {agent_product_id:this.goods_id}).then(res => {
  139. this.$msg('添加收藏成功!')
  140. this.is_collect = true
  141. console.log(res)
  142. })
  143. }
  144. },
  145. // 拨打电话
  146. makePhoneCall(phoneStr){
  147. uni.makePhoneCall({
  148. phoneNumber: String(phoneStr)
  149. })
  150. },
  151. // 打开地图
  152. openMap(){
  153. let { address, lat, lng } = this.goods_detail?.store || {};
  154. uni.openLocation({
  155. longitude: Number(lat),
  156. latitude: Number(lng),
  157. scale: 20,
  158. name: address
  159. });
  160. },
  161. // 跳转到确认下单页面
  162. toAddOrder(){
  163. let goods_id = this.goods_detail.id;
  164. this.$url('/pages/order/confirm_order?goods_id='+ goods_id);
  165. },
  166. // 预览图片
  167. lookImg(index){
  168. this.$u.throttle(() => {
  169. let goods_banner = this.goods_detail.banners || [];
  170. let banners = goods_banner.map(item => item.cover);
  171. uni.previewImage({
  172. urls: banners,
  173. current: index
  174. })
  175. }, 200);
  176. },
  177. // 富文本处理
  178. formatRichText(richText){
  179. if(richText != null){
  180. let newRichText= richText.replace(/<img[^>]*>/gi, function(match, capture){
  181. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  182. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  183. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  184. return match;
  185. });
  186. newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){
  187. match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;');
  188. return match;
  189. });
  190. newRichText = newRichText.replace(/<br[^>]*\/>/gi, '');
  191. newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
  192. return newRichText;
  193. }else{
  194. return null;
  195. }
  196. }
  197. },
  198. onShareAppMessage(){
  199. let goods = this.goods_detail;
  200. let title = goods.name;
  201. let imageUrl = goods.share_cover || goods.cover;
  202. let path = '/pages/route/index?route=goods_detail&id='+ goods.id;
  203. return {
  204. title,
  205. path,
  206. imageUrl
  207. }
  208. }
  209. }
  210. </script>
  211. <style>
  212. page{
  213. background-color: #f5f5f5;
  214. overflow-x: hidden;
  215. }
  216. </style>
  217. <style lang="scss" scoped="scoped">
  218. .swiper-box{
  219. width: 750rpx;
  220. height: 490rpx;
  221. background-color: #FFFFFF;
  222. }
  223. .head-info{
  224. width: 750rpx;
  225. height: auto;
  226. box-sizing: border-box;
  227. padding: 0 32rpx;
  228. padding-top: 20rpx;
  229. background-color: #FFFFFF;
  230. // .price>view:nth-of-type(1){
  231. // color: #FF0000;
  232. // margin-right: 22rpx;
  233. // font-weight: bold;
  234. // }
  235. .price>view:nth-of-type(1){
  236. text-decoration: line-through;
  237. color: #777777;
  238. margin-right: 22rpx;
  239. }
  240. .price>view:nth-of-type(2){
  241. width: max-content;
  242. padding: 0 18rpx;
  243. height: 46rpx;
  244. background-color: #1998FE;
  245. border-radius: 10rpx;
  246. display: flex;
  247. justify-content: center;
  248. align-items: center;
  249. color: #FFFFFF;
  250. }
  251. .label-box{
  252. min-height: 130rpx;
  253. width: 100%;
  254. border-top: 1rpx solid #E5E5E5;
  255. display: flex;
  256. flex-wrap: wrap;
  257. padding: 30rpx 0 10rpx 0;
  258. .label-item{
  259. width: max-content;
  260. padding: 20rpx;
  261. height: 70rpx;
  262. border-radius: 10rpx;
  263. border: 2rpx solid #1998FE;
  264. display: flex;
  265. justify-content: center;
  266. align-items: center;
  267. font-size: 28rpx;
  268. color: #1998FE;
  269. margin-right: 20rpx;
  270. margin-bottom: 20rpx;
  271. }
  272. }
  273. }
  274. .address-box{
  275. width: 750rpx;
  276. height: auto;
  277. box-sizing: border-box;
  278. background-color: #FFFFFF;
  279. padding: 32rpx;
  280. margin-top: 20rpx;
  281. .shop-img{
  282. width: 60rpx;
  283. height: 60rpx;
  284. border-radius: 50%;
  285. }
  286. }
  287. .goods-detail{
  288. width: 750rpx;
  289. height: auto;
  290. background-color: #FFFFFF;
  291. padding: 32rpx;
  292. box-sizing: border-box;
  293. margin-top: 20rpx;
  294. .goods-img{
  295. width: 100%;
  296. }
  297. }
  298. .extra{
  299. width: 100%;
  300. height: 120rpx;
  301. padding-bottom: constant(safe-area-inset-bottom);
  302. padding-bottom: env(safe-area-inset-bottom);
  303. box-sizing: content-box;
  304. }
  305. .fixed-bottom{
  306. position: fixed;
  307. bottom: 0;
  308. left: 0;
  309. background-color: #FFFFFF;
  310. width: 100%;
  311. height: auto;
  312. padding: 0 32rpx;
  313. border-top: 1rpx solid #e5e5e5;
  314. padding-bottom: constant(safe-area-inset-bottom);
  315. padding-bottom: env(safe-area-inset-bottom);
  316. .icon-item{
  317. margin-right: 16rpx;
  318. background-color: transparent;
  319. margin: 0;
  320. line-height: initial;
  321. font-size: 28rpx;
  322. font-weight: inherit;
  323. margin-right: 10rpx;
  324. padding: 0;
  325. width: 88rpx;
  326. position: relative;
  327. &:first-child{
  328. padding-left: 0;
  329. }
  330. .icon-img{
  331. height: 50rpx;
  332. width: 50rpx;
  333. }
  334. }
  335. .btn{
  336. margin: 0;
  337. padding: 0;
  338. width: 208rpx;
  339. height: 80rpx;
  340. background-color: #1998FE;
  341. color: #FFFFFF;
  342. line-height: 80rpx;
  343. font-size: 32rpx;
  344. border-radius: 42rpx;
  345. }
  346. }
  347. </style>