Flatten nested repos
This commit is contained in:
134
test/vuex/cpone-card-reader/modules/delivery.js
Normal file
134
test/vuex/cpone-card-reader/modules/delivery.js
Normal file
@@ -0,0 +1,134 @@
|
||||
// 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,
|
||||
mou_id: 0,
|
||||
data_deliveries:[],
|
||||
selected_data_delivery:[],
|
||||
checked_id: []
|
||||
},
|
||||
mutations: {
|
||||
update_data_deliveries(state,value){
|
||||
state.data_deliveries = value
|
||||
},
|
||||
update_selected_data_delivery(state,value){
|
||||
state.selected_data_delivery = value
|
||||
},
|
||||
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 (typeof val.p_id !== 'undefined')
|
||||
state.patient_id = val.p_id;
|
||||
if (typeof val.o_id !== 'undefined')
|
||||
state.order_id = val.o_id;
|
||||
if (typeof val.d_id !== 'undefined')
|
||||
state.doctor_id = val.d_id;
|
||||
if (typeof val.m_id !== 'undefined')
|
||||
state.mou_id = val.m_id;
|
||||
|
||||
|
||||
},
|
||||
update_checked_id(state, val) {
|
||||
state.checked_id = val
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async search(context) {
|
||||
console.log(context.rootState.company.selected_company)
|
||||
context.commit("update_search_status",1)
|
||||
try {
|
||||
let resp= await api.search(context.state.order_id,
|
||||
context.state.patient_id,
|
||||
context.state.doctor_id,
|
||||
context.state.mou_id,
|
||||
context.rootState.company.selected_company.M_CompanyID)
|
||||
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
|
||||
}
|
||||
let deliveries = resp.data.records
|
||||
if(deliveries.length > 0)
|
||||
context.commit("update_deliveries",deliveries)
|
||||
}
|
||||
} catch(e) {
|
||||
context.commit("update_search_status",3)
|
||||
context.commit("update_search_error_message",e.message )
|
||||
}
|
||||
},
|
||||
async search_deliveries(context,prm) {
|
||||
console.log(context.rootState.company.selected_company)
|
||||
context.commit("update_search_status",1)
|
||||
try {
|
||||
prm.token = one_token()
|
||||
let resp= await api.search_deliveries(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
|
||||
}
|
||||
let deliveries = resp.data.records
|
||||
|
||||
var existing_deliveries = context.state.data_deliveries
|
||||
var exclude_type = _.filter(existing_deliveries, function(o) { return o.type !== prm.type })
|
||||
if(deliveries.length > 0){
|
||||
deliveries.forEach(function(delivery) {
|
||||
exclude_type.push(delivery)
|
||||
})
|
||||
}
|
||||
context.commit("update_data_deliveries",exclude_type)
|
||||
|
||||
|
||||
}
|
||||
} catch(e) {
|
||||
context.commit("update_search_status",3)
|
||||
context.commit("update_search_error_message",e.message )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user