giveawaysVip.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <script setup lang="ts">
  2. import router from '@/router'
  3. definePage({
  4. name: 'smqjh-giveaways-vip',
  5. islogin: true,
  6. style: {
  7. navigationBarTitleText: '选择赠品',
  8. },
  9. })
  10. onMounted(() => {
  11. getGiftsList()
  12. })
  13. const { selectedAddress } = storeToRefs(useUserStore())
  14. const giveawaysList = ref<Api.giftsListModel[]>([])
  15. const isPicking = ref(false)
  16. async function getGiftsList() {
  17. const res = await Apis.sys.giftsList({})
  18. giveawaysList.value = res.data || []
  19. }
  20. function handleChange(value: any) {
  21. console.log(value)
  22. }
  23. async function pickUp() {
  24. const addressId = selectedAddress.value?.id
  25. if (!addressId) {
  26. useGlobalToast().show({ msg: '请选择收货地址' })
  27. return
  28. }
  29. if (!giveawaysList.value.length) {
  30. useGlobalToast().show({ msg: '暂无可领取赠品' })
  31. return
  32. }
  33. const firstGift = giveawaysList.value[0]
  34. const hasInvalidGift = giveawaysList.value.some(item => !item.skuId || !item.shopId || !item.channelId)
  35. if (hasInvalidGift) {
  36. useGlobalToast().show({ msg: '赠品数据异常' })
  37. return
  38. }
  39. const hasDifferentShopOrChannel = giveawaysList.value.some((item) => {
  40. return item.shopId !== firstGift.shopId || item.channelId !== firstGift.channelId
  41. })
  42. if (hasDifferentShopOrChannel) {
  43. useGlobalToast().show({ msg: '赠品需来自同一门店和渠道' })
  44. return
  45. }
  46. if (isPicking.value) {
  47. return
  48. }
  49. isPicking.value = true
  50. try {
  51. const items = giveawaysList.value.map((item) => {
  52. return {
  53. skuId: item.skuId!,
  54. quantity: Number(item.quantity || 1),
  55. shopId: item.shopId!,
  56. channelId: item.channelId!,
  57. }
  58. })
  59. const totalGoodsPrice = giveawaysList.value.reduce((sum, item) => {
  60. return sum + Number(item.price || 0) * Number(item.quantity || 1)
  61. }, 0)
  62. const orderInfo = {
  63. totalPrice: 0,
  64. transfee: 0,
  65. offsetPoints: 0,
  66. shopName: firstGift.shopName || '',
  67. price: totalGoodsPrice,
  68. amount: 0,
  69. coupon: 0,
  70. couponName: '',
  71. orderCouponItemDTOS: [],
  72. memberGiftAddressId: addressId,
  73. memberGiftItems: items,
  74. skuList: giveawaysList.value.map((item) => {
  75. return {
  76. prodId: item.spuId || 0,
  77. num: Number(item.quantity || 1),
  78. pic: item.picUrl,
  79. price: item.price ?? '0',
  80. shopId: item.shopId!,
  81. shopSkuStocks: String(item.stock ?? ''),
  82. skuId: item.skuId!,
  83. skuName: item.spuName || item.skuName,
  84. spec: item.skuName,
  85. }
  86. }),
  87. }
  88. router.push({
  89. name: 'xsb-confirmOrder',
  90. params: { data: JSON.stringify(orderInfo) },
  91. })
  92. }
  93. finally {
  94. isPicking.value = false
  95. }
  96. }
  97. </script>
  98. <template>
  99. <view class="px24rpx">
  100. <view class="h-20rpx" />
  101. <view v-for="item in giveawaysList" :key="item.channelId" class="mb-20rpx flex items-center gap-20rpx rounded-16rpx bg-#FFF p-24rpx">
  102. <view class="w-32rpx">
  103. <wd-icon name="check-circle-filled" size="20px" color="#9ED605" />
  104. </view>
  105. <view class="flex items-center gap-20rpx">
  106. <image
  107. :src="item.picUrl"
  108. class="h-200rpx w-200rpx rounded-16rpx"
  109. />
  110. <view>
  111. <view class="text-32rpx font-bold line-height-40rpx">
  112. <text class="mr-8rpx rounded-8rpx bg-#FF4D3A px-12rpx py-4rpx text-22rpx text-#FFF">
  113. 赠品
  114. </text>
  115. {{ item.spuName }}
  116. </view>
  117. <view class="mt-14rpx text-24rpx text-#AAA">
  118. 规格:{{ item.skuName }}
  119. </view>
  120. <view class="mt-14rpx flex items-center justify-between">
  121. <view class="text-36rpx text-#FF4D3A font-800">
  122. ¥{{ item.price }}
  123. </view>
  124. <wd-input-number :model-value="Number(item.quantity) || 1" disabled @change="handleChange" />
  125. </view>
  126. </view>
  127. </view>
  128. </view>
  129. <StatusTip v-if="giveawaysList?.length === 0" tip="暂无内容" />
  130. <view class="h-180rpx" />
  131. </view>
  132. <view class="fixed bottom-0 left-0 right-0 z-9999 h-140rpx w-702rpx rounded-16rpx bg-#FFF p-24rpx shadow-[0rpx_-6rpx_12rpx_2rpx_rgba(0,0,0,0.05)]">
  133. <wd-button custom-class="h-80rpx w-full" :loading="isPicking" @click="pickUp">
  134. 免费领取
  135. </wd-button>
  136. </view>
  137. </template>
  138. <style lang="scss" scoped></style>