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

342 lines
10 KiB

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