56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import * as api from "../api/company.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
loading: false,
|
|
company: { CorporateID : 0 , CorporateName : 'All'},
|
|
companies: [],
|
|
error: '',
|
|
token: {}
|
|
},
|
|
mutations: {
|
|
update_loading(state,status) {
|
|
state.loading= status
|
|
},
|
|
update_company(state,status) {
|
|
state.company= status
|
|
},
|
|
update_companies(state,status) {
|
|
state.companies= status
|
|
},
|
|
update_error(state,status) {
|
|
state.error= status
|
|
},
|
|
update_token(state,status) {
|
|
state.token= status
|
|
},
|
|
},
|
|
actions: {
|
|
async search(context,qry) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let token = context.state.token
|
|
if (token.hasOwnProperty("token")) {
|
|
token.cancel()
|
|
}
|
|
token = axios.CancelToken.source()
|
|
context.commit("update_token",token)
|
|
|
|
let resp= await api.search(one_token(),qry, token.token)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_error", resp.message)
|
|
} else {
|
|
context.commit("update_loading",false)
|
|
context.commit("update_error","")
|
|
context.commit('update_companies',resp.data.data)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_loading",false)
|
|
context.commit("update_error",e.message )
|
|
}
|
|
}
|
|
}
|
|
}
|