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

344 lines
10 KiB

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