index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <route lang="json5">
  2. {
  3. style: {
  4. navigationBarTitleText: '确认订单',
  5. navigationBarBackgroundColor: '#fff',
  6. },
  7. }
  8. </route>
  9. <script setup lang="ts">
  10. import Card from '@/components/card.vue'
  11. import SectionHeading from '@/components/section-heading.vue'
  12. import BottomAppBar from '@/components/bottom-app-bar.vue'
  13. import { requestToast } from '../../../../core/utils/common'
  14. import { getOrderAmount, getProductCoupons, orderPay } from '../../../../core/libs/requests'
  15. import { useUserStore } from '../../../../store'
  16. import { storeToRefs } from 'pinia'
  17. import { useRouter } from '../../../../core/utils/router'
  18. import { Coupon } from '../../../../core/libs/models'
  19. import { sort } from 'radash'
  20. import CouponsSelector from '@/pages/common/components/coupons-selector.vue'
  21. import { right } from '../../../../core/libs/svgs'
  22. import ButtonEvo from '@/components/button-evo.vue'
  23. import { handleClickInstruction } from '../../../../core/libs/actions'
  24. import { useMessage } from 'wot-design-uni'
  25. const router = useRouter()
  26. const userStore = useUserStore()
  27. const { userInfo } = storeToRefs(userStore)
  28. const show = ref(false)
  29. const { alert } = useMessage()
  30. const data = ref()
  31. const selectedCoupons = ref<Coupon[]>()
  32. const requestData = computed(() => ({
  33. ...data.value,
  34. couponList:
  35. selectedCoupons.value?.map((it) => ({
  36. couponId: it.id,
  37. projectIds: it.productIds,
  38. buinessId: it.buinessId,
  39. })) || [],
  40. }))
  41. const { data: confirmOrder, run: setConfirmOrder } = useRequest(() =>
  42. getOrderAmount(requestData.value),
  43. )
  44. const offerPoints = computed(() => {
  45. const products = sort(data.value?.list, (it: any) => it.points).reverse()
  46. let sumBrandPoints = 0
  47. products.forEach((product: any) => {
  48. if (selectedCoupons.value) {
  49. selectedCoupons.value.forEach((coupon) => {
  50. if (
  51. coupon.buinessId === product.vendorId &&
  52. coupon.productIds.split(',').includes(product.productId)
  53. ) {
  54. sumBrandPoints += product.points
  55. }
  56. })
  57. }
  58. })
  59. console.log(sumBrandPoints)
  60. return Number(sumBrandPoints)
  61. })
  62. const handlePay = async () => {
  63. console.log(111)
  64. const couponList =
  65. selectedCoupons.value?.map((it) => ({
  66. couponId: it.id,
  67. projectIds: it.productIds,
  68. buinessId: it.buinessId,
  69. })) || []
  70. const { code } = await requestToast(
  71. () =>
  72. orderPay({
  73. ...data?.value,
  74. couponList,
  75. }),
  76. { success: true, successTitle: '兑换成功' },
  77. )
  78. if (code === 0) {
  79. await router.replace('/pages/home/mall/purchased/success/index')
  80. }
  81. }
  82. const handleQ = async () => {
  83. // await setCoupons()
  84. show.value = true
  85. }
  86. const handleSelect = (coupon: Coupon) => {
  87. selectedCoupons.value = [coupon]
  88. show.value = false
  89. }
  90. const handleClose = () => {
  91. show.value = false
  92. setConfirmOrder()
  93. }
  94. onLoad(async (query: { data: string }) => {
  95. data.value = JSON.parse(query.data)
  96. await setConfirmOrder()
  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="confirmOrder?.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
  173. title="实付积分"
  174. :end-text="confirmOrder?.totalsCurrPoints"
  175. size="sm"
  176. ></SectionHeading>
  177. </div>
  178. </Card>
  179. <BottomAppBar fixed placeholder>
  180. <div class="h-[63px] bg-white backdrop-blur-[20px] flex items-center justify-between">
  181. <div class="flex items-end gap-1.25">
  182. <div class="text-[#ef4343] text-2xl font-normal font-['D-DIN_Exp'] leading-7">
  183. {{ confirmOrder?.totalsCurrPoints }}
  184. </div>
  185. <div class="text-black/40 text-base font-normal font-['PingFang_SC']">积分</div>
  186. </div>
  187. <div class="">
  188. <ButtonEvo @click="handlePay">确认兑换</ButtonEvo>
  189. </div>
  190. </div>
  191. </BottomAppBar>
  192. <CouponsSelector
  193. v-model="selectedCoupons"
  194. type="product"
  195. :show="show"
  196. :products="data?.list"
  197. @close="handleClose"
  198. @click-instruction="(e) => handleClickInstruction(alert, e)"
  199. ></CouponsSelector>
  200. <!-- <CouponsSelector></CouponsSelector> -->
  201. <!-- <wd-action-sheet title="优惠券" v-model="show">
  202. <view class="">
  203. <wd-tabs>
  204. <wd-tab title="可用优惠券"></wd-tab>
  205. <wd-tab title="不可用优惠券"></wd-tab>
  206. </wd-tabs>
  207. <div class="bg-[#f6f6f6] py-3.5 flex flex-col gap-4">
  208. <template v-for="(it, i) in coupons" :key="i">
  209. <CouponCard
  210. :options="{ couponType: 2, ...it }"
  211. canSelect
  212. :selected="selectedCoupons?.map(({ id }) => id).includes(it.id)"
  213. @select="handleSelect"
  214. ></CouponCard>
  215. </template>
  216. </div>
  217. </view>
  218. </wd-action-sheet> -->
  219. </view>
  220. </template>
  221. <style scoped lang="scss"></style>