goods.vue 14 KB

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