261 lines
8.5 KiB
JavaScript
261 lines
8.5 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/packet.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
|
|
search_status: 0,
|
|
search_error_message: '',
|
|
|
|
query_company: '',
|
|
companies: [],
|
|
selected_company: {},
|
|
total_company: 0,
|
|
default_company: {},
|
|
|
|
query_mou: '',
|
|
mous: [],
|
|
selected_mou: null,
|
|
total_mou: 0,
|
|
default_mou: {},
|
|
|
|
query_packet: '',
|
|
packets: [],
|
|
selected_packet: null,
|
|
total_packet: 0,
|
|
new_packet: {amount:0, disc:0, discrp:0, sub_total:0, other:0, total:0, cito:'N'},
|
|
edit_packet: false,
|
|
|
|
query_addon: '',
|
|
addons: [],
|
|
selected_addon: {},
|
|
total_addon: 0,
|
|
new_addon_name: '',
|
|
|
|
// others: [{id:1, name:'Jasa Dokter', packet:10000}, {id:2, name:'Lain - lain', packet:5000}],
|
|
others: [],
|
|
selected_other: {},
|
|
total_other: 0,
|
|
|
|
dialog_px_new: false,
|
|
dialog_addon_new: false,
|
|
dialog_packet: false,
|
|
|
|
auto_selected_packet_id: 0
|
|
},
|
|
mutations: {
|
|
|
|
update_search_error_message(state, patient) {
|
|
state.search_error_message = patient
|
|
},
|
|
|
|
// MOU
|
|
update_query_mou(state, q) {
|
|
state.query_mou = q
|
|
},
|
|
|
|
update_mous(state, d) {
|
|
state.mous = d.records
|
|
state.total_mou = d.total
|
|
},
|
|
|
|
update_selected_mou(state, d) {
|
|
state.selected_mou = d
|
|
},
|
|
|
|
// COMPANY
|
|
update_query_company(state, q) {
|
|
state.query_company = q
|
|
},
|
|
|
|
update_companies(state, d) {
|
|
state.companies = d.records
|
|
state.total_company = d.total
|
|
},
|
|
|
|
update_selected_company(state, d) {
|
|
state.selected_company = d
|
|
|
|
// update mous
|
|
if (d) {
|
|
state.mous = d.mou
|
|
state.selected_mou = {}
|
|
state.total_mou = d.mou.length
|
|
} else {
|
|
state.mous = []
|
|
state.selected_mou = {}
|
|
state.total_mou = 0
|
|
}
|
|
|
|
},
|
|
|
|
// PRICE
|
|
update_query_packet(state, q) {
|
|
state.query_packet = q
|
|
},
|
|
|
|
update_packets(state, d) {
|
|
state.packets = d.records
|
|
state.total_packet = d.total
|
|
},
|
|
|
|
update_selected_packet(state, d) {
|
|
state.selected_packet = d
|
|
},
|
|
|
|
update_new_packet(state, d) {
|
|
state.new_packet = d
|
|
},
|
|
|
|
update_edit_packet(state, d) {
|
|
state.edit_packet = d
|
|
},
|
|
|
|
update_search_status(state, val) {
|
|
state.search_status = val
|
|
},
|
|
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
|
|
update_dialog_packet(state, val) {
|
|
state.dialog_packet = val
|
|
},
|
|
|
|
update_default_mou(state, val) {
|
|
state.default_mou = val
|
|
},
|
|
|
|
update_default_company(state, val) {
|
|
state.default_company = val
|
|
},
|
|
|
|
update_auto_selected_packet_id(state, val) {
|
|
state.auto_selected_packet_id = val
|
|
}
|
|
},
|
|
actions: {
|
|
async search_company(context) {
|
|
|
|
try {
|
|
let resp = await api.search_company(one_token(), context.state.query_company)
|
|
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_mou(context) {
|
|
|
|
try {
|
|
let resp = await api.search_mou(one_token(), context.state.selected_company.M_CompanyID, context.state.query_mou)
|
|
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_mous", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async search_default_mou(context) {
|
|
|
|
try {
|
|
let resp = await api.search_default_mou()
|
|
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", "")
|
|
|
|
context.commit('update_default_mou', resp.data.mou)
|
|
context.commit('update_default_company', resp.data.company)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async search_packet(context) {
|
|
|
|
try {
|
|
let resp = await api.search_packet(one_token(), context.state.selected_mou.M_MouID, context.state.selected_type, context.state.query_packet)
|
|
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_packets", data)
|
|
|
|
// Auto selected after save
|
|
if (context.state.auto_selected_packet_id) {
|
|
for(let i in data.records)
|
|
if (data.records[i].T_PacketID == context.state.auto_selected_packet_id) {
|
|
context.commit('update_selected_packet', data.records[i])
|
|
context.dispatch('px/search_px', null, {root:true})
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async del_packet(context, id) {
|
|
|
|
try {
|
|
let resp = await api.del_packet(one_token(), 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", "")
|
|
|
|
context.dispatch('search_packet')
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
}
|
|
}
|
|
} |