cart.vue 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. <template>
  2. <div class="cart">
  3. <div class="content">
  4. <div class="step-box">
  5. <div class="left">
  6. <span class="img"></span>
  7. <span class="text">{{$t('cart.cart')}}</span>
  8. </div>
  9. <div class="steps">
  10. <div class="item active">
  11. <div class="number">step 01.</div>
  12. <div class="text">{{$t('cart.selectProductToBuy')}}</div>
  13. </div>
  14. <div class="item">
  15. <div class="number">step 02.</div>
  16. <div class="text">{{$t('cart.confirmOrderInformation')}}</div>
  17. </div>
  18. <div class="item">
  19. <div class="number">step 03.</div>
  20. <div class="text">{{$t('cart.payToCompleteTheOrder')}}</div>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="cart-tab">
  25. <div class="tab-check" v-if="shopCartList.length">
  26. <input
  27. type="checkbox"
  28. class="checkbox default"
  29. :class="{ checked: allChecked, default: !allChecked }"
  30. @click="checkAll()"
  31. />
  32. <span class="text">{{$t('all')}}</span>
  33. </div>
  34. <div class="tab-img">&nbsp;</div>
  35. <div class="tab-name">{{$t('products')}}</div>
  36. <div class="tab-price">{{$t('priceOne')}}</div>
  37. <div class="tab-number">{{$t('quantity')}}</div>
  38. <div class="tab-total">{{$t('subtotal')}}</div>
  39. <div class="tab-action">{{$t('operation')}}</div>
  40. </div>
  41. <div class="empty" v-if="!shopCartList.length">
  42. <div class="img">
  43. <img src="~/assets/images/emptyPic/cart-empty.png" alt />
  44. </div>
  45. <div class="action">
  46. <div class="text">{{$t('cart.yourShoppingCartIsEmpty')}}</div>
  47. <nuxt-link :to="'/'" class="btn">{{$t('cart.goShopping')}}</nuxt-link>
  48. </div>
  49. </div>
  50. <div v-for="(shopCart, shopIndex) in shopCartList" :key="shopIndex">
  51. <div class="cart-con">
  52. <div class="shop-box">
  53. <div class="shop-msg">
  54. <input
  55. type="checkbox"
  56. class="checkbox default"
  57. :class="{ checked: shopCart.checked, default: !shopCart.checked }"
  58. @click="handleCheckShop(shopIndex)"
  59. />
  60. <span class="self" v-if="shopCart.shopId === 1">{{$t('prodDetail.selfEmployed')}}</span>
  61. <nuxt-link :to="'shopIndex?sid=' + shopCart.shopId" class="shop-name">{{
  62. shopCart.shopName
  63. }}</nuxt-link>
  64. </div>
  65. </div>
  66. <div class="activity-list">
  67. <div
  68. class="cart-con"
  69. v-for="(shopCartItem,
  70. shopCartItemIndex) in shopCart.shopCartItemDiscounts"
  71. :key="shopCartItemIndex"
  72. >
  73. <div class="activity-list">
  74. <div
  75. class="activity-msg"
  76. v-if="shopCartItem.chooseDiscountItemDto"
  77. >
  78. <div class="a-info">
  79. <div class="icon">
  80. {{
  81. [$t('cart.fullReduction'), $t('cart.fullPieceDiscount'), $t('cart.fullDiscount'), $t('cart.discountOnFullPieces')][
  82. shopCartItem.chooseDiscountItemDto.discountRule
  83. ]
  84. }}
  85. </div>
  86. <div
  87. class="text"
  88. v-if="
  89. shopCartItem.chooseDiscountItemDto.discountRule == 0
  90. "
  91. >
  92. <span
  93. v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
  94. >
  95. {{$t('cart.activeItemsAreFullyPurchased')}}¥{{
  96. parsePrice(
  97. shopCartItem.chooseDiscountItemDto.needAmount
  98. )[0]
  99. }}.{{
  100. parsePrice(
  101. shopCartItem.chooseDiscountItemDto.needAmount
  102. )[1]
  103. }}(
  104. <span class="text-red"
  105. >{{$t('cart.reduced')}}¥{{
  106. parsePrice(
  107. shopCartItem.chooseDiscountItemDto.reduceAmount
  108. )[0]
  109. }}.{{
  110. parsePrice(
  111. shopCartItem.chooseDiscountItemDto.reduceAmount
  112. )[1]
  113. }}</span
  114. >)
  115. </span>
  116. <span v-else
  117. >{{$t('cart.activeItemsPurchasedOver')}}¥{{
  118. parsePrice(
  119. shopCartItem.chooseDiscountItemDto.needAmount
  120. )[0]
  121. }}.{{
  122. parsePrice(
  123. shopCartItem.chooseDiscountItemDto.needAmount
  124. )[1]
  125. }}
  126. {{$t('cart.getAFullDiscount')}}</span
  127. >
  128. </div>
  129. <div
  130. class="text"
  131. v-if="
  132. shopCartItem.chooseDiscountItemDto.discountRule == 1
  133. "
  134. >
  135. <span
  136. v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
  137. >
  138. {{$t('cart.activeItemsAreFullyPurchased')}}
  139. {{ shopCartItem.chooseDiscountItemDto.needAmount }}件{{$t('items')}}(
  140. <span class="text-red"
  141. >{{$t('cart.reduced')}}¥{{
  142. parsePrice(
  143. shopCartItem.chooseDiscountItemDto.reduceAmount
  144. )[0]
  145. }}.{{
  146. parsePrice(
  147. shopCartItem.chooseDiscountItemDto.reduceAmount
  148. )[1]
  149. }}</span
  150. >)
  151. </span>
  152. <span v-else
  153. >{{$t('cart.activeItemsPurchasedOver')}}
  154. {{ shopCartItem.chooseDiscountItemDto.needAmount }}
  155. {{$t('items')}}{{$t('cart.getAFullDiscount')}}
  156. </span
  157. >
  158. </div>
  159. <div
  160. class="text"
  161. v-if="
  162. shopCartItem.chooseDiscountItemDto.discountRule == 2
  163. "
  164. >
  165. <span
  166. v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
  167. >
  168. {{$t('cart.activeItemsAreFullyPurchased')}}¥{{
  169. parsePrice(
  170. shopCartItem.chooseDiscountItemDto.needAmount
  171. )[0]
  172. }}.{{
  173. parsePrice(
  174. shopCartItem.chooseDiscountItemDto.needAmount
  175. )[1]
  176. }}(
  177. <span class="text-red"
  178. >{{$t('cart.reduced')}}¥{{
  179. parsePrice(
  180. shopCartItem.chooseDiscountItemDto.reduceAmount
  181. )[0]
  182. }}.{{
  183. parsePrice(
  184. shopCartItem.chooseDiscountItemDto.reduceAmount
  185. )[1]
  186. }}</span
  187. >)
  188. </span>
  189. <span v-else
  190. >{{$t('cart.activeItemsPurchasedOver')}}¥{{
  191. parsePrice(
  192. shopCartItem.chooseDiscountItemDto.needAmount
  193. )[0]
  194. }}.{{
  195. parsePrice(
  196. shopCartItem.chooseDiscountItemDto.needAmount
  197. )[1]
  198. }}
  199. {{$t('cart.enjoyAFullDiscount')}}</span
  200. >
  201. </div>
  202. <div
  203. class="text"
  204. v-if="
  205. shopCartItem.chooseDiscountItemDto.discountRule == 3
  206. "
  207. >
  208. <span
  209. v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
  210. >
  211. {{$t('cart.activeItemsAreFullyPurchased')}}
  212. {{ shopCartItem.chooseDiscountItemDto.needAmount }}{{$t('items')}}(
  213. <span class="text-red"
  214. >{{$t('cart.reduced')}}¥{{
  215. parsePrice(
  216. shopCartItem.chooseDiscountItemDto.reduceAmount
  217. )[0]
  218. }}.{{
  219. parsePrice(
  220. shopCartItem.chooseDiscountItemDto.reduceAmount
  221. )[1]
  222. }}</span
  223. >)
  224. </span>
  225. <span v-else
  226. >{{$t('cart.activeItemsPurchasedOver')}}
  227. {{ shopCartItem.chooseDiscountItemDto.needAmount }}
  228. {{$t('items')}} {{$t('cart.enjoyAFullDiscount')}}</span
  229. >
  230. </div>
  231. <nuxt-link
  232. :to="
  233. '/discount-detail?discountId=' +
  234. shopCartItem.chooseDiscountItemDto.discountId
  235. "
  236. class="link"
  237. >
  238. {{
  239. shopCartItem.chooseDiscountItemDto.reduceAmount
  240. ? $t('cart.goToAdd')
  241. : $t('cart.goToTheList')
  242. }}
  243. <span class="arr">>></span>
  244. </nuxt-link>
  245. </div>
  246. <div class="a-price">
  247. <!-- <div class="total">
  248. <span>¥{{parsePrice(shopCartItem.checkedGoodsTotal)[0]}}.{{parsePrice(shopCartItem.checkedGoodsTotal)[1]}}</span>
  249. </div>-->
  250. <div class="discount">
  251. <span
  252. v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
  253. >-¥{{
  254. parsePrice(
  255. shopCartItem.chooseDiscountItemDto.reduceAmount
  256. )[0]
  257. }}.{{
  258. parsePrice(
  259. shopCartItem.chooseDiscountItemDto.reduceAmount
  260. )[1]
  261. }}</span
  262. >
  263. </div>
  264. </div>
  265. </div>
  266. <!-- 套餐提示 -->
  267. <div
  268. v-if="shopCartItem.comboId"
  269. class="combo-msg"
  270. >
  271. <div class="combo-info">
  272. <span class="combo-icon">{{$t('cart.combo')}}</span>
  273. <span class="combo-name">{{shopCartItem.chooseComboItemDto.name}}</span>
  274. (<span class="combo-reduce"> {{$t('cart.reduced')}} {{shopCartItem.chooseComboItemDto.preferentialAmount}} {{$t('memberCenter.yuan')}}</span>)
  275. </div>
  276. <div class="combo-unit-price">
  277. ¥{{parsePrice(shopCartItem.chooseComboItemDto.comboAmount)[0]}}.{{parsePrice(shopCartItem.chooseComboItemDto.comboAmount)[1]}}
  278. </div>
  279. <div class="combo-count">
  280. <span
  281. class="reduce"
  282. :class="{ limit: shopCartItem.chooseComboItemDto.comboCount === 1 }"
  283. @click="handleChangeNum(shopCart.shopId, shopCartItem.comboId, shopCartItem.shopCartItems[0], -1)"
  284. >-</span
  285. >
  286. <input
  287. type="text"
  288. class="number"
  289. v-model="shopCartItem.chooseComboItemDto.comboCount"
  290. readonly="true"
  291. />
  292. <span
  293. class="increase"
  294. @click="handleChangeNum(shopCart.shopId, shopCartItem.comboId, shopCartItem.shopCartItems[0], 1)"
  295. >+</span
  296. >
  297. </div>
  298. <div class="combo-total-price">¥{{ parsePrice(shopCartItem.chooseComboItemDto.comboTotalAmount)[0] }}.{{parsePrice(shopCartItem.chooseComboItemDto.comboTotalAmount)[1]}}</div>
  299. <div class="combo-del-btn" @click="handleDelCombo(shopCartItem.comboId)">{{$t('delete')}}</div>
  300. </div>
  301. <div class="activity-goods"
  302. v-for="(prod, prodIndex) in shopCartItem.shopCartItems"
  303. :key="prodIndex">
  304. <!-- 商品项 -->
  305. <div
  306. :class="[
  307. prod.isCheck ? 'active item' : 'item',
  308. (prod.discountId > 0 && shopCartItem.chooseDiscountItemDto) || shopCartItem.comboId ? 'activity-goods-checked' : '',
  309. ]"
  310. >
  311. <div class="item-goods">
  312. <div class="tab-check">
  313. <input
  314. v-if="!shopCartItem.comboId || (shopCartItem.comboId && !prod.parentBasketId)"
  315. type="checkbox"
  316. class="checkbox"
  317. checkbox
  318. :class="{
  319. checked: prod.isCheck,
  320. default: !prod.isCheck
  321. }"
  322. @click="handleCheckProdItem(shopIndex, shopCartItemIndex, prodIndex, prod.isCheck)"
  323. />
  324. </div>
  325. <div class="tab-img">
  326. <nuxt-link :to="'/detail/' + prod.prodId" class="img-box">
  327. <img v-if="prod.pic" :src="prod.pic" alt @error="handlePicError" />
  328. <img v-else src="~/assets/img/def.png" alt />
  329. </nuxt-link>
  330. </div>
  331. <div class="tab-name">
  332. <nuxt-link :to="'/detail/' + prod.prodId" class="name">{{
  333. prod.prodName
  334. }}</nuxt-link>
  335. <!-- <span class="sku">{{ prod.skuName }}</span> -->
  336. <span class="sku" @click="getSkuListByProdId(prod)">
  337. <!-- :sku-list="mainProd.skuList" -->
  338. <SelectSku
  339. v-if="prod.skuName"
  340. :sku-id="prod.skuId"
  341. :sku-name="prod.skuName"
  342. :prod-id="prod.prodId"
  343. :combo-id="prod.comboId"
  344. @getSku="handleSetSku"
  345. />
  346. </span>
  347. </div>
  348. <div class="tab-price">
  349. <div class="unit-price">
  350. ¥{{ parsePrice(shopCartItem.comboId ? prod.comboPrice : prod.price)[0] }}.{{
  351. parsePrice(shopCartItem.comboId ? prod.comboPrice : prod.price)[1]
  352. }}
  353. </div>
  354. <div class="promotion-box">
  355. <div
  356. class="p-tit"
  357. v-if="prod.discountId > 0 || prod.discountId == -1"
  358. :data-basketid="prod.basketId"
  359. @click.prevent="onShowDisList(prod.basketId, prod.discountId)"
  360. >
  361. {{$t('promotion')}}
  362. </div>
  363. <transition name="fade">
  364. <div
  365. class="p-con"
  366. v-if="
  367. showDiscountsList &&
  368. prod.basketId == currentBasketId
  369. "
  370. >
  371. <div class="p-items-con">
  372. <div
  373. class="p-item"
  374. v-for="(discountItem, index) in prod.discounts"
  375. :key="discountItem.discountId"
  376. >
  377. <input
  378. @change="setChooseDiscountId(discountItem.discountId)"
  379. :id="index"
  380. type="radio"
  381. class="radio"
  382. :name="prod.prodId"
  383. :checked="
  384. discountItem.discountId == prod.discountId
  385. "
  386. />
  387. <label :for="index" class="p-info">{{
  388. discountItem.discountName
  389. }}</label>
  390. </div>
  391. <div class="p-item">
  392. <input
  393. @change="setChooseDiscountId(-1)"
  394. id="nodiscount"
  395. type="radio"
  396. class="radio"
  397. :name="prod.prodId"
  398. :checked="prod.discountId == -1"
  399. />
  400. <label for="nodiscount" class="p-info"
  401. >{{$t('cart.noEventDiscount')}}</label
  402. >
  403. </div>
  404. </div>
  405. <div class="p-btns">
  406. <a
  407. href="javascript:void(0)"
  408. class="sure"
  409. @click="onChooseDiscount(
  410. switchDiscountId,
  411. prod.basketId
  412. )"
  413. >{{$t('determine')}}</a
  414. >
  415. <a
  416. href="javascript:void(0)"
  417. class="cancel"
  418. @click="showDiscountsList = false"
  419. >{{$t('cancel')}}</a
  420. >
  421. </div>
  422. </div>
  423. </transition>
  424. </div>
  425. </div>
  426. <div class="tab-number">
  427. <div class="goods-number">
  428. <span
  429. v-if="!shopCartItem.comboId"
  430. class="reduce"
  431. :class="{ limit: prod.prodCount === 1 }"
  432. @click="handleChangeNum(shopCart.shopId, shopCartItem.comboId, prod, -1)"
  433. >-</span
  434. >
  435. <input
  436. type="text"
  437. class="number"
  438. v-model="prod.prodCount"
  439. readonly="true"
  440. />
  441. <span
  442. v-if="!shopCartItem.comboId"
  443. class="increase"
  444. @click="handleChangeNum(shopCart.shopId, shopCartItem.comboId, prod, 1)"
  445. >+</span
  446. >
  447. </div>
  448. </div>
  449. <!-- <div class="tab-total">¥{{parsePrice(prod.productTotalAmount)[0]}}.{{parsePrice(prod.productTotalAmount)[1]}}</div> -->
  450. <div class="tab-total">
  451. ¥{{ parsePrice(prod.prodCount * (shopCartItem.comboId ? prod.comboPrice : prod.price))[0] }}.{{
  452. parsePrice(prod.prodCount * (shopCartItem.comboId ? prod.comboPrice : prod.price))[1]
  453. }}
  454. </div>
  455. <div class="tab-action">
  456. <!-- <a
  457. href="JavaScript:;"
  458. class="action-a collect"
  459. @click="collection(index, shopCartItemIndex, prodIndex)"
  460. >{{ prod.isCollection ? '取消收藏' : '移入收藏夹' }}</a
  461. > -->
  462. <!-- 活动商品不可收藏 -->
  463. <a
  464. href="JavaScript:;"
  465. v-if="prod.prodType !== 5"
  466. class="action-a collect"
  467. :style="$t('language')=='en'?moveToFavorites:''"
  468. @click="collection(shopIndex, shopCartItemIndex, prodIndex)"
  469. >{{$t('cart.moveToFavorites')}}</a
  470. >
  471. <a
  472. v-if="!shopCartItem.comboId"
  473. href="JavaScript:;"
  474. class="action-a del"
  475. @click="openPopup(prod.basketId)"
  476. >{{$t('delete')}}</a
  477. >
  478. </div>
  479. </div>
  480. <!-- 赠品展示 -->
  481. <div v-if="prod.giveaway" class="gift-con">
  482. <div v-for="(giveawayItem, giveawayIndex) in prod.giveaway.giveawayProds" :key="giveawayIndex" class="gift-item">
  483. <nuxt-link class="gift-item-name" :to="'/detail/' + giveawayItem.prodId">
  484. {{$t('cart.giveaways')}} {{giveawayItem.prodName}}
  485. <span class="gift-item-sku-name">{{giveawayItem.skuName}} x{{giveawayItem.giveawayNum}}</span>
  486. </nuxt-link>
  487. </div>
  488. </div>
  489. </div>
  490. </div>
  491. </div>
  492. </div>
  493. </div>
  494. </div>
  495. </div>
  496. <div class="cart-bottom" v-if="shopCartList.length">
  497. <div class="total-box">
  498. <div class="check-all">
  499. <input
  500. type="checkbox"
  501. class="checkbox"
  502. :class="{ checked: allChecked, default: !allChecked }"
  503. @click="checkAll()"
  504. />
  505. <span class="text" @click="checkAll()">{{$t('cart.selectAll')}}</span>
  506. </div>
  507. <a href="JavaScript:;" class="del-selected" @click="openPopup()"
  508. >{{$t('cart.deleteSelectedProducts')}}</a
  509. >
  510. </div>
  511. <div class="settlement-box">
  512. <div class="amount">
  513. {{$t('cart.selected')}}
  514. <span class="number">{{ this.count }}</span
  515. >{{$t('cart.itemsProducts')}}
  516. </div>
  517. <div class="price-box">
  518. <div class="total-price">
  519. {{$t('cart.totalPrice')}}:
  520. <span class="text"
  521. >¥{{ parsePrice(this.finalMoney)[0] }}.{{
  522. parsePrice(this.finalMoney)[1]
  523. }}</span
  524. >
  525. </div>
  526. <div class="discount-price">
  527. {{$t('cart.offers')}}:
  528. <span class="text"
  529. >-¥{{ parsePrice(this.subtractMoney)[0] }}.{{
  530. parsePrice(this.subtractMoney)[1]
  531. }}</span
  532. >
  533. </div>
  534. </div>
  535. <a href="JavaScript:;" class="btn" @click="submit()" :style="{fontSize:$t('language')=='en'?'14px':'16px'}">{{$t('cart.goToSettlement')}}</a>
  536. </div>
  537. </div>
  538. <div class="popup-mask" v-if="isPopup"></div>
  539. <!-- 删除提示弹窗 -->
  540. <div class="popup-box" v-if="isPopup">
  541. <div class="tit">
  542. <div class="text">{{$t('tips')}}</div>
  543. <div class="close" @click="closePopup()"></div>
  544. </div>
  545. <div class="con">
  546. <div class="tip">
  547. <div class="tip-icon warning"></div>
  548. <div class="tip-info">
  549. <div class="result">{{$t('cart.deleteThisItem')}}</div>
  550. <div class="date">{{$t('cart.removeCart')}}</div>
  551. <div class="btns">
  552. <a href="JavaScript:;" class="btn-r" @click="handleDeletProd">{{$t('delete')}}</a>
  553. <a href="JavaScript:;" class="btn-g" @click="closePopup"
  554. >{{$t('cancel')}}</a
  555. >
  556. </div>
  557. </div>
  558. </div>
  559. </div>
  560. </div>
  561. </div>
  562. </div>
  563. </template>
  564. <script>
  565. import { _debounce } from "~/plugins/util"; //防抖
  566. import util from '~/plugins/util'
  567. import SelectSku from '~/components/select-sku.vue'
  568. export default {
  569. data () {
  570. return {
  571. shopCartList: [],
  572. allChecked: true,
  573. count: 0,
  574. finalMoney: 0,
  575. subtractMoney: 0,
  576. totalMoney: 0,
  577. isPopup: false,
  578. basketId: null,
  579. showDiscountsList: false, // 促销活动显隐
  580. currentBasketId: '',
  581. discountData: {},
  582. reqData: [],
  583. moveToFavorites:{
  584. position: "relative",
  585. left: "-25px"
  586. },
  587. baskets: [],
  588. isSwichDiscount: false,
  589. switchDiscountId: -1,
  590. // 是否显示套装商品
  591. isCombo: false,
  592. // 是否显示赠品
  593. showGift: false,
  594. // 当前修改的购物车商品项
  595. currentProdItem: {},
  596. showSkuPop: false,
  597. isClick: true //限制加减按钮点击
  598. }
  599. },
  600. components: {
  601. SelectSku
  602. },
  603. mounted () {
  604. // 设置网页标题
  605. document.title = this.$t('cart.cart')
  606. this.loadBasketData()
  607. },
  608. methods: {
  609. handlePicError(e){
  610. e.target.src=require('@/assets/img/def.png')
  611. },
  612. /**
  613. * 修改sku
  614. */
  615. handleSetSku(sku) {
  616. const currentProdItem = this.currentProdItem
  617. const params = {
  618. basketId: currentProdItem.basketId,
  619. comboId: currentProdItem.comboId,
  620. count: 0,
  621. shopId: currentProdItem.shopId,
  622. prodId: currentProdItem.prodId,
  623. skuId: sku.skuId,
  624. }
  625. this.updateBasket(params)
  626. },
  627. loadBasketData () {
  628. var shopCartIds = []
  629. this.$axios.post('/p/shopCart/info', this.baskets).then(({ data }) => {
  630. if(this.isSwichDiscount) {
  631. for(let i = this.baskets.length -1; i >= 0 ; i--) {
  632. if(!this.baskets[i].isCheck) {
  633. this.baskets.splice(i, 1)
  634. }
  635. }
  636. this.isSwichDiscount = false
  637. }
  638. var shopCartList = data
  639. if (data.length > 0) {
  640. if (shopCartIds.length == 0) { // 初始加载
  641. shopCartList.forEach(shopCart => {
  642. shopCart.shopCartItemDiscounts.forEach(shopCartItemDiscount => {
  643. if (shopCartItemDiscount.comboId) {
  644. shopCartItemDiscount.mainProdBasketId = shopCartItemDiscount.shopCartItems[0].basketId
  645. }
  646. })
  647. })
  648. this.shopCartList = shopCartList
  649. } else { // 修改购物车
  650. var checkedLog = []
  651. this.shopCartList.forEach(shopCart => {
  652. shopCart.shopCartItemDiscounts.forEach(shopCartItemDiscount => {
  653. shopCartItemDiscount.shopCartItems.forEach(shopCartItem => {
  654. if (shopCartItem.checked) {
  655. checkedLog.push(shopCartItem.basketId)
  656. }
  657. })
  658. })
  659. })
  660. data.forEach(newShopCart => {
  661. newShopCart.shopCartItemDiscounts.forEach(newShopCartItemDiscount => {
  662. newShopCartItemDiscount.shopCartItems.forEach(shopCartItem => {
  663. if (checkedLog.includes(shopCartItem.basketId)) {
  664. shopCartItem.checked = true
  665. }else {
  666. shopCartItem.checked = false
  667. }
  668. })
  669. });
  670. })
  671. this.shopCartList = data
  672. }
  673. } else {
  674. this.shopCartList = []
  675. }
  676. this.checkAllSelected()
  677. // 计算总价
  678. this.calTotalPrice()
  679. // 购物车数量
  680. // this.getCartCount()
  681. this.isClick = true
  682. })
  683. },
  684. /**
  685. * 计算购物车总额
  686. */
  687. calTotalPrice () {
  688. var shopCartIds = [];
  689. this.baskets.forEach(item => {
  690. if (item.isCheck) {
  691. shopCartIds.push(item.basketId)
  692. }
  693. })
  694. this.$axios.post('/p/shopCart/totalPay', shopCartIds).then(({ data }) => {
  695. this.count = data.count
  696. this.finalMoney = data.finalMoney,
  697. this.totalMoney = data.totalMoney,
  698. this.subtractMoney = data.subtractMoney
  699. })
  700. },
  701. //收藏商品
  702. collection: _debounce(function(shopIndex, shopCartItemIndex, prodIndex) {
  703. const item = this.shopCartList[shopIndex].shopCartItemDiscounts[shopCartItemIndex].shopCartItems[prodIndex]
  704. var prodId = item.prodId
  705. this.$axios.get('/p/user/collection/isCollection', { params: { prodId } }).then(({ data }) => {
  706. if (data == true) {
  707. this.$message({
  708. message: this.$t('cart.theProductIsAlreadyInTheFavorites'),
  709. type: 'success',
  710. duration: 1000
  711. })
  712. } else {
  713. this.$axios.post('/p/user/collection/orderProdCollectionAll', item.prodId).then(({ data }) => {
  714. this.$message({
  715. message: this.$t('prodDetail.collectionSuccess'),
  716. type: 'success',
  717. duration: 1000
  718. })
  719. // item.isCollection = true
  720. return
  721. })
  722. }
  723. })
  724. },500),
  725. /**
  726. * 点击套装的删除按钮
  727. */
  728. handleDelCombo (comboId) {
  729. for (let i = 0; i < this.shopCartList.length; i++) {
  730. const shop = this.shopCartList[i];
  731. for (let k = 0; k < shop.shopCartItemDiscounts.length; k++) {
  732. const shopCartItemDiscount = shop.shopCartItemDiscounts[k]
  733. for (let j = 0; j < shopCartItemDiscount.shopCartItems.length; j++) {
  734. const shopCartItem = shopCartItemDiscount.shopCartItems[j];
  735. if (shopCartItemDiscount.comboId === comboId && shopCartItem.parentBasketId === 0) {
  736. this.openPopup(shopCartItem.basketId)
  737. break
  738. }
  739. }
  740. }
  741. }
  742. },
  743. //打开弹窗
  744. openPopup (basketId) {
  745. this.isPopup = true
  746. this.basketId = basketId
  747. },
  748. //关闭弹窗
  749. closePopup () {
  750. this.isPopup = false
  751. this.basketId = null
  752. },
  753. // 删除购物车商品
  754. handleDeletProd () {
  755. var shopCartIds = []
  756. if (!this.basketId) {
  757. this.shopCartList.forEach(shop => {
  758. shop.shopCartItemDiscounts.forEach(item => {
  759. item.shopCartItems.forEach(shopCart => {
  760. if (shopCart.isCheck) {
  761. shopCartIds.push(shopCart.basketId);
  762. }
  763. });
  764. });
  765. });
  766. } else {
  767. shopCartIds.push(this.basketId)
  768. }
  769. if (!shopCartIds.length) {
  770. this.$message({
  771. type: 'warning',
  772. message: this.$t('cart.pleaseCheckTheItemsWantToDelete')
  773. })
  774. this.isPopup = false
  775. return
  776. }
  777. this.$axios.put('/p/shopCart/deleteItem', shopCartIds).then(({ data }) => {
  778. this.loadBasketData()
  779. this.getCartCount()
  780. })
  781. this.isPopup = false
  782. },
  783. /**
  784. * 每一项的选择事件
  785. */
  786. handleCheckProdItem (shopIndex, shopCartItemIndex, prodIndex,isCheck) {
  787. var shopCartList = this.shopCartList;
  788. var shopCartItemDiscounts = shopCartList[shopIndex].shopCartItemDiscounts; // 获取购物车列表
  789. var checked = shopCartItemDiscounts[shopCartItemIndex].shopCartItems[prodIndex].checked; // 获取当前商品的选中状态
  790. shopCartItemDiscounts[shopCartItemIndex].shopCartItems[prodIndex].checked = !checked; // 改变状态
  791. const shopCartItem = shopCartItemDiscounts[shopCartItemIndex].shopCartItems[prodIndex]
  792. this.generateRequestData(shopCartItem.basketId, !isCheck)
  793. this.loadBasketData()
  794. this.checkAllSelected(); //检查全选状态
  795. },
  796. isBasketPresence(prod) {
  797. for(let i = 0; i < this.baskets.length; i++) {
  798. if(prod.basketId === this.baskets[i].basketId) {
  799. return i
  800. }
  801. }
  802. return false
  803. },
  804. /**
  805. * 店铺勾选事件
  806. */
  807. handleCheckShop (shopIndex) {
  808. this.shopCartList[shopIndex].checked = !this.shopCartList[shopIndex].checked
  809. var checked = this.shopCartList[shopIndex].checked
  810. this.shopCartList[shopIndex].shopCartItemDiscounts.forEach(item => {
  811. item.checked = checked
  812. item.shopCartItems.forEach(prodItem => {
  813. prodItem.isCheck = checked
  814. this.generateRequestData(prodItem.basketId, checked)
  815. })
  816. })
  817. this.loadBasketData()
  818. this.checkAllSelected()
  819. },
  820. /**
  821. * 全选事件
  822. */
  823. checkAll () {
  824. this.handleCheckAll(this.shopCartList, !this.allChecked)
  825. },
  826. /**
  827. * 全选
  828. */
  829. handleCheckAll () {
  830. var allChecked = this.allChecked;
  831. allChecked = !allChecked; //改变状态
  832. var shopCartList = this.shopCartList;
  833. shopCartList.forEach(shopCart => {
  834. shopCart.checked = allChecked;
  835. var shopCartItemDiscounts = shopCart.shopCartItemDiscounts;
  836. for (var i = 0; i < shopCartItemDiscounts.length; i++) {
  837. var cItems = shopCartItemDiscounts[i].shopCartItems;
  838. for (var j = 0; j < cItems.length; j++) {
  839. cItems[j].checked = allChecked;
  840. if(allChecked) {
  841. this.generateRequestData(cItems[j].basketId, allChecked)
  842. } else {
  843. this.baskets = []
  844. }
  845. }
  846. }
  847. });
  848. this.allChecked = allChecked
  849. this.shopCartList = shopCartList
  850. this.loadBasketData()
  851. // this.calTotalPrice(); //计算总价
  852. },
  853. /**
  854. * 检查全选状态
  855. */
  856. checkAllSelected () {
  857. var allChecked = true;
  858. var shopCartList = this.shopCartList;
  859. var flag = false;
  860. shopCartList.forEach(shopCart => {
  861. var shopChecked = true;
  862. var shopCartItemDiscounts = shopCart.shopCartItemDiscounts;
  863. for (var i = 0; i < shopCartItemDiscounts.length; i++) {
  864. var cItems = shopCartItemDiscounts[i].shopCartItems;
  865. for (var j = 0; j < cItems.length; j++) {
  866. if (!cItems[j].isCheck) {
  867. shopChecked = false;
  868. allChecked = false;
  869. flag = true;
  870. break;
  871. }
  872. }
  873. if (flag) {
  874. break;
  875. }
  876. }
  877. shopCart.checked = shopChecked;
  878. });
  879. this.allChecked = allChecked
  880. this.shopCartList = shopCartList
  881. },
  882. /**
  883. * 修改购物车数量
  884. * @param {Number} shopId 店铺
  885. * @param {Number} comboId 套餐id
  886. * @param {Object} prod 修改的商品项
  887. * @param {Number} count 商品数量增量
  888. */
  889. handleChangeNum(shopId, comboId, prod, count) {
  890. if(!this.isClick) {
  891. return
  892. }
  893. this.isClick = false
  894. let matchingSkuIds = []
  895. if (comboId) {
  896. const shopCartList = this.shopCartList
  897. let shopIndex = shopCartList.findIndex(el => el.shopId === shopId)
  898. let shopCartItemDiscounts = shopCartList[shopIndex].shopCartItemDiscounts
  899. let shopCartItemIndex = shopCartItemDiscounts.findIndex(el => el.comboId === comboId && el.mainProdBasketId === prod.basketId)
  900. if (shopCartItemDiscounts[shopCartItemIndex].shopCartItems[0].comboCount === 1 && count === -1) {
  901. this.isClick = true
  902. return
  903. }
  904. shopCartItemDiscounts[shopCartItemIndex].shopCartItems.forEach(el => {
  905. if (el.parentBasketId !== 0) {
  906. matchingSkuIds.push(el.skuId)
  907. }
  908. })
  909. }
  910. // else {
  911. this.currentProdItem = prod
  912. // }
  913. const updateBasketParam = {
  914. basketId: prod.basketId,
  915. comboId: comboId,
  916. count: count,
  917. matchingSkuIds: comboId ? matchingSkuIds : undefined,
  918. prodId: prod.prodId,
  919. shopId: shopId,
  920. skuId: prod.skuId
  921. }
  922. this.updateBasket(updateBasketParam)
  923. },
  924. /**
  925. * 更新购物车
  926. * @param {Object} updateBasketParam 请求的参数
  927. */
  928. updateBasket: _debounce(function (updateBasketParam) {
  929. if (updateBasketParam.count == -1 && this.currentProdItem.prodCount == 1) {
  930. this.isClick = true
  931. return
  932. }
  933. this.$axios({
  934. url: updateBasketParam.count === 0 ? "/p/shopCart/changeShopCartSku" : "/p/shopCart/changeItem",
  935. method: updateBasketParam.count === 0 ? "PUT" : "POST",
  936. data: updateBasketParam
  937. }).then(({data})=> {
  938. this.getCartCount()
  939. this.loadBasketData()
  940. if (updateBasketParam.count && updateBasketParam.count >= 1) {
  941. const flowAnalysisLogDto = JSON.parse(localStorage.getItem('flowAnalysisLogDto'))
  942. flowAnalysisLogDto.bizData = updateBasketParam.prodId
  943. flowAnalysisLogDto.bizType = 0
  944. localStorage.setItem('flowAnalysisLogDto', JSON.stringify(flowAnalysisLogDto))
  945. util.tapLog(4, '', '', updateBasketParam.count)
  946. }
  947. })
  948. }, 420),
  949. /**
  950. * 去结算
  951. */
  952. submit () {
  953. var shopCartIds = []
  954. this.baskets.forEach(basket => {
  955. shopCartIds.push(basket.basketId);
  956. })
  957. if (shopCartIds.length < 1) {
  958. this.$message({
  959. message: this.$t('cart.pleaseSelectAtLeastOneItem'),
  960. type: 'error',
  961. duration: 1000
  962. })
  963. return
  964. }
  965. var basketIds = JSON.stringify(shopCartIds)
  966. sessionStorage.setItem('basketIds', basketIds);
  967. this.$router.push({ path: '/submit-order?orderEntry=0' })
  968. },
  969. /**
  970. * 价格处理
  971. */
  972. parsePrice: (value) => {
  973. var val = Number(value)
  974. if (!val) {
  975. val = 0;
  976. }
  977. // 截取小数点后两位,并以小数点为切割点将val转化为数组
  978. return val.toFixxed(2).split(".");
  979. },
  980. /**
  981. * 当前选中的活动id
  982. */
  983. setChooseDiscountId(discountId) {
  984. this.switchDiscountId = discountId
  985. },
  986. /**
  987. * 修改促销活动
  988. */
  989. onChooseDiscount (discountId, basketId) {
  990. let flag = false
  991. for(let i = 0; i < this.baskets.length; i++) {
  992. if(this.baskets[i].basketId === basketId) {
  993. this.baskets[i].discountId = discountId
  994. flag = true
  995. break
  996. }
  997. }
  998. if(!flag) {
  999. this.baskets.push({
  1000. discountId,
  1001. basketId
  1002. })
  1003. }
  1004. this.submitDiscount()
  1005. },
  1006. /**
  1007. * 提交促销活动修改
  1008. */
  1009. submitDiscount () {
  1010. // var reqData = this.discountData
  1011. this.loadBasketData()
  1012. this.showDiscountsList = false
  1013. this.isSwichDiscount = true
  1014. },
  1015. /**
  1016. * 促销按钮
  1017. */
  1018. onShowDisList (val, discountId) {
  1019. this.showDiscountsList = true
  1020. this.currentBasketId = val
  1021. this.switchDiscountId = discountId || -1
  1022. },
  1023. /**
  1024. * 获取购物车商品总数
  1025. */
  1026. getCartCount () {
  1027. this.$axios.get('/p/shopCart/prodCount').then(({ data }) => {
  1028. this.$store.commit('cartNumber/changeCartNumber', data)
  1029. })
  1030. },
  1031. /**
  1032. * 生成请求购物车的数据
  1033. * @param {Number} basketId 商品的购物车id
  1034. * @param {Boolean} isCheck 商品的选择状态
  1035. */
  1036. generateRequestData(basketId, isCheck) {
  1037. let matchingProdBasketsId = []
  1038. for (let i = 0; i < this.shopCartList.length; i++) {
  1039. const shopCart = this.shopCartList[i];
  1040. for (let j = 0; j < shopCart.shopCartItemDiscounts.length; j++) {
  1041. const cItems = shopCart.shopCartItemDiscounts[j];
  1042. for (let k = 0; k < cItems.shopCartItems.length; k++) {
  1043. const pItem = cItems.shopCartItems[k];
  1044. if (cItems.comboId === pItem.comboId && pItem.parentBasketId === basketId) {
  1045. matchingProdBasketsId.push(pItem.basketId)
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if (this.baskets.length) {
  1051. this.setBasketsWhileNotEmpty(basketId, isCheck)
  1052. // 套餐商品
  1053. for (let i = 0; i < matchingProdBasketsId.length; i++) {
  1054. this.setBasketsWhileNotEmpty(matchingProdBasketsId[i], isCheck)
  1055. }
  1056. } else {
  1057. this.setBaskets(basketId, isCheck)
  1058. // 套餐商品
  1059. for (let i = 0; i < matchingProdBasketsId.length; i++) {
  1060. this.setBaskets(matchingProdBasketsId[i], isCheck)
  1061. }
  1062. }
  1063. },
  1064. /**
  1065. * 生成请求购物车的数据: 当baskets不为空时
  1066. */
  1067. setBasketsWhileNotEmpty (basketId, isCheck) {
  1068. let index = this.baskets.findIndex(el => el.basketId === basketId)
  1069. if (index > -1) {
  1070. this.baskets[index].isCheck = isCheck
  1071. } else {
  1072. this.setBaskets(basketId, isCheck)
  1073. }
  1074. },
  1075. /**
  1076. * 生成请求购物车的数据: 当basketId 中未包含当前修改的商品的购物车id时
  1077. */
  1078. setBaskets (basketId, isCheck) {
  1079. this.baskets.push({
  1080. basketId: basketId,
  1081. discountId: '',
  1082. isCheck: isCheck
  1083. })
  1084. },
  1085. /**
  1086. * 根据商品id获取skuList
  1087. * @param {Object} prod 当前要修改的选项
  1088. */
  1089. getSkuListByProdId(prod) {
  1090. let comboList = []
  1091. if (prod.comboId) {
  1092. const shopCartList = this.shopCartList
  1093. let shopIndex = shopCartList.findIndex(el => el.shopId === prod.shopId)
  1094. let shopCartItemDiscounts = shopCartList[shopIndex].shopCartItemDiscounts
  1095. let shopCartItemIndex = shopCartItemDiscounts.findIndex(el => el.comboId === prod.comboId)
  1096. shopCartItemDiscounts[shopCartItemIndex].shopCartItems.forEach(el => {
  1097. comboList.push({
  1098. basketId: el.basketId,
  1099. skuId: el.skuId,
  1100. prodId: el.prodId
  1101. })
  1102. })
  1103. prod.comboList = comboList
  1104. }
  1105. this.currentProdItem = prod
  1106. },
  1107. /**
  1108. * sku
  1109. */
  1110. handleShowSkuPop() {
  1111. console.log('sku弹窗显示了');
  1112. }
  1113. }
  1114. }
  1115. </script>
  1116. <style scoped src='~/assets/css/cart.css'>
  1117. </style>