273 lines
9.0 KiB
JavaScript
273 lines
9.0 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/fisik.js";
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
last_id: -1,
|
|
current_page: 1,
|
|
lookup_fisik: 0,
|
|
lookup_error_message: "",
|
|
fisiks: [],
|
|
total_fisiks: 0,
|
|
total_filter_fisiks: 0,
|
|
selected_fisik: {},
|
|
x_search: "",
|
|
dialog_fisik: false,
|
|
act: "new",
|
|
save_status: 2,
|
|
loading_save: false,
|
|
error_message: "",
|
|
alert_error: false,
|
|
dialog_error: false,
|
|
msg_success: "",
|
|
alert_success: false,
|
|
nat_tests: [],
|
|
selected_nat_test: {},
|
|
snackbar: {
|
|
value: false,
|
|
color: "info",
|
|
mode: "single-line",
|
|
timeout: 500,
|
|
text: "",
|
|
top:false,
|
|
bottom:true,
|
|
left:false,
|
|
right:true,
|
|
},
|
|
},
|
|
mutations: {
|
|
update_snackbar(state, val) {
|
|
state.snackbar = val;
|
|
},
|
|
update_nat_tests(state, val) {
|
|
state.nat_tests = val;
|
|
},
|
|
update_selected_nat_test(state, val) {
|
|
state.selected_nat_test = val;
|
|
},
|
|
update_lookup_fisik(state, status) {
|
|
state.lookup_fisik = status;
|
|
},
|
|
update_lookup_error_message(state, status) {
|
|
state.lookup_error_message = status;
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val;
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val;
|
|
},
|
|
update_fisiks(state, data) {
|
|
state.fisiks = data.records;
|
|
state.total_fisiks = data.total;
|
|
state.total_filter_fisiks = data.total_filter;
|
|
},
|
|
update_selected_fisik(state, val) {
|
|
state.selected_fisik = val;
|
|
},
|
|
update_x_search(state, val) {
|
|
state.x_search = val;
|
|
},
|
|
update_dialog_fisik(state, val) {
|
|
state.dialog_fisik = val;
|
|
},
|
|
update_act(state, val) {
|
|
state.act = val;
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val;
|
|
},
|
|
update_loading_save(state, val) {
|
|
state.loading_save = val;
|
|
},
|
|
update_error_message(state, val) {
|
|
state.error_message = val;
|
|
},
|
|
update_alert_error(state, val) {
|
|
state.alert_error = val;
|
|
},
|
|
update_dialog_error(state, val) {
|
|
state.dialog_error = val;
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val;
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val;
|
|
},
|
|
},
|
|
actions: {
|
|
async fisikTemplateMappingList(context, prm) {
|
|
context.commit("update_lookup_fisik", 1);
|
|
try {
|
|
prm.token = one_token();
|
|
prm.status = context.rootState.fisikdetail.selected_filter_flag.value;
|
|
prm.id
|
|
let resp = await api.fisikTemplateMappingList(prm);
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_fisik", 3);
|
|
context.commit("update_lookup_error_message", resp.message);
|
|
} else {
|
|
context.commit("update_lookup_fisik", 2);
|
|
context.commit("update_lookup_error_message", "");
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter,
|
|
};
|
|
context.commit("update_fisiks", data);
|
|
if (prm.lastid === -1) {
|
|
var pat = data.records[0];
|
|
context.commit("update_selected_fisik", data.records[0]);
|
|
context.dispatch(
|
|
"fisikdetail/findFisikTemplate",
|
|
{
|
|
id: pat.id,
|
|
code: "",
|
|
name: "",
|
|
current_page: 1,
|
|
status: context.rootState.fisikdetail.selected_filter_flag.value,
|
|
lastid: -1,
|
|
},
|
|
{
|
|
root: true,
|
|
}
|
|
);
|
|
} else {
|
|
var pat = data.records[prm.lastid];
|
|
context.commit("update_selected_fisik", data.records[prm.lastid]);
|
|
context.dispatch(
|
|
"fisikdetail/findFisikTemplate",
|
|
{
|
|
id: pat.id,
|
|
code: "",
|
|
name: "",
|
|
current_page: 1,
|
|
status: context.rootState.fisikdetail.selected_filter_flag.value,
|
|
lastid: -1,
|
|
},
|
|
{
|
|
root: true,
|
|
}
|
|
);
|
|
}
|
|
|
|
context.commit("fisikdetail/update_selected_filter_status", {'value': 'Y', 'text': 'Sudah dipilih'},{root: true});
|
|
context.dispatch("searchNatTest", {
|
|
search_nat_test: "",
|
|
filter_status: context.rootState.fisikdetail.selected_filter_status
|
|
});
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_fisik", 3);
|
|
context.commit("update_lookup_error_message", e.message);
|
|
}
|
|
},
|
|
|
|
async addFisikTemplateMapping(context, prm) {
|
|
context.commit("update_save_status", 1);
|
|
try {
|
|
context.commit("update_loading_save", true);
|
|
prm.token = one_token();
|
|
let resp = await api.addFisikTemplateMapping(prm);
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3);
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", resp.message);
|
|
context.commit("update_alert_error", true);
|
|
context.commit("update_dialog_error", true);
|
|
} else {
|
|
context.commit("update_save_status", 2);
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", "");
|
|
context.commit("update_dialog_error", false);
|
|
let data = resp.data;
|
|
var msg = "Fisik template " + prm.name + " berhasil disimpan";
|
|
context.commit("update_msg_success", msg);
|
|
context.commit("update_alert_success", true);
|
|
context.commit("update_dialog_error", true);
|
|
context.commit("update_dialog_fisik", false);
|
|
context.dispatch("fisikTemplateMappingList", {
|
|
fisikname: "",
|
|
current_page: 1,
|
|
lastid: -1,
|
|
});
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", e.message);
|
|
context.commit("update_alert_error", true);
|
|
}
|
|
},
|
|
async searchNatTest(context, prm) {
|
|
context.commit("update_save_status", 1);
|
|
try {
|
|
context.commit("update_loading_save", true);
|
|
prm.token = one_token();
|
|
prm.id = context.rootState.fisik.selected_fisik.id;
|
|
let resp = await api.searchNatTest(prm);
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3);
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", resp.message);
|
|
context.commit("update_alert_error", true);
|
|
context.commit("update_dialog_error", true);
|
|
} else {
|
|
context.commit("update_save_status", 2);
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", "");
|
|
context.commit("update_dialog_error", false);
|
|
context.commit("update_nat_tests", resp.data.records);
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", e.message);
|
|
context.commit("update_alert_error", true);
|
|
}
|
|
},
|
|
async addNatTestMapping(context, prm) {
|
|
context.commit("update_save_status", 1);
|
|
try {
|
|
context.commit("update_loading_save", true);
|
|
prm.token = one_token();
|
|
let resp = await api.addNatTestMapping(prm);
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3);
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", resp.message);
|
|
context.commit("update_alert_error", true);
|
|
context.commit("update_dialog_error", true);
|
|
} else {
|
|
context.commit("update_save_status", 2);
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", "");
|
|
context.commit("update_dialog_error", false);
|
|
context.dispatch("searchNatTest", {
|
|
search_nat_test: "",
|
|
filter_status: context.rootState.fisikdetail.selected_filter_status
|
|
});
|
|
context.commit("update_snackbar", {
|
|
value: true,
|
|
color: "success",
|
|
mode: "single-line",
|
|
timeout: 3000,
|
|
text: resp.data.records.status == "Y" ? "Tes " + prm.Nat_TestName + " berhasil dipilih" : "Tes " + prm.Nat_TestName + " berhasil dihapus",
|
|
top:false,
|
|
bottom:true,
|
|
left:false,
|
|
right:true,
|
|
});
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading_save", false);
|
|
context.commit("update_error_message", e.message);
|
|
context.commit("update_alert_error", true);
|
|
}
|
|
},
|
|
|
|
},
|
|
};
|