feat: create component product
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import {action, makeAutoObservable} from "mobx";
|
||||
import {http} from "../utils/http";
|
||||
|
||||
export class Categories {
|
||||
page = 0;
|
||||
pageSize = 10
|
||||
data = [];
|
||||
total_data = 0
|
||||
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
@action
|
||||
async getData() {
|
||||
const response = await http.get(`/product/sub-categories?page=${this.page}&pageSize=${this.pageSize}`);
|
||||
console.log(response, 'Data cate')
|
||||
console.log(JSON.stringify(response.body.data), 'Data')
|
||||
|
||||
this.data = response.body.data ?? []
|
||||
this.total_data = response.body.total_data ?? 0
|
||||
}
|
||||
|
||||
@action
|
||||
async create(data) {
|
||||
return await http.post('/user').send(data)
|
||||
}
|
||||
|
||||
@action
|
||||
async update(id, data) {
|
||||
return await http.put('/user/' + id).send(data);
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
return await http.del('/product/' + id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import {Authentication} from "./authentication";
|
||||
import {User} from "./user";
|
||||
import {Membership} from "./membership";
|
||||
import {Product} from "./product";
|
||||
import {Categories} from "./categories";
|
||||
import {TokenUtil} from "../utils/token";
|
||||
|
||||
export class Store {
|
||||
@@ -12,7 +11,6 @@ export class Store {
|
||||
user = new User(this);
|
||||
membership = new Membership(this);
|
||||
product = new Product(this);
|
||||
categories = new Categories(this);
|
||||
|
||||
constructor() {
|
||||
TokenUtil.loadToken();
|
||||
|
||||
@@ -5,33 +5,66 @@ export class Product {
|
||||
page = 0;
|
||||
pageSize = 10
|
||||
data = [];
|
||||
total_data = 0
|
||||
total_data = 0;
|
||||
filterCategory = null;
|
||||
|
||||
pageCategories = 0;
|
||||
pageSizeCategories = 10
|
||||
dataCategories = [];
|
||||
total_dataCategories = 0;
|
||||
|
||||
pageSubCategories = 0;
|
||||
pageSizeSubCategories = 10
|
||||
dataSubCategories = [];
|
||||
total_dataSubCategories = 0;
|
||||
|
||||
visibleModal = false;
|
||||
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
@action
|
||||
async getData() {
|
||||
const response = await http.get(`/product?page=${this.page}&pageSize=${this.pageSize}`);
|
||||
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
|
||||
}
|
||||
|
||||
@action
|
||||
async create(data) {
|
||||
return await http.post('/product').send(data)
|
||||
async getDataSubCategories() {
|
||||
const response = await http.get(`/product/sub-categories?pageSize=${this.pageSizeSubCategories}`);
|
||||
this.dataSubCategories = response.body.data ?? []
|
||||
this.total_dataSubCategories = response.body.count ?? 0
|
||||
}
|
||||
|
||||
async getDataCategories() {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
async create(data) {
|
||||
const response = await http.post('/product', data);
|
||||
await this.getData();
|
||||
return response;
|
||||
}
|
||||
|
||||
async update(id, data) {
|
||||
return await http.put('/user/' + id).send(data);
|
||||
const response = await http.put(`/product/${id}`, data);
|
||||
await this.getData();
|
||||
return response;
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
return await http.del('/product/' + id);
|
||||
const response = await http.del(`/product/${id}`);
|
||||
await this.getData();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user