72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
// State
|
|
// data ...
|
|
// Mutations
|
|
//
|
|
//
|
|
// Actions
|
|
import * as api from "./api.js";
|
|
|
|
export const store = new Vuex.Store({
|
|
state: {
|
|
rows: [],
|
|
midPages: [],
|
|
isLoading: false,
|
|
isError: false,
|
|
errorMessage: "",
|
|
query: "",
|
|
page: 1,
|
|
totalPage: 2,
|
|
totalRecord: 11
|
|
},
|
|
mutations: {
|
|
updatePatient(state, data) {
|
|
// console.log(data);
|
|
if (data.status == "ERR") {
|
|
state.isError = true;
|
|
if (data.db_error) {
|
|
state.errorMessage = data.db_error.message;
|
|
} else {
|
|
state.errorMessage = data.message;
|
|
}
|
|
state.query = data.query;
|
|
state.page = 0;
|
|
state.totalPage = 0;
|
|
state.totalRecord = 0;
|
|
state.rows = [];
|
|
state.midPages = [];
|
|
} else {
|
|
state.isError = false;
|
|
state.errorMessage = "";
|
|
state.query = data.query;
|
|
state.page = data.page;
|
|
state.totalPage = data.totalPage;
|
|
state.totalRecord = data.totalRecord;
|
|
state.rows = data.rows;
|
|
state.midPages = data.midPages;
|
|
}
|
|
},
|
|
updateLoading(state, flag) {
|
|
state.isLoading = flag;
|
|
},
|
|
resetError(state) {
|
|
state.isError = false;
|
|
state.errorMessage = "";
|
|
}
|
|
},
|
|
actions: {
|
|
async searchPatient(context, data) {
|
|
context.commit("updateLoading", true);
|
|
let resp = await api.searchPatient(
|
|
data.query,
|
|
data.page,
|
|
data.rowPerPage
|
|
);
|
|
context.commit("updateLoading", false);
|
|
context.commit("updatePatient", resp);
|
|
setTimeout(function() {
|
|
context.commit("resetError");
|
|
}, 5000);
|
|
}
|
|
}
|
|
});
|