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

343 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="goods_detail.banners.length > 1 ? true : false" :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 mode="aspectFill" :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 mode="aspectFill" class="lf-fle shop-img" :src="goods_detail.store.cover" v-if="goods_detail.store.cover"></image>
  35. <image mode="aspectFill" 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" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}" :icon-style="{color: '#ffffff'}"></u-back-top> -->
  82. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
  83. </block>
  84. </skeleton>
  85. </view>
  86. </template>
  87. <script>
  88. export default {
  89. data(){
  90. return {
  91. current: 0, // 轮播下标
  92. goods_id: 0,
  93. goods_detail: {},
  94. is_collect: 0, // 1为当前收藏商品了,0为否
  95. skeletonLoading: true
  96. }
  97. },
  98. computed: {
  99. isRight(){
  100. return function(val){
  101. return this.$shared.isRight(val);
  102. }
  103. }
  104. },
  105. onLoad(options){
  106. this.goods_id = options.id;
  107. this.getGoodsDetail();
  108. },
  109. methods: {
  110. getGoodsDetail(){
  111. let that = this;
  112. this.$http(this.API.API_GOODS_DETAIL, {goods_id: this.goods_id}).then(res => {
  113. this.skeletonLoading = false;
  114. this.goods_detail = res.data;
  115. this.is_collect = Boolean(res.data.user.is_collect);
  116. }).catch(err => {
  117. this.skeletonLoading = false;
  118. setTimeout(() => {
  119. that.$toBack();
  120. }, 1000);
  121. })
  122. },
  123. // 切换商品收藏
  124. switchCollect(){
  125. let userInfo = uni.getStorageSync('userinfo') || {};
  126. if(!userInfo.id || !userInfo.nickname || !userInfo.avatar){
  127. this.$url('/pages/login/index?type=userinfo');
  128. return;
  129. }
  130. this.$http(this.API.API_COLLECT_DEAL, {goods_id: this.goods_id}).then(res => {
  131. this.$msg(res.msg);
  132. this.is_collect = Boolean(res.data.user.is_collect);
  133. })
  134. },
  135. // 拨打电话
  136. makePhoneCall(phoneStr){
  137. uni.makePhoneCall({
  138. phoneNumber: String(phoneStr)
  139. })
  140. },
  141. // 打开地图
  142. openMap(){
  143. // return;
  144. uni.openLocation({
  145. longitude: 108.36637,
  146. latitude: 22.817746,
  147. scale: 18,
  148. name: this.goods_detail.store.address
  149. })
  150. },
  151. // 跳转到确认下单页面
  152. toAddOrder(){
  153. let goods_id = this.goods_detail.id;
  154. let goods_specs_id = this.goods_detail.specs[0].id
  155. this.$url('/pages/order/confirm-order?goods_id='+ goods_id +'&goods_specs_id='+ goods_specs_id);
  156. },
  157. // 预览图片
  158. lookImg(index){
  159. this.$u.throttle(() => {
  160. let goods_banner = this.goods_detail.banners || [];
  161. let banners = goods_banner.map(item => item.cover);
  162. uni.previewImage({
  163. urls: banners,
  164. current: index
  165. })
  166. }, 200);
  167. },
  168. // 富文本处理
  169. formatRichText(richText){
  170. if(richText != null){
  171. let newRichText= richText.replace(/<img[^>]*>/gi, function(match, capture){
  172. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  173. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  174. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  175. return match;
  176. });
  177. newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){
  178. match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;');
  179. return match;
  180. });
  181. newRichText = newRichText.replace(/<br[^>]*\/>/gi, '');
  182. newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
  183. return newRichText;
  184. }else{
  185. return null;
  186. }
  187. }
  188. },
  189. onShareAppMessage(){
  190. let goods = this.goods_detail;
  191. let title = goods.name;
  192. let imageUrl = goods.share_cover || goods.cover;
  193. let path = '/pages/route/index?route=goods_detail&id='+ goods.id;
  194. return {
  195. title,
  196. path,
  197. imageUrl
  198. }
  199. }
  200. }
  201. </script>
  202. <style>
  203. page{
  204. background-color: #f5f5f5;
  205. overflow-x: hidden;
  206. }
  207. </style>
  208. <style lang="scss" scoped="scoped">
  209. .swiper-box{
  210. width: 750rpx;
  211. height: 520rpx;
  212. background-color: #FFFFFF;
  213. }
  214. .head-info{
  215. width: 750rpx;
  216. height: auto;
  217. box-sizing: border-box;
  218. padding: 0 32rpx;
  219. padding-top: 20rpx;
  220. background-color: #FFFFFF;
  221. // .price>view:nth-of-type(1){
  222. // color: #FF0000;
  223. // margin-right: 22rpx;
  224. // font-weight: bold;
  225. // }
  226. .price>view:nth-of-type(1){
  227. text-decoration: line-through;
  228. color: #777777;
  229. margin-right: 22rpx;
  230. }
  231. .price>view:nth-of-type(2){
  232. width: max-content;
  233. padding: 0 18rpx;
  234. height: 46rpx;
  235. background-color: #FE9903;
  236. border-radius: 10rpx;
  237. display: flex;
  238. justify-content: center;
  239. align-items: center;
  240. color: #FFFFFF;
  241. }
  242. .label-box{
  243. min-height: 130rpx;
  244. width: 100%;
  245. border-top: 1rpx solid #E5E5E5;
  246. display: flex;
  247. flex-wrap: wrap;
  248. padding: 30rpx 0 10rpx 0;
  249. .label-item{
  250. width: 156rpx;
  251. height: 70rpx;
  252. border-radius: 10rpx;
  253. border: 2rpx solid #FE9903;
  254. display: flex;
  255. justify-content: center;
  256. align-items: center;
  257. font-size: 28rpx;
  258. color: #FE9903;
  259. margin-right: 20rpx;
  260. margin-bottom: 20rpx;
  261. }
  262. }
  263. }
  264. .address-box{
  265. width: 750rpx;
  266. height: auto;
  267. box-sizing: border-box;
  268. background-color: #FFFFFF;
  269. padding: 32rpx;
  270. margin-top: 20rpx;
  271. .shop-img{
  272. width: 60rpx;
  273. height: 60rpx;
  274. border-radius: 50%;
  275. }
  276. }
  277. .goods-detail{
  278. width: 750rpx;
  279. height: auto;
  280. background-color: #FFFFFF;
  281. padding: 32rpx;
  282. box-sizing: border-box;
  283. margin-top: 20rpx;
  284. .goods-img{
  285. width: 100%;
  286. }
  287. }
  288. .extra{
  289. width: 100%;
  290. height: 120rpx;
  291. padding-bottom: constant(safe-area-inset-bottom);
  292. padding-bottom: env(safe-area-inset-bottom);
  293. box-sizing: content-box;
  294. }
  295. .fixed-bottom{
  296. position: fixed;
  297. bottom: 0;
  298. left: 0;
  299. background-color: #FFFFFF;
  300. width: 100%;
  301. height: auto;
  302. padding: 0 32rpx;
  303. border-top: 1rpx solid #e5e5e5;
  304. padding-bottom: constant(safe-area-inset-bottom);
  305. padding-bottom: env(safe-area-inset-bottom);
  306. .icon-item{
  307. margin-right: 16rpx;
  308. background-color: transparent;
  309. margin: 0;
  310. line-height: initial;
  311. font-size: 28rpx;
  312. font-weight: inherit;
  313. margin-right: 10rpx;
  314. padding: 0;
  315. width: 88rpx;
  316. &:first-child{
  317. padding-left: 0;
  318. }
  319. .icon-img{
  320. height: 50rpx;
  321. width: 50rpx;
  322. }
  323. }
  324. .btn{
  325. margin: 0;
  326. padding: 0;
  327. width: 208rpx;
  328. height: 80rpx;
  329. background-color: #FE9903;
  330. color: #FFFFFF;
  331. line-height: 80rpx;
  332. font-size: 32rpx;
  333. border-radius: 42rpx;
  334. }
  335. }
  336. </style>