goods.vue 11 KB

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