combinedSales.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <template>
  2. <view v-if="selectComposeData && selectComposeData.length > 0" class="group-list">
  3. <view class="group-warp">
  4. <view class="title">
  5. <label>
  6. <image class="title-img" src="../../static/images/origin/combinationIcon.png" alt="组合销售" mode="widthFix">
  7. </image>
  8. </label>
  9. <view class="price-text">
  10. 组合价:¥{{ composePrice }}
  11. </view>
  12. </view>
  13. <view>
  14. <scroll-view class="tabs-nav" scroll-x="true">
  15. <view class="ul">
  16. <view
  17. v-for="(item, index) in selectComposeData" :key="index" class="li" :class="tabIndex === index && 'on'"
  18. @click="tabChange(index)"
  19. >
  20. {{ item.composeName }}
  21. </view>
  22. </view>
  23. </scroll-view>
  24. <view
  25. v-for="(item, index) in selectComposeData" :key="index" class="tabs-item"
  26. :class="tabIndex === index && 'on'"
  27. >
  28. <swiper
  29. class="swiper pro-box" :indicator-dots="false" :autoplay="true"
  30. :display-multiple-items="item.composeProductInfoList.length < 3 ? item.composeProductInfoList.length : 3"
  31. :disable-touch="item.composeProductInfoList.length <= 3" @change="swiperChange"
  32. >
  33. <swiper-item v-for="(itemJ, indexJ) in item.composeProductInfoList" :key="indexJ" class="pro-item-warp">
  34. <view class="pro-item-inner">
  35. <view class="pro-item">
  36. <view class="pro-item-img">
  37. <image class="img" :src="itemJ.productImage"></image>
  38. </view>
  39. <view class="pro-item-info">
  40. <h3 class="name">
  41. {{ itemJ.productName }}
  42. </h3>
  43. <view class="sku" @click.stop="changeSkuItemValue(itemJ, indexJ)">
  44. <view class="text">{{ itemJ.skuItem.skuName }}</view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </swiper-item>
  50. </swiper>
  51. <view v-if="item.composeProductInfoList.length > 3" class="swiper-dots">
  52. <text
  53. v-for="(dot, index) in item.composeProductInfoList.length - 2" :key="index" class="dot"
  54. :class="{ 'dot-active': swiperCurrent === index }"
  55. ></text>
  56. </view>
  57. </view>
  58. <view class="btn-buy" @click="doBuy">立即购买</view>
  59. </view>
  60. </view>
  61. <!-- 商品详情 -->
  62. <u-popup v-model="goodsDetailShowFlag" mode="bottom" border-radius="14">
  63. <view class="goosDetailshow-box">
  64. <view class="detailImg-box flex-row-plus">
  65. <image class="detailImg" :src="selectedSku.image"></image>
  66. <view class="flex-column-plus mar-left-40">
  67. <view class="font-color-C5AA7B">
  68. <label class="fs24">¥</label>
  69. <label class="fs36 mar-left-10" v-text="getPrice(selectedSku)"></label>
  70. </view>
  71. <label class="fs24 font-color-999 mar-top-20">库存 {{ selectedSku.stockNumber }} 件</label>
  72. <label class="fs24 mar-top-20">已选</label>
  73. </view>
  74. </view>
  75. <view class="color-box flex-column-plus">
  76. <view v-for="(attritem, index) in skuProData.names" :key="index" class="skuStyle">
  77. <label class="fs24 font-color-999">{{ attritem.skuName }}</label>
  78. <view class="colorName-box">
  79. <view v-for="(attrRes, resIndex) in attritem.values" :key="resIndex" class="pad-bot-30">
  80. <view
  81. class="colorName"
  82. :class="{ 'colorName-on': getselectedAttrVal(attritem.nameCode) == attrRes.valueCode }"
  83. @click="nameCodeValueCodeClick(attritem.nameCode, attrRes.valueCode, true)"
  84. >
  85. {{ attrRes.skuValue }}
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. <!-- <view class="goodsNum-box flex-row-plus flex-sp-between" :class="{'bottom-line' :supportHuabei}"> -->
  92. <!-- <label class="font-color-999 fs24">数量</label> -->
  93. <!-- <view class="goodsNum"> -->
  94. <!-- <text class="subtract" @click="updateNumSub()">-</text> -->
  95. <!-- <text class="goodsNumber" v-model="buyNum">{{buyNum}}</text> -->
  96. <!-- <text class="add" @click.stop=" -->
  97. <!-- ()">+</text> -->
  98. <!-- </view> -->
  99. <!-- </view> -->
  100. <view class="goosDetailbut-box flex-items-plus">
  101. <!-- <button type="default" @click="goodsDateils(shopId,productId,skuId)" >查看详情</button> -->
  102. <button type="default" class="submitBtn" @click="submitBtn()">确认</button>
  103. </view>
  104. </view>
  105. </u-popup>
  106. </view>
  107. </template>
  108. <script>
  109. import NET from '../../utils/request'
  110. import API from '../../config/api'
  111. export default {
  112. name: 'CombinedSales',
  113. props: {
  114. pid: {
  115. type: String,
  116. default: ''
  117. },
  118. productData: {
  119. type: Object,
  120. default: () => { }
  121. }
  122. },
  123. data() {
  124. return {
  125. skuShowFalg: false,
  126. tabIndex: 0,
  127. swiperCurrent: 0,
  128. selectComposeData: [],
  129. curProIndex: 0,
  130. selectedSku: [],
  131. selectedAttr: [],
  132. skuProData: {},
  133. goodsDetailShowFlag: false,
  134. composePrice: 0
  135. }
  136. },
  137. mounted() {
  138. this.getSelectCompose()
  139. },
  140. methods: {
  141. // 切换套餐
  142. tabChange(index) {
  143. this.tabIndex = index
  144. this.calculatePrice()
  145. },
  146. // 滑动回调方法
  147. swiperChange(e) {
  148. this.swiperCurrent = e.detail.current
  149. },
  150. // 获取组合销售数据
  151. getSelectCompose() {
  152. NET.request(
  153. API.selectCompose, {
  154. productId: this.pid
  155. },
  156. 'GET'
  157. ).then((res) => {
  158. this.selectComposeData = res.data
  159. for (let i = 0; i < this.selectComposeData.length; i++) {
  160. const proList = this.selectComposeData[i].composeProductInfoList
  161. for (let j = 0; j < proList.length; j++) {
  162. proList[j].skuItem = proList[j].composeSkuInfoList[0]
  163. }
  164. }
  165. this.calculatePrice()
  166. })
  167. .catch((res) => {
  168. })
  169. },
  170. // 更换商品样式
  171. changeSkuItemValue(item, index) {
  172. this.curProIndex = index
  173. uni.showLoading({
  174. mask: true,
  175. title: '加载中...'
  176. })
  177. NET.request(
  178. API.QueryProductDetail, {
  179. shopId: this.productData.shopId,
  180. productId: item.productId,
  181. skuId: item.skuItem.skuId,
  182. terminal: 1
  183. },
  184. 'GET'
  185. ).then((res) => {
  186. uni.hideLoading()
  187. this.skuProData = res.data
  188. // 如果是单款式商品,需要特殊处理productData.names
  189. const mapKeys = Object.keys(this.skuProData.map)
  190. if (mapKeys.length === 1 && mapKeys[0] === '单款项') {
  191. this.skuProData.names[0].values.push({
  192. skuValue: '单款项',
  193. valueCode: '单款项'
  194. })
  195. }
  196. // 如果sku的图像为空,设置为商品的图像
  197. for (var key in this.skuProData.map) {
  198. const skuImage = this.skuProData.map[key].image
  199. if (!skuImage) {
  200. this.skuProData.map[key].image = this.skuProData.images[0]
  201. }
  202. }
  203. this.goodsDetailShowFlag = true
  204. this.selectBySkuId(item.skuItem.skuId)
  205. })
  206. .catch((res) => {
  207. uni.hideLoading()
  208. })
  209. },
  210. selectBySkuId(skuId) {
  211. if (skuId) {
  212. const mapinfo = this.skuProData.map
  213. let flag = true
  214. for (var key in mapinfo) {
  215. if (parseInt(mapinfo[key].skuId) === parseInt(skuId)) {
  216. flag = false
  217. this.selectedSku = mapinfo[key]
  218. // 选中sku对应的规格
  219. const valueCodeList = key.split(',')
  220. this.selectedAttr = []
  221. this.skuProData.names.forEach((attr) => {
  222. for (var index in attr.values) {
  223. const valueCode = attr.values[index].valueCode
  224. if (valueCodeList.includes(valueCode)) {
  225. this.nameCodeValueCodeClick(attr.nameCode, valueCode, false)
  226. break
  227. }
  228. }
  229. })
  230. break
  231. }
  232. }
  233. // 匹配不上就赋值第一个
  234. if (flag) {
  235. for (var key in mapinfo) {
  236. this.selectedSku = mapinfo[key]
  237. break
  238. }
  239. }
  240. }
  241. },
  242. nameCodeValueCodeClick(nameCode, valueCode, reSelectSku) {
  243. this.selectedAttr[nameCode] = valueCode
  244. if (reSelectSku) {
  245. const attrList = []
  246. for (var key in this.selectedAttr) {
  247. attrList.push(this.selectedAttr[key])
  248. }
  249. const attrkey = attrList.join(',')
  250. const mapinfo = this.skuProData.map
  251. for (var key in mapinfo) {
  252. if (attrkey === key) {
  253. this.selectedSku = mapinfo[key]
  254. }
  255. }
  256. }
  257. this.$forceUpdate() // 重绘
  258. },
  259. // 提交更换商品规格
  260. submitBtn() {
  261. const curPro = this.selectComposeData[this.tabIndex].composeProductInfoList[this.curProIndex]
  262. for (let i = 0; i < curPro.composeSkuInfoList.length; i++) {
  263. if (curPro.composeSkuInfoList[i].skuId === this.selectedSku.skuId) {
  264. this.selectedSku.skuName = curPro.composeSkuInfoList[i].skuName
  265. }
  266. }
  267. curPro.skuItem = this.selectedSku
  268. this.calculatePrice()
  269. this.goodsDetailShowFlag = false
  270. },
  271. // 计算组合价
  272. calculatePrice() {
  273. const proList = this.selectComposeData[this.tabIndex].composeProductInfoList; const composeType = this.selectComposeData[this.tabIndex].composeType; const promote = this.selectComposeData[this.tabIndex].promote
  274. let total = 0
  275. for (let i = 0; i < proList.length; i++) {
  276. total += this.getPrice(proList[i].skuItem)
  277. }
  278. switch (composeType) {
  279. case 1:
  280. this.composePrice = promote.toFixed(2)
  281. break
  282. case 2:
  283. this.composePrice = (total - promote).toFixed(2)
  284. break
  285. case 3:
  286. this.composePrice = parseFloat(total * promote / 10).toFixed(2)
  287. break
  288. }
  289. },
  290. // 根据活动显示不同价格
  291. getPrice(item) {
  292. // 所属活动 0-常规商品 1-拼团活动 2-秒杀活动 3-限时折扣活动 4-平台秒杀 5-平台折扣 6-定价捆绑 7-组合捆绑 8-场景营销 9-会员价
  293. if (item.activityType) {
  294. if (item.activityType === 0 || item.activityType === 6 || item.activityType === 7) {
  295. return item.price
  296. }
  297. return item.originalPrice
  298. }
  299. return item.price
  300. },
  301. // 立即购买
  302. doBuy() {
  303. const addCart = []
  304. const shopObj = {}
  305. shopObj.shopId = this.productData.shopId
  306. shopObj.composeId = this.selectComposeData[this.tabIndex].composeId
  307. shopObj.skus = []
  308. const proList = this.selectComposeData[this.tabIndex].composeProductInfoList
  309. const len2 = proList.length
  310. for (let j = 0; j < len2; j++) {
  311. const skusObj = {}
  312. skusObj.number = 1
  313. skusObj.skuId = proList[j].skuItem.skuId
  314. shopObj.skus.push(skusObj)
  315. }
  316. addCart.push(shopObj)
  317. uni.setStorageSync('skuItemDTOList', addCart)
  318. uni.navigateTo({
  319. url: '../../pages_category_page1/orderModule/orderConfirm?type=1'
  320. })
  321. },
  322. getselectedAttrVal(item) {
  323. return this.selectedAttr[item]
  324. }
  325. }
  326. }
  327. </script>
  328. <style lang="scss" scoped>
  329. .group-list {
  330. padding: 10upx 20upx 60upx;
  331. border-top: 12upx solid #F8F8F8;
  332. .group-warp {
  333. height: 680upx;
  334. background: #333333;
  335. box-shadow: 0 20upx 30upx rgba(0, 0, 0, 0.3);
  336. opacity: 1;
  337. border-radius: 20upx;
  338. }
  339. .title {
  340. display: flex;
  341. align-items: center;
  342. position: relative;
  343. justify-content: space-between;
  344. padding: 32upx 0 20upx 30upx;
  345. .title-img {
  346. width: 203upx;
  347. }
  348. .price-text {
  349. padding: 0 34upx;
  350. margin-right: 10upx;
  351. height: 50upx;
  352. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  353. box-shadow: 0 6upx 12upx rgba(233, 0, 0, 0.3);
  354. border-radius: 26upx;
  355. font-size: 24upx;
  356. color: #fff;
  357. text-align: center;
  358. line-height: 50upx;
  359. margin-left: 20upx;
  360. .swiper {
  361. height: 50upx;
  362. }
  363. }
  364. }
  365. .tabs-nav {
  366. padding: 0 10upx;
  367. margin-bottom: 20upx;
  368. .ul {
  369. display: flex;
  370. .li {
  371. //flex: 1 0 auto;
  372. text-align: center;
  373. font-size: 26rpx;
  374. color: #999;
  375. position: relative;
  376. padding: 12px 40px;
  377. word-break: keep-all;
  378. &:first-child {
  379. margin-left: 0;
  380. }
  381. &.on {
  382. color: #FFEBC4;
  383. &:after {
  384. content: '';
  385. width: 100%;
  386. height: 2rpx;
  387. background: #FFEBC4;
  388. position: absolute;
  389. left: 0;
  390. bottom: 0;
  391. }
  392. }
  393. }
  394. }
  395. }
  396. .tabs-item {
  397. display: none;
  398. &.on {
  399. display: block;
  400. }
  401. }
  402. .pro-box {
  403. height: 318upx;
  404. padding: 0 2upx 20upx;
  405. .pro-item-inner {
  406. padding: 0 8upx;
  407. display: flex;
  408. justify-content: center;
  409. }
  410. .pro-item {
  411. width: 219upx;
  412. background: #FFFFFF;
  413. padding: 10upx;
  414. height: 318upx;
  415. .pro-item-img {
  416. width: 100%;
  417. height: 160upx;
  418. .img {
  419. width: 100%;
  420. height: 100%;
  421. object-fit: contain;
  422. }
  423. }
  424. .pro-item-info {
  425. .name {
  426. font-size: 24upx;
  427. line-height: 34upx;
  428. color: #333333;
  429. overflow: hidden;
  430. text-overflow: ellipsis;
  431. white-space: nowrap;
  432. text-align: center;
  433. font-weight: normal;
  434. margin: 8upx 0 26upx;
  435. }
  436. .sku {
  437. width: 180upx;
  438. height: 50upx;
  439. margin: 0 auto;
  440. line-height: 50upx;
  441. border: 2upx solid #E4E5E6;
  442. background: url("../../static/images/origin/arrow-suk-select.png") no-repeat right center / 60upx 60upx;
  443. .text {
  444. font-size: 24upx;
  445. color: #999;
  446. padding-left: 20upx;
  447. width: 126px;
  448. text-overflow: ellipsis;
  449. white-space: nowrap;
  450. }
  451. }
  452. }
  453. }
  454. }
  455. .swiper-dots {
  456. display: flex;
  457. justify-content: center;
  458. .dot {
  459. display: block;
  460. width: 24upx;
  461. height: 4upx;
  462. background: #FFFFFF;
  463. opacity: 0.5;
  464. border-radius: 2upx;
  465. margin: 0 20upx;
  466. &.dot-active {
  467. opacity: 1;
  468. }
  469. }
  470. }
  471. }
  472. .btn-buy {
  473. width: 688upx;
  474. height: 84upx;
  475. //border: 2upx solid rgba(0, 0, 0, 0);
  476. background: linear-gradient(88deg, #C5AA7B 0%, #FFEBC4 100%);
  477. font-size: 28upx;
  478. color: #333;
  479. line-height: 84upx;
  480. margin: 30upx auto 0;
  481. text-align: center;
  482. }
  483. .goosDetailshow-box {
  484. .detailImg-box {
  485. margin-top: 30rpx;
  486. margin-left: 30rpx;
  487. border-radius: 10rpx;
  488. border-bottom: 1rpx solid #EDEDED;
  489. padding-bottom: 20rpx;
  490. width: 690rpx;
  491. .detailImg {
  492. width: 180rpx;
  493. height: 180rpx;
  494. }
  495. }
  496. .color-box {
  497. padding: 30rpx 30rpx;
  498. border-bottom: 1rpx solid #EDEDED;
  499. width: 690rpx;
  500. .skuStyle {
  501. padding: 20rpx 0;
  502. }
  503. .skuStyle:nth-child(2) {
  504. border-top: 1px solid #F3F4F5;
  505. }
  506. .colorName-box {
  507. display: flex;
  508. flex-wrap: wrap;
  509. flex-direction: row;
  510. justify-content: flex-start;
  511. align-items: center;
  512. margin-top: 30rpx;
  513. margin-left: -30rpx;
  514. .colorName-on {
  515. background-color: #FFE5D0;
  516. color: #C5AA7B;
  517. margin-left: 30rpx;
  518. padding: 10rpx 32rpx;
  519. border-radius: 28rpx;
  520. border: 1rpx solid #C5AA7B;
  521. font-size: 26rpx;
  522. text-align: center;
  523. z-index: 1;
  524. }
  525. .colorName {
  526. background-color: #F5F5F5;
  527. margin-left: 30rpx;
  528. padding: 10rpx 32rpx;
  529. border-radius: 28rpx;
  530. font-size: 26rpx;
  531. z-index: 2;
  532. }
  533. }
  534. }
  535. .modelNum-box {
  536. padding: 30rpx 30rpx;
  537. border-bottom: 1rpx solid #EDEDED;
  538. width: 690rpx;
  539. .modelNumName-box {
  540. display: flex;
  541. flex-wrap: wrap;
  542. flex-direction: row;
  543. justify-content: flex-start;
  544. align-items: center;
  545. margin-top: 30rpx;
  546. margin-left: -30rpx;
  547. .modelNumName-on {
  548. background-color: #FFE4D0;
  549. color: #C5AA7B;
  550. margin-left: 30rpx;
  551. padding: 10rpx 32rpx;
  552. border-radius: 28rpx;
  553. border: 1rpx solid #C5AA7B;
  554. font-size: 26rpx;
  555. text-align: center;
  556. }
  557. .modelNumName {
  558. background-color: #F5F5F5;
  559. margin-left: 30rpx;
  560. padding: 10rpx 32rpx;
  561. border-radius: 28rpx;
  562. font-size: 26rpx;
  563. }
  564. }
  565. }
  566. .goodsNum-box {
  567. padding: 30rpx 30rpx;
  568. width: 690rpx;
  569. padding-bottom: 140rpx;
  570. .goodsNumber {
  571. text-align: center;
  572. border: 1rpx solid #999999;
  573. padding: 3rpx 20rpx;
  574. }
  575. .subtract {
  576. border: 1rpx solid #999999;
  577. padding: 3rpx 20rpx;
  578. margin-right: -1rpx;
  579. }
  580. .add {
  581. border: 1rpx solid #999999;
  582. padding: 3rpx 20rpx;
  583. margin-left: -1rpx;
  584. }
  585. }
  586. .goosDetailbut-box {
  587. .joinShopCartBut {
  588. width: 343rpx;
  589. height: 80rpx;
  590. background-color: #FFC300;
  591. color: #FFFEFE;
  592. font-size: 28rpx;
  593. line-height: 80rpx;
  594. text-align: center;
  595. margin-left: 30rpx;
  596. }
  597. .buyNowBut {
  598. width: 343rpx;
  599. height: 80rpx;
  600. border-radius: 0 40rpx 40rpx 0;
  601. background-color: #FF6F00;
  602. color: #FFFEFE;
  603. font-size: 28rpx;
  604. line-height: 80rpx;
  605. text-align: center;
  606. }
  607. }
  608. .submitBtn {
  609. width: 342rpx;
  610. height: 100rpx;
  611. line-height: 100rpx;
  612. font-size: 28rpx;
  613. border: 1px solid;
  614. border-radius: 0;
  615. color: #FFEBC4;
  616. background: #333333;
  617. margin: 20rpx 0;
  618. }
  619. }
  620. </style>