204 lines
7.4 KiB
JavaScript
204 lines
7.4 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
lastidx:0,
|
|
lookup_status:0,
|
|
lookup_error_message:'',
|
|
search_patient: 0,
|
|
search_error_message: '',
|
|
start_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
end_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
search:'',
|
|
total_patiens: 0,
|
|
total_filter_patiens: 0,
|
|
patients: [],
|
|
total_patient: 0,
|
|
selected_patient: {totalbill:0},
|
|
save_error_message: '',
|
|
statuses:[{name:'Belum Lunas',value:'N'},{name:'Lunas',value:'Y'}, {name:'Semua',value:'A'}],
|
|
selected_status:{name:'Belum Lunas',value:'N'},
|
|
open_alert_no_pay: false,
|
|
msg_alert_no_pay: "Loh ... Gak jadi bayar dong ?",
|
|
current_page:1,
|
|
total_page:0,
|
|
filters:[{id:'day',name:'Hari ini'},{id:'notsampled',name:'Belum sampling'},{id:'all',name:'Tampilkan semua'}],
|
|
selected_filter:{id:'day',name:'Hari ini'},
|
|
promise_dialog:false,
|
|
promises:[],
|
|
errors:[],
|
|
save_status:0,
|
|
save_error_message:'',
|
|
},
|
|
mutations: {
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_save_error_message(state, val) {
|
|
state.save_error_message = val
|
|
},
|
|
update_lookup_error_message(state,val) {
|
|
state.lookup_error_message = val
|
|
},
|
|
update_lookup_status(state,status) {
|
|
state.lookup_status = status
|
|
},
|
|
update_promise_dialog(state, val) {
|
|
state.promise_dialog = val
|
|
},
|
|
update_promises(state, val) {
|
|
state.promises = val
|
|
},
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_lastidx(state, val) {
|
|
state.lastidx = val
|
|
},
|
|
update_selected_filter(state, val) {
|
|
state.selected_filter = val
|
|
},
|
|
update_filters(state, val) {
|
|
state.filters = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = val
|
|
},
|
|
|
|
update_total_patient(state, val) {
|
|
state.total_patient = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
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
|
|
state.total_page = data.total
|
|
state.total_patients = data.total
|
|
state.total_filter_patients = data.total_filter
|
|
},
|
|
update_selected_patient(state, val) {
|
|
state.selected_patient = val
|
|
},
|
|
update_start_date(state, val) {
|
|
state.start_date = val
|
|
},
|
|
update_end_date(state, val) {
|
|
state.end_date = val
|
|
},
|
|
update_search(state, val) {
|
|
state.search = val
|
|
},
|
|
update_selected_status(state, val) {
|
|
state.selected_status = val
|
|
},
|
|
update_open_alert_no_pay(state, val) {
|
|
state.open_alert_no_pay = val
|
|
},
|
|
update_msg_alert_no_pay(state, val) {
|
|
state.msg_alert_no_pay = val
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
context.commit("update_search_patient", 1)
|
|
try {
|
|
console.log(prm)
|
|
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,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("update_patients", data)
|
|
context.commit("update_total_page", data.total)
|
|
if(prm.lastidx === 0){
|
|
context.commit("update_selected_patient", data.records[0])
|
|
if(!_.isEmpty(data.records[0]))
|
|
context.commit("payment/update_notes",data.records[0].notes,{root:true})
|
|
else
|
|
context.commit("payment/update_notes",[],{root:true})
|
|
}
|
|
else{
|
|
context.commit("update_selected_patient", data.records[prm.lastidx])
|
|
context.commit("payment/update_notes",data.records[prm.lastidx].notes,{root:true})
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_patient", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async lookup_promises(context,prm) {
|
|
context.commit("update_lookup_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.lookup_promises(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status",3)
|
|
context.commit("update_lookup_error_message",resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status",2)
|
|
context.commit("update_lookup_error_message","")
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_promises",data.records)
|
|
context.commit("update_promise_dialog",true)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_lookup_status",3)
|
|
context.commit("update_lookup_error_message",e.message )
|
|
}
|
|
},
|
|
async savepromises(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.save_promises(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_save_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_promises",data.records)
|
|
context.commit("update_promise_dialog",false)
|
|
var xsearch = prm.search
|
|
|
|
context.dispatch("search",xsearch)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
}
|
|
}
|