order.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { defineStore } from 'pinia'
  2. import {
  3. getOrderDetailApi,
  4. getOrderListApi,
  5. submitOrderApi,
  6. submitOrderTelApi,
  7. getOrderViewListApi2,
  8. getOrderViewDetailApi2,
  9. } from '@/service/order'
  10. import { until } from '@vueuse/core'
  11. import type { ListType } from '@/types/list'
  12. export const useOrderStore = defineStore(
  13. 'order',
  14. () => {
  15. // 获取订单列表
  16. const getOrderList = async (ordersuserid: string) => {
  17. const { data: orderList, loading } = useRequest(
  18. () => getOrderListApi({ ordersuserid }, { pageindex: 1, rows: 99999 }),
  19. {
  20. immediate: true,
  21. },
  22. )
  23. await until(loading).toBe(false)
  24. return orderList.value.Data
  25. }
  26. // 获取订单详情
  27. const getOrderDetail = async (ordersid: string) => {
  28. const { data: orderDetail, loading } = useRequest(() => getOrderDetailApi(ordersid), {
  29. immediate: true,
  30. })
  31. await until(loading).toBe(false)
  32. return orderDetail.value
  33. }
  34. // 使用优惠劵提交订单
  35. const submitOrder = async (params: {
  36. ordersproductid: string
  37. orderscouponid: string
  38. ordersproductsn: string
  39. ordersuserid1: string
  40. ordersphone?: string
  41. filesid: string
  42. }) => {
  43. const { data: order, loading } = useRequest(() => submitOrderApi(params), {
  44. immediate: true,
  45. })
  46. await until(loading).toBe(false)
  47. return order.value
  48. }
  49. // 使用优惠劵提交订单tel
  50. const submitOrderTel = async (params: {
  51. ordersproductid: string
  52. orderscouponid: string
  53. ordersproductsn: string
  54. ordersuserid1: string
  55. ordersphone?: string
  56. filesid: string
  57. }) => {
  58. const { data: order, loading } = useRequest(() => submitOrderTelApi(params), {
  59. immediate: true,
  60. })
  61. await until(loading).toBe(false)
  62. return order.value
  63. }
  64. // 订单_产品_用户_我的优惠劵_列表(视图)
  65. const getOrderViewList = async (params, page: Partial<ListType>) => {
  66. const { data: orderViewList, loading } = useRequest(
  67. () => getOrderViewListApi2(params, page),
  68. {
  69. immediate: true,
  70. },
  71. )
  72. await until(loading).toBe(false)
  73. return orderViewList.value.Data
  74. }
  75. // 订单_产品_用户_我的优惠劵_详情(视图)
  76. const getOrderViewDetail = async (params) => {
  77. const { data: orderViewDetail, loading } = useRequest(() => getOrderViewDetailApi2(params), {
  78. immediate: true,
  79. })
  80. await until(loading).toBe(false)
  81. return orderViewDetail.value
  82. }
  83. return {
  84. getOrderList,
  85. getOrderDetail,
  86. submitOrder,
  87. submitOrderTel,
  88. getOrderViewList,
  89. getOrderViewDetail,
  90. }
  91. },
  92. {
  93. persist: true,
  94. },
  95. )