goods.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. this.getliveGoods()
  136. },
  137. methods: {
  138. // swiper变化事件
  139. swiperChange(event) {
  140. this.activeBanner = event.detail.current + 1
  141. },
  142. doAddCart(type) {
  143. if (this.totalNum == 0) {
  144. uni.showToast({
  145. icon: 'none',
  146. title: "库存不足",
  147. });
  148. return;
  149. }
  150. var isBuy = type == "buy" ? 1 : 0;
  151. if (type == "buy") {
  152. this.getKey()
  153. } else {
  154. uni.showToast({
  155. icon: 'success',
  156. title: "添加成功",
  157. });
  158. }
  159. },
  160. // 获得key
  161. getKey() {
  162. liveOrderKey().then(res => {
  163. if (res.code == 200) {
  164. // console.log("下订单的key>>>>", res)
  165. this.orderKey = res.orderKey
  166. uni.navigateTo({
  167. url: '/pages_shopping/live/confirmCreateOrder?&orderKey=' + this.orderKey +
  168. '&liveId=' + this.liveId + '&goodsId=' + this.goodsId +
  169. '&productId=' + this.productId + '&totalNum=' + this
  170. .totalNum
  171. })
  172. } else {
  173. uni.showToast({
  174. title: res.msg,
  175. icon: 'none'
  176. });
  177. }
  178. },
  179. rej => {}
  180. );
  181. },
  182. // 选择商品数量
  183. goodsNumChange(e) {
  184. console.log('当前选择商品数量为: ' + e.value)
  185. this.totalNum = e.value
  186. },
  187. // 提交
  188. submit() {
  189. this.specVisible = false
  190. this.doAddCart(this.type);
  191. },
  192. // 加入购物车
  193. addCart(type) {
  194. this.type = type;
  195. this.specVisible = true
  196. },
  197. //商品详情
  198. getliveGoods() {
  199. if (!this.productId) return;
  200. uni.showLoading({
  201. title: '加载中'
  202. });
  203. liveGoodsDetail(this.productId).then(res => {
  204. uni.hideLoading()
  205. if (res.code == 200) {
  206. // console.log("小黄车 商品详情>>>>", res)
  207. this.goosDetail = res.data
  208. this.banner = res.data.sliderImage.split(',');
  209. } else {
  210. uni.showToast({
  211. title: res.msg,
  212. icon: 'none'
  213. });
  214. }
  215. },
  216. rej => {}
  217. );
  218. },
  219. }
  220. }
  221. </script>
  222. <style lang="scss">
  223. [v-cloak] {
  224. display: none;
  225. }
  226. .content {
  227. font-family: PingFang SC;
  228. }
  229. .shop-banner {
  230. height: 756rpx;
  231. background-color: #FFFFFF;
  232. position: relative;
  233. .swiper-item {
  234. box-sizing: border-box;
  235. position: relative;
  236. }
  237. .swiper,
  238. .swiper-item,
  239. .swiper-item image {
  240. width: 100%;
  241. height: 100%;
  242. }
  243. .banner-mask {
  244. width: 100%;
  245. height: 44rpx;
  246. position: absolute;
  247. left: 0;
  248. bottom: 0;
  249. z-index: 9;
  250. background-size: 20rpx 44rpx;
  251. background-repeat: repeat-x;
  252. }
  253. .num-box {
  254. width: 80rpx;
  255. height: 40rpx;
  256. line-height: 40rpx;
  257. text-align: center;
  258. font-size: 24rpx;
  259. color: #FFFFFF;
  260. background: rgba(0, 0, 0, .7);
  261. border-radius: 20rpx;
  262. position: absolute;
  263. right: 40rpx;
  264. bottom: 34rpx;
  265. z-index: 10;
  266. }
  267. }
  268. .guige {
  269. padding: 24rpx;
  270. border-radius: 16rpx;
  271. background: #fff;
  272. width: auto;
  273. font-size: 24rpx;
  274. color: #222426;
  275. margin: 24rpx;
  276. .safe-box {
  277. display: flex;
  278. align-items: center;
  279. padding-top: 24rpx;
  280. font-size: 24rpx;
  281. color: #222426;
  282. .text {
  283. color: #999999;
  284. margin-right: 40rpx;
  285. }
  286. .box {
  287. display: flex;
  288. align-items: center;
  289. image {
  290. width: 28rpx;
  291. height: 28rpx;
  292. margin-right: 10rpx;
  293. }
  294. view {
  295. display: flex;
  296. align-items: center;
  297. margin-right: 40rpx;
  298. &:last-child {
  299. margin-right: 0;
  300. image {
  301. margin-right: 0;
  302. }
  303. }
  304. }
  305. }
  306. }
  307. }
  308. .det-info {
  309. background: #FFFFFF;
  310. padding: 24rpx;
  311. margin: 24rpx;
  312. border-radius: 16rpx;
  313. .price-box {
  314. display: flex;
  315. align-items: flex-end;
  316. justify-content: space-between;
  317. .price {
  318. display: flex;
  319. align-items: flex-end;
  320. .label {
  321. font-weight: 500;
  322. font-size: 24rpx;
  323. color: #FF5030;
  324. line-height: 1.3;
  325. margin-right: 10rpx;
  326. }
  327. .unit {
  328. font-size: 26rpx;
  329. font-weight: bold;
  330. color: #FF6633;
  331. line-height: 1.3;
  332. }
  333. .num {
  334. font-size: 48rpx;
  335. font-weight: bold;
  336. color: #FF5030;
  337. margin-right: 20rpx;
  338. line-height: 1;
  339. }
  340. .old {
  341. font-size: 24rpx;
  342. font-family: PingFang SC;
  343. font-weight: 400;
  344. text-decoration: line-through;
  345. color: #898E91;
  346. margin-left: 10rpx;
  347. line-height: 1.3;
  348. }
  349. }
  350. }
  351. .name-box {
  352. font-size: 32rpx;
  353. font-weight: bold;
  354. color: #111111;
  355. line-height: 44rpx;
  356. margin-top: 32rpx;
  357. .tag {
  358. display: inline-block;
  359. padding: 2rpx 8rpx;
  360. height: 32rpx;
  361. background: #F5A623;
  362. border-radius: 4rpx;
  363. margin-right: 10rpx;
  364. font-weight: 400;
  365. font-size: 20rpx;
  366. color: #FFFFFF;
  367. line-height: 30rpx;
  368. float: left;
  369. margin-top: 7rpx;
  370. }
  371. }
  372. }
  373. .det-box {
  374. margin-top: 10rpx;
  375. background-color: #FFFFFF;
  376. padding: 24rpx;
  377. margin: 24rpx 24rpx 175rpx 24rpx;
  378. border-radius: 16rpx;
  379. .title {
  380. font-size: 32rpx;
  381. font-weight: bold;
  382. color: #333333;
  383. line-height: 60rpx;
  384. margin-bottom: 30rpx;
  385. padding-bottom: 24rpx;
  386. border-bottom: 1px solid #ECECEC;
  387. }
  388. .inner {
  389. margin-bottom: 100rpx;
  390. }
  391. }
  392. .btn-foot {
  393. box-sizing: border-box;
  394. width: 100%;
  395. height: 151rpx;
  396. background: #FFFFFF;
  397. padding: 0 24rpx;
  398. display: flex;
  399. align-items: center;
  400. justify-content: space-between;
  401. position: fixed;
  402. left: 0;
  403. bottom: 0;
  404. z-index: 99;
  405. .menu-box {
  406. display: flex;
  407. align-items: center;
  408. }
  409. .btn-box {
  410. display: flex;
  411. align-items: center;
  412. .btn {
  413. width: 200rpx;
  414. height: 88rpx;
  415. line-height: 88rpx;
  416. text-align: center;
  417. border-radius: 44rpx;
  418. margin-left: 20rpx;
  419. font-size: 28rpx;
  420. font-weight: bold;
  421. color: #FFFFFF;
  422. &:first-child {
  423. margin-left: 0;
  424. }
  425. &.buy {
  426. background: #2bc7b9;
  427. }
  428. }
  429. }
  430. }
  431. .product-spec {
  432. padding-bottom: 30rpx;
  433. .pro-info {
  434. display: flex;
  435. align-items: center;
  436. .img-box {
  437. width: 200rpx;
  438. height: 200rpx;
  439. background: #FFFFFF;
  440. border-radius: 16rpx;
  441. overflow: hidden;
  442. margin-right: 30rpx;
  443. image {
  444. width: 100%;
  445. height: 100%;
  446. }
  447. }
  448. .info-text {
  449. height: 200rpx;
  450. display: flex;
  451. flex-direction: column;
  452. justify-content: space-between;
  453. .info-title {
  454. font-family: PingFang SC;
  455. font-weight: 600;
  456. font-size: 28rpx;
  457. color: #222426;
  458. text-align: left;
  459. }
  460. .price {
  461. display: flex;
  462. align-items: flex-end;
  463. .label {
  464. font-weight: 500;
  465. font-size: 24rpx;
  466. color: #FF5030;
  467. line-height: 1.3;
  468. margin-right: 10rpx;
  469. }
  470. .unit {
  471. font-size: 32rpx;
  472. font-weight: bold;
  473. color: #FF6633;
  474. line-height: 1.2;
  475. margin-right: 10rpx;
  476. }
  477. .num {
  478. font-size: 50rpx;
  479. font-weight: bold;
  480. color: #FF6633;
  481. line-height: 1;
  482. }
  483. }
  484. .desc-box {
  485. display: flex;
  486. flex-direction: column;
  487. padding-bottom: 9rpx;
  488. .text {
  489. font-size: 26rpx;
  490. font-weight: 500;
  491. color: #999999;
  492. margin-top: 27rpx;
  493. line-height: 1;
  494. &:first-child {
  495. margin-top: 0;
  496. }
  497. }
  498. }
  499. }
  500. }
  501. .price-num {
  502. display: flex;
  503. align-items: center;
  504. justify-content: space-between;
  505. margin-top: 30rpx;
  506. .label {
  507. font-size: 36rpx;
  508. font-weight: bold;
  509. color: #111111;
  510. }
  511. }
  512. .sub-btn {
  513. width: 100%;
  514. height: 88rpx;
  515. line-height: 88rpx;
  516. text-align: center;
  517. font-size: 32rpx;
  518. font-weight: bold;
  519. color: #FFFFFF;
  520. background: #2BC7B9;
  521. border-radius: 44rpx;
  522. margin-top: 30rpx;
  523. }
  524. }
  525. </style>