index.vue 7.1 KB

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