goods.vue 14 KB

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