goods.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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://kntobs.jnmyunl.com/shop/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://kntobs.jnmyunl.com/shop/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. let userInfoStr = uni.getStorageSync('userInfo');
  219. if(Object.prototype.toString.call(userInfoStr) == '[object String]'){
  220. userInfoStr = JSON.parse(userInfoStr)
  221. }
  222. if (!userInfoStr || userInfoStr && !userInfoStr.maOpenId) {
  223. uni.navigateTo({
  224. url: '/pages/auth/login'
  225. });
  226. return;
  227. }
  228. }
  229. this.type = type;
  230. this.specVisible = true
  231. },
  232. //商品详情
  233. getliveGoods() {
  234. if (!this.productId) return;
  235. uni.showLoading({
  236. title: '加载中'
  237. });
  238. liveGoodsDetail(this.productId).then(res => {
  239. uni.hideLoading()
  240. if (res.code == 200) {
  241. this.goosDetail = res.product
  242. this.banner = res.product.sliderImage.split(',');
  243. this.attrs = res.productAttr;
  244. this.attrs.forEach((item, index, arr) => {
  245. item.values = item.attrValues.split(',');
  246. item.index = 0
  247. });
  248. this.values = res.productValues;
  249. this.choseSpec(0, 0)
  250. } else {
  251. uni.showToast({
  252. title: res.msg,
  253. icon: 'none'
  254. });
  255. }
  256. },
  257. rej => {}
  258. );
  259. },
  260. getValueSelect() {
  261. var valueSelect = this.values.filter((item) => {
  262. return item.sku == this.selectVal;
  263. });
  264. return valueSelect;
  265. },
  266. // 规格选择
  267. choseSpec(index, subIndex) {
  268. this.attrs[index].index = subIndex;
  269. this.$forceUpdate();
  270. let productAttr = this.attrs;
  271. let values = [];
  272. for (let i = 0; i < productAttr.length; i++) {
  273. for (let j = 0; j < productAttr[i].values.length; j++) {
  274. if (productAttr[i].index === j) { //筛选出默认规格
  275. values.push(productAttr[i].values[j]);
  276. }
  277. }
  278. }
  279. let selectVal = values.sort().join(","); //返回值:默认
  280. this.selectVal = selectVal;
  281. // var valueSelect=this.values.filter((item)=>{
  282. // return item.sku==selectVal;
  283. // });
  284. var valueSelect = this.getValueSelect();
  285. console.log("qxj valueSelect:" + valueSelect);
  286. if (valueSelect != null && valueSelect.length > 0) {
  287. this.productValueSelect = valueSelect[0];
  288. }
  289. console.log("qxj productValueSelect:" + JSON.stringify(this.productValueSelect));
  290. this.updateSpecNum();
  291. },
  292. //更新数量
  293. updateSpecNum() {
  294. if (this.productValueSelect.stock == 0) {
  295. this.totalNum = 0;
  296. } else {
  297. this.totalNum = 1;
  298. }
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss">
  304. [v-cloak] {
  305. display: none;
  306. }
  307. .content {
  308. font-family: PingFang SC;
  309. }
  310. .shop-banner {
  311. height: 756rpx;
  312. background-color: #FFFFFF;
  313. position: relative;
  314. .swiper-item {
  315. box-sizing: border-box;
  316. position: relative;
  317. }
  318. .swiper,
  319. .swiper-item,
  320. .swiper-item image {
  321. width: 100%;
  322. height: 100%;
  323. }
  324. .banner-mask {
  325. width: 100%;
  326. height: 44rpx;
  327. position: absolute;
  328. left: 0;
  329. bottom: 0;
  330. z-index: 9;
  331. background-size: 20rpx 44rpx;
  332. background-repeat: repeat-x;
  333. }
  334. .num-box {
  335. width: 80rpx;
  336. height: 40rpx;
  337. line-height: 40rpx;
  338. text-align: center;
  339. font-size: 24rpx;
  340. color: #FFFFFF;
  341. background: rgba(0, 0, 0, .7);
  342. border-radius: 20rpx;
  343. position: absolute;
  344. right: 40rpx;
  345. bottom: 34rpx;
  346. z-index: 10;
  347. }
  348. }
  349. .guige {
  350. padding: 24rpx;
  351. border-radius: 16rpx;
  352. background: #fff;
  353. width: auto;
  354. font-size: 24rpx;
  355. color: #222426;
  356. margin: 24rpx;
  357. .safe-box {
  358. display: flex;
  359. align-items: center;
  360. padding-top: 24rpx;
  361. font-size: 24rpx;
  362. color: #222426;
  363. .text {
  364. color: #999999;
  365. margin-right: 40rpx;
  366. }
  367. .box {
  368. display: flex;
  369. align-items: center;
  370. image {
  371. width: 28rpx;
  372. height: 28rpx;
  373. margin-right: 10rpx;
  374. }
  375. view {
  376. display: flex;
  377. align-items: center;
  378. margin-right: 40rpx;
  379. &:last-child {
  380. margin-right: 0;
  381. image {
  382. margin-right: 0;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. }
  389. .det-info {
  390. background: #FFFFFF;
  391. padding: 24rpx;
  392. margin: 24rpx;
  393. border-radius: 16rpx;
  394. .price-box {
  395. display: flex;
  396. align-items: flex-end;
  397. justify-content: space-between;
  398. .price {
  399. display: flex;
  400. align-items: flex-end;
  401. .label {
  402. font-weight: 500;
  403. font-size: 24rpx;
  404. color: #FF5030;
  405. line-height: 1.3;
  406. margin-right: 10rpx;
  407. }
  408. .unit {
  409. font-size: 26rpx;
  410. font-weight: bold;
  411. color: #FF6633;
  412. line-height: 1.3;
  413. }
  414. .num {
  415. font-size: 48rpx;
  416. font-weight: bold;
  417. color: #FF5030;
  418. margin-right: 20rpx;
  419. line-height: 1;
  420. }
  421. .old {
  422. font-size: 24rpx;
  423. font-family: PingFang SC;
  424. font-weight: 400;
  425. text-decoration: line-through;
  426. color: #898E91;
  427. margin-left: 10rpx;
  428. line-height: 1.3;
  429. }
  430. }
  431. }
  432. .name-box {
  433. font-size: 32rpx;
  434. font-weight: bold;
  435. color: #111111;
  436. line-height: 44rpx;
  437. margin-top: 32rpx;
  438. .tag {
  439. display: inline-block;
  440. padding: 2rpx 8rpx;
  441. height: 32rpx;
  442. background: #F5A623;
  443. border-radius: 4rpx;
  444. margin-right: 10rpx;
  445. font-weight: 400;
  446. font-size: 20rpx;
  447. color: #FFFFFF;
  448. line-height: 30rpx;
  449. float: left;
  450. margin-top: 7rpx;
  451. }
  452. }
  453. }
  454. .det-box {
  455. margin-top: 10rpx;
  456. background-color: #FFFFFF;
  457. padding: 24rpx;
  458. margin: 24rpx 24rpx 175rpx 24rpx;
  459. border-radius: 16rpx;
  460. .title {
  461. font-size: 32rpx;
  462. font-weight: bold;
  463. color: #333333;
  464. line-height: 60rpx;
  465. margin-bottom: 30rpx;
  466. padding-bottom: 24rpx;
  467. border-bottom: 1px solid #ECECEC;
  468. }
  469. .inner {
  470. margin-bottom: 100rpx;
  471. }
  472. }
  473. .btn-foot {
  474. box-sizing: border-box;
  475. width: 100%;
  476. height: 151rpx;
  477. background: #FFFFFF;
  478. padding: 0 24rpx;
  479. display: flex;
  480. align-items: center;
  481. justify-content: space-between;
  482. position: fixed;
  483. left: 0;
  484. bottom: 0;
  485. z-index: 99;
  486. .menu-box {
  487. display: flex;
  488. align-items: center;
  489. }
  490. .btn-box {
  491. display: flex;
  492. align-items: center;
  493. .btn {
  494. width: 200rpx;
  495. height: 88rpx;
  496. line-height: 88rpx;
  497. text-align: center;
  498. border-radius: 44rpx;
  499. margin-left: 20rpx;
  500. font-size: 28rpx;
  501. font-weight: bold;
  502. color: #FFFFFF;
  503. &:first-child {
  504. margin-left: 0;
  505. }
  506. &.buy {
  507. background: #2bc7b9;
  508. }
  509. }
  510. }
  511. }
  512. .product-spec {
  513. padding-bottom: 30rpx;
  514. .pro-info {
  515. display: flex;
  516. align-items: center;
  517. .img-box {
  518. width: 200rpx;
  519. height: 200rpx;
  520. background: #FFFFFF;
  521. border-radius: 16rpx;
  522. overflow: hidden;
  523. margin-right: 30rpx;
  524. image {
  525. width: 100%;
  526. height: 100%;
  527. }
  528. }
  529. .info-text {
  530. height: 200rpx;
  531. display: flex;
  532. flex-direction: column;
  533. justify-content: space-between;
  534. .info-title {
  535. font-family: PingFang SC;
  536. font-weight: 600;
  537. font-size: 28rpx;
  538. color: #222426;
  539. text-align: left;
  540. }
  541. .price {
  542. display: flex;
  543. align-items: flex-end;
  544. .label {
  545. font-weight: 500;
  546. font-size: 24rpx;
  547. color: #FF5030;
  548. line-height: 1.3;
  549. margin-right: 10rpx;
  550. }
  551. .unit {
  552. font-size: 32rpx;
  553. font-weight: bold;
  554. color: #FF6633;
  555. line-height: 1.2;
  556. margin-right: 10rpx;
  557. }
  558. .num {
  559. font-size: 50rpx;
  560. font-weight: bold;
  561. color: #FF6633;
  562. line-height: 1;
  563. }
  564. }
  565. .desc-box {
  566. display: flex;
  567. flex-direction: column;
  568. padding-bottom: 9rpx;
  569. .text {
  570. font-size: 26rpx;
  571. font-weight: 500;
  572. color: #999999;
  573. margin-top: 27rpx;
  574. line-height: 1;
  575. &:first-child {
  576. margin-top: 0;
  577. }
  578. }
  579. }
  580. }
  581. }
  582. .spec-box {
  583. padding-top: 50upx;
  584. .title {
  585. font-size: 34upx;
  586. font-family: PingFang SC;
  587. font-weight: bold;
  588. color: #111111;
  589. line-height: 1;
  590. }
  591. .spec-list {
  592. display: flex;
  593. flex-wrap: wrap;
  594. margin-top: 30upx;
  595. .item {
  596. box-sizing: border-box;
  597. height: 64upx;
  598. padding: 0 30upx;
  599. line-height: 64upx;
  600. font-size: 28upx;
  601. font-family: PingFang SC;
  602. font-weight: 500;
  603. color: #111111;
  604. background: #F7F7F7;
  605. border: 1px solid #F7F7F7;
  606. border-radius: 32upx;
  607. margin-right: 20upx;
  608. margin-bottom: 30upx;
  609. &.active {
  610. background: #F1FFFE;
  611. border: 1px solid #8AD5CE;
  612. color: #2BC7B9;
  613. }
  614. }
  615. }
  616. }
  617. .price-num {
  618. display: flex;
  619. align-items: center;
  620. justify-content: space-between;
  621. margin-top: 30rpx;
  622. .label {
  623. font-size: 36rpx;
  624. font-weight: bold;
  625. color: #111111;
  626. }
  627. }
  628. .sub-btn {
  629. width: 100%;
  630. height: 88rpx;
  631. line-height: 88rpx;
  632. text-align: center;
  633. font-size: 32rpx;
  634. font-weight: bold;
  635. color: #FFFFFF;
  636. background: #2BC7B9;
  637. border-radius: 44rpx;
  638. margin-top: 30rpx;
  639. }
  640. }
  641. </style>