goods.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <template>
  2. <view class="">
  3. <view class="content" v-cloak>
  4. <view class="shop-banner">
  5. <swiper class="swiper" :indicator-dots="false" :circular="true" :autoplay="true" :interval="3000"
  6. :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff"
  7. @change="swiperChange">
  8. <swiper-item class="swiper-item" v-for="(item,index) in banner" :key="index">
  9. <image :src="item" mode="aspectFill"></image>
  10. </swiper-item>
  11. </swiper>
  12. <!-- 底部遮罩 -->
  13. <view class="banner-mask"></view>
  14. <!-- 数量 -->
  15. <view class="num-box">{{ activeBanner }}/{{ banner.length }}</view>
  16. </view>
  17. <!-- 详细信息 -->
  18. <view class="det-info">
  19. <view class="price-box">
  20. <view class="price">
  21. <text class="label">会员价</text>
  22. <text class="unit">¥</text>
  23. <text class="num">{{goosDetail.price}}</text>
  24. <text class="fs24 color-text2">零售价</text>
  25. <text class="old">¥{{goosDetail.otPrice}}</text>
  26. </view>
  27. <text class="fs24 color-text2">月售{{goosDetail.sales}}件</text>
  28. </view>
  29. <view class="name-box">
  30. {{goosDetail.productName}}
  31. </view>
  32. </view>
  33. </view>
  34. <view class="guige">
  35. <view class="safe-box">
  36. <text class="text">服务</text>
  37. <view class="box">
  38. <image class="mr20" src="/static/images/safe.png" mode=""></image>
  39. <view class="mr30" v-for="(item,index) in serviceList" :key="index">
  40. <text>{{item}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 购买人数、库存 -->
  46. <view class="det-box">
  47. <view class="title">图文详情</view>
  48. <view class="inner">
  49. <view v-html="goosDetail.description" style="font-size:0"></view>
  50. </view>
  51. </view>
  52. <!-- 底部按钮 -->
  53. <view class="btn-foot">
  54. <view class="menu-box">
  55. </view>
  56. <view class="btn-box">
  57. <view class="btn buy" @click="addCart('buy')">{{buyText}}</view>
  58. </view>
  59. </view>
  60. <!-- 选择药品规格弹窗 -->
  61. <popupBottom ref="popup" :visible.sync="specVisible" title=" " radius="32" maxHeight="800">
  62. <view class="product-spec">
  63. <view class="pro-info">
  64. <view class="img-box">
  65. <image :src="goosDetail.image ||'/static/images/img.png'" mode="aspectFill"></image>
  66. </view>
  67. <view class="info-text">
  68. <view class="info-title">{{goosDetail.productName}}</view>
  69. <view class="price">
  70. <view class="label">会员价</view>
  71. <text class="unit">¥</text>
  72. <text class="num">{{ goosDetail.price}}</text>
  73. </view>
  74. <view class="desc-box">
  75. <text class="text">月售{{goosDetail.sales}}件</text>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="price-num">
  80. <view class="label">数量</view>
  81. <u-number-box bgColor="#f3f3f3" v-model="goodsNum" @change="goodsNumChange"></u-number-box>
  82. </view>
  83. <view class="sub-btn" @click="submit">确定</view>
  84. </view>
  85. </popupBottom>
  86. </view>
  87. </template>
  88. <script>
  89. import {
  90. liveGoodsDetail
  91. } from '@/api/living'
  92. import {
  93. liveOrderKey, // 生成订单key
  94. } from "@/api/order.js"
  95. import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue'
  96. export default {
  97. components: {
  98. popupBottom
  99. },
  100. data() {
  101. return {
  102. banner: [],
  103. goodsId: null,
  104. totalNum: 1,
  105. orderKey: null,
  106. type: null,
  107. liveId: null,
  108. storeId: null,
  109. serviceList: ['品质保障', '药师服务', '隐私保护'],
  110. productId: null,
  111. goosDetail: {}, //商品详情
  112. buyText: "立即购买",
  113. goodsNum: 0, //商品选择数量
  114. // 当前轮播的图片
  115. activeBanner: 1,
  116. // 规格弹窗
  117. specVisible: false,
  118. };
  119. },
  120. onLoad(options) {
  121. // console.log("商品详情options", options)
  122. if (options.productId) {
  123. this.productId = options.productId;
  124. }
  125. this.liveId = options.liveId
  126. this.goodsId = options.goodsId
  127. if (options.storeId) {
  128. this.storeId = options.storeId || ""
  129. } else {
  130. uni.showToast({
  131. title: "storeId不存在~",
  132. icon: "none"
  133. })
  134. }
  135. },
  136. mounted() {
  137. this.getliveGoods()
  138. },
  139. methods: {
  140. // swiper变化事件
  141. swiperChange(event) {
  142. this.activeBanner = event.detail.current + 1
  143. },
  144. doAddCart(type) {
  145. if (this.totalNum == 0) {
  146. uni.showToast({
  147. icon: 'none',
  148. title: "库存不足",
  149. });
  150. return;
  151. }
  152. var isBuy = type == "buy" ? 1 : 0;
  153. if (type == "buy") {
  154. this.getKey()
  155. } else {
  156. uni.showToast({
  157. icon: 'success',
  158. title: "添加成功",
  159. });
  160. }
  161. },
  162. // 获得key
  163. getKey() {
  164. liveOrderKey().then(res => {
  165. if (res.code == 200) {
  166. // console.log("下订单的key>>>>", res)
  167. this.orderKey = res.orderKey
  168. uni.navigateTo({
  169. url: '/pages_shopping/live/confirmCreateOrder?&orderKey=' + this.orderKey +
  170. '&liveId=' + this.liveId + '&goodsId=' + this.goodsId +
  171. '&productId=' + this.productId + '&totalNum=' + this
  172. .totalNum
  173. })
  174. } else {
  175. uni.showToast({
  176. title: res.msg,
  177. icon: 'none'
  178. });
  179. }
  180. },
  181. rej => {}
  182. );
  183. },
  184. // 选择商品数量
  185. goodsNumChange(e) {
  186. console.log('当前选择商品数量为: ' + e.value)
  187. this.totalNum = e.value
  188. },
  189. // 提交
  190. submit() {
  191. this.specVisible = false
  192. this.doAddCart(this.type);
  193. },
  194. // 加入购物车
  195. addCart(type) {
  196. this.type = type;
  197. this.specVisible = true
  198. },
  199. //商品详情
  200. getliveGoods() {
  201. if (!this.productId) return;
  202. uni.showLoading({
  203. title: '加载中'
  204. });
  205. liveGoodsDetail(this.productId).then(res => {
  206. uni.hideLoading()
  207. if (res.code == 200) {
  208. // console.log("小黄车 商品详情>>>>", res)
  209. this.goosDetail = res.data
  210. this.banner = res.data.sliderImage.split(',');
  211. } else {
  212. uni.showToast({
  213. title: res.msg,
  214. icon: 'none'
  215. });
  216. }
  217. },
  218. rej => {}
  219. );
  220. },
  221. }
  222. }
  223. </script>
  224. <style lang="scss">
  225. [v-cloak] {
  226. display: none;
  227. }
  228. .content {
  229. font-family: PingFang SC;
  230. }
  231. .shop-banner {
  232. height: 756rpx;
  233. background-color: #FFFFFF;
  234. position: relative;
  235. .swiper-item {
  236. box-sizing: border-box;
  237. position: relative;
  238. }
  239. .swiper,
  240. .swiper-item,
  241. .swiper-item image {
  242. width: 100%;
  243. height: 100%;
  244. }
  245. .banner-mask {
  246. width: 100%;
  247. height: 44rpx;
  248. position: absolute;
  249. left: 0;
  250. bottom: 0;
  251. z-index: 9;
  252. background-size: 20rpx 44rpx;
  253. background-repeat: repeat-x;
  254. }
  255. .num-box {
  256. width: 80rpx;
  257. height: 40rpx;
  258. line-height: 40rpx;
  259. text-align: center;
  260. font-size: 24rpx;
  261. color: #FFFFFF;
  262. background: rgba(0, 0, 0, .7);
  263. border-radius: 20rpx;
  264. position: absolute;
  265. right: 40rpx;
  266. bottom: 34rpx;
  267. z-index: 10;
  268. }
  269. }
  270. .guige {
  271. padding: 24rpx;
  272. border-radius: 16rpx;
  273. background: #fff;
  274. width: auto;
  275. font-size: 24rpx;
  276. color: #222426;
  277. margin: 24rpx;
  278. .safe-box {
  279. display: flex;
  280. align-items: center;
  281. padding-top: 24rpx;
  282. font-size: 24rpx;
  283. color: #222426;
  284. .text {
  285. color: #999999;
  286. margin-right: 40rpx;
  287. }
  288. .box {
  289. display: flex;
  290. align-items: center;
  291. image {
  292. width: 28rpx;
  293. height: 28rpx;
  294. margin-right: 10rpx;
  295. }
  296. view {
  297. display: flex;
  298. align-items: center;
  299. margin-right: 40rpx;
  300. &:last-child {
  301. margin-right: 0;
  302. image {
  303. margin-right: 0;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. }
  310. .det-info {
  311. background: #FFFFFF;
  312. padding: 24rpx;
  313. margin: 24rpx;
  314. border-radius: 16rpx;
  315. .price-box {
  316. display: flex;
  317. align-items: flex-end;
  318. justify-content: space-between;
  319. .price {
  320. display: flex;
  321. align-items: flex-end;
  322. .label {
  323. font-weight: 500;
  324. font-size: 24rpx;
  325. color: #FF5030;
  326. line-height: 1.3;
  327. margin-right: 10rpx;
  328. }
  329. .unit {
  330. font-size: 26rpx;
  331. font-weight: bold;
  332. color: #FF6633;
  333. line-height: 1.3;
  334. }
  335. .num {
  336. font-size: 48rpx;
  337. font-weight: bold;
  338. color: #FF5030;
  339. margin-right: 20rpx;
  340. line-height: 1;
  341. }
  342. .old {
  343. font-size: 24rpx;
  344. font-family: PingFang SC;
  345. font-weight: 400;
  346. text-decoration: line-through;
  347. color: #898E91;
  348. margin-left: 10rpx;
  349. line-height: 1.3;
  350. }
  351. }
  352. }
  353. .name-box {
  354. font-size: 32rpx;
  355. font-weight: bold;
  356. color: #111111;
  357. line-height: 44rpx;
  358. margin-top: 32rpx;
  359. .tag {
  360. display: inline-block;
  361. padding: 2rpx 8rpx;
  362. height: 32rpx;
  363. background: #F5A623;
  364. border-radius: 4rpx;
  365. margin-right: 10rpx;
  366. font-weight: 400;
  367. font-size: 20rpx;
  368. color: #FFFFFF;
  369. line-height: 30rpx;
  370. float: left;
  371. margin-top: 7rpx;
  372. }
  373. }
  374. }
  375. .det-box {
  376. margin-top: 10rpx;
  377. background-color: #FFFFFF;
  378. padding: 24rpx;
  379. margin: 24rpx 24rpx 175rpx 24rpx;
  380. border-radius: 16rpx;
  381. .title {
  382. font-size: 32rpx;
  383. font-weight: bold;
  384. color: #333333;
  385. line-height: 60rpx;
  386. margin-bottom: 30rpx;
  387. padding-bottom: 24rpx;
  388. border-bottom: 1px solid #ECECEC;
  389. }
  390. .inner {
  391. margin-bottom: 100rpx;
  392. }
  393. }
  394. .btn-foot {
  395. box-sizing: border-box;
  396. width: 100%;
  397. height: 151rpx;
  398. background: #FFFFFF;
  399. padding: 0 24rpx;
  400. display: flex;
  401. align-items: center;
  402. justify-content: space-between;
  403. position: fixed;
  404. left: 0;
  405. bottom: 0;
  406. z-index: 99;
  407. .menu-box {
  408. display: flex;
  409. align-items: center;
  410. }
  411. .btn-box {
  412. display: flex;
  413. align-items: center;
  414. .btn {
  415. width: 200rpx;
  416. height: 88rpx;
  417. line-height: 88rpx;
  418. text-align: center;
  419. border-radius: 44rpx;
  420. margin-left: 20rpx;
  421. font-size: 28rpx;
  422. font-weight: bold;
  423. color: #FFFFFF;
  424. &:first-child {
  425. margin-left: 0;
  426. }
  427. &.buy {
  428. background: #2bc7b9;
  429. }
  430. }
  431. }
  432. }
  433. .product-spec {
  434. padding-bottom: 30rpx;
  435. .pro-info {
  436. display: flex;
  437. align-items: center;
  438. .img-box {
  439. width: 200rpx;
  440. height: 200rpx;
  441. background: #FFFFFF;
  442. border-radius: 16rpx;
  443. overflow: hidden;
  444. margin-right: 30rpx;
  445. image {
  446. width: 100%;
  447. height: 100%;
  448. }
  449. }
  450. .info-text {
  451. height: 200rpx;
  452. display: flex;
  453. flex-direction: column;
  454. justify-content: space-between;
  455. .info-title {
  456. font-family: PingFang SC;
  457. font-weight: 600;
  458. font-size: 28rpx;
  459. color: #222426;
  460. text-align: left;
  461. }
  462. .price {
  463. display: flex;
  464. align-items: flex-end;
  465. .label {
  466. font-weight: 500;
  467. font-size: 24rpx;
  468. color: #FF5030;
  469. line-height: 1.3;
  470. margin-right: 10rpx;
  471. }
  472. .unit {
  473. font-size: 32rpx;
  474. font-weight: bold;
  475. color: #FF6633;
  476. line-height: 1.2;
  477. margin-right: 10rpx;
  478. }
  479. .num {
  480. font-size: 50rpx;
  481. font-weight: bold;
  482. color: #FF6633;
  483. line-height: 1;
  484. }
  485. }
  486. .desc-box {
  487. display: flex;
  488. flex-direction: column;
  489. padding-bottom: 9rpx;
  490. .text {
  491. font-size: 26rpx;
  492. font-weight: 500;
  493. color: #999999;
  494. margin-top: 27rpx;
  495. line-height: 1;
  496. &:first-child {
  497. margin-top: 0;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. .price-num {
  504. display: flex;
  505. align-items: center;
  506. justify-content: space-between;
  507. margin-top: 30rpx;
  508. .label {
  509. font-size: 36rpx;
  510. font-weight: bold;
  511. color: #111111;
  512. }
  513. }
  514. .sub-btn {
  515. width: 100%;
  516. height: 88rpx;
  517. line-height: 88rpx;
  518. text-align: center;
  519. font-size: 32rpx;
  520. font-weight: bold;
  521. color: #FFFFFF;
  522. background: #2BC7B9;
  523. border-radius: 44rpx;
  524. margin-top: 30rpx;
  525. }
  526. }
  527. </style>