时空网前端
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.

341 lines
10 KiB

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