195 lines
6.5 KiB
JavaScript
195 lines
6.5 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/company.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search: '',
|
|
search_status:0,
|
|
search_error_message:'',
|
|
companies: [],
|
|
total_company: 0,
|
|
selected_company: {},
|
|
selected_mou: {},
|
|
selected_px_tab: 'px',
|
|
show_alias_doctor:false,
|
|
order_companies:[],
|
|
projects:[],
|
|
selected_project:{},
|
|
is_loading_project:false,
|
|
fisik_templates:[],
|
|
selected_fisik_template:{},
|
|
is_loading_fisik_template:false
|
|
},
|
|
mutations: {
|
|
update_is_loading_fisik_template(state,val) {
|
|
state.is_loading_fisik_template = val
|
|
},
|
|
update_fisik_templates(state,val) {
|
|
state.fisik_templates = val
|
|
},
|
|
update_selected_fisik_template(state,val) {
|
|
if(val === null || val === undefined || (typeof val === 'object' && Object.keys(val).length === 0 && val.constructor === Object)) {
|
|
state.selected_fisik_template = {}
|
|
} else {
|
|
state.selected_fisik_template = val
|
|
}
|
|
},
|
|
update_is_loading_project(state,val) {
|
|
state.is_loading_project = val
|
|
},
|
|
update_selected_project(state,val) {
|
|
state.selected_project = val
|
|
},
|
|
update_projects(state,val) {
|
|
state.projects = val
|
|
},
|
|
update_order_companies(state,val) {
|
|
state.order_companies = val
|
|
},
|
|
update_show_alias_doctor(state,tab) {
|
|
state.show_alias_doctor = tab
|
|
},
|
|
update_selected_px_tab(state,tab) {
|
|
state.selected_px_tab = tab
|
|
},
|
|
update_search_error_message(state,status) {
|
|
state.search_error_message = status
|
|
},
|
|
update_selected_mou(state,val) {
|
|
state.selected_mou = val
|
|
},
|
|
update_search(state,val) {
|
|
state.search=val
|
|
},
|
|
update_search_status(state,status) {
|
|
state.search_status = status
|
|
},
|
|
update_companies(state,data) {
|
|
state.companies= data.records
|
|
state.total_company= data.total
|
|
},
|
|
update_selected_company(state,val) {
|
|
state.selected_company=val
|
|
},
|
|
|
|
reset_company(state) {
|
|
state.companies = []
|
|
state.total_company = 0
|
|
state.search = ""
|
|
state.selected_company = {}
|
|
state.selected_mou = {}
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
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 = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_companies",data)
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
async search_project(context, prm) {
|
|
context.commit("update_is_loading_project",true)
|
|
try {
|
|
prm.token = window.one_token()
|
|
let resp= await api.search_project(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_is_loading_project",false)
|
|
context.commit("update_search_error_message",resp.message)
|
|
} else {
|
|
context.commit("update_is_loading_project",false)
|
|
context.commit("update_search_error_message","")
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_projects",data.records)
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_is_loading_project",false)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
|
|
async search_fisik_template(context, prm) {
|
|
context.commit("update_is_loading_fisik_template",true)
|
|
try {
|
|
prm.token = window.one_token()
|
|
let resp= await api.search_fisik_template(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_is_loading_fisik_template",false)
|
|
context.commit("update_search_error_message",resp.message)
|
|
} else {
|
|
context.commit("update_is_loading_fisik_template",false)
|
|
context.commit("update_search_error_message","")
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_fisik_templates",data.records)
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_is_loading_fisik_template",false)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
|
|
async search_default(context) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
let resp= await api.search_default()
|
|
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
|
|
}
|
|
context.commit("update_companies", data)
|
|
context.commit("update_selected_company", data.records[0])
|
|
|
|
for(let i in data.records[0].mou) {
|
|
let cmou = data.records[0].mou[i]
|
|
if (cmou.M_MouIsDefault == "Y") {
|
|
context.commit("update_selected_mou", cmou)
|
|
context.dispatch("delivery/search_deliveries", {type:'mou',id:cmou.M_MouID}, {root:true})
|
|
}
|
|
|
|
}
|
|
|
|
// search px
|
|
console.log("mulai search")
|
|
context.dispatch('px/search', null, {root:true})
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
}
|
|
}
|
|
}
|