111 lines
3.4 KiB
JavaScript
111 lines
3.4 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search_status: 0,
|
|
search_error_message: '',
|
|
|
|
query: '',
|
|
patients: [],
|
|
selected_patient: {},
|
|
total_patient: 0,
|
|
total_patient_page: 0,
|
|
curr_patient_page: 1,
|
|
|
|
is_internal: "N",
|
|
snackbar: false,
|
|
selected_order: []
|
|
},
|
|
mutations: {
|
|
|
|
update_search_error_message(state, patient) {
|
|
state.search_error_message = patient
|
|
},
|
|
|
|
update_search_status(state, v) {
|
|
state.search_status = v
|
|
},
|
|
|
|
update_query(state, q) {
|
|
state.query = q
|
|
},
|
|
|
|
update_patients(state, d) {
|
|
state.patients = d.records
|
|
state.total_patient = d.total
|
|
state.total_patient_page = d.total_page
|
|
},
|
|
|
|
update_selected_patient(state, d) {
|
|
state.selected_patient = d
|
|
},
|
|
|
|
update_curr_patient_page(state, d) {
|
|
state.curr_patient_page = d
|
|
},
|
|
|
|
update_is_internal(state, d) {
|
|
state.is_internal = d
|
|
},
|
|
|
|
update_snackbar(state, d) {
|
|
state.snackbar = d
|
|
},
|
|
|
|
update_selected_order(state, d) {
|
|
state.selected_order = d
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context) {
|
|
|
|
try {
|
|
let resp = await api.search(context.state.query, context.rootState.company.selected_company.company_id, context.rootState.company.is_internal, context.state.curr_patient_page)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_status", 2)
|
|
context.commit("update_search_error_message", "")
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_page: resp.data.total_page
|
|
}
|
|
|
|
|
|
context.commit("update_patients", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async send(context, ids) {
|
|
|
|
try {
|
|
let resp = await api.send(one_token(), ids)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_status", 2)
|
|
context.commit("update_search_error_message", "")
|
|
|
|
context.commit('update_snackbar', true)
|
|
context.commit('update_selected_order', [])
|
|
context.dispatch("search")
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
}
|
|
}
|
|
} |