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

494 lines
17 KiB

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