137 lines
5.7 KiB
JavaScript
137 lines
5.7 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/rack.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
racks: [],
|
|
save_status: 0,
|
|
save_error_message: '',
|
|
dialog_form_rack: false,
|
|
lookup_rack: 0,
|
|
errors:[],
|
|
samples:[],
|
|
alert_delete:false
|
|
},
|
|
mutations: {
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_samples(state, val) {
|
|
state.samples = val
|
|
},
|
|
update_racks(state, data) {
|
|
state.racks = data
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_save_error_message(state, val) {
|
|
state.save_error_message = val
|
|
},
|
|
update_dialog_form_rack(state, val) {
|
|
state.dialog_form_rack = val
|
|
console.log(state.dialog_form_schedule_promise)
|
|
},
|
|
update_lookup_rack(state, val) {
|
|
state.lookup_rack = val
|
|
},
|
|
update_alert_delete(state, val) {
|
|
state.alert_delete = val
|
|
}
|
|
},
|
|
actions: {
|
|
async save(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.save(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("almari/update_save_status", 3, { root: true })
|
|
context.commit("almari/update_save_error_message", resp.message, { root: true })
|
|
} else {
|
|
var data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
if(data.total !== -1){
|
|
context.commit("almari/update_save_status", 2, { root: true })
|
|
context.commit("almari/update_save_error_message", resp.message, { root: true })
|
|
context.commit("almari/update_alert_success", true, { root: true })
|
|
context.commit("update_dialog_form_rack", false)
|
|
//context.commit("update_alert_delete", false)
|
|
var msg = "Lemari " + prm.almariname + " sudah update dong"
|
|
context.commit("almari/update_msg_success", msg, { root: true })
|
|
context.commit("almari/update_alert_success", true, { root: true })
|
|
context.dispatch("lookup", {
|
|
id: prm.almariid
|
|
})
|
|
}else{
|
|
context.commit("update_errors", resp.data.errors)
|
|
context.commit("update_samples", resp.data.samples)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async lookup(context, prm) {
|
|
context.commit("update_lookup_rack", 1)
|
|
try {
|
|
let resp = await api.lookup(one_token(),prm.id)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_rack", 3)
|
|
} else {
|
|
context.commit("update_lookup_rack", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_racks", data.records)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_rack", 3)
|
|
}
|
|
},
|
|
async delete(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
let resp = await api.xdelete(one_token(),prm.xid)
|
|
if (resp.status != "OK") {
|
|
context.commit("almari/update_save_status", 3, { root: true })
|
|
context.commit("almari/update_save_error_message", resp.message, { root: true })
|
|
} else {
|
|
var data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
if(data.total !== -1){
|
|
context.commit("almari/update_save_status", 2, { root: true })
|
|
context.commit("almari/update_save_error_message", resp.message, { root: true })
|
|
context.commit("almari/update_alert_success", true, { root: true })
|
|
context.commit("update_alert_delete", false)
|
|
//context.commit("update_dialog_form_schedule_promise", false)
|
|
var msg = "Rak "+prm.name+" dari almari " + prm.almariname + " sudah dihapus dong"
|
|
context.commit("almari/update_msg_success", msg, { root: true })
|
|
context.commit("almari/update_alert_success", true, { root: true })
|
|
context.dispatch("lookup", {
|
|
id: prm.almariid
|
|
})
|
|
}
|
|
else{
|
|
context.commit("update_errors", resp.data.errors)
|
|
context.commit("update_samples", resp.data.samples)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
} |