| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- import { defineStore } from 'pinia'
- import {
- getCouponListApi,
- receiveCouponApi,
- receiveCouponApiNew,
- getCoupon2idApi,
- getCoupon2ListApi,
- } from '@/service/coupon1'
- import {
- getCoupon2ViewmListApi,
- getCoupon2DetailApi,
- getCoupon2ModifyApi,
- getCoupon2AuditListApi,
- getCoupon2AuditDetailApi,
- submitCoupon2AuditApi,
- } from '@/service/coupon2'
- import { until } from '@vueuse/core'
- export const useCouponStore = defineStore(
- 'coupon',
- () => {
- // 获取优惠券列表
- const getCouponList = async (couponproductids: string) => {
- const { data: couponList, loading } = useRequest(
- () => getCouponListApi({ couponproductids }, { pageindex: 1, rows: 99999 }),
- {
- immediate: true,
- },
- )
- await until(loading).toBe(false)
- return couponList.value.Data
- }
- // 领取优惠券 旧 已弃用
- const receiveCoupon = async ({ couponid, coupon2phone, coupon2productids }) => {
- const { data: couponList, loading } = useRequest(
- () => receiveCouponApi({ couponid, coupon2phone, coupon2productids }),
- {
- immediate: true,
- },
- )
- await until(loading).toBe(false)
- return couponList.value
- }
- // 领取优惠券 new
- const receiveCouponNew = ({
- couponid,
- userstype,
- usersidcardnumber,
- usersshtyxydm,
- usersname,
- usersaddress,
- coupon2productids,
- coupon2phone,
- filesid,
- coupon2merchantid,
- }) => {
- // eslint-disable-next-line no-async-promise-executor
- return new Promise(async (resolve, reject) => {
- const {
- data: couponList,
- loading,
- error,
- } = useRequest(
- () =>
- receiveCouponApiNew({
- couponid,
- userstype,
- usersidcardnumber,
- usersshtyxydm,
- usersname,
- usersaddress,
- coupon2productids,
- coupon2phone,
- filesid,
- coupon2merchantid,
- }),
- {
- immediate: true,
- },
- )
- await until(loading).toBe(false)
- if (error.value) {
- reject(new Error('领取优惠券失败'))
- }
- resolve(couponList.value)
- })
- }
- // 获取该用户下,已领取的优惠劵id,用于判断是否可以领取
- const getCoupon2id = async (params) => {
- const { data: couponList, loading } = useRequest(() => getCoupon2idApi(params), {
- immediate: true,
- })
- await until(loading).toBe(false)
- return couponList.value
- }
- // 通过优惠券code获取产品信息(视图)
- const getCoupon2ViewmList = async (params: { coupon2code: string }) => {
- const { data: couponList, loading } = useRequest(
- () => getCoupon2ViewmListApi(params, { pageindex: 1, rows: 99999 }),
- {
- immediate: true,
- },
- )
- await until(loading).toBe(false)
- return couponList.value
- }
- // 获取已关联到当前用户的优惠券列表
- const getCoupon2List = async (params) => {
- const { data: couponList, loading } = useRequest(
- () => getCoupon2ListApi(params, { pageindex: 1, rows: 99999 }),
- {
- immediate: true,
- },
- )
- await until(loading).toBe(false)
- return couponList.value
- }
- // 通过优惠券id获取产品信息(视图)
- const getCoupon2ViewDetailBySid = async (params: { coupon2sid: string }) => {
- const { data: couponList, loading } = useRequest(() => getCoupon2DetailApi(params), {
- immediate: true,
- })
- await until(loading).toBe(false)
- return couponList.value
- }
- // 优惠劵审核修改
- // coupon2sid: 优惠券id 必传
- const getCoupon2Modify = async (params) => {
- // eslint-disable-next-line no-async-promise-executor
- return new Promise(async (resolve, reject) => {
- const {
- data: couponList,
- loading,
- error,
- } = useRequest(() => getCoupon2ModifyApi(params), {
- immediate: true,
- })
- await until(loading).toBe(false)
- if (error.value) {
- reject(new Error('优惠劵审核修改失败'))
- }
- resolve(couponList.value)
- })
- }
- // 优惠劵审核_列表
- const getCoupon2AuditList = async (params, page = { pageindex: 1, rows: 10 }) => {
- const { data: couponList, loading } = useRequest(() => getCoupon2AuditListApi(params, page), {
- immediate: true,
- })
- await until(loading).toBe(false)
- return couponList.value
- }
- // 优惠劵审核_详情
- const getCoupon2AuditDetail = async (params) => {
- const { data: couponList, loading } = useRequest(() => getCoupon2AuditDetailApi(params), {
- immediate: true,
- })
- await until(loading).toBe(false)
- return couponList.value
- }
- // 优惠劵审核_提交
- const submitCoupon2Audit = async (params) => {
- // eslint-disable-next-line no-async-promise-executor
- return new Promise(async (resolve, reject) => {
- const {
- data: couponList,
- loading,
- error,
- } = useRequest(() => submitCoupon2AuditApi(params), {
- immediate: true,
- })
- await until(loading).toBe(false)
- if (error.value) {
- reject(new Error('优惠劵审核提交失败'))
- }
- resolve(couponList.value)
- })
- }
- return {
- getCouponList,
- receiveCoupon,
- receiveCouponNew,
- getCoupon2id,
- getCoupon2ViewmList,
- getCoupon2List,
- getCoupon2ViewDetailBySid,
- getCoupon2Modify,
- getCoupon2AuditList,
- getCoupon2AuditDetail,
- submitCoupon2Audit,
- }
- },
- {
- persist: true,
- },
- )
|