StoreShopCart.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view>
  3. <view>
  4. <tui-drawer
  5. mode="bottom" :visible="visibleDrawer" :mask-z-index="996" :z-index="998"
  6. @close="visibleDrawer = false"
  7. >
  8. <ATFShopCartList
  9. ref="refATFShopCartList" type="single" :shop-id="brandId" is-sub-delete
  10. max-height="50vh"
  11. @update-msg="handleUpdateMoneyAndNum"
  12. ></ATFShopCartList>
  13. </tui-drawer>
  14. </view>
  15. <view
  16. style="position: fixed;bottom: 0;z-index: 2;width: 100%;padding: 20upx;background-color: #ffffff;box-sizing: border-box;"
  17. >
  18. <view
  19. style="display: flex;justify-content: flex-end;align-items: flex-end;font-size: 28upx;"
  20. @click="visibleDrawer = !visibleDrawer"
  21. >
  22. <view
  23. style="position: absolute;left: 46upx;bottom: 26upx;padding: 28upx;background-color: #ff973f;border-radius: 50%;"
  24. >
  25. <tui-icon name="cart" :size="56" unit="upx" color="#fbfbfb"></tui-icon>
  26. </view>
  27. <text style="color: #949494;padding-right: 12upx;">共{{ cartMsgObj.allNum }}件</text>
  28. <text>合计:</text>
  29. <text style="padding-right: 20upx;font-weight: bold;font-size: 42upx;color: #ff1111;">
  30. ¥{{ cartMsgObj.checkMoney }}
  31. </text>
  32. <view>
  33. <tui-button
  34. type="danger" width="180rpx" height="58rpx" style="border-radius: 50rpx;"
  35. :size="28" @click="handleSettlementTap()"
  36. >
  37. 立即结算
  38. </tui-button>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. getSettlementOrderApi
  47. } from '../../../../api/anotherTFInterface'
  48. import { T_SKU_ITEM_DTO_LIST } from '../../../../constant'
  49. export default {
  50. name: 'StoreShopCart',
  51. components: {},
  52. props: {
  53. brandId: {
  54. type: Number,
  55. required: true
  56. }
  57. },
  58. data() {
  59. return {
  60. visibleDrawer: false,
  61. cartMsgObj: {
  62. allNum: 0,
  63. checkNum: 0,
  64. checkMoney: 0,
  65. isAllCheck: false
  66. }
  67. }
  68. },
  69. mounted() {
  70. },
  71. methods: {
  72. async handleUpdateMoneyAndNum(cartData) {
  73. uni.showLoading()
  74. let allNumber = 0
  75. let checkNumber = 0
  76. let isAllCheck = true
  77. const addCartSelectedList = []
  78. for (let i = 0; i < cartData.length; i++) {
  79. const shopCurrentObj = cartData[i]
  80. const shopObj = { shopId: cartData[i].shopId, skus: [] }
  81. for (let j = 0; j < shopCurrentObj.skus.length; j++) {
  82. const good = cartData[i].skus[j]
  83. allNumber += good.number
  84. if (good.selected === 1) {
  85. shopObj.skus.push({ ifLogistics: good.ifLogistics, number: good.number, selected: good.selected, skuId: good.skuId })
  86. checkNumber += good.number
  87. } else if (isAllCheck) {
  88. isAllCheck = false
  89. }
  90. }
  91. if (shopObj.skus.length > 0) addCartSelectedList.push(shopObj)
  92. }
  93. try {
  94. const res = await getSettlementOrderApi({
  95. type: 2,
  96. shopId: this.brandId, // '购物车结算'的'商家购物车结算'对应的商家
  97. shops: addCartSelectedList,
  98. voucherTotalAll: 0,
  99. isVoucher: false,
  100. voucherId: 0
  101. })
  102. const money = res.data.shops.reduce((previousValue, currentValue) => previousValue + currentValue.total, 0) // 根据选中的购物车数据获取价格
  103. this.cartMsgObj.checkMoney = money.toFixed(2)
  104. this.cartMsgObj.isAllCheck = isAllCheck
  105. this.cartMsgObj.allNum = allNumber
  106. this.cartMsgObj.checkNum = checkNumber
  107. } finally {
  108. uni.hideLoading()
  109. }
  110. },
  111. // 去结算
  112. handleSettlementTap() {
  113. if (this.$refs.refATFShopCartList) {
  114. const shopCartList = this.$refs.refATFShopCartList.getShopCartListData()
  115. if (this.cartMsgObj.checkNum) {
  116. const addCartSelectedList = []
  117. for (let i = 0; i < shopCartList.length; i++) {
  118. const shopObj = { shopId: shopCartList[i].shopId, skus: [] }
  119. for (let j = 0; j < shopCartList[i].skus.length; j++) {
  120. const theCurrentSku = shopCartList[i].skus[j]
  121. if (theCurrentSku.selected) shopObj.skus.push({ ifLogistics: theCurrentSku.ifLogistics, number: theCurrentSku.number, selected: theCurrentSku.selected, skuId: theCurrentSku.skuId })
  122. }
  123. if (shopObj.skus.length > 0) addCartSelectedList.push(shopObj)
  124. }
  125. uni.setStorageSync(T_SKU_ITEM_DTO_LIST, addCartSelectedList)
  126. this.go(`/another-tf/another-serve/orderConfirm/index?type=2&brandId=${this.brandId}`)
  127. } else {
  128. this.$showToast('请先勾选商品')
  129. }
  130. } else {
  131. this.$showToast('获取购物车数据失败')
  132. }
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="less" scoped></style>