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

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