goods.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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"
  39. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/safe.png" mode="">
  40. </image>
  41. <view class="mr30" v-for="(item,index) in serviceList" :key="index">
  42. <text>{{item}}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 购买人数、库存 -->
  48. <view class="det-box">
  49. <view class="title">图文详情</view>
  50. <view class="inner">
  51. <view v-html="goosDetail.description" style="font-size:0"></view>
  52. </view>
  53. </view>
  54. <!-- 底部按钮 -->
  55. <view class="btn-foot">
  56. <view class="menu-box">
  57. </view>
  58. <view class="btn-box">
  59. <view class="btn buy" @click="addCart('buy')">{{buyText}}</view>
  60. </view>
  61. </view>
  62. <!-- 选择产品规格弹窗 -->
  63. <popupBottom ref="popup" :visible.sync="specVisible" title=" " radius="32" maxHeight="800">
  64. <view class="product-spec">
  65. <view class="pro-info">
  66. <view class="img-box">
  67. <image
  68. :src="goosDetail.image ||'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/img.png'"
  69. mode="aspectFill"></image>
  70. </view>
  71. <view class="info-text">
  72. <view class="info-title">{{goosDetail.productName}}</view>
  73. <view class="price">
  74. <view class="label">会员价</view>
  75. <text class="unit">¥</text>
  76. <text class="num">{{ goosDetail.price}}</text>
  77. </view>
  78. <view class="desc-box">
  79. <text class="text">月售{{goosDetail.sales}}件</text>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 规格 -->
  84. <view class="spec-box">
  85. <view v-for="(item,index) in attrs" :key="index">
  86. <view class="title">{{item.attrName}}</view>
  87. <view class="spec-list">
  88. <view v-for="(subItem,subindex) in item.values" :key="subindex"
  89. :class="subindex==item.index?'item active':'item'" @click="choseSpec(index,subindex)">
  90. {{ subItem }}
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. <view class="price-num">
  96. <view class="label">数量</view>
  97. <u-number-box bgColor="#f3f3f3" v-model="totalNum" @change="goodsNumChange"></u-number-box>
  98. </view>
  99. <view class="sub-btn" @click="submit">确定</view>
  100. </view>
  101. </popupBottom>
  102. </view>
  103. </template>
  104. <script>
  105. import {
  106. liveGoodsDetail
  107. } from '@/api/living'
  108. import {
  109. liveOrderKey, // 生成订单key
  110. } from "@/api/order.js"
  111. import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue'
  112. export default {
  113. components: {
  114. popupBottom
  115. },
  116. data() {
  117. return {
  118. attrs: [],
  119. banner: [],
  120. goodsId: null,
  121. totalNum: 1,
  122. orderKey: null,
  123. type: null,
  124. liveId: null,
  125. storeId: null,
  126. serviceList: ['品质保障', '隐私保护'],
  127. productId: null,
  128. goosDetail: null, //商品详情
  129. buyText: "立即购买",
  130. goodsNum: 0, //商品选择数量
  131. // 当前轮播的图片
  132. activeBanner: 1,
  133. // 规格弹窗
  134. specVisible: false,
  135. };
  136. },
  137. onLoad(options) {
  138. // console.log("商品详情options", options)
  139. if (options.productId) {
  140. this.productId = options.productId;
  141. }
  142. this.liveId = options.liveId
  143. this.goodsId = options.goodsId
  144. if (options.storeId) {
  145. this.storeId = options.storeId || ""
  146. } else {
  147. uni.showToast({
  148. title: "storeId不存在~",
  149. icon: "none"
  150. })
  151. }
  152. this.getliveGoods()
  153. },
  154. methods: {
  155. // swiper变化事件
  156. swiperChange(event) {
  157. this.activeBanner = event.detail.current + 1
  158. },
  159. doAddCart(type) {
  160. if (this.totalNum == 0) {
  161. uni.showToast({
  162. icon: 'none',
  163. title: "库存不足",
  164. });
  165. return;
  166. }
  167. var isBuy = type == "buy" ? 1 : 0;
  168. if (type == "buy") {
  169. this.getKey()
  170. } else {
  171. uni.showToast({
  172. icon: 'success',
  173. title: "添加成功",
  174. });
  175. }
  176. },
  177. // 获得key
  178. getKey() {
  179. liveOrderKey().then(res => {
  180. if (res.code == 200) {
  181. // console.log("下订单的key>>>>", res)
  182. this.orderKey = res.orderKey
  183. uni.navigateTo({
  184. url: '/pages_shopping/live/confirmCreateOrder?&orderKey=' + this.orderKey +
  185. '&liveId=' + this.liveId + '&goodsId=' + this.goodsId +
  186. '&productId=' + this.productId + '&totalNum=' + this.totalNum +
  187. "&productValueSelect=" + this.productValueSelect.id
  188. })
  189. } else {
  190. uni.showToast({
  191. title: res.msg,
  192. icon: 'none'
  193. });
  194. }
  195. },
  196. rej => {}
  197. );
  198. },
  199. // 选择商品数量
  200. goodsNumChange(e) {
  201. console.log('当前选择商品数量为: ' + e.value)
  202. this.totalNum = e.value
  203. if (this.totalNum < 1) {
  204. this.totalNum = 1
  205. }
  206. if (this.totalNum >= this.productValueSelect.stock) {
  207. this.totalNum = this.productValueSelect.stock
  208. }
  209. },
  210. // 提交
  211. submit() {
  212. this.specVisible = false
  213. this.doAddCart(this.type);
  214. },
  215. // 加入购物车
  216. addCart(type) {
  217. if (type == 'buy') {
  218. const userInfoStr = uni.getStorageSync('userInfo');
  219. if (!userInfoStr || !JSON.parse(userInfoStr).maOpenId) {
  220. uni.navigateTo({
  221. url: '/pages/auth/login'
  222. });
  223. return;
  224. }
  225. }
  226. this.type = type;
  227. this.specVisible = true
  228. },
  229. //商品详情
  230. getliveGoods() {
  231. if (!this.productId) return;
  232. uni.showLoading({
  233. title: '加载中'
  234. });
  235. liveGoodsDetail(this.productId).then(res => {
  236. uni.hideLoading()
  237. if (res.code == 200) {
  238. this.goosDetail = res.product
  239. this.banner = res.product.sliderImage.split(',');
  240. this.attrs = res.productAttr;
  241. this.attrs.forEach((item, index, arr) => {
  242. item.values = item.attrValues.split(',');
  243. item.index = 0
  244. });
  245. this.values = res.productValues;
  246. this.choseSpec(0, 0)
  247. } else {
  248. uni.showToast({
  249. title: res.msg,
  250. icon: 'none'
  251. });
  252. }
  253. },
  254. rej => {}
  255. );
  256. },
  257. getValueSelect() {
  258. var valueSelect = this.values.filter((item) => {
  259. return item.sku == this.selectVal;
  260. });
  261. return valueSelect;
  262. },
  263. // 规格选择
  264. choseSpec(index, subIndex) {
  265. this.attrs[index].index = subIndex;
  266. this.$forceUpdate();
  267. let productAttr = this.attrs;
  268. let values = [];
  269. for (let i = 0; i < productAttr.length; i++) {
  270. for (let j = 0; j < productAttr[i].values.length; j++) {
  271. if (productAttr[i].index === j) { //筛选出默认规格
  272. values.push(productAttr[i].values[j]);
  273. }
  274. }
  275. }
  276. let selectVal = values.sort().join(","); //返回值:默认
  277. this.selectVal = selectVal;
  278. // var valueSelect=this.values.filter((item)=>{
  279. // return item.sku==selectVal;
  280. // });
  281. var valueSelect = this.getValueSelect();
  282. console.log("qxj valueSelect:" + valueSelect);
  283. if (valueSelect != null && valueSelect.length > 0) {
  284. this.productValueSelect = valueSelect[0];
  285. }
  286. console.log("qxj productValueSelect:" + JSON.stringify(this.productValueSelect));
  287. this.updateSpecNum();
  288. },
  289. //更新数量
  290. updateSpecNum() {
  291. if (this.productValueSelect.stock == 0) {
  292. this.totalNum = 0;
  293. } else {
  294. this.totalNum = 1;
  295. }
  296. }
  297. }
  298. }
  299. </script>
  300. <style lang="scss">
  301. [v-cloak] {
  302. display: none;
  303. }
  304. .content {
  305. font-family: PingFang SC;
  306. }
  307. .shop-banner {
  308. height: 756rpx;
  309. background-color: #FFFFFF;
  310. position: relative;
  311. .swiper-item {
  312. box-sizing: border-box;
  313. position: relative;
  314. }
  315. .swiper,
  316. .swiper-item,
  317. .swiper-item image {
  318. width: 100%;
  319. height: 100%;
  320. }
  321. .banner-mask {
  322. width: 100%;
  323. height: 44rpx;
  324. position: absolute;
  325. left: 0;
  326. bottom: 0;
  327. z-index: 9;
  328. background-size: 20rpx 44rpx;
  329. background-repeat: repeat-x;
  330. }
  331. .num-box {
  332. width: 80rpx;
  333. height: 40rpx;
  334. line-height: 40rpx;
  335. text-align: center;
  336. font-size: 24rpx;
  337. color: #FFFFFF;
  338. background: rgba(0, 0, 0, .7);
  339. border-radius: 20rpx;
  340. position: absolute;
  341. right: 40rpx;
  342. bottom: 34rpx;
  343. z-index: 10;
  344. }
  345. }
  346. .guige {
  347. padding: 24rpx;
  348. border-radius: 16rpx;
  349. background: #fff;
  350. width: auto;
  351. font-size: 24rpx;
  352. color: #222426;
  353. margin: 24rpx;
  354. .safe-box {
  355. display: flex;
  356. align-items: center;
  357. padding-top: 24rpx;
  358. font-size: 24rpx;
  359. color: #222426;
  360. .text {
  361. color: #999999;
  362. margin-right: 40rpx;
  363. }
  364. .box {
  365. display: flex;
  366. align-items: center;
  367. image {
  368. width: 28rpx;
  369. height: 28rpx;
  370. margin-right: 10rpx;
  371. }
  372. view {
  373. display: flex;
  374. align-items: center;
  375. margin-right: 40rpx;
  376. &:last-child {
  377. margin-right: 0;
  378. image {
  379. margin-right: 0;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. }
  386. .det-info {
  387. background: #FFFFFF;
  388. padding: 24rpx;
  389. margin: 24rpx;
  390. border-radius: 16rpx;
  391. .price-box {
  392. display: flex;
  393. align-items: flex-end;
  394. justify-content: space-between;
  395. .price {
  396. display: flex;
  397. align-items: flex-end;
  398. .label {
  399. font-weight: 500;
  400. font-size: 24rpx;
  401. color: #FF5030;
  402. line-height: 1.3;
  403. margin-right: 10rpx;
  404. }
  405. .unit {
  406. font-size: 26rpx;
  407. font-weight: bold;
  408. color: #FF6633;
  409. line-height: 1.3;
  410. }
  411. .num {
  412. font-size: 48rpx;
  413. font-weight: bold;
  414. color: #FF5030;
  415. margin-right: 20rpx;
  416. line-height: 1;
  417. }
  418. .old {
  419. font-size: 24rpx;
  420. font-family: PingFang SC;
  421. font-weight: 400;
  422. text-decoration: line-through;
  423. color: #898E91;
  424. margin-left: 10rpx;
  425. line-height: 1.3;
  426. }
  427. }
  428. }
  429. .name-box {
  430. font-size: 32rpx;
  431. font-weight: bold;
  432. color: #111111;
  433. line-height: 44rpx;
  434. margin-top: 32rpx;
  435. .tag {
  436. display: inline-block;
  437. padding: 2rpx 8rpx;
  438. height: 32rpx;
  439. background: #F5A623;
  440. border-radius: 4rpx;
  441. margin-right: 10rpx;
  442. font-weight: 400;
  443. font-size: 20rpx;
  444. color: #FFFFFF;
  445. line-height: 30rpx;
  446. float: left;
  447. margin-top: 7rpx;
  448. }
  449. }
  450. }
  451. .det-box {
  452. margin-top: 10rpx;
  453. background-color: #FFFFFF;
  454. padding: 24rpx;
  455. margin: 24rpx 24rpx 175rpx 24rpx;
  456. border-radius: 16rpx;
  457. .title {
  458. font-size: 32rpx;
  459. font-weight: bold;
  460. color: #333333;
  461. line-height: 60rpx;
  462. margin-bottom: 30rpx;
  463. padding-bottom: 24rpx;
  464. border-bottom: 1px solid #ECECEC;
  465. }
  466. .inner {
  467. margin-bottom: 100rpx;
  468. }
  469. }
  470. .btn-foot {
  471. box-sizing: border-box;
  472. width: 100%;
  473. height: 151rpx;
  474. background: #FFFFFF;
  475. padding: 0 24rpx;
  476. display: flex;
  477. align-items: center;
  478. justify-content: space-between;
  479. position: fixed;
  480. left: 0;
  481. bottom: 0;
  482. z-index: 99;
  483. .menu-box {
  484. display: flex;
  485. align-items: center;
  486. }
  487. .btn-box {
  488. display: flex;
  489. align-items: center;
  490. .btn {
  491. width: 200rpx;
  492. height: 88rpx;
  493. line-height: 88rpx;
  494. text-align: center;
  495. border-radius: 44rpx;
  496. margin-left: 20rpx;
  497. font-size: 28rpx;
  498. font-weight: bold;
  499. color: #FFFFFF;
  500. &:first-child {
  501. margin-left: 0;
  502. }
  503. &.buy {
  504. background: #2bc7b9;
  505. }
  506. }
  507. }
  508. }
  509. .product-spec {
  510. padding-bottom: 30rpx;
  511. .pro-info {
  512. display: flex;
  513. align-items: center;
  514. .img-box {
  515. width: 200rpx;
  516. height: 200rpx;
  517. background: #FFFFFF;
  518. border-radius: 16rpx;
  519. overflow: hidden;
  520. margin-right: 30rpx;
  521. image {
  522. width: 100%;
  523. height: 100%;
  524. }
  525. }
  526. .info-text {
  527. height: 200rpx;
  528. display: flex;
  529. flex-direction: column;
  530. justify-content: space-between;
  531. .info-title {
  532. font-family: PingFang SC;
  533. font-weight: 600;
  534. font-size: 28rpx;
  535. color: #222426;
  536. text-align: left;
  537. }
  538. .price {
  539. display: flex;
  540. align-items: flex-end;
  541. .label {
  542. font-weight: 500;
  543. font-size: 24rpx;
  544. color: #FF5030;
  545. line-height: 1.3;
  546. margin-right: 10rpx;
  547. }
  548. .unit {
  549. font-size: 32rpx;
  550. font-weight: bold;
  551. color: #FF6633;
  552. line-height: 1.2;
  553. margin-right: 10rpx;
  554. }
  555. .num {
  556. font-size: 50rpx;
  557. font-weight: bold;
  558. color: #FF6633;
  559. line-height: 1;
  560. }
  561. }
  562. .desc-box {
  563. display: flex;
  564. flex-direction: column;
  565. padding-bottom: 9rpx;
  566. .text {
  567. font-size: 26rpx;
  568. font-weight: 500;
  569. color: #999999;
  570. margin-top: 27rpx;
  571. line-height: 1;
  572. &:first-child {
  573. margin-top: 0;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. .spec-box {
  580. padding-top: 50upx;
  581. .title {
  582. font-size: 34upx;
  583. font-family: PingFang SC;
  584. font-weight: bold;
  585. color: #111111;
  586. line-height: 1;
  587. }
  588. .spec-list {
  589. display: flex;
  590. flex-wrap: wrap;
  591. margin-top: 30upx;
  592. .item {
  593. box-sizing: border-box;
  594. height: 64upx;
  595. padding: 0 30upx;
  596. line-height: 64upx;
  597. font-size: 28upx;
  598. font-family: PingFang SC;
  599. font-weight: 500;
  600. color: #111111;
  601. background: #F7F7F7;
  602. border: 1px solid #F7F7F7;
  603. border-radius: 32upx;
  604. margin-right: 20upx;
  605. margin-bottom: 30upx;
  606. &.active {
  607. background: #F1FFFE;
  608. border: 1px solid #8AD5CE;
  609. color: #2BC7B9;
  610. }
  611. }
  612. }
  613. }
  614. .price-num {
  615. display: flex;
  616. align-items: center;
  617. justify-content: space-between;
  618. margin-top: 30rpx;
  619. .label {
  620. font-size: 36rpx;
  621. font-weight: bold;
  622. color: #111111;
  623. }
  624. }
  625. .sub-btn {
  626. width: 100%;
  627. height: 88rpx;
  628. line-height: 88rpx;
  629. text-align: center;
  630. font-size: 32rpx;
  631. font-weight: bold;
  632. color: #FFFFFF;
  633. background: #2BC7B9;
  634. border-radius: 44rpx;
  635. margin-top: 30rpx;
  636. }
  637. }
  638. </style>