海南旅游项目 前端仓库
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.

360 lines
11 KiB

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