combinedSales.vue 16 KB

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