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

311 lines
8.6 KiB

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