54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import axios from '../plugins/axios'
|
|
import { defineStore } from 'pinia'
|
|
|
|
export const useDiscountStore = defineStore('discounts', {
|
|
state: () => ({
|
|
items: [],
|
|
brands: [],
|
|
categories: [],
|
|
fetching: true,
|
|
total: 0
|
|
}),
|
|
actions: {
|
|
async add(form) {
|
|
this.fetching = true
|
|
const { status, data } = await axios.post('/admins/discount', form)
|
|
this.fetching = false
|
|
return data
|
|
},
|
|
async history() {
|
|
this.fetching = true
|
|
const { status, data } = await axios.get('/admins/discountHistory')
|
|
this.fetching = false
|
|
return data
|
|
},
|
|
async index() {
|
|
this.items = [];
|
|
this.fetching = true
|
|
const { status, data } = await axios.get('/admins/discount')
|
|
this.fetching = false
|
|
return this.items = data
|
|
|
|
},
|
|
|
|
async getDiscount(id) {
|
|
this.items = [];
|
|
this.fetching = true
|
|
const { status, data } = await axios.get(`/admins/discount/${id}`)
|
|
this.fetching = false
|
|
return this.items = data
|
|
|
|
},
|
|
async update(form) {
|
|
const { status, data } = await axios.put('/admins/discount', form)
|
|
this.fetching = false
|
|
return data
|
|
},
|
|
async changeStatus(form) {
|
|
const { status, data } = await axios.patch('/admins/discount/status', form)
|
|
this.fetching = false
|
|
return data
|
|
}
|
|
|
|
}
|
|
}) |