113 lines
4.2 KiB
JavaScript
113 lines
4.2 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/history.js"
|
|
import doctor from "./doctor.js"
|
|
window.api = api
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
noreg:'',
|
|
search: '',
|
|
search_status:0,
|
|
search_error_message:'',
|
|
search_dialog_is_active: false,
|
|
histories: [],
|
|
|
|
history_dialog: false
|
|
},
|
|
mutations: {
|
|
update_search_dialog_is_active(state,status) {
|
|
state.search_dialog_is_active = status
|
|
},
|
|
|
|
update_search_error_message(state,status) {
|
|
state.search_error_message = status
|
|
},
|
|
|
|
update_search(state,val) {
|
|
state.search=val
|
|
},
|
|
|
|
update_search_status(state,status) {
|
|
state.search_status = status
|
|
},
|
|
|
|
update_histories(state, data) {
|
|
state.histories = data
|
|
},
|
|
|
|
update_history_dialog(state, v) {
|
|
state.history_dialog = v
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
let resp = await api.search(context.rootState.patient.selected_patient.M_PatientID)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_status",2)
|
|
context.commit("update_search_error_message","")
|
|
|
|
let data = {
|
|
records : resp.data.records
|
|
}
|
|
context.commit("update_histories", resp.data.records)
|
|
context.commit('update_history_dialog',true)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
async get_databyorder_id(context,prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.get_databyorder_id(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_status",2)
|
|
context.commit("update_search_error_message","")
|
|
|
|
let data = {
|
|
records : resp.data.records
|
|
}
|
|
console.log(data.records.status)
|
|
if(data.records.status === 'N'){
|
|
context.commit('update_message_error', 'satu...dua...tiga permen manis rasanya, coba cek agreement sepertinya sudah kadaluarsa', {root:true})
|
|
context.commit('update_dialog_error', true, {root:true})
|
|
}
|
|
else{
|
|
var rst = data.records.data
|
|
//console.log(rst)
|
|
let doctors = []
|
|
doctors.push(rst['selected_doctor'])
|
|
//console.log(doctors)
|
|
context.commit('doctor/update_doctors', {records:doctors,total:doctors.length}, {root:true})
|
|
context.commit('doctor/update_selected_doctor', doctors[0], {root:true})
|
|
context.commit('doctor/update_selected_address', rst['selected_address'], {root:true})
|
|
context.commit('company/update_companies', {records:rst['companies'],total:rst['companies'].length}, {root:true})
|
|
context.commit('company/update_selected_company', rst['selected_company'], {root:true})
|
|
context.commit('company/update_selected_mou', rst['selected_mou'], {root:true})
|
|
context.commit('delivery/update_data_deliveries', rst['data_deliveries'], {root:true})
|
|
context.commit('history/update_history_dialog',false,{root:true})
|
|
context.dispatch('px/search_pxs', prm.order_id, {root:true})
|
|
}
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
}
|
|
}
|
|
}
|