147 lines
5.2 KiB
JavaScript
147 lines
5.2 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
patient: [],
|
|
selected_patient: {},
|
|
search_status: false,
|
|
current_page: 1,
|
|
total_patients: 0,
|
|
x_search: "",
|
|
last_id: -1,
|
|
start_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
end_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
save_status: 0,
|
|
save_error_message: "",
|
|
alert_error: false,
|
|
alert_success: false,
|
|
msg_success: "",
|
|
dialog_error: false
|
|
},
|
|
mutations: {
|
|
update_patient(state, data) {
|
|
state.patient = data
|
|
},
|
|
update_selected_patient(state, val) {
|
|
state.selected_patient = val
|
|
},
|
|
update_search_status(state, val) {
|
|
state.search_status = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_total_patients(state, data) {
|
|
state.total_patients = data
|
|
},
|
|
update_x_search(state, val) {
|
|
state.x_search = val
|
|
state.current_page = 1
|
|
},
|
|
update_start_date(state, data) {
|
|
state.start_date = data
|
|
},
|
|
update_end_date(state, data) {
|
|
state.end_date = data
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
},
|
|
update_save_error_message(state, val) {
|
|
state.save_error_message = val
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_alert_error(state, val) {
|
|
state.alert_error = val;
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val;
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
},
|
|
update_dialog_error(state, data) {
|
|
state.dialog_error = data
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context) {
|
|
context.commit("update_search_status", true)
|
|
try {
|
|
var prm = {
|
|
token: one_token(),
|
|
current_page: context.state.current_page,
|
|
search: context.state.x_search,
|
|
start_date: context.state.start_date,
|
|
end_date: context.state.end_date,
|
|
last_id: -1
|
|
}
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status", false)
|
|
console.log(resp.message)
|
|
} else {
|
|
context.commit("update_search_status", false)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("update_patient", data.records)
|
|
context.commit("update_total_patients", resp.data.total)
|
|
if (
|
|
!(
|
|
Object.keys(context.state.selected_patient).length === 0 &&
|
|
context.state.selected_patient.constructor === Object
|
|
)
|
|
) {
|
|
let idx = _.findIndex(resp.data.records, function (o) {
|
|
return o.T_OrderHeaderID == context.state.selected_patient.T_OrderHeaderID
|
|
});
|
|
if (idx >= 0) {
|
|
context.commit("update_selected_patient", resp.data.records[idx]);
|
|
}
|
|
console.log(idx);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", false)
|
|
console.log(e)
|
|
}
|
|
},
|
|
|
|
async confirm(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.confirm(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_error_message", resp.message)
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_alert_error", true)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_dialog_error", false)
|
|
let data = resp.data
|
|
var msg = "Email berhasil dikonfirmasi"
|
|
context.commit("update_msg_success", msg)
|
|
context.commit("update_alert_success", true)
|
|
context.dispatch("search")
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_save_error_message", e.message)
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_alert_error", true)
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
} |