365 lines
13 KiB
JavaScript
365 lines
13 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/sample.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
last_id:-1,
|
|
last_saved_id:-1,
|
|
x_addr_id:0,
|
|
act:'new',
|
|
act_addr:'new',
|
|
get_data_status:0,
|
|
search_trx: 0,
|
|
search_status: 0,
|
|
search_error_message: '',
|
|
start_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
end_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
total_transaction: 0,
|
|
transactions:[],
|
|
stations:[],
|
|
selected_station:{},
|
|
selected_transaction: {},
|
|
save_status: 0,
|
|
name_lab:'',
|
|
btn_save_seen: true,
|
|
pgrs_save: false,
|
|
save_error_message: '',
|
|
no_save: 0,
|
|
open_alert_confirmation:false,
|
|
alert_success: false,
|
|
msg_success: "",
|
|
dialog_success: false,
|
|
dialog_confirmation_delete: false,
|
|
msg_confirmation_delete: "",
|
|
autocomplete_status:0,
|
|
dialog_form_address: false,
|
|
errors:[],
|
|
open_dialog_info:false,
|
|
msg_info:'',
|
|
dialog_action:false,
|
|
msg_action:'',
|
|
current_status:null,
|
|
uploaded_files:[],
|
|
uploaded_error:null,
|
|
photos:[],
|
|
selected_photo:{},
|
|
dialog_image:false,
|
|
image:'',
|
|
doctors:[],
|
|
selected_doctor:{},
|
|
doctor_address:[],
|
|
selected_doctor_address:{},
|
|
current_page:1,
|
|
total_page:1
|
|
},
|
|
mutations: {
|
|
update_x_addr_id(state, val) {
|
|
state.x_addr_id = val
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
},
|
|
update_last_saved_id(state, val) {
|
|
state.last_saved_id = val
|
|
},
|
|
update_act(state, val) {
|
|
state.act = val
|
|
},
|
|
update_start_date(state, val) {
|
|
state.start_date = val
|
|
},
|
|
update_end_date(state, val) {
|
|
state.end_date = val
|
|
},
|
|
update_name_lab(state, val) {
|
|
state.name_lab = val
|
|
},
|
|
update_stations(state, val) {
|
|
state.stations = val
|
|
},
|
|
update_selected_station(state, val) {
|
|
state.selected_station = val
|
|
},
|
|
update_act_addr(state, val) {
|
|
state.act_addr = 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_transaction(state, val) {
|
|
state.search_transaction = val
|
|
},
|
|
update_transactions(state, data) {
|
|
state.transactions = data
|
|
},
|
|
update_selected_transaction(state, val) {
|
|
state.selected_transaction = val
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_btn_save_seen(state, val) {
|
|
state.btn_save_seen = val
|
|
},
|
|
update_pgrs_save(state, val) {
|
|
state.pgrs_save = val
|
|
},
|
|
update_save_error_message(state, msg) {
|
|
state.save_error_message = ''
|
|
},
|
|
update_no_save(state, val) {
|
|
state.no_save = val
|
|
},
|
|
update_open_alert_confirmation(state, val) {
|
|
state.open_alert_confirmation = val
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
},
|
|
update_dialog_success(state, val) {
|
|
state.dialog_success = val
|
|
},
|
|
update_dialog_confirmation_delete(state, val) {
|
|
state.dialog_confirmation_delete = val
|
|
},
|
|
update_msg_confirmation_delete(state, val) {
|
|
state.msg_confirmation_delete = val
|
|
},
|
|
update_search_status(state, val) {
|
|
state.search_status = val
|
|
},
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_total_transactions(state, val) {
|
|
state.total_transactions = val
|
|
},
|
|
update_open_dialog_info(state, val) {
|
|
state.open_dialog_info = val
|
|
},
|
|
update_msg_info(state, val) {
|
|
state.msg_info = val
|
|
},
|
|
update_dialog_action(state, val) {
|
|
state.dialog_action = val
|
|
},
|
|
update_msg_action(state, val) {
|
|
state.msg_action = val
|
|
},
|
|
update_current_status(state, val) {
|
|
state.current_status = val
|
|
},
|
|
update_uploaded_files(state, val) {
|
|
state.uploaded_files = val
|
|
},
|
|
update_uploaded_error(state, val) {
|
|
state.uploaded_error = val
|
|
},
|
|
update_photos(state, val) {
|
|
state.photos = val
|
|
},
|
|
update_selected_photo(state, val) {
|
|
state.selected_photo = val
|
|
},
|
|
update_dialog_image(state, val) {
|
|
state.dialog_image = val
|
|
},
|
|
update_image(state, val) {
|
|
state.image = val
|
|
},
|
|
update_doctors(state, val) {
|
|
state.doctors = val
|
|
},
|
|
update_selected_doctor(state, val) {
|
|
state.selected_doctor = val
|
|
},
|
|
update_doctor_address(state, val) {
|
|
state.doctor_address = val
|
|
},
|
|
update_selected_doctor_address(state, val) {
|
|
state.selected_doctor_address = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
context.commit("update_search_transaction", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_transaction", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_transaction", 2)
|
|
context.commit("update_search_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_transactions", resp.data.records)
|
|
context.commit("update_total_transactions", data.total)
|
|
context.commit("update_total_page", data.total)
|
|
context.commit("update_no_save", 0)
|
|
var trx = [];
|
|
if(prm.lastid === -1){
|
|
context.commit("update_selected_transaction", resp.data.records[0])
|
|
if(resp.data.records[0].photos){
|
|
context.commit("update_photos", resp.data.records[0].photos)
|
|
}
|
|
|
|
trx = resp.data.records[0]
|
|
}
|
|
else{
|
|
context.commit("update_selected_transaction", resp.data.records[prm.lastid])
|
|
if(resp.data.records[prm.lastid].photos){
|
|
context.commit("update_photos", resp.data.records[prm.lastid].photos)
|
|
}
|
|
trx = resp.data.records[prm.lastid]
|
|
}
|
|
|
|
context.commit("update_doctors",trx.doctors)
|
|
if(trx.doctor_fulname !== null){
|
|
//console.log(trx.doctor_fulname)
|
|
context.commit("update_selected_doctor",{id:trx.T_SamplingSoM_DoctorID,name:trx.doctor_fullname})
|
|
context.commit("update_doctor_address",trx.doctoraddress)
|
|
context.commit("update_selected_doctor_address",{id:trx.T_SamplingSoM_DoctorAddressID,name:trx.doctor_address})
|
|
}
|
|
else{
|
|
context.commit("update_selected_doctor",{})
|
|
context.commit("update_doctor_address",[])
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_transaction", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async getstation(context,prm) {
|
|
context.commit("update_get_data_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.getstation(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_get_data_status",3)
|
|
} else {
|
|
context.commit("update_get_data_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_stations",data.records.stations)
|
|
context.commit("update_selected_station",data.records.stations[0])
|
|
prm.stationid = data.records.stations[0].id
|
|
console.log(prm)
|
|
context.dispatch("search",prm)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_get_data_status",3)
|
|
}
|
|
},
|
|
async upload(context,prm) {
|
|
context.commit("update_get_data_status",1)
|
|
try {
|
|
|
|
let resp= await api.upload(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_get_data_status",3)
|
|
} else {
|
|
context.commit("update_get_data_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total,
|
|
error:resp.data.errors.error
|
|
}
|
|
context.commit("update_uploaded_files",data.records)
|
|
|
|
var msg = "Photo telah berhasil diupload"
|
|
if(data.error){
|
|
msg = data.error
|
|
context.commit("update_current_status",'STATUS_FAILED')
|
|
}
|
|
else{
|
|
context.commit("update_current_status",'STATUS_SUCCESS')
|
|
}
|
|
|
|
context.commit("update_msg_info",msg)
|
|
context.commit("update_open_dialog_info",true)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_get_data_status",3)
|
|
}
|
|
},
|
|
async doaction(context,prm) {
|
|
context.commit("update_save_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.doaction(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status",3)
|
|
} else {
|
|
context.commit("update_save_status",2)
|
|
context.commit("update_act",'-')
|
|
context.commit("update_dialog_action",false)
|
|
context.dispatch("search",prm)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_save_status",3)
|
|
}
|
|
},
|
|
async deletephoto(context,prm) {
|
|
context.commit("update_save_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.deletephoto(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status",3)
|
|
} else {
|
|
context.commit("update_save_status",2)
|
|
context.commit("update_act",'-')
|
|
context.commit("update_dialog_confirmation_delete",false)
|
|
context.commit("update_selected_photo",{})
|
|
context.dispatch("search",prm)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_save_status",3)
|
|
}
|
|
},
|
|
async getdoctoraddress(context,prm) {
|
|
context.commit("update_save_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.getdoctoraddress(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status",3)
|
|
} else {
|
|
context.commit("update_save_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_doctor_address",data.records)
|
|
context.commit("update_selected_doctor_address",{})
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_save_status",3)
|
|
}
|
|
}
|
|
}
|
|
} |