132 lines
4.8 KiB
JavaScript
132 lines
4.8 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
companys: [],
|
|
autocomplete_status: 0,
|
|
selected_company: {id:0, name:'Semua'},
|
|
patients: [],
|
|
total_patients: 0,
|
|
search_patient: 0,
|
|
search_error_message: "",
|
|
selected_patient: {},
|
|
x_search: "",
|
|
start_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
end_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
companyid: 0,
|
|
last_id: -1
|
|
},
|
|
mutations: {
|
|
update_companys(state, val) {
|
|
state.companys = val
|
|
},
|
|
update_autocomplete_status(state, val) {
|
|
state.autocomplete_status = val
|
|
},
|
|
update_selected_company(state, val) {
|
|
state.selected_company = val
|
|
},
|
|
update_patients(state, val) {
|
|
state.patients = val
|
|
},
|
|
update_search_patient(state, val) {
|
|
state.search_patient = val
|
|
},
|
|
update_search_error_message(state, val) {
|
|
state.search_error_message = val
|
|
},
|
|
update_total_patients(state, val) {
|
|
state.total_patients = val
|
|
},
|
|
update_selected_patient(state, val) {
|
|
state.selected_patient = val
|
|
},
|
|
update_x_search(state, val) {
|
|
state.x_search = val
|
|
},
|
|
update_start_date(state, val) {
|
|
state.start_date = val
|
|
},
|
|
update_end_date(state, val) {
|
|
state.end_date = val
|
|
},
|
|
update_companyid(state, val) {
|
|
state.companyid = val
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
}
|
|
},
|
|
actions: {
|
|
async getcompany(context,prm) {
|
|
context.commit("update_autocomplete_status",1)
|
|
try {
|
|
let resp= await api.getcompany(one_token(),prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_autocomplete_status",3)
|
|
} else {
|
|
context.commit("update_autocomplete_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total_display
|
|
}
|
|
context.commit("update_companys",resp.data.records)
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_autocomplete_status",3)
|
|
}
|
|
},
|
|
|
|
async search(context, prm) {
|
|
context.commit("update_search_patient", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
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_filter
|
|
}
|
|
context.commit("update_patients", data.records)
|
|
context.commit("update_total_patients", data.total)
|
|
// if (prm.lastid === -1) {
|
|
// if (resp.data && data.records.length > 0) {
|
|
// context.commit("update_selected_patient", data.records[0])
|
|
// } else {
|
|
// context.commit("update_selected_patient", {})
|
|
// }
|
|
// } else {
|
|
// context.commit("update_selected_patient", data.records[prm.lastid])
|
|
// }
|
|
|
|
if (context.state.last_id == -1) {
|
|
if (resp.data && resp.data.records.length > 0) {
|
|
context.commit("update_selected_patient", resp.data.records[0])
|
|
}
|
|
} else {
|
|
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]);
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_patient", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
} |