182 lines
7.4 KiB
JavaScript
182 lines
7.4 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/bahan.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
bahans: [],
|
|
save_status: 0,
|
|
save_error_message: '',
|
|
dialog_form_bahan: false,
|
|
dialog_form_bahan_edit : false,
|
|
lookup_bahan: 0,
|
|
error_name: false,
|
|
error_code: false,
|
|
error_xstationname: false,
|
|
update_error_xstation: false,
|
|
show_all:'N',
|
|
stationnames:[],
|
|
selected_stationname:{},
|
|
errors:[]
|
|
},
|
|
mutations: {
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_error_name(state, val) {
|
|
state.error_name = val
|
|
},
|
|
update_error_code(state, val) {
|
|
state.error_code = val
|
|
},
|
|
update_error_xstationname(state, val) {
|
|
state.error_xstationname = val
|
|
},
|
|
update_error_xstation(state, val) {
|
|
state.error_xstation = val
|
|
},
|
|
update_bahans(state, data) {
|
|
state.bahans = data
|
|
},
|
|
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_form_bahan_edit(state, val) {
|
|
state.dialog_form_bahan_edit = val
|
|
},
|
|
update_stationnames(state, val) {
|
|
state.stationnames = val
|
|
},
|
|
update_selected_stationname(state, val) {
|
|
state.selected_stationname = val
|
|
},
|
|
update_lookup_bahan(state, val) {
|
|
state.lookup_bahan = val
|
|
}
|
|
},
|
|
actions: {
|
|
async save_edit(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.save_edit(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("station/update_save_status", 3, { root: true })
|
|
context.commit("station/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("station/update_save_status", 2, { root: true })
|
|
context.commit("station/update_save_error_message", resp.message, { root: true })
|
|
context.commit("station/update_alert_success", true, { root: true })
|
|
|
|
context.commit("update_dialog_form_bahan_edit", false)
|
|
var msg = "Bahan " + prm.name + " sudah update dong"
|
|
context.commit("station/update_msg_success", msg, { root: true })
|
|
context.commit("station/update_alert_success", true, { root: true })
|
|
context.dispatch("lookup", {
|
|
id: prm.stationid
|
|
})
|
|
}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 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("station/update_save_status", 3, { root: true })
|
|
context.commit("station/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("station/update_save_status", 2, { root: true })
|
|
context.commit("station/update_save_error_message", resp.message, { root: true })
|
|
context.commit("station/update_alert_success", true, { root: true })
|
|
|
|
context.commit("update_dialog_form_bahan", false)
|
|
var msg = "Bahan " + prm.name + " sudah update dong"
|
|
context.commit("station/update_msg_success", msg, { root: true })
|
|
context.commit("station/update_alert_success", true, { root: true })
|
|
context.dispatch("lookup", {
|
|
id: prm.stationid
|
|
})
|
|
}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 lookup(context, prm) {
|
|
context.commit("update_lookup_bahan", 1)
|
|
try {
|
|
let resp = await api.lookup(one_token(),prm.id)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_bahan", 3)
|
|
} else {
|
|
context.commit("update_lookup_bahan", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_bahans", data.records)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_bahan", 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("station/update_save_status", 3, { root: true })
|
|
context.commit("station/update_save_error_message", resp.message, { root: true })
|
|
} else {
|
|
context.commit("station/update_save_status", 2, { root: true })
|
|
context.commit("station/update_save_error_message", resp.message, { root: true })
|
|
context.commit("station/update_alert_success", true, { root: true })
|
|
|
|
//context.commit("update_dialog_form_schedule_promise", false)
|
|
var msg = "Bahan "+prm.name+" dari station " + prm.stationname + " sudah dihapus dong"
|
|
context.commit("station/update_msg_success", msg, { root: true })
|
|
context.commit("station/update_alert_success", true, { root: true })
|
|
context.dispatch("lookup", {
|
|
id: prm.stationid
|
|
})
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
}
|