This commit is contained in:
2019-01-06 00:33:30 +07:00
parent 295a125862
commit f1fdbbd6e6
4 changed files with 112 additions and 2 deletions

View File

@@ -56,6 +56,7 @@ import {Tags} from './tags';
import Surf from './surf';
import Odoo from './odoo';
import Vouchers from './vouchers';
export default class AppState {
http = new Http(this.token);
@@ -101,6 +102,7 @@ export default class AppState {
userBanks = new UserBanks(this);
stores = new Stores(this);
storeList = new StoreList(this);
vouchers = new Vouchers(this);
userAddress = new UserAddress(this);
item = new ItemStore(this);
myStore = new MyStoreStore(this);

View File

@@ -0,0 +1,101 @@
import { observable, action, computed } from 'mobx';
export default class Vouchers {
@observable list = [];
@observable selected = {};
@observable istLoading = false;
@observable isSearching = false;
@observable filtered = [];
constructor(context) {
this.http = context.http;
this.context = context;
}
@action
getList(){
console.log('res');
this.isLoading = true;
return this.http.get("items")
.then(res => {
console.log(res.data,'res list')
this.list = res.data;
this.isLoading = false;
})
.catch(err => {
this.isLoading = false;
throw err;
})
}
@action
getDetail(id){
this.isLoading = true;
return this.http.get(`stores/${id}`)
.then(res => {
this.selected = res;
this.isLoading = false;
})
.catch(err => {
this.isLoading = false;
throw err;
})
}
@action
post(data){
this.isLoading = true;
return this.http.post("stores", data)
.then(res => {
this.isLoading = false;
this.getList();
return res;
})
.catch(err => {
this.isLoading = false;
throw err;
})
}
@action
put(id,data){
this.isLoading = true;
return this.http.put(`stores/${id}`, data)
.then(res => {
this.isLoading = false;
this.getList();
return res;
})
.catch(err => {
this.isLoading = false;
throw err;
})
}
@action
delete(id){
this.isLoading = true;
return this.http.delete(`stores/${id}`)
.then(res => {
this.isLoading = false;
this.getList();
return res;
})
.catch(err => {
this.isLoading = false;
throw err;
})
}
filterItems = (query) => {
return this.list.filter((el) =>
el.name.toLowerCase().indexOf(query.toLowerCase()) > -1
);
}
@action
search(text){
this.filtered = this.filterItems(text);
}
}