133 lines
4.5 KiB
JavaScript
133 lines
4.5 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patientlist-api.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
last_id:-1,
|
|
get_data_status:0,
|
|
search_patient: 0,
|
|
search_status: 0,
|
|
search_error_message: '',
|
|
patients: [],
|
|
selected_patient: {},
|
|
companies:[{id:0,name:'Semua'}],
|
|
selected_company:{id:0,name:'Semua'},
|
|
total_patients:0,
|
|
total_all:0,
|
|
autocomplete_status:0,
|
|
filter_search:'',
|
|
start_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
current_page:1
|
|
},
|
|
mutations: {
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_start_date(state, val) {
|
|
state.start_date = val
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
},
|
|
update_companies(state, val) {
|
|
state.companies = val
|
|
},
|
|
update_selected_company(state, val) {
|
|
state.selected_company = val
|
|
},
|
|
update_filter_search(state, val) {
|
|
state.filter_search = val
|
|
},
|
|
update_get_data_status(state, val) {
|
|
state.get_data_status = 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
|
|
},
|
|
update_selected_patient(state, val) {
|
|
state.selected_patient = val
|
|
},
|
|
update_autocomplete_status(state,val){
|
|
state.autocomplete_status = val
|
|
},
|
|
update_search_status(state, val) {
|
|
state.search_status = val
|
|
},
|
|
update_total_patients(state, val) {
|
|
state.total_patients = val
|
|
},
|
|
update_total_all(state, val) {
|
|
state.total_all = val
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
context.commit("update_search_patient", 1)
|
|
window.key_enter = ''
|
|
try {
|
|
console.log(prm)
|
|
console.log('search')
|
|
prm.token = one_token()
|
|
console.log(prm)
|
|
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
|
|
}
|
|
console.log(data.records)
|
|
context.commit("update_patients", data.records)
|
|
context.commit("update_total_patients", data.total)
|
|
context.commit("update_total_all", resp.data.total_all)
|
|
|
|
if(data.records){
|
|
context.commit("update_selected_patient", data.records[0])
|
|
}
|
|
}
|
|
} 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)
|
|
var xprm = {
|
|
search:context.state.filter_search,
|
|
companyid:context.state.selected_company.id,
|
|
xdate:context.state.start_date,
|
|
current_page:context.state.current_page
|
|
}
|
|
context.dispatch("search", xprm)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_autocomplete_status",3)
|
|
}
|
|
}
|
|
}
|
|
} |