235 lines
8.4 KiB
JavaScript
235 lines
8.4 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
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:'',
|
|
patients: [],
|
|
total_patient: 0,
|
|
selected_patient: {},
|
|
save_error_message: '',
|
|
statuses:[{name:'Semua',value:'A'},{value:'SUCCESS',name:'SUCCESS'},{value:'ERROR',name:'ERROR'}],
|
|
selected_status:{name:'Semua',value:'A'},
|
|
open_alert_no_pay: false,
|
|
msg_alert_no_pay: "Loh ... Gak jadi bayar dong ?",
|
|
current_page:1,
|
|
total_page:0,
|
|
pay_disabled:'Y',
|
|
autocomplete_status:0,
|
|
companies:[{id:0,name:'Semua'}],
|
|
selected_company:{id:0,name:'Semua'},
|
|
logs:[],
|
|
unduhan:[],
|
|
loading_download:false,
|
|
loading_send:false,
|
|
lastidx:-1
|
|
},
|
|
mutations: {
|
|
update_lastidx(state,val){
|
|
state.lastidx = val
|
|
},
|
|
update_loading_send(state,val){
|
|
state.loading_send = val
|
|
},
|
|
update_loading_download(state,val){
|
|
state.loading_download = val
|
|
},
|
|
update_unduhan(state,val){
|
|
state.unduhan = val
|
|
},
|
|
update_logs(state,val){
|
|
state.logs = val
|
|
},
|
|
update_autocomplete_status(state,val){
|
|
state.autocomplete_status = val
|
|
},
|
|
update_companies(state, val) {
|
|
state.companies = val
|
|
},
|
|
update_selected_company(state, val) {
|
|
state.selected_company = val
|
|
},
|
|
update_pay_disabled(state, val) {
|
|
state.pay_disabled = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = 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
|
|
},
|
|
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 {
|
|
prm.token = one_token()
|
|
prm.company = context.state.selected_company.id
|
|
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
|
|
}
|
|
context.commit("update_patients", data)
|
|
context.commit("update_selected_patient", [])
|
|
context.commit("update_total_page", data.total)
|
|
|
|
if(context.state.lastidx != -1){
|
|
context.commit("update_selected_patient", data.records[context.state.lastidx])
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_patient", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async searchcompany(context,prm) {
|
|
context.commit("update_autocomplete_status",1)
|
|
try {
|
|
let resp= await api.searchcompany(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
|
|
}
|
|
context.commit("update_companies",resp.data.records)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_autocomplete_status",3)
|
|
}
|
|
},
|
|
async rePushOrder(context,prm) {
|
|
context.commit("update_autocomplete_status",true)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.rePushOrder(prm)
|
|
if(resp.status != "OK"){
|
|
context.commit("update_autocomplete_status",3)
|
|
}else{
|
|
context.commit("update_autocomplete_status",2)
|
|
context.dispatch("search",{
|
|
startdate:context.state.start_date,
|
|
enddate:context.state.start_date,
|
|
search: context.state.search,
|
|
status: context.state.selected_status.value,
|
|
current_page:context.state.current_page,
|
|
lastidx:0
|
|
})
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_autocomplete_status",3)
|
|
|
|
}
|
|
},
|
|
async download_data(context,prm) {
|
|
context.commit("update_loading_download",true)
|
|
try {
|
|
let resp= await api.download_data(one_token(),prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading_download",false)
|
|
} else {
|
|
context.commit("update_loading_download",false)
|
|
context.commit("update_unduhan",resp.data.records)
|
|
context.commit("paymentnew/update_dialog_pay_success",true,{root:true})
|
|
context.commit("update_autocomplete_status",2)
|
|
context.dispatch("search",{
|
|
startdate:context.state.start_date,
|
|
enddate:context.state.start_date,
|
|
search: context.state.search,
|
|
status: context.state.selected_status.value,
|
|
current_page:1,
|
|
lastidx:0
|
|
})
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_loading_download",false)
|
|
}
|
|
},
|
|
async sendresult(context,prm) {
|
|
context.commit("update_loading_send",true)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.sendresult(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading_send",false)
|
|
} else {
|
|
|
|
context.dispatch("getlogs",{})
|
|
//alert("Proses unduh selesai")
|
|
context.commit("update_loading_send",false)
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_loading_send",false)
|
|
}
|
|
},
|
|
async getlogs(context,prm) {
|
|
context.commit("update_autocomplete_status",1)
|
|
try {
|
|
prm = context.state.selected_patient
|
|
prm.token = one_token()
|
|
let resp= await api.getlogs(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_autocomplete_status",3)
|
|
} else {
|
|
|
|
context.commit("update_logs",resp.data.records)
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_autocomplete_status",3)
|
|
}
|
|
},
|
|
|
|
}
|
|
} |