198 lines
7.9 KiB
JavaScript
198 lines
7.9 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/listing.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
act:'new',
|
|
lookup_bahan: 0,
|
|
lookup_error_message: '',
|
|
bahans: [],
|
|
total_bahans: 0,
|
|
total_filter_bahans: 0,
|
|
selected_bahan: { name: "[ Belum memilih Bahan ]" },
|
|
save_status: 0,
|
|
save_error_message: '',
|
|
dialog_form_bahan: false,
|
|
dialog_edit_form_bahan:false,
|
|
alert_success: false,
|
|
msg_success: "",
|
|
show_all:'N',
|
|
errors:[]
|
|
},
|
|
mutations: {
|
|
update_act(state, val) {
|
|
state.act = val
|
|
},
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_show_all(state, val) {
|
|
state.show_all = val
|
|
},
|
|
update_lookup_error_message(state, status) {
|
|
state.lookup_error_message = status
|
|
},
|
|
update_lookup_bahan(state, status) {
|
|
state.lookup_bahan = status
|
|
},
|
|
update_bahans(state, data) {
|
|
state.bahans = data.records
|
|
state.total_bahans = data.total
|
|
state.total_filter_bahans = data.total_filter
|
|
},
|
|
update_selected_bahan(state, val) {
|
|
state.selected_bahan = val
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_save_error_message(state, val) {
|
|
state.save_error_message = val
|
|
},
|
|
update_dialog_form_bahan(state, val) {
|
|
state.dialog_form_bahan = val
|
|
},
|
|
update_dialog_edit_form_bahan(state, val) {
|
|
state.dialog_edit_form_bahan = val
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
}
|
|
|
|
},
|
|
actions: {
|
|
async lookup(context, prm) {
|
|
context.commit("update_lookup_bahan", 1)
|
|
try {
|
|
let resp = await api.lookup(one_token(), prm.search, prm.all)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_bahan", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_bahan", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("update_bahans", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_bahan", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
},
|
|
async save(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
context.commit("update_error_code", false)
|
|
context.commit("update_error_name", false)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.save(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_save_error_message", resp.message)
|
|
context.commit("update_save_error_message", resp.message)
|
|
var data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
|
|
if(data.total !== -1){
|
|
context.commit("update_errors",[])
|
|
context.commit("update_alert_success", true)
|
|
context.commit("update_dialog_form_bahan", false)
|
|
var msg = "Bahan " + prm.name + " sudah tersimpan dong ..."
|
|
context.commit("update_msg_success", msg)
|
|
context.dispatch("lookup", { search: "" , all:context.show_all})
|
|
}else{
|
|
context.commit("update_errors", resp.data.errors)
|
|
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async update(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
context.commit("update_error_code", false)
|
|
context.commit("update_error_name", false)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.update(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_save_error_message", resp.message)
|
|
context.commit("update_save_error_message", resp.message)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
|
|
if(data.total !== -1){
|
|
context.commit("update_error_code", false)
|
|
context.commit("update_error_name", false)
|
|
context.commit("update_alert_success", true)
|
|
context.commit("update_dialog_form_bahan", false)
|
|
var msg = "Bahan " + prm.name + " sudah terupdate dong ..."
|
|
context.commit("update_msg_success", msg)
|
|
context.dispatch("lookup", { search: "" , all:context.show_all})
|
|
}else{
|
|
if(resp.data.errorcode === 'Y'){
|
|
context.commit("update_error_code", true)
|
|
}
|
|
if(resp.data.errorname === 'Y'){
|
|
context.commit("update_error_name", true)
|
|
}
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async delete(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
let resp = await api.xdelete(one_token(),prm.bahanid)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_save_error_message", resp.message)
|
|
context.commit("update_alert_success", true)
|
|
|
|
var msg = "Schedule " + prm.bahanname + " sudah dihapus dong"
|
|
context.commit("update_msg_success", msg)
|
|
context.commit("update_alert_success", true)
|
|
context.commit("update_selected_bahan", {})
|
|
context.dispatch("lookup", { search: "" })
|
|
context.commit("sampletype/update_bahan_sampletype", [], { root: true })
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
} |