index.vue 7.8 KB

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