350 lines
11 KiB
JavaScript
350 lines
11 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/priceref.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
|
|
search_status: 0,
|
|
search_error_message: '',
|
|
|
|
companies: [],
|
|
selected_company: {},
|
|
total_company: 0,
|
|
|
|
query_mou: '',
|
|
mous: [],
|
|
selected_mou: {},
|
|
total_mou: 0,
|
|
|
|
query_price: '',
|
|
prices: [],
|
|
selected_price: {},
|
|
total_price: 0,
|
|
new_price: {amount:0, start_date:null, end_date:null},
|
|
edit_price: false,
|
|
|
|
query_px: '',
|
|
pxs: [],
|
|
selected_px: {},
|
|
total_px: 0,
|
|
|
|
query_addon: '',
|
|
addons: [],
|
|
selected_addon: {},
|
|
total_addon: 0,
|
|
new_addon_name: '',
|
|
|
|
// others: [{id:1, name:'Jasa Dokter', price:10000}, {id:2, name:'Lain - lain', price:5000}],
|
|
others: [],
|
|
selected_other: {},
|
|
total_other: 0,
|
|
|
|
dialog_px_new: false,
|
|
dialog_addon_new: false,
|
|
|
|
refresh_date: false
|
|
},
|
|
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_companies(state, d) {
|
|
state.companies = d.records
|
|
state.total_company = d.total
|
|
},
|
|
|
|
update_selected_company(state, d) {
|
|
state.selected_company = d
|
|
},
|
|
|
|
// PRICE
|
|
update_query_price(state, q) {
|
|
state.query_price = q
|
|
},
|
|
|
|
update_prices(state, d) {
|
|
state.prices = d.records
|
|
state.total_price = d.total
|
|
},
|
|
|
|
update_selected_price(state, d) {
|
|
state.selected_price = d
|
|
},
|
|
|
|
update_new_price(state, d) {
|
|
state.new_price = d
|
|
},
|
|
|
|
update_edit_price(state, d) {
|
|
state.edit_price = d
|
|
},
|
|
|
|
// PX
|
|
update_query_px(state, q) {
|
|
state.query_px = q
|
|
},
|
|
|
|
update_pxs(state, d) {
|
|
state.pxs = d.records
|
|
state.total_px = d.total
|
|
},
|
|
|
|
update_selected_px(state, d) {
|
|
state.selected_px = d
|
|
},
|
|
|
|
// ADDON
|
|
update_addons(state, d) {
|
|
state.addons = d.records
|
|
state.total_addon = d.total
|
|
},
|
|
|
|
update_selected_addon(state, d) {
|
|
state.selected_addon = d
|
|
},
|
|
|
|
// OTHER
|
|
update_others(state, d) {
|
|
state.others = d.records
|
|
state.total_other = d.total
|
|
},
|
|
|
|
update_selected_other(state, d) {
|
|
state.selected_other = d
|
|
},
|
|
|
|
add_other(state) {
|
|
let x = state.selected_addon
|
|
let y = state.others
|
|
y.push({id:x.T_AddonID, name:x.T_AddonName, price:0})
|
|
|
|
state.others = y
|
|
},
|
|
|
|
remove_other(state, item) {
|
|
// console.log('np')
|
|
// console.log(state.new_price)
|
|
|
|
let x = state.others
|
|
for (let i in x)
|
|
if (x[i].id == item.id)
|
|
{
|
|
x.splice(i, 1)
|
|
// x[i].disabled = true
|
|
let y = state.new_price
|
|
// console.log('y1')
|
|
// console.log(y)
|
|
|
|
|
|
y.other = Math.round(y.other) - Math.round(item.price)
|
|
y.total = Math.round(y.sub_total) + Math.round(y.other)
|
|
|
|
|
|
state.new_price = y
|
|
}
|
|
|
|
state.others = x
|
|
},
|
|
|
|
update_other_price(state, d) {
|
|
let x = state.others
|
|
x[d.idx].price = d.price
|
|
|
|
state.others = x
|
|
let y = state.new_price
|
|
y.other = 0
|
|
for (let i in state.others)
|
|
y.other = Math.round(y.other) + Math.round(state.others[i].price)
|
|
|
|
y.total = Math.round(y.sub_total) + Math.round(y.other)
|
|
state.new_price = y
|
|
|
|
},
|
|
|
|
update_search_status(state, val) {
|
|
state.search_status = val
|
|
},
|
|
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
|
|
update_dialog_px_new(state, val) {
|
|
state.dialog_px_new = val
|
|
},
|
|
|
|
update_dialog_addon_new(state, val) {
|
|
state.dialog_addon_new = val
|
|
},
|
|
|
|
update_new_addon_name(state, val) {
|
|
state.new_addon_name = val
|
|
},
|
|
|
|
update_refresh_date(state, val) {
|
|
state.refresh_date = val
|
|
}
|
|
},
|
|
actions: {
|
|
async search_company(context) {
|
|
|
|
try {
|
|
let resp = await api.search_company(one_token())
|
|
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_price(context) {
|
|
|
|
try {
|
|
let resp = await api.search_price(one_token(), context.state.selected_mou.M_MouID, context.state.query_price)
|
|
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_prices", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async del_price(context, id) {
|
|
|
|
try {
|
|
let resp = await api.del_price(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_price')
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async search_px(context) {
|
|
|
|
try {
|
|
let resp = await api.search_px(one_token(), context.state.query_px)
|
|
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_pxs", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async save_px(context, price_id) {
|
|
|
|
try {
|
|
let c = context.state.new_price
|
|
let data = {
|
|
test_id: context.state.selected_px.T_TestID,
|
|
mou_id: context.state.selected_mou.M_MouID,
|
|
price: c.amount,
|
|
start_date: c.start_date,
|
|
end_date: c.end_date
|
|
}
|
|
if (price_id) data.id = price_id
|
|
|
|
let resp = await api.save_px(one_token(), JSON.stringify(data))
|
|
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_price")
|
|
context.commit("update_dialog_px_new", false)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
}
|
|
}
|
|
}
|
|
} |