combinedSales.vue 18 KB

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