84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/delivery.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search_status:0,
|
|
search_error_message:'',
|
|
deliveries: [],
|
|
patient_id: 0,
|
|
doctor_id: 0,
|
|
order_id: 0,
|
|
|
|
checked_id: []
|
|
},
|
|
mutations: {
|
|
update_search_error_message(state,status) {
|
|
state.search_error_message = status
|
|
},
|
|
update_search_status(state,status) {
|
|
state.search_status = status
|
|
},
|
|
update_deliveries(state,data) {
|
|
for (var i in data) {
|
|
if (state.checked_id.indexOf(data[i].idx) > -1)
|
|
data[i].selected = true
|
|
else
|
|
data[i].selected = false
|
|
}
|
|
|
|
state.deliveries = data
|
|
},
|
|
update_deliveries_2(state) {
|
|
for (var i in state.deliveries) {
|
|
if (state.checked_id.indexOf(state.deliveries[i].idx) > -1)
|
|
state.deliveries[i].selected = true
|
|
else
|
|
state.deliveries[i].selected = false
|
|
}
|
|
// state.deliveries= data
|
|
},
|
|
update_selected_delivery(state,val) {
|
|
state.selected_delivery=val
|
|
},
|
|
update_params(state, val) {
|
|
if (val.p_id)
|
|
state.patient_id = val.p_id;
|
|
if (val.o_id)
|
|
state.order_id = val.o_id;
|
|
if (val.d_id)
|
|
state.doctor_id = val.d_id;
|
|
},
|
|
update_checked_id(state, val) {
|
|
state.checked_id = val
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
let resp= await api.search(store.state.delivery.order_id,
|
|
store.state.delivery.patient_id,
|
|
store.state.delivery.doctor_id)
|
|
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_deliveries",data.records)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
}
|
|
}
|
|
}
|