86 lines
2.8 KiB
JavaScript
86 lines
2.8 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/company.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search_status: 0,
|
|
search_error_message: '',
|
|
|
|
query: '',
|
|
companies: [],
|
|
selected_company: {},
|
|
total_company: 0,
|
|
total_company_page: 0,
|
|
curr_company_page: 1,
|
|
|
|
is_internal: "N"
|
|
},
|
|
mutations: {
|
|
|
|
update_search_error_message(state, patient) {
|
|
state.search_error_message = patient
|
|
},
|
|
|
|
update_search_status(state, v) {
|
|
state.search_status = v
|
|
},
|
|
|
|
update_query(state, q) {
|
|
state.query = q
|
|
},
|
|
|
|
update_companies(state, d) {
|
|
state.companies = d.records
|
|
state.total_company = d.total
|
|
state.total_company_page = d.total_page
|
|
},
|
|
|
|
update_selected_company(state, d) {
|
|
state.selected_company = d
|
|
},
|
|
|
|
update_curr_company_page(state, d) {
|
|
state.curr_company_page = d
|
|
},
|
|
|
|
update_is_internal(state, d) {
|
|
state.is_internal = d
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context) {
|
|
|
|
try {
|
|
let resp = await api.search(context.state.query, context.state.is_internal, context.state.curr_company_page)
|
|
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,
|
|
total: resp.data.total,
|
|
total_page: resp.data.total_page
|
|
}
|
|
|
|
context.commit('patient/update_patients', {records:[],total:0,total_page:0}, {root:true})
|
|
context.commit('patient/update_curr_patient_page', 1, {root:true})
|
|
try {
|
|
context.commit('update_selected_company', data.records[0])
|
|
context.commit('patient/update_selected_order', [], {root:true})
|
|
context.dispatch('patient/search', null, {root:true})
|
|
} catch(ee) {}
|
|
context.commit("update_companies", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
}
|
|
}
|
|
} |