coupon.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import { defineStore } from 'pinia'
  2. import {
  3. getCouponListApi,
  4. receiveCouponApi,
  5. receiveCouponApiNew,
  6. getCoupon2idApi,
  7. getCoupon2ListApi,
  8. } from '@/service/coupon1'
  9. import {
  10. getCoupon2ViewmListApi,
  11. getCoupon2DetailApi,
  12. getCoupon2ModifyApi,
  13. getCoupon2AuditListApi,
  14. getCoupon2AuditDetailApi,
  15. submitCoupon2AuditApi,
  16. } from '@/service/coupon2'
  17. import { until } from '@vueuse/core'
  18. export const useCouponStore = defineStore(
  19. 'coupon',
  20. () => {
  21. // 获取优惠券列表
  22. const getCouponList = async (couponproductids: string) => {
  23. const { data: couponList, loading } = useRequest(
  24. () => getCouponListApi({ couponproductids }, { pageindex: 1, rows: 99999 }),
  25. {
  26. immediate: true,
  27. },
  28. )
  29. await until(loading).toBe(false)
  30. return couponList.value.Data
  31. }
  32. // 领取优惠券 旧 已弃用
  33. const receiveCoupon = async ({ couponid, coupon2phone, coupon2productids }) => {
  34. const { data: couponList, loading } = useRequest(
  35. () => receiveCouponApi({ couponid, coupon2phone, coupon2productids }),
  36. {
  37. immediate: true,
  38. },
  39. )
  40. await until(loading).toBe(false)
  41. return couponList.value
  42. }
  43. // 领取优惠券 new
  44. const receiveCouponNew = ({
  45. couponid,
  46. userstype,
  47. usersidcardnumber,
  48. usersshtyxydm,
  49. usersname,
  50. usersaddress,
  51. coupon2productids,
  52. coupon2phone,
  53. filesid,
  54. coupon2merchantid,
  55. }) => {
  56. // eslint-disable-next-line no-async-promise-executor
  57. return new Promise(async (resolve, reject) => {
  58. const {
  59. data: couponList,
  60. loading,
  61. error,
  62. } = useRequest(
  63. () =>
  64. receiveCouponApiNew({
  65. couponid,
  66. userstype,
  67. usersidcardnumber,
  68. usersshtyxydm,
  69. usersname,
  70. usersaddress,
  71. coupon2productids,
  72. coupon2phone,
  73. filesid,
  74. coupon2merchantid,
  75. }),
  76. {
  77. immediate: true,
  78. },
  79. )
  80. await until(loading).toBe(false)
  81. if (error.value) {
  82. reject(new Error('领取优惠券失败'))
  83. }
  84. resolve(couponList.value)
  85. })
  86. }
  87. // 获取该用户下,已领取的优惠劵id,用于判断是否可以领取
  88. const getCoupon2id = async (params) => {
  89. const { data: couponList, loading } = useRequest(() => getCoupon2idApi(params), {
  90. immediate: true,
  91. })
  92. await until(loading).toBe(false)
  93. return couponList.value
  94. }
  95. // 通过优惠券code获取产品信息(视图)
  96. const getCoupon2ViewmList = async (params: { coupon2code: string }) => {
  97. const { data: couponList, loading } = useRequest(
  98. () => getCoupon2ViewmListApi(params, { pageindex: 1, rows: 99999 }),
  99. {
  100. immediate: true,
  101. },
  102. )
  103. await until(loading).toBe(false)
  104. return couponList.value
  105. }
  106. // 获取已关联到当前用户的优惠券列表
  107. const getCoupon2List = async (params) => {
  108. const { data: couponList, loading } = useRequest(
  109. () => getCoupon2ListApi(params, { pageindex: 1, rows: 99999 }),
  110. {
  111. immediate: true,
  112. },
  113. )
  114. await until(loading).toBe(false)
  115. return couponList.value
  116. }
  117. // 通过优惠券id获取产品信息(视图)
  118. const getCoupon2ViewDetailBySid = async (params: { coupon2sid: string }) => {
  119. const { data: couponList, loading } = useRequest(() => getCoupon2DetailApi(params), {
  120. immediate: true,
  121. })
  122. await until(loading).toBe(false)
  123. return couponList.value
  124. }
  125. // 优惠劵审核修改
  126. // coupon2sid: 优惠券id 必传
  127. const getCoupon2Modify = async (params) => {
  128. // eslint-disable-next-line no-async-promise-executor
  129. return new Promise(async (resolve, reject) => {
  130. const {
  131. data: couponList,
  132. loading,
  133. error,
  134. } = useRequest(() => getCoupon2ModifyApi(params), {
  135. immediate: true,
  136. })
  137. await until(loading).toBe(false)
  138. if (error.value) {
  139. reject(new Error('优惠劵审核修改失败'))
  140. }
  141. resolve(couponList.value)
  142. })
  143. }
  144. // 优惠劵审核_列表
  145. const getCoupon2AuditList = async (params, page = { pageindex: 1, rows: 10 }) => {
  146. const { data: couponList, loading } = useRequest(() => getCoupon2AuditListApi(params, page), {
  147. immediate: true,
  148. })
  149. await until(loading).toBe(false)
  150. return couponList.value
  151. }
  152. // 优惠劵审核_详情
  153. const getCoupon2AuditDetail = async (params) => {
  154. const { data: couponList, loading } = useRequest(() => getCoupon2AuditDetailApi(params), {
  155. immediate: true,
  156. })
  157. await until(loading).toBe(false)
  158. return couponList.value
  159. }
  160. // 优惠劵审核_提交
  161. const submitCoupon2Audit = async (params) => {
  162. // eslint-disable-next-line no-async-promise-executor
  163. return new Promise(async (resolve, reject) => {
  164. const {
  165. data: couponList,
  166. loading,
  167. error,
  168. } = useRequest(() => submitCoupon2AuditApi(params), {
  169. immediate: true,
  170. })
  171. await until(loading).toBe(false)
  172. if (error.value) {
  173. reject(new Error('优惠劵审核提交失败'))
  174. }
  175. resolve(couponList.value)
  176. })
  177. }
  178. return {
  179. getCouponList,
  180. receiveCoupon,
  181. receiveCouponNew,
  182. getCoupon2id,
  183. getCoupon2ViewmList,
  184. getCoupon2List,
  185. getCoupon2ViewDetailBySid,
  186. getCoupon2Modify,
  187. getCoupon2AuditList,
  188. getCoupon2AuditDetail,
  189. submitCoupon2Audit,
  190. }
  191. },
  192. {
  193. persist: true,
  194. },
  195. )