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

325 lines
9.2 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. this.$u.throttle(() => {
  162. let goods_banner = this.goods_detail.banners || [];
  163. let banners = goods_banner.map(item => item.cover);
  164. uni.previewImage({
  165. urls: banners,
  166. current: index
  167. })
  168. }, 200);
  169. },
  170. },
  171. onShareAppMessage(){
  172. let goods = this.goods_detail;
  173. let title = goods.name;
  174. let imageUrl = goods.share_cover || goods.cover;
  175. let path = '/pages/route/index?route=goods_detail&id='+ goods.id;
  176. return {
  177. title,
  178. path,
  179. imageUrl
  180. }
  181. }
  182. }
  183. </script>
  184. <style>
  185. page{
  186. background-color: #f5f5f5;
  187. overflow-x: hidden;
  188. }
  189. </style>
  190. <style lang="scss" scoped="scoped">
  191. .swiper-box{
  192. width: 750rpx;
  193. height: 520rpx;
  194. background-color: #FFFFFF;
  195. }
  196. .head-info{
  197. width: 750rpx;
  198. height: auto;
  199. box-sizing: border-box;
  200. padding: 0 32rpx;
  201. padding-top: 20rpx;
  202. background-color: #FFFFFF;
  203. .price>view:nth-of-type(1){
  204. color: #FF0000;
  205. margin-right: 22rpx;
  206. font-weight: bold;
  207. }
  208. .price>view:nth-of-type(2){
  209. text-decoration: line-through;
  210. color: #777777;
  211. margin-right: 22rpx;
  212. }
  213. .price>view:nth-of-type(3){
  214. width: max-content;
  215. padding: 0 18rpx;
  216. height: 46rpx;
  217. background-color: #FE9903;
  218. border-radius: 10rpx;
  219. display: flex;
  220. justify-content: center;
  221. align-items: center;
  222. color: #FFFFFF;
  223. }
  224. .label-box{
  225. min-height: 130rpx;
  226. width: 100%;
  227. border-top: 1rpx solid #E5E5E5;
  228. display: flex;
  229. flex-wrap: wrap;
  230. padding: 30rpx 0 10rpx 0;
  231. .label-item{
  232. width: 156rpx;
  233. height: 70rpx;
  234. border-radius: 10rpx;
  235. border: 2rpx solid #FE9903;
  236. display: flex;
  237. justify-content: center;
  238. align-items: center;
  239. font-size: 28rpx;
  240. color: #FE9903;
  241. margin-right: 20rpx;
  242. margin-bottom: 20rpx;
  243. }
  244. }
  245. }
  246. .address-box{
  247. width: 750rpx;
  248. height: auto;
  249. box-sizing: border-box;
  250. background-color: #FFFFFF;
  251. padding: 32rpx;
  252. margin-top: 20rpx;
  253. .shop-img{
  254. width: 60rpx;
  255. height: 60rpx;
  256. border-radius: 10rpx;
  257. }
  258. }
  259. .goods-detail{
  260. width: 750rpx;
  261. height: auto;
  262. background-color: #FFFFFF;
  263. padding: 32rpx;
  264. box-sizing: border-box;
  265. margin-top: 20rpx;
  266. .goods-img{
  267. width: 100%;
  268. }
  269. }
  270. .extra{
  271. width: 100%;
  272. height: 120rpx;
  273. padding-bottom: constant(safe-area-inset-bottom);
  274. padding-bottom: env(safe-area-inset-bottom);
  275. box-sizing: content-box;
  276. }
  277. .fixed-bottom{
  278. position: fixed;
  279. bottom: 0;
  280. left: 0;
  281. background-color: #FFFFFF;
  282. width: 100%;
  283. height: auto;
  284. padding: 0 32rpx;
  285. border-top: 1rpx solid #e5e5e5;
  286. padding-bottom: constant(safe-area-inset-bottom);
  287. padding-bottom: env(safe-area-inset-bottom);
  288. .icon-item{
  289. margin-right: 16rpx;
  290. background-color: transparent;
  291. margin: 0;
  292. line-height: initial;
  293. font-size: 28rpx;
  294. font-weight: inherit;
  295. margin-right: 10rpx;
  296. padding: 0;
  297. width: 88rpx;
  298. &:first-child{
  299. padding-left: 0;
  300. }
  301. .icon-img{
  302. height: 50rpx;
  303. width: 50rpx;
  304. }
  305. }
  306. .btn{
  307. margin: 0;
  308. padding: 0;
  309. width: 208rpx;
  310. height: 80rpx;
  311. background-color: #FE9903;
  312. color: #FFFFFF;
  313. line-height: 80rpx;
  314. font-size: 32rpx;
  315. border-radius: 42rpx;
  316. }
  317. }
  318. </style>