update navigation all
This commit is contained in:
94
registration/modules/patient.js
Normal file
94
registration/modules/patient.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const URL = "https://devcpone.aplikasi.web.id/one-api/mockup/fo/registration_v27/patient";
|
||||
const store = {
|
||||
state() {
|
||||
return {
|
||||
loading:false,
|
||||
patients: [],
|
||||
selected_patient: {},
|
||||
current_page:1,
|
||||
search:'',
|
||||
loadmore:true,
|
||||
itemsperpage:10,
|
||||
itemsperpageoptions: [10, 20, 50],
|
||||
sortby: [{ key: 'M_PatientNoReg', order: 'asc' } ], // Format: [ { key: 'value', order: 'asc' } ]
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
setLoading(state, data) {
|
||||
state.loading = data
|
||||
},
|
||||
setPatients(state, data) {
|
||||
state.patients = data
|
||||
},
|
||||
setSelectedPatient(state, data) {
|
||||
state.selected_patient = data
|
||||
},
|
||||
setCurrentPage(state, data) {
|
||||
state.current_page = data
|
||||
},
|
||||
setSearch(state, data) {
|
||||
state.search = data
|
||||
},
|
||||
setLoadMore(state, data) {
|
||||
state.loadmore = data
|
||||
},
|
||||
setItemsPerPage(state, data) {
|
||||
state.itemsperpage = data
|
||||
},
|
||||
setItemPerPageOptions(state, data) {
|
||||
state.itemsperpageoptions = data
|
||||
},
|
||||
setSortBy(state, data) {
|
||||
state.sortby = data
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async searchPatients({ commit, state }, params) {
|
||||
commit('setLoading', true);
|
||||
try {
|
||||
const formData = new URLSearchParams();
|
||||
for (const key in params) {
|
||||
formData.append(key, params[key]);
|
||||
}
|
||||
|
||||
const response = await axios.post(URL + '/search', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
let respData = response.data;
|
||||
if (respData.status === "OK") {
|
||||
commit('setLoadMore', true);
|
||||
let datas = respData.data.records;
|
||||
|
||||
if (datas.length === 0) {
|
||||
commit('setLoadMore', false);
|
||||
}
|
||||
|
||||
if (params.current_page === 1) {
|
||||
commit('setPatients', datas);
|
||||
} else {
|
||||
let bf_patients = state.patients; // Gunakan state yang diterima dari parameter
|
||||
//console.log(bf_patients)
|
||||
let new_patients = _.concat(bf_patients, datas); // Pastikan lodash sudah terdefinisi
|
||||
//console.log(new_patients)
|
||||
commit('setPatients', new_patients);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert("err");
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
commit('setLoading', false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default store
|
||||
Reference in New Issue
Block a user