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

492 lines
14 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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" :autoplay="false" :interval="2500" :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="goods-detail" v-if="goods_detail.know">
  32. <view class="lf-font-32 lf-font-bold lf-m-b-20">购买须知</view>
  33. <rich-text :nodes="formatRichText(goods_detail.know)"></rich-text>
  34. </view>
  35. <!-- 景区类型 -->
  36. <view v-if="goods_detail.type == 2">
  37. <view class="goods-detail">
  38. <view class="lf-font-32 lf-font-bold lf-m-b-20">景区开放时间</view>
  39. <view >
  40. <u-table>
  41. <u-tr>
  42. <u-th>节点</u-th>
  43. <u-th>夏季</u-th>
  44. <u-th>冬季</u-th>
  45. </u-tr>
  46. <u-tr>
  47. <u-td>周一至周五</u-td>
  48. <u-td>08:0021:00</u-td>
  49. <u-td>09:0020:00</u-td>
  50. </u-tr>
  51. <u-tr>
  52. <u-td>周六至周日</u-td>
  53. <u-td>07:3023:00</u-td>
  54. <u-td>08:3021:00</u-td>
  55. </u-tr>
  56. </u-table>
  57. </view>
  58. </view>
  59. <view class="goods-detail">
  60. <view class="lf-font-32 lf-font-bold lf-m-b-20">包含项目</view>
  61. <view class="lf-flex-column">
  62. <view class="lf-row-between lf-m-b-20">
  63. <view class="lf-color-gray lf-font-28">项目名称</view>
  64. <view class="lf-color-gray lf-font-28">数量</view>
  65. <view class="lf-color-gray lf-font-28">额外费用</view>
  66. </view>
  67. <view class="lf-row-between">
  68. <view class="lf-font-28 lf-color-black">过山车</view>
  69. <view class="lf-font-28 lf-color-black">1</view>
  70. <view class="lf-font-28 lf-color-black">0</view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 餐厅类型 -->
  76. <view v-if="goods_detail.type == 3">
  77. <view class="goods-detail">
  78. <view class="lf-font-32 lf-font-bold lf-m-b-20">餐厅开放时间</view>
  79. <view >
  80. <u-table>
  81. <u-tr>
  82. <u-th>节点</u-th>
  83. <u-th>上午</u-th>
  84. <u-th>下午</u-th>
  85. </u-tr>
  86. <u-tr>
  87. <u-td>周一至周五</u-td>
  88. <u-td>08:0021:00</u-td>
  89. <u-td>09:0020:00</u-td>
  90. </u-tr>
  91. <u-tr>
  92. <u-td>周六至周日</u-td>
  93. <u-td>07:3023:00</u-td>
  94. <u-td>08:3021:00</u-td>
  95. </u-tr>
  96. </u-table>
  97. </view>
  98. </view>
  99. <view class="goods-detail">
  100. <view class="lf-font-32 lf-font-bold lf-m-b-20">包含套餐</view>
  101. <view class="lf-flex-column">
  102. <view class="lf-row-between lf-m-b-20">
  103. <view class="lf-color-333 lf-font-28">米饭 x1</view>
  104. <view class="lf-color-333 lf-font-28">¥3</view>
  105. </view>
  106. <view class="lf-row-between">
  107. <view class="lf-color-333 lf-font-28">清蒸鲈鱼 x1</view>
  108. <view class="lf-color-333 lf-font-28">50</view>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. <!-- 酒店类型 -->
  114. <view class="goods-detail" style="padding-bottom: 0;" v-if="goods_detail.type == 1">
  115. <view class="lf-font-32 lf-font-bold lf-m-b-20">酒店设施</view>
  116. <view>
  117. <view class="label-box1">
  118. <view class="label-item" v-for="i of 7">智能电视</view>
  119. </view>
  120. </view>
  121. </view>
  122. <!-- 旅游路线类型 -->
  123. <view v-if="goods_detail.type == 0">
  124. <view class="goods-detail">
  125. <view class="lf-font-32 lf-font-bold lf-m-b-20">包含项目</view>
  126. <view class="lf-flex-column">
  127. <view class="lf-row-between lf-m-b-20">
  128. <view class="lf-color-gray lf-font-28">项目名称</view>
  129. <view class="lf-color-gray lf-font-28">数量</view>
  130. <view class="lf-color-gray lf-font-28">额外费用</view>
  131. </view>
  132. <view class="lf-row-between">
  133. <view class="lf-font-28 lf-color-black">过山车</view>
  134. <view class="lf-font-28 lf-color-black">1</view>
  135. <view class="lf-font-28 lf-color-black">0</view>
  136. </view>
  137. </view>
  138. </view>
  139. <view class="goods-detail" >
  140. <view class="lf-m-b-20 lf-row-between">
  141. <view class="lf-font-32 lf-font-bold">
  142. 行程时间
  143. </view>
  144. <view class="lf-font-28 lf-color-black ">
  145. 2021年9月
  146. </view>
  147. </view>
  148. <view class="lf-flex-column">
  149. <view class="lf-row-between lf-m-b-20">
  150. <view class="lf-color-333 lf-font-28">行程天数</view>
  151. <view class="lf-color-333 lf-font-28">3</view>
  152. </view>
  153. <view class="lf-row-between">
  154. <view class="lf-color-333 lf-font-28">行程日期</view>
  155. <view class="lf-color-333 lf-font-28">2021-09-18~2021-09-21</view>
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. <!-- 公共部分 -->
  161. <view class="goods-detail" v-if="goods_detail.content">
  162. <view class="lf-font-32 lf-font-bold lf-m-b-20">商品详情</view>
  163. <rich-text :nodes="formatRichText(goods_detail.content)"></rich-text>
  164. </view>
  165. <!-- 修饰专用 -->
  166. <view class="extra"></view>
  167. <!-- 吸底操作按钮 -->
  168. <view class="lf-row-between fixed-bottom">
  169. <view class="lf-flex lf-p-t-10 lf-p-b-10">
  170. <view class="lf-flex-column lf-row-center icon-item" @click="$url('/pages/index/index', {type: 'switch'})">
  171. <image class="icon-img" src="../../static/tabbar/home1.png"></image>
  172. <view class="lf-m-t-1">首页</view>
  173. </view>
  174. <button class="lf-flex-column lf-row-center icon-item" open-type="contact">
  175. <image class="icon-img" src="../../static/center/service.png"></image>
  176. <view class="lf-m-t-1">客服</view>
  177. </button>
  178. <view class="lf-flex-column lf-row-center icon-item" @click="switchCollect">
  179. <image class="icon-img" src="../../static/center/collect-active.png" v-if="is_collect"></image>
  180. <image class="icon-img" src="../../static/center/collect.png" v-else></image>
  181. <view class="lf-m-t-1">{{ is_collect ? '已收藏' : '收藏' }}</view>
  182. </view>
  183. <button class="lf-flex-column lf-row-center icon-item" open-type="share">
  184. <image class="icon-img" src="../../static/center/share.png"></image>
  185. <view class="lf-m-t-1">分享</view>
  186. </button>
  187. </view>
  188. <button class="btn" @click="toAddOrder">立即购买</button>
  189. </view>
  190. <!-- 回到顶部 -->
  191. <!-- <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}" :icon-style="{color: '#ffffff'}"></u-back-top> -->
  192. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
  193. </block>
  194. </skeleton>
  195. </view>
  196. </template>
  197. <script>
  198. export default {
  199. data(){
  200. return {
  201. current: 0, // 轮播下标
  202. goods_id: 0,
  203. goods_detail: {},
  204. is_collect: false, // 1为当前收藏商品了,0为否
  205. skeletonLoading: true
  206. }
  207. },
  208. onLoad(options){
  209. this.goods_id = options.goods_id || options.id;
  210. console.log('商品',this.goods_id)
  211. this.getGoodsDetail();
  212. },
  213. computed: {
  214. isRight() {
  215. return function(val) {
  216. return this.$shared.isRight(val);
  217. }
  218. }
  219. },
  220. methods: {
  221. getGoodsDetail(){
  222. this.$http(this.API.API_ADVICEDETAILS, {id: this.goods_id}).then(res => {
  223. this.skeletonLoading = false;
  224. this.goods_detail = res.data;
  225. this.is_collect = Boolean(res.data.is_collect) || false;
  226. }).catch(err => {
  227. this.skeletonLoading = false;
  228. setTimeout(() => {
  229. this.$toBack();
  230. }, 1000);
  231. })
  232. },
  233. // 切换商品收藏
  234. switchCollect(){
  235. let userInfo = uni.getStorageSync('userinfo') || {};
  236. if(!userInfo.id || !userInfo.nickname || !userInfo.avatar){
  237. this.$url('/pages/login/index?type=userinfo');
  238. return;
  239. }
  240. if(this.is_collect) {
  241. this.$http(this.API.API_DELCOLLECT, {agent_product_id:this.goods_id}).then(res => {
  242. this.$msg('取消收藏成功!')
  243. this.is_collect = false
  244. console.log(res)
  245. })
  246. }else {
  247. this.$http(this.API.API_ADDCOLLECT, {agent_product_id:this.goods_id}).then(res => {
  248. this.$msg('添加收藏成功!')
  249. this.is_collect = true
  250. console.log(res)
  251. })
  252. }
  253. },
  254. // 拨打电话
  255. makePhoneCall(phoneStr){
  256. uni.makePhoneCall({
  257. phoneNumber: String(phoneStr)
  258. })
  259. },
  260. // 打开地图
  261. openMap(){
  262. let { address, lat, lng } = this.goods_detail?.store || {};
  263. uni.openLocation({
  264. longitude: Number(lat),
  265. latitude: Number(lng),
  266. scale: 20,
  267. name: address
  268. });
  269. },
  270. // 跳转到确认下单页面
  271. toAddOrder(){
  272. let goods_id = this.goods_detail.id;
  273. this.$url('/pages/order/confirm_order?goods_id='+ goods_id);
  274. },
  275. // 预览图片
  276. lookImg(index){
  277. this.$u.throttle(() => {
  278. let goods_banner = this.goods_detail.banners || [];
  279. let banners = goods_banner.map(item => item.cover);
  280. uni.previewImage({
  281. urls: banners,
  282. current: index
  283. })
  284. }, 200);
  285. },
  286. // 富文本处理
  287. formatRichText(richText){
  288. if(richText != null){
  289. let newRichText= richText.replace(/<img[^>]*>/gi, function(match, capture){
  290. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  291. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  292. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  293. return match;
  294. });
  295. newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){
  296. match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;');
  297. return match;
  298. });
  299. newRichText = newRichText.replace(/<br[^>]*\/>/gi, '');
  300. newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
  301. return newRichText;
  302. }else{
  303. return null;
  304. }
  305. }
  306. },
  307. onShareAppMessage(){
  308. let goods = this.goods_detail;
  309. let title = goods.title;
  310. let imageUrl = goods.pictures[0] || goods.picture;
  311. let path = '/pages/route/index?route=goods_detail&id='+ goods.id;
  312. console.log("path", path);
  313. return {
  314. title,
  315. path,
  316. imageUrl
  317. }
  318. }
  319. }
  320. </script>
  321. <style>
  322. page{
  323. background-color: #f5f5f5;
  324. overflow-x: hidden;
  325. }
  326. </style>
  327. <style lang="scss" scoped="scoped">
  328. .swiper-box{
  329. width: 750rpx;
  330. height: 490rpx;
  331. background-color: #FFFFFF;
  332. }
  333. .head-info{
  334. width: 750rpx;
  335. height: auto;
  336. box-sizing: border-box;
  337. padding: 0 32rpx;
  338. padding-top: 20rpx;
  339. background-color: #FFFFFF;
  340. // .price>view:nth-of-type(1){
  341. // color: #FF0000;
  342. // margin-right: 22rpx;
  343. // font-weight: bold;
  344. // }
  345. .price>view:nth-of-type(1){
  346. text-decoration: line-through;
  347. color: #777777;
  348. margin-right: 22rpx;
  349. }
  350. .price>view:nth-of-type(2){
  351. width: max-content;
  352. padding: 0 18rpx;
  353. height: 46rpx;
  354. background-color: #1998FE;
  355. border-radius: 10rpx;
  356. display: flex;
  357. justify-content: center;
  358. align-items: center;
  359. color: #FFFFFF;
  360. }
  361. }
  362. .label-box{
  363. min-height: 130rpx;
  364. width: 100%;
  365. border-top: 1rpx solid #E5E5E5;
  366. display: flex;
  367. flex-wrap: wrap;
  368. padding: 30rpx 0 10rpx 0;
  369. .label-item{
  370. width: max-content;
  371. padding: 20rpx;
  372. height: 70rpx;
  373. border-radius: 10rpx;
  374. border: 2rpx solid #1998FE;
  375. display: flex;
  376. justify-content: center;
  377. align-items: center;
  378. font-size: 28rpx;
  379. color: #1998FE;
  380. margin-right: 20rpx;
  381. margin-bottom: 20rpx;
  382. }
  383. }
  384. .label-box1{
  385. min-height: 130rpx;
  386. width: 100%;
  387. border-top: 1rpx solid #E5E5E5;
  388. display: flex;
  389. flex-wrap: wrap;
  390. padding: 30rpx 0 10rpx 0;
  391. .label-item{
  392. width: max-content;
  393. padding: 0 10rpx;
  394. height: 54rpx;
  395. border-radius: 10rpx;
  396. border: 2rpx solid #1998FE;
  397. display: flex;
  398. justify-content: center;
  399. align-items: center;
  400. font-size: 24rpx;
  401. color: #1998FE;
  402. background: rgba(25, 152, 254, 0.05);
  403. margin-right: 20rpx;
  404. margin-bottom: 20rpx;
  405. }
  406. }
  407. .address-box{
  408. width: 750rpx;
  409. height: auto;
  410. box-sizing: border-box;
  411. background-color: #FFFFFF;
  412. padding: 32rpx;
  413. margin-top: 20rpx;
  414. .shop-img{
  415. width: 60rpx;
  416. height: 60rpx;
  417. border-radius: 50%;
  418. }
  419. }
  420. .goods-detail{
  421. width: 750rpx;
  422. height: auto;
  423. background-color: #FFFFFF;
  424. padding: 32rpx;
  425. box-sizing: border-box;
  426. margin-top: 20rpx;
  427. .goods-img{
  428. width: 100%;
  429. }
  430. }
  431. .extra{
  432. width: 100%;
  433. height: 120rpx;
  434. padding-bottom: constant(safe-area-inset-bottom);
  435. padding-bottom: env(safe-area-inset-bottom);
  436. box-sizing: content-box;
  437. }
  438. .fixed-bottom{
  439. position: fixed;
  440. bottom: 0;
  441. left: 0;
  442. background-color: #FFFFFF;
  443. width: 100%;
  444. height: auto;
  445. padding: 0 32rpx;
  446. border-top: 1rpx solid #e5e5e5;
  447. padding-bottom: constant(safe-area-inset-bottom);
  448. padding-bottom: env(safe-area-inset-bottom);
  449. .icon-item{
  450. margin-right: 16rpx;
  451. background-color: transparent;
  452. margin: 0;
  453. line-height: initial;
  454. font-size: 28rpx;
  455. font-weight: inherit;
  456. margin-right: 10rpx;
  457. padding: 0;
  458. width: 88rpx;
  459. position: relative;
  460. &:first-child{
  461. padding-left: 0;
  462. }
  463. .icon-img{
  464. height: 50rpx;
  465. width: 50rpx;
  466. }
  467. }
  468. .btn{
  469. margin: 0;
  470. padding: 0;
  471. width: 208rpx;
  472. height: 80rpx;
  473. background-color: #1998FE;
  474. color: #FFFFFF;
  475. line-height: 80rpx;
  476. font-size: 32rpx;
  477. border-radius: 42rpx;
  478. }
  479. }
  480. </style>