index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <route lang="json5">
  2. {
  3. style: {
  4. navigationBarTitleText: '确认订单',
  5. navigationBarBackgroundColor: '#fff',
  6. },
  7. }
  8. </route>
  9. <script setup lang="ts">
  10. import TiltedButton from '@/components/tilted-button.vue'
  11. import Product from '../components/product.vue'
  12. import { shoppingBag } from '@designer-hub/assets/src/assets/svgs/index'
  13. import InvertedTrapezoidButton from '@/components/inverted-trapezoid-button.vue'
  14. import TrapeziumButton from '@/components/trapezium-button.vue'
  15. import Card from '@/components/card.vue'
  16. import SectionHeading from '@/components/section-heading.vue'
  17. import BottomAppBar from '@/components/bottom-app-bar.vue'
  18. import { requestToast } from '../../../../core/utils/common'
  19. import { getProductCoupons, orderPay } from '../../../../core/libs/requests'
  20. import { useUserStore } from '../../../../store'
  21. import { storeToRefs } from 'pinia'
  22. import { useRouter } from '../../../../core/utils/router'
  23. import dayjs from 'dayjs'
  24. import { Coupon } from '../../../../core/libs/models'
  25. import CouponCard from '@/pages/common/components/coupon-card.vue'
  26. import { select, sort } from 'radash'
  27. import CouponsSelector from '@/pages/common/components/coupons-selector.vue'
  28. import { right } from '../../../../core/libs/svgs'
  29. import ButtonEvo from '@/components/button-evo.vue'
  30. import { handleClickInstruction } from '../../../../core/libs/actions'
  31. import { useMessage } from 'wot-design-uni'
  32. const router = useRouter()
  33. const userStore = useUserStore()
  34. const { userInfo } = storeToRefs(userStore)
  35. const show = ref(false)
  36. const { alert } = useMessage()
  37. const data = ref()
  38. const selectedCoupons = ref<Coupon[]>()
  39. const { data: coupons, run: setCoupons } = useRequest(() =>
  40. getProductCoupons({
  41. userId: userInfo.value.userId,
  42. productIds: data.value.list.map((it) => it.productId).join(','),
  43. isUse: 0,
  44. }),
  45. )
  46. const offerPoints = computed(() => {
  47. const products = sort(data.value?.list, (it: any) => it.points).reverse()
  48. let sumBrandPoints = 0
  49. products.forEach((product: any) => {
  50. if (selectedCoupons.value) {
  51. selectedCoupons.value.forEach((coupon) => {
  52. if (
  53. coupon.buinessId === product.vendorId &&
  54. coupon.productIds.split(',').includes(product.productId)
  55. ) {
  56. sumBrandPoints += product.points
  57. }
  58. })
  59. }
  60. })
  61. console.log(sumBrandPoints)
  62. return Number(sumBrandPoints)
  63. })
  64. const paidPoints = computed(() => {
  65. return (data.value?.totalsPoints - offerPoints.value || 0).toString()
  66. })
  67. const handlePay = async () => {
  68. console.log(111)
  69. const couponList =
  70. selectedCoupons.value?.map((it) => ({
  71. couponId: it.id,
  72. projectIds: it.productIds,
  73. buinessId: it.buinessId,
  74. })) || []
  75. const { code } = await requestToast(
  76. () =>
  77. orderPay({
  78. ...data?.value,
  79. couponList,
  80. }),
  81. { success: true, successTitle: '兑换成功' },
  82. )
  83. if (code === 0) {
  84. router.replace('/pages/home/mall/purchased/success/index')
  85. }
  86. }
  87. const handleQ = async () => {
  88. // await setCoupons()
  89. show.value = true
  90. }
  91. const handleSelect = (coupon: Coupon) => {
  92. selectedCoupons.value = [coupon]
  93. show.value = false
  94. }
  95. onLoad(async (query: { data: string }) => {
  96. data.value = JSON.parse(query.data)
  97. })
  98. </script>
  99. <template>
  100. <view class="flex-grow flex flex-col px-3.5 py-5.5 gap-6">
  101. <Card>
  102. <div class="flex flex-col gap-6">
  103. <template v-for="(it, i) in data?.list" :key="i">
  104. <div class="flex gap-3">
  105. <div class="w-16 h-16 bg-[#f6f6f6] rounded-lg overflow-hidden">
  106. <wd-img width="100%" height="100%" :src="it.orderImgUrl"></wd-img>
  107. </div>
  108. <div class="flex flex-col justify-between flex-1">
  109. <div class="text-black/40 text-base font-normal font-['PingFang_SC'] leading-normal">
  110. {{ it.productName }}
  111. </div>
  112. <div class="text-black/40 text-xs font-normal font-['PingFang_SC'] leading-normal">
  113. {{ it.points }}积分
  114. </div>
  115. </div>
  116. <div>
  117. <div class="text-black/90 text-sm font-normal font-['PingFang_SC'] leading-[10.18px]">
  118. ×{{ it.nums }}
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. </div>
  124. </Card>
  125. <Card>
  126. <div class="flex flex-col gap-8">
  127. <SectionHeading
  128. title="总积分"
  129. :end-text="data?.totalsPoints.toString()"
  130. size="sm"
  131. ></SectionHeading>
  132. <div @click="handleQ">
  133. <SectionHeading
  134. title="优惠券"
  135. :end-text="`已选${selectedCoupons?.length || 0}张`"
  136. end-arrow
  137. size="sm"
  138. >
  139. <template #start>
  140. <div
  141. v-if="selectedCoupons?.length"
  142. class="px-1 py-.75 rounded border border-solid border-[#ef4343] justify-center items-center gap-2.5 inline-flex"
  143. >
  144. <div
  145. class="text-[#ef4343] text-[9px] font-normal font-['PingFang_SC'] leading-[10.18px]"
  146. >
  147. 已选{{ selectedCoupons?.length }}张
  148. </div>
  149. </div>
  150. </template>
  151. <template #append>
  152. <div class="flex items-center gap-1">
  153. <template v-if="!selectedCoupons?.length">
  154. <div
  155. class="text-black/40 text-sm font-normal font-['PingFang_SC'] leading-[10.18px]"
  156. >
  157. 选择优惠券
  158. </div>
  159. </template>
  160. <template v-else>
  161. <div
  162. class="text-[#ef4343] text-sm font-normal font-['PingFang_SC'] leading-[10.18px]"
  163. >
  164. -{{ offerPoints }}
  165. </div>
  166. </template>
  167. <wd-img :src="right" width="12" height="12"></wd-img>
  168. </div>
  169. </template>
  170. </SectionHeading>
  171. </div>
  172. <SectionHeading title="实付积分" :end-text="paidPoints" size="sm"></SectionHeading>
  173. </div>
  174. </Card>
  175. <BottomAppBar fixed placeholder>
  176. <div class="h-[63px] bg-white backdrop-blur-[20px] flex items-center justify-between">
  177. <div class="flex items-end gap-1.25">
  178. <div class="text-[#ef4343] text-2xl font-normal font-['D-DIN_Exp'] leading-7">
  179. {{ paidPoints }}
  180. </div>
  181. <div class="text-black/40 text-base font-normal font-['PingFang_SC']">积分</div>
  182. </div>
  183. <div class="">
  184. <ButtonEvo @click="handlePay">确认兑换</ButtonEvo>
  185. </div>
  186. </div>
  187. </BottomAppBar>
  188. <CouponsSelector
  189. v-model="selectedCoupons"
  190. type="product"
  191. :show="show"
  192. :products="data?.list"
  193. @close="show = false"
  194. @click-instruction="(e) => handleClickInstruction(alert, e)"
  195. ></CouponsSelector>
  196. <!-- <CouponsSelector></CouponsSelector> -->
  197. <!-- <wd-action-sheet title="优惠券" v-model="show">
  198. <view class="">
  199. <wd-tabs>
  200. <wd-tab title="可用优惠券"></wd-tab>
  201. <wd-tab title="不可用优惠券"></wd-tab>
  202. </wd-tabs>
  203. <div class="bg-[#f6f6f6] py-3.5 flex flex-col gap-4">
  204. <template v-for="(it, i) in coupons" :key="i">
  205. <CouponCard
  206. :options="{ couponType: 2, ...it }"
  207. canSelect
  208. :selected="selectedCoupons?.map(({ id }) => id).includes(it.id)"
  209. @select="handleSelect"
  210. ></CouponCard>
  211. </template>
  212. </div>
  213. </view>
  214. </wd-action-sheet> -->
  215. </view>
  216. </template>
  217. <style scoped lang="scss"></style>