// 1 => LOADING // 2 => DONE // 3 => ERROR import * as api from "../api/patient.js" export default { namespaced: true, state: { search_patient: 0, search_error_message: '', patients: [], total_patient: 0, selected_patient: {}, save_error_message: '' }, mutations: { update_search_error_message(state, patient) { state.search_error_message = patient }, update_search_patient(state, patient) { state.search_patient = patient }, update_patients(state, data) { state.patients = data.records state.total_patient = data.total }, update_selected_patient(state, val) { state.selected_patient = val } }, actions: { async search(context, prm) { context.commit("update_search_patient", 1) try { let resp = await api.search(prm) if (resp.status != "OK") { context.commit("update_search_patient", 3) context.commit("update_search_error_message", resp.message) } else { context.commit("update_search_patient", 2) context.commit("update_search_error_message", "") let data = { records: resp.data.records, total: resp.data.total } context.commit("update_patients", data) } } catch (e) { context.commit("update_search_patient", 3) context.commit("update_search_error_message", e.message) console.log(e) } } } }