127 lines
3.4 KiB
JavaScript
127 lines
3.4 KiB
JavaScript
import {makeAutoObservable} from "mobx";
|
|
import {http} from "../utils/http";
|
|
|
|
export class Transaction {
|
|
page = 0;
|
|
pageSize = 10
|
|
data = [];
|
|
total_data = 0;
|
|
filterCategory = null;
|
|
visibleModalProduct = false;
|
|
|
|
pageCategories = 0;
|
|
pageSizeCategories = 10
|
|
dataCategories = [];
|
|
total_dataCategories = 0;
|
|
|
|
pageSubCategories = 0;
|
|
pageSizeSubCategories = 10
|
|
dataSubCategories = [];
|
|
total_dataSubCategories = 0;
|
|
|
|
pageHistoryTransaction = 0;
|
|
// pageSizeHistoryTransaction = 10
|
|
dataHistoryTransaction = [];
|
|
total_dataHistoryTransaction = 0;
|
|
|
|
constructor(ctx) {
|
|
this.ctx = ctx;
|
|
makeAutoObservable(this);
|
|
}
|
|
|
|
async getData() {
|
|
try {
|
|
const response = await http.get(`/product/by-categories?categories=${this.filterCategory}&page=${this.page}&pageSize=${this.pageSize}`);
|
|
this.data = response.body.data ?? []
|
|
this.total_data = response.body.total_data ?? 0
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async getDataSubCategories() {
|
|
try {
|
|
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
|
|
this.dataSubCategories = response.body.data ?? []
|
|
this.total_dataSubCategories = response.body.count ?? 0
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async getDataCategories() {
|
|
try {
|
|
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`);
|
|
|
|
this.dataCategories = response.body.data ?? []
|
|
this.total_dataCategories = response.body.total_data ?? 0
|
|
if (this.dataCategories.length > 0) {
|
|
this.filterCategory = this.dataCategories[0].id
|
|
}
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async getDataHistoryTransaction() {
|
|
try {
|
|
const response = await http.get(`/transaction/history?page=${this.pageHistoryTransaction}`);
|
|
|
|
this.dataHistoryTransaction = response.body.data ?? []
|
|
this.total_dataHistoryTransaction = response.body.total_data ?? 0
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async create(data) {
|
|
try {
|
|
const response = await http.post('/product').send(data);
|
|
await this.getData();
|
|
return response;
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async update(id, data) {
|
|
try {
|
|
const response = await http.put(`/product/${id}`).send(data);
|
|
await this.getData();
|
|
return response;
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async delete(id) {
|
|
try {
|
|
const response = await http.del(`/product/${id}`);
|
|
await this.getData();
|
|
return response;
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async distribute(data) {
|
|
try {
|
|
const response = await http.post('/transaction/distribute').send(data);
|
|
return response;
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async distributeAdmin(data) {
|
|
try {
|
|
const response = await http.post('/transaction/distribute-admin').send(data);
|
|
return response;
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
|