多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1085 lines
32 KiB

2 years ago
  1. <template>
  2. <view class="content">
  3. <!-- 骨架屏 -->
  4. <u-skeleton
  5. el-color="#efefef"
  6. bg-color="#fff"
  7. :loading="loading && isFirstComeIn"
  8. :animation="true"
  9. ></u-skeleton>
  10. <global-loading />
  11. <!-- 购物车 -->
  12. <view class="u-skeleton">
  13. <view v-if="!isEmpty">
  14. <u-sticky bg-color="#fff">
  15. <view class="cart-bg u-skeleton-fillet">
  16. <view class="cart-num-box">
  17. <image
  18. class=" u-skeleton-fillet"
  19. src="https://ceres.zkthink.com/static/images/logoTop.png"
  20. ></image>
  21. <text
  22. class="btn-box "
  23. @click="showManage = !showManage"
  24. v-if="!showManage"
  25. >管理
  26. </text>
  27. <text
  28. class="btn-box"
  29. @click="showManage = !showManage"
  30. v-if="showManage"
  31. >完成
  32. </text>
  33. </view>
  34. <view>
  35. <text class="num-box u-skeleton-fillet">
  36. <text class="num">{{ settleAccountsObj.allNum }}</text>
  37. 件宝贝
  38. </text>
  39. </view>
  40. </view>
  41. </u-sticky>
  42. <view class="cart-list-box">
  43. <view
  44. class="itemBox"
  45. v-for="(item, index) in dataList"
  46. :key="item.shopId"
  47. >
  48. <view
  49. class="item"
  50. v-if="item.skus.length >0"
  51. >
  52. <view class="shop-box">
  53. <image
  54. mode="aspectFill u-skeleton-fillet"
  55. v-if="item.selected === 1"
  56. src="https://ceres.zkthink.com/static/images/selectActive.png"
  57. class="cart-select-img"
  58. @click.stop="handleSelectShop(index,0)"
  59. ></image>
  60. <image
  61. mode="aspectFill u-skeleton-fillet"
  62. v-else
  63. src="https://ceres.zkthink.com/static/images/selectEmpty.png"
  64. class="cart-select-img"
  65. @click.stop="handleSelectShop(index,1)"
  66. ></image>
  67. <view
  68. class="shop-name-box u-skeleton-fillet"
  69. @click="$jump(`${jumpObj.store}?storeId=${item.shopId}`)"
  70. >
  71. <image
  72. src="https://ceres.zkthink.com/static/images/orderStoreIcon.png"
  73. class="shop-img"
  74. ></image>
  75. <text class="shop-name">{{ item.shopName }}</text>
  76. <image
  77. src="https://ceres.zkthink.com/static/images/arrowRight.png"
  78. class="arrow-right-img"
  79. ></image>
  80. </view>
  81. </view>
  82. <view
  83. class="rulesBox flex-items"
  84. v-if="item.currentRules && item.currentRules.number"
  85. >
  86. <image
  87. class="mar-right-20"
  88. src="https://ceres.zkthink.com/static/images/zuheIcon.png"
  89. ></image>
  90. <view class="fs24 font-color-C83732">
  91. 已满足{{ item.currentRules.price }}元任选{{ item.currentRules.number }}
  92. </view>
  93. </view>
  94. <view
  95. v-for="(skuItem, cIndex) in dataList[index].skus"
  96. class="product-list-box "
  97. >
  98. <view
  99. class="pro-item"
  100. @click="$jump(`${jumpObj.detail}?shopId=${item.shopId}&productId=${skuItem.productId}&skuId=${skuItem.skuId}`)"
  101. >
  102. <image
  103. mode="aspectFill u-skeleton-fillet"
  104. v-if="skuItem.selected == 1"
  105. src="https://ceres.zkthink.com/static/images/selectActive.png"
  106. @click.stop="handleSelectSku(index,cIndex,0)"
  107. class="cart-select-img"
  108. ></image>
  109. <image
  110. mode="aspectFill u-skeleton-fillet"
  111. v-else
  112. src="https://ceres.zkthink.com/static/images/selectEmpty.png"
  113. @click.stop="handleSelectSku(index,cIndex,1)"
  114. class="cart-select-img"
  115. ></image>
  116. <view class="pro-r">
  117. <image
  118. :src="skuItem.image"
  119. class="pro-img default-img u-skeleton-fillet"
  120. ></image>
  121. <view class="pro-r-r u-skeleton-fillet">
  122. <view class="pro-name">{{ skuItem.productName }}</view>
  123. <view class="sku-box">
  124. <text v-if="skuItem.value">{{ skuItem.value }}</text>
  125. <text v-else>默认规格</text>
  126. <!-- <text></text> -->
  127. </view>
  128. <view class="pro-price-num-box">
  129. <view class="pro-price-box">
  130. <text class="fuhao"></text>
  131. <text>{{ skuItem.price }}</text>
  132. </view>
  133. <view class="pro-num-box">
  134. <text
  135. class="num-btn r"
  136. @click.stop="handleSubSkuNumber(index,cIndex)"
  137. >-
  138. </text>
  139. <text class="num">{{ skuItem.number }}</text>
  140. <text
  141. class="num-btn l"
  142. @click.stop="handleAddSkuNumber(index,cIndex)"
  143. >+
  144. </text>
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. </view>
  152. </view>
  153. </view>
  154. <!-- #ifdef H5 -->
  155. <view class="cart-bottom-box-h5">
  156. <!-- #endif -->
  157. <!-- #ifndef H5 -->
  158. <view class="cart-bottom-box-app">
  159. <!-- #endif -->
  160. <view class="cart-bottom">
  161. <view class="left">
  162. <image
  163. mode="aspectFill"
  164. v-if="settleAccountsObj.isAllCheck"
  165. src="https://ceres.zkthink.com/static/images/selectActive.png"
  166. class="cart-select-img"
  167. @click="handleSelectAll(0)"
  168. ></image>
  169. <image
  170. mode="aspectFill"
  171. v-else
  172. src="https://ceres.zkthink.com/static/images/selectEmpty.png"
  173. class="cart-select-img"
  174. @click="handleSelectAll(1)"
  175. ></image>
  176. <text>全选</text>
  177. </view>
  178. <view
  179. class="right"
  180. v-if="!showManage"
  181. >
  182. <view class="price-box">
  183. <text>合计</text>
  184. <text class="price">¥{{ settleAccountsObj.checkMoney }}</text>
  185. </view>
  186. <view
  187. class="btn-confirm"
  188. @click="settlementTap"
  189. >结算{{ settleAccountsObj.checkNum }}
  190. </view>
  191. </view>
  192. <view
  193. class="right"
  194. v-if="showManage"
  195. >
  196. <view
  197. class="btn-delete"
  198. @click="handleOpenDelete"
  199. >删除
  200. </view>
  201. </view>
  202. </view>
  203. </view>
  204. </view>
  205. </view>
  206. <!-- 购物车为空 -->
  207. <view
  208. v-if="isEmpty"
  209. class="emptyCart-box flex-items-plus flex-column"
  210. >
  211. <image
  212. class="emptyCart-img"
  213. src="https://ceres.zkthink.com/static/images/cartEmpty.png"
  214. ></image>
  215. <label class="font-color-999 fs26 mar-top-30">你的购物车还没有宝贝哦</label>
  216. <label class="font-color-999 fs26 mar-top-10">快去首页选一个吧</label>
  217. <view
  218. class="goToShopping"
  219. @click="$jumpToTabbar(jumpObj.shopping)"
  220. >去购物
  221. </view>
  222. </view>
  223. <!-- 热门推荐 -->
  224. <HotTemplate class="u-skeleton-fillet"/>
  225. <view style="width: 100%;height: 120rpx;background-color:#fff;"></view>
  226. <!-- 删除确认弹窗 -->
  227. <DeleteModal
  228. :showTip.sync="showDeleteModal"
  229. @confirm="handleDoDelete"
  230. ></DeleteModal>
  231. </view>
  232. </view>
  233. </template>
  234. <script>
  235. import HotTemplate from '../../../components/hoteRecommed/index.vue'
  236. import DeleteModal from "./components/DeleteModal";
  237. import api from "../../../components/canvasShow/config/api";
  238. import { defaultCartList, getCartNumberBySelect, getPriceBySelect } from "./cartUtils";
  239. import lodash from 'lodash'
  240. let cacheKey = ''
  241. const NET = require('../../../utils/request')
  242. const API = require('../../../config/api')
  243. export default {
  244. components: {
  245. HotTemplate,
  246. DeleteModal
  247. },
  248. data() {
  249. return {
  250. isFirstComeIn:true, // 是否是首次进入
  251. loading: true, // 是否在加载
  252. showManage: false, // 是否开启管理
  253. dataList: [
  254. {skus: []}
  255. ], // 购物车数据
  256. showDeleteModal: false, // 是否展示删除
  257. isEmpty: false, // 购物车是否为空
  258. userInfo: {}, // 用户信息
  259. // 跳转对象
  260. jumpObj: {
  261. store: '/pages_category_page1/store/index',
  262. detail: '/pages_category_page1/goodsModule/goodsDetails',
  263. shopping: '/pages/tabbar/index/index'
  264. },
  265. // 底部结算条对象
  266. settleAccountsObj: {
  267. allNum: 0,// 所有sku数量(头部)
  268. checkNum: 0, // 选中sku的数量
  269. checkMoney: 0, // 选中sku的总价
  270. isAllCheck: false, // 是否宣布选中
  271. }
  272. }
  273. },
  274. onShow() {
  275. this.isFirstComeIn = true
  276. this.loading = true
  277. this.userInfo = uni.getStorageSync('storage_key')
  278. cacheKey = this.userInfo.buyerUserId + "cart_info"
  279. this.dataList = defaultCartList
  280. this.isEmpty = false
  281. this.getDataList()
  282. },
  283. methods: {
  284. /**
  285. * 获取购物车列表
  286. */
  287. getDataList:lodash.debounce(async function () {
  288. this.isEmpty = false
  289. this.loading = true
  290. try {
  291. const res = await NET.request(API.ShoppingCart, {}, 'GET')
  292. this.dataList = res.data
  293. this.settleAccountsObj.allNum = this.dataList.length
  294. console.log(this.dataList)
  295. if (this.dataList.length === 0) {
  296. this.isEmpty = true
  297. uni.setStorageSync('allCartNum', 0)
  298. uni.removeTabBarBadge({
  299. index: 2
  300. })
  301. }
  302. // sku为空的山沟
  303. const emptySkuShopArray = []
  304. this.dataList.forEach((shopObj, shopIndex) => {
  305. shopObj['currentIds'] = []
  306. shopObj['priceNumber'] = 0
  307. shopObj['rules'] = []
  308. shopObj['currentRules'] = {}
  309. shopObj['ids'] = 0
  310. // 处理下架商品
  311. for (let i = shopObj.skus.length - 1; i >= 0; i--) {
  312. // shelveState是否上架
  313. if (shopObj.skus[i].shelveState === 0) {
  314. // 删掉下架商品
  315. // todo 失效商品
  316. shopObj.skus.splice(i, 1)
  317. continue
  318. }
  319. if (shopObj.skus[i].activityType === 6 && shopObj.skus[i].selected === 1) {
  320. shopObj.currentIds.push(shopObj.skus[i].priceId)
  321. shopObj.priceNumber += shopObj.skus[i].number
  322. }
  323. }
  324. for (let i = 0; i < shopObj.skus.length; i++) {
  325. if (shopObj.skus[i].activityType === 6) {
  326. shopObj.ids = shopObj.skus[i].priceId
  327. break
  328. }
  329. }
  330. // 根据店铺索引获取规则
  331. this.getData(shopObj).then(res => {
  332. shopObj.rules = res.data ? res.data[0].rules : {}
  333. this.handleSetGroupGood(shopIndex)
  334. })
  335. shopObj.skus.length === 0?emptySkuShopArray.push(shopObj):undefined
  336. })
  337. this.isEmpty = emptySkuShopArray.length >=this.dataList.length
  338. this.handleRenderCart()
  339. // 数据回来就直接关闭骨架屏
  340. this.loading = false
  341. this.isFirstComeIn = false
  342. await this.handleUpdateMoneyAndNum()
  343. } finally {
  344. uni.hideLoading()
  345. }
  346. },500),
  347. /**
  348. * 获取组合定价
  349. * @param item
  350. * @return {Promise<unknown>}
  351. */
  352. getData(item) {
  353. return new Promise(((resolve, reject) => {
  354. if (item.ids) {
  355. NET.request(api.getPrices, {
  356. shopId: item.shopId,
  357. ids: item.ids,
  358. page: 1,
  359. pageSize: 10
  360. }, 'GET').then(res => {
  361. resolve(res)
  362. }).catch(e => {
  363. reject(e)
  364. })
  365. } else {
  366. resolve([])
  367. }
  368. }))
  369. },
  370. /**
  371. * 单个SKU数量减
  372. * @param shopIndex 店铺索引
  373. * @param skuIndex index店铺下sku商品索引
  374. */
  375. async handleSubSkuNumber(shopIndex, skuIndex) {
  376. const selectSku = this.dataList[shopIndex].skus[skuIndex]
  377. if (selectSku.number <= 1) {
  378. return uni.showToast({
  379. title: '亲!至少一件哦!',
  380. icon: "none"
  381. })
  382. }
  383. --selectSku.number
  384. await this.handleUpdateCart(selectSku.skuId, selectSku.number)
  385. setTimeout(async ()=>{
  386. await this.getDataList()
  387. },500)
  388. },
  389. /**
  390. * 单个SKU数量加
  391. * @param shopIndex 店铺索引
  392. * @param skuIndex index店铺下sku商品索引
  393. */
  394. async handleAddSkuNumber(shopIndex, skuIndex) {
  395. const selectSku = this.dataList[shopIndex].skus[skuIndex]
  396. if (selectSku.number >= selectSku.stockNumber) {
  397. selectSku.number = selectSku.stockNumber
  398. return uni.showToast({
  399. title: '库存不足!',
  400. icon: 'none'
  401. })
  402. }
  403. if (selectSku.number < selectSku.stockNumber) {
  404. ++selectSku.number
  405. await this.handleUpdateCart(selectSku.skuId, selectSku.number)
  406. setTimeout(async ()=>{
  407. await this.getDataList()
  408. },500)
  409. }
  410. },
  411. /**
  412. * 更新总价和总数底部结算栏头部总数
  413. * @return {Promise<void>}
  414. */
  415. async handleUpdateMoneyAndNum() {
  416. const {allNumber, checkNumber, isAllCheck} = await getCartNumberBySelect(this.dataList)
  417. const {money} = await getPriceBySelect(this.dataList)
  418. this.settleAccountsObj.checkMoney = money
  419. this.settleAccountsObj.isAllCheck = isAllCheck
  420. this.settleAccountsObj.allNum = allNumber
  421. this.settleAccountsObj.checkNum = checkNumber
  422. },
  423. /**
  424. * 请求服务端更新购物车数量
  425. * @param skuId :需要更新的skuId
  426. * @param number: 数量
  427. */
  428. handleUpdateCart:lodash.debounce(async function(skuId, number) {
  429. // 重新算钱和数量
  430. await NET.request(API.UpdateNumberCart, {
  431. skuId: skuId,
  432. number: number
  433. }, 'POST')
  434. },500),
  435. /**
  436. * 选中店铺
  437. * @param shopIndex 店铺索引
  438. * @param type 0否1是
  439. */
  440. handleSelectShop(shopIndex, type) {
  441. const shopObj = this.dataList[shopIndex]
  442. const shopCarts = [{
  443. shopId: shopObj.shopId,
  444. skus: []
  445. }]
  446. shopObj.selected = type
  447. // 设置当前店铺下的所有sku
  448. shopObj.skus.forEach(skuObj => {
  449. skuObj.selected = type
  450. shopCarts[0].skus.push({
  451. skuId: skuObj.skuId,
  452. selected: skuObj.selected
  453. })
  454. })
  455. this.handleSetGroupGood(shopIndex)
  456. this.handleUpdateSelected(shopCarts)
  457. }
  458. ,
  459. /**
  460. * 商品单选
  461. * @param shopIndex 店铺索引dataList
  462. * @param skuIndex sku索引dataList[index].skus
  463. * @param type 是否选中 0否1是
  464. */
  465. handleSelectSku(shopIndex, skuIndex, type) {
  466. const shopObj = this.dataList[shopIndex]
  467. const skuObj = this.dataList[shopIndex].skus[skuIndex]
  468. skuObj.selected = type
  469. let shopCarts = [{
  470. shopId: shopObj.shopId,
  471. skus: [{
  472. skuId: skuObj.skuId,
  473. selected: skuObj.selected,
  474. }]
  475. }]
  476. if (type === 1) {
  477. // 过滤店铺内未选择的sku
  478. const noSelectSkuList = shopObj.skus.filter(sku => sku.selected === 0);
  479. if (noSelectSkuList.length >= 0) {
  480. shopObj.selected = 0
  481. } else {
  482. shopObj.selected = 1
  483. }
  484. } else {
  485. shopObj.selected = type
  486. }
  487. // 渲染组合商品
  488. this.handleSetGroupGood(shopIndex)
  489. this.handleUpdateSelected(shopCarts)
  490. }
  491. ,
  492. /**
  493. * 全选
  494. * @param type 是否选中 0否1是
  495. */
  496. handleSelectAll(type) {
  497. this.dataList.forEach((shopObj, shopIndex) => {
  498. // 组合支付商品数量
  499. const goodsOfJointNumber = shopObj.skus.reduce((prev, skuObj) => {
  500. skuObj.selected = type
  501. // 如果是组合支付
  502. if (skuObj.selected === 1 && skuObj.activityType === 6) {
  503. return prev + skuObj.number
  504. }
  505. }, 0)
  506. shopObj.selected = type
  507. shopObj.priceNumber = goodsOfJointNumber
  508. shopObj.currentRules = {}
  509. // 处理选中的组合商品
  510. if (type === 1) {
  511. this.handleSetGroupGood(shopIndex)
  512. }
  513. })
  514. this.handleUpdateSelected([])
  515. }
  516. ,
  517. /**
  518. * 处理组合商品(设置currentRules渲染横幅)
  519. * @param shopIndex
  520. */
  521. handleSetGroupGood(shopIndex) {
  522. const shopObj = this.dataList[shopIndex]
  523. shopObj.currentRules = {}
  524. shopObj.priceNumber = 0
  525. shopObj.skus.forEach((skuObj) => {
  526. if (skuObj.activityType === 6 && skuObj.selected === 1) {
  527. shopObj.priceNumber += skuObj.number
  528. }
  529. })
  530. const shopRules = this.dataList[shopIndex].rules
  531. for (let i = 0; i < shopRules.length; i++) {
  532. if (shopRules[i].number === shopObj.priceNumber) {
  533. shopObj.currentRules = shopRules[i]
  534. break
  535. } else if (shopRules[shopRules.length - 1].number < shopObj.priceNumber) {
  536. shopObj.currentRules = shopRules[shopRules.length - 1]
  537. break
  538. }
  539. }
  540. }
  541. ,
  542. /**
  543. * 更新缓存sku勾选和价格数量显示
  544. * @param shopCarts:{shopId:number,skus:{skuId:number,select:number}}[] 只有一个对象店铺全选传空数组
  545. */
  546. handleUpdateSelected(shopCarts) {
  547. this.handleSetCache(shopCarts)
  548. this.handleUpdateMoneyAndNum()
  549. }
  550. ,
  551. /**
  552. * 设置购物车本地缓存先存入本地缓存再调用handleRenderCart根据本地缓存渲染
  553. * @param shopCarts:{shopId:number,skus:{skuId:number,select:number}}[] 只有一个对象店铺全选传空数组
  554. */
  555. handleSetCache(shopCarts) {
  556. let cartInfo = uni.getStorageSync(cacheKey);
  557. if (cartInfo === '') {
  558. // 全选
  559. if (shopCarts.length <= 0) {
  560. // 全选直接缓存整个列表
  561. uni.setStorageSync(cacheKey, JSON.stringify(this.dataList))
  562. // 渲染视图
  563. this.handleRenderCart()
  564. return
  565. }
  566. // 无购物车信息
  567. cartInfo = shopCarts
  568. uni.setStorageSync(cacheKey, JSON.stringify(cartInfo))
  569. } else {
  570. cartInfo = JSON.parse(cartInfo)
  571. // 全选
  572. if (shopCarts.length <= 0) {
  573. // 全选直接缓存整个列表
  574. uni.setStorageSync(cacheKey, JSON.stringify(this.dataList))
  575. // 渲染视图
  576. this.handleRenderCart()
  577. return
  578. }
  579. // 看了代码逻辑结构,一次只会传一个商铺过来,大胆取0
  580. const shopItem = shopCarts[0]
  581. const cacheHaveInfo = cartInfo.findIndex(item => item.shopId === shopItem.shopId)
  582. if (cacheHaveInfo < 0) {
  583. // 如果缓存中不存在当前商店信息,写入缓存
  584. cartInfo.push(shopItem)
  585. } else {
  586. // 获取到缓存项
  587. const cacheShopItem = cartInfo[cacheHaveInfo]
  588. // 判断传入的sku大小,sku length为1就是点单项,sku length>1就是点击了整个店铺
  589. if (shopItem.skus.length > 1) {
  590. // 点击整个店铺,直接赋值
  591. cartInfo[cacheHaveInfo] = shopItem
  592. } else {
  593. // 点击单项sku,获取到sku // 数据结构只会传入一项
  594. const shopItemSkuItem = shopItem.skus[0];
  595. // 在缓存中寻找
  596. const cacheShopItemSkuItemIndex = cacheShopItem.skus.findIndex(item => item.skuId === shopItemSkuItem.skuId);
  597. cacheShopItemSkuItemIndex >= 0 ? cacheShopItem.skus[cacheShopItemSkuItemIndex] = shopItemSkuItem : cacheShopItem.skus.push(shopItemSkuItem)
  598. }
  599. }
  600. // 逻辑处理完毕更新缓存
  601. uni.setStorageSync(cacheKey, JSON.stringify(cartInfo))
  602. // 渲染视图
  603. this.handleRenderCart()
  604. }
  605. }
  606. ,
  607. /**
  608. * 根据本地缓存渲染购物车勾选
  609. * @constructor
  610. */
  611. handleRenderCart() {
  612. // 取消所有勾选
  613. this.dataList.forEach(shop => {
  614. shop.selected = 0
  615. shop.skus.forEach(sku => {
  616. sku.selected = 0
  617. })
  618. })
  619. // 校验缓存中的数据是否存在于购物车中
  620. this.handleCheckCacheAndUpdate()
  621. // 缓存内购物车信息
  622. let cartInfo = uni.getStorageSync(cacheKey);
  623. if (cartInfo === '') return
  624. cartInfo = JSON.parse(cartInfo)
  625. // 遍历购物车信息,寻找缓存比对
  626. this.dataList.forEach(nowCartShopItem => {
  627. let shopSelect = 1
  628. const cacheCartShopItem = cartInfo.find(item => item.shopId === nowCartShopItem.shopId);
  629. if (cacheCartShopItem) {
  630. // 如果缓存中有当前店铺,遍历当前购物车sku
  631. nowCartShopItem.skus.forEach(nowCartSkuItem => {
  632. const cacheCartSkuItem = cacheCartShopItem.skus.find(item => item.skuId === nowCartSkuItem.skuId);
  633. if (cacheCartSkuItem) {
  634. // 如果有一个未选中当前店铺就不能全选
  635. !cacheCartSkuItem.selected ? shopSelect = 0 : ''
  636. nowCartSkuItem.selected = cacheCartSkuItem.selected
  637. } else {
  638. shopSelect = 0
  639. }
  640. })
  641. } else {
  642. shopSelect = 0
  643. }
  644. nowCartShopItem.selected = shopSelect
  645. })
  646. }
  647. ,
  648. /**
  649. * 比较缓存内数据和后端数据是否一致,并且更新缓存
  650. * @constructor
  651. */
  652. handleCheckCacheAndUpdate() {
  653. // 缓存内购物车信息
  654. let cartInfo = uni.getStorageSync(cacheKey);
  655. if (cartInfo === '') return
  656. cartInfo = JSON.parse(cartInfo)
  657. // 校验缓存中的数据是否存在于购物车中
  658. cartInfo.forEach((cacheCartShopItem, cacheCartShopIndex) => {
  659. const nowCartShopItem = this.dataList.find(item => item.shopId === cacheCartShopItem.shopId);
  660. if (!nowCartShopItem) {
  661. cartInfo.splice(cacheCartShopIndex, 1)
  662. } else {
  663. // 存在就校验缓存中的sku在不在后端返回的列表内
  664. cacheCartShopItem.skus.forEach((cacheCartSkuItem, cacheCartSkuIndex) => {
  665. const nowCartSkuItem = nowCartShopItem.skus.find(item => item.skuId === cacheCartSkuItem.skuId)
  666. if (!nowCartSkuItem) {
  667. cacheCartShopItem.skus.splice(cacheCartSkuIndex, 1)
  668. }
  669. })
  670. }
  671. })
  672. uni.setStorageSync(cacheKey, JSON.stringify(cartInfo))
  673. }
  674. ,
  675. /**
  676. * 打开删除弹窗
  677. */
  678. handleOpenDelete() {
  679. if (!this.settleAccountsObj.checkNum) return uni.showToast({
  680. title: '请先选择对应商品',
  681. icon: 'none'
  682. })
  683. this.showDeleteModal = true
  684. console.log(123123,this.settleAccountsObj,this.showDeleteModal)
  685. }
  686. ,
  687. /**
  688. * 执行删除
  689. * @return {Promise<void>}
  690. */
  691. async handleDoDelete() {
  692. let ids = []
  693. for (const shopObj of this.dataList) {
  694. ids = [...ids, ...shopObj.skus.filter(sku => (sku.selected === 1 || sku.selected === true)).map(sku => sku.skuId)]
  695. }
  696. await NET.request(API.DeleteCart, {ids}, 'POST')
  697. this.showDeleteModal = false
  698. await this.getDataList()
  699. }
  700. ,
  701. /**
  702. * 结算购物车
  703. * @return {Promise<void>}
  704. */
  705. async settlementTap() {
  706. const {shopList} = await getPriceBySelect(this.dataList)
  707. uni.setStorageSync('skuItemDTOList', shopList)
  708. this.$jump('/pages_category_page1/orderModule/orderConfirm?type=2')
  709. }
  710. }
  711. }
  712. </script>
  713. <style
  714. lang="scss"
  715. scoped
  716. >
  717. .content {
  718. //overflow: hidden;
  719. //opacity: 0;
  720. .cart-bg {
  721. width: 100%;
  722. height: 180rpx;
  723. background-color: #fff;
  724. .cart-num-box {
  725. display: flex;
  726. flex-direction: row;
  727. align-items: center;
  728. justify-content: space-between;
  729. image {
  730. width: 286rpx;
  731. height: 72rpx;
  732. }
  733. .btn-box {
  734. font-size: 30rpx;
  735. color: #333333;
  736. padding: 30rpx;
  737. box-sizing: border-box;
  738. display: inline-block;
  739. }
  740. }
  741. .num-box {
  742. padding: 30rpx 0 30rpx 30rpx;
  743. box-sizing: border-box;
  744. font-size: 30rpx;
  745. color: #C5CACF;
  746. }
  747. }
  748. .cart-list-box {
  749. box-sizing: border-box;
  750. .itemBox {
  751. .item {
  752. background: #fff;
  753. border-bottom: 16rpx solid #F8F9FA;
  754. .shop-box {
  755. margin-top: 5rpx;
  756. display: flex;
  757. flex-direction: row;
  758. align-items: center;
  759. border-bottom: 1px solid #eee;
  760. position: relative;
  761. .cart-select-img {
  762. width: 40rpx;
  763. height: 40rpx;
  764. margin: 30rpx;
  765. box-sizing: border-box;
  766. }
  767. .shop-name-box {
  768. display: flex;
  769. flex-direction: row;
  770. align-items: center;
  771. .shop-img {
  772. width: 36rpx;
  773. height: 36rpx;
  774. margin-right: 10rpx;
  775. }
  776. .shop-name {
  777. font-size: 30rpx;
  778. color: #333;
  779. font-weight: bold;
  780. display: inline-block;
  781. margin-left: 10rpx;
  782. }
  783. .arrow-right-img {
  784. width: 30rpx;
  785. height: 30rpx;
  786. box-sizing: border-box;
  787. margin-left: 30rpx;
  788. position: absolute;
  789. right: 30rpx;
  790. }
  791. }
  792. }
  793. .rulesBox {
  794. height: 86rpx;
  795. background: #F9F6F1;
  796. padding: 0 20rpx;
  797. image {
  798. width: 126rpx;
  799. height: 46rpx;
  800. }
  801. }
  802. .product-list-box {
  803. margin: 8rpx 0;
  804. .pro-item {
  805. display: flex;
  806. flex-direction: row;
  807. align-items: center;
  808. .cart-select-img {
  809. width: 40rpx;
  810. height: 40rpx;
  811. margin: 30rpx;
  812. box-sizing: border-box;
  813. }
  814. .pro-r {
  815. flex: 1;
  816. border-bottom: 1px solid #eee;
  817. display: flex;
  818. flex-direction: row;
  819. padding: 30rpx 30rpx 30rpx 0;
  820. box-sizing: border-box;
  821. overflow: hidden;
  822. .pro-img {
  823. width: 180rpx;
  824. height: 180rpx;
  825. border-radius: 10rpx;
  826. margin-right: 30rpx;
  827. }
  828. .pro-r-r {
  829. flex: 1;
  830. font-size: 26rpx;
  831. color: #333;
  832. overflow: hidden;
  833. display: flex;
  834. flex-direction: column;
  835. justify-content: space-between;
  836. .pro-name {
  837. height: 66rpx;
  838. line-height: 33rpx;
  839. display: -webkit-box;
  840. overflow: hidden;
  841. text-overflow: ellipsis;
  842. word-break: break-all;
  843. -webkit-box-orient: vertical;
  844. -webkit-line-clamp: 2;
  845. }
  846. .sku-box {
  847. width: auto;
  848. display: inline;
  849. height: 40rpx;
  850. border-radius: 4rpx;
  851. padding: 0 0 0 10rpx;
  852. box-sizing: border-box;
  853. font-size: 24rpx;
  854. color: #999;
  855. text {
  856. border: 2rpx solid #E4E5E6;
  857. padding: 2rpx 10rpx;
  858. }
  859. }
  860. .pro-price-num-box {
  861. display: flex;
  862. flex-direction: row;
  863. align-items: center;
  864. justify-content: space-between;
  865. .pro-price-box {
  866. font-size: 36rpx;
  867. color: #333333;
  868. font-weight: 400;
  869. .fuhao {
  870. font-size: 24rpx;
  871. }
  872. }
  873. .pro-num-box {
  874. width: 140rpx;
  875. height: 40rpx;
  876. border: 1px solid #ddd;
  877. border-radius: 4rpx;
  878. display: flex;
  879. flex-direction: row;
  880. justify-content: space-between;
  881. overflow: hidden;
  882. .num-btn {
  883. font-size: 34rpx;
  884. color: #999999;
  885. display: inline-block;
  886. width: 40rpx;
  887. text-align: center;
  888. line-height: 32rpx;
  889. height: 40rpx;
  890. }
  891. .num-btn.r {
  892. border-right: 1px solid #ddd;
  893. }
  894. .num-btn.l {
  895. border-left: 1px solid #ddd;
  896. }
  897. .num {
  898. font-size: 26rpx;
  899. color: #333;
  900. }
  901. }
  902. }
  903. }
  904. }
  905. }
  906. .pro-item:last-of-type .pro-r {
  907. border-bottom: none;
  908. }
  909. }
  910. }
  911. }
  912. .itemBox:first-child {
  913. .shop-box {
  914. border-top: 2rpx solid #eee;
  915. }
  916. }
  917. .itemBox:last-child {
  918. .item {
  919. border-bottom: none;
  920. }
  921. }
  922. }
  923. .emptyCart-box {
  924. margin: 100rpx 0;
  925. .emptyCart-img {
  926. width: 216rpx;
  927. height: 156rpx;
  928. }
  929. .goToShopping {
  930. width: 282rpx;
  931. height: 84rpx;
  932. line-height: 84rpx;
  933. text-align: center;
  934. background: #333333;
  935. margin-top: 40rpx;
  936. color: #FFEBC4;
  937. font-size: 28rpx;
  938. }
  939. }
  940. .cart-bottom-box-h5 {
  941. position: fixed;
  942. bottom: 80rpx;
  943. width: 100%;
  944. z-index: 99;
  945. }
  946. .cart-bottom-box-app {
  947. position: fixed;
  948. bottom: 0rpx;
  949. width: 100%;
  950. z-index: 99;
  951. }
  952. .cart-bottom {
  953. height: 120rpx;
  954. background: #fff;
  955. display: flex;
  956. flex-direction: row;
  957. align-items: center;
  958. justify-content: space-between;
  959. border-top: 1rpx solid #eee;
  960. }
  961. .left {
  962. display: flex;
  963. flex-direction: row;
  964. align-items: center;
  965. font-size: 28rpx;
  966. color: #666;
  967. .cart-select-img {
  968. width: 40rpx;
  969. height: 40rpx;
  970. margin: 30rpx;
  971. box-sizing: border-box;
  972. }
  973. }
  974. .right {
  975. display: flex;
  976. flex-direction: row;
  977. align-items: center;
  978. box-sizing: border-box;
  979. .price-box {
  980. font-size: 30rpx;
  981. color: #333;
  982. .price {
  983. font-size: 40rpx;
  984. color: #C83732;
  985. font-weight: bold;
  986. }
  987. }
  988. .btn-confirm {
  989. width: 232rpx;
  990. height: 120rpx;
  991. background: #333333;
  992. margin-left: 18rpx;
  993. text-align: center;
  994. line-height: 120rpx;
  995. font-size: 28rpx;
  996. color: #FFEBC4;
  997. }
  998. .btn-delete {
  999. width: 232rpx;
  1000. height: 120rpx;
  1001. line-height: 120rpx;
  1002. text-align: center;
  1003. font-size: 28rpx;
  1004. color: #FFFFFF;
  1005. background: #C83732;
  1006. }
  1007. }
  1008. }
  1009. </style>