121 lines
3.6 KiB
JavaScript
121 lines
3.6 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/doctor.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search : '',
|
|
search_status: 0,
|
|
search_error_message: "",
|
|
doctors: [],
|
|
total_doctor: 0,
|
|
selected_doctor: {},
|
|
selected_address: {},
|
|
|
|
doctors_pj: [],
|
|
selected_doctor_pj : {},
|
|
search_pj_status: 0,
|
|
search_pj_error_message: "",
|
|
|
|
mounted: 0
|
|
},
|
|
mutations: {
|
|
update_search(state,val) {
|
|
state.search=val
|
|
},
|
|
update_search_error_message(state,status) {
|
|
state.search_error_message = status
|
|
},
|
|
update_search_status(state,status) {
|
|
state.search_status = status
|
|
},
|
|
update_doctors(state,data) {
|
|
state.doctors = data.records
|
|
state.total_doctor= data.total
|
|
},
|
|
update_selected_doctor(state,doc) {
|
|
state.selected_doctor= doc
|
|
|
|
if (!doc) return
|
|
if (doc.address.length> 0) {
|
|
state.selected_address = doc.address[0]
|
|
} else {
|
|
state.selected_address = {}
|
|
}
|
|
},
|
|
update_selected_address(state,addr) {
|
|
state.selected_address = addr
|
|
},
|
|
update_search_pj_error_message(state,status) {
|
|
state.search_pj_error_message = status
|
|
},
|
|
update_search_pj_status(state,status) {
|
|
state.search_pj_status = status
|
|
},
|
|
update_doctors_pj(state,data) {
|
|
state.doctors_pj = data.records
|
|
let flag_found = false
|
|
data.records.forEach(function(d) {
|
|
if (d.M_DoctorIsDefaultPJ == 'Y' ) {
|
|
state.selected_doctor_pj = d
|
|
flag_found = true
|
|
}
|
|
})
|
|
if (! flag_found & data.records.length > 0 ) state.selected_doctor_pj = data.records[0]
|
|
},
|
|
update_selected_doctor_pj(state,doc) {
|
|
state.selected_doctor_pj = doc
|
|
},
|
|
|
|
increment_mounted(state, n) {
|
|
state.mounted = state.mounted + n;
|
|
}
|
|
},
|
|
actions: {
|
|
async search_pj(context) {
|
|
context.commit("update_search_pj_status",1)
|
|
try {
|
|
let resp= await api.searchPj()
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_pj_status",3)
|
|
context.commit("update_search_pj_error_message",resp.message)
|
|
} else {
|
|
context.commit("update_search_pj_status",2)
|
|
context.commit("update_search_pj_error_message","")
|
|
let data = {
|
|
total : resp.data.total,
|
|
records : resp.data.records
|
|
}
|
|
context.commit("update_doctors_pj",data)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_pj_status",3)
|
|
context.commit("update_search_pj_error_message",e.message )
|
|
}
|
|
},
|
|
async search(context) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
let resp= await api.search(context.state.search)
|
|
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 = {
|
|
total : resp.data.total,
|
|
records : resp.data.records
|
|
}
|
|
context.commit("update_doctors",data)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
}
|
|
}
|
|
}
|