coupon.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { defineStore } from 'pinia'
  2. import {
  3. getCouponListApi,
  4. receiveCouponApi,
  5. getCoupon2idApi,
  6. getCoupon2ListApi,
  7. } from '@/service/coupon1'
  8. import { getCoupon2ViewmListApi } from '@/service/coupon2'
  9. import { until } from '@vueuse/core'
  10. export const useCouponStore = defineStore(
  11. 'coupon',
  12. () => {
  13. // 获取优惠券列表
  14. const getCouponList = async (couponproductids: string) => {
  15. const { data: couponList, loading } = useRequest(
  16. () => getCouponListApi({ couponproductids }, { pageindex: 1, rows: 999 }),
  17. {
  18. immediate: true,
  19. },
  20. )
  21. await until(loading).toBe(false)
  22. return couponList.value.Data
  23. }
  24. // 领取优惠券
  25. const receiveCoupon = async ({ couponid, coupon2phone, coupon2productids }) => {
  26. const { data: couponList, loading } = useRequest(
  27. () => receiveCouponApi({ couponid, coupon2phone, coupon2productids }),
  28. {
  29. immediate: true,
  30. },
  31. )
  32. await until(loading).toBe(false)
  33. return couponList.value
  34. }
  35. // 获取该用户下,已领取的优惠劵id,用于判断是否可以领取
  36. const getCoupon2id = async (params) => {
  37. const { data: couponList, loading } = useRequest(() => getCoupon2idApi(params), {
  38. immediate: true,
  39. })
  40. await until(loading).toBe(false)
  41. return couponList.value
  42. }
  43. // 通过优惠券id获取产品信息(视图)
  44. const getCoupon2ViewmList = async (params: { coupon2code: string }) => {
  45. const { data: couponList, loading } = useRequest(
  46. () => getCoupon2ViewmListApi(params, { pageindex: 1, rows: 999 }),
  47. {
  48. immediate: true,
  49. },
  50. )
  51. await until(loading).toBe(false)
  52. return couponList.value
  53. }
  54. // 获取已关联到当前用户的优惠券列表
  55. const getCoupon2List = async (params: { coupon2userid: string }) => {
  56. const { data: couponList, loading } = useRequest(
  57. () => getCoupon2ListApi(params, { pageindex: 1, rows: 999 }),
  58. {
  59. immediate: true,
  60. },
  61. )
  62. await until(loading).toBe(false)
  63. return couponList.value
  64. }
  65. return {
  66. getCouponList,
  67. receiveCoupon,
  68. getCoupon2id,
  69. getCoupon2ViewmList,
  70. getCoupon2List,
  71. }
  72. },
  73. {
  74. persist: true,
  75. },
  76. )