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

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