169 lines
7.1 KiB
JavaScript
169 lines
7.1 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/nattestlang.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
nattestlangs: [],
|
|
save_status: 0,
|
|
save_error_message: '',
|
|
dialog_form_nattestlang: false,
|
|
lookup_nattestlang: 0,
|
|
lookupnattestlang: 0,
|
|
errors:[],
|
|
startdate:moment(new Date()).format('YYYY-MM-DD'),
|
|
enddate:moment(new Date()).format('YYYY-MM-DD')
|
|
},
|
|
mutations: {
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_nattestlangs(state, data) {
|
|
state.nattestlangs = data
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_save_error_message(state, val) {
|
|
state.save_error_message = val
|
|
},
|
|
update_dialog_form_nattestlang(state, val) {
|
|
state.dialog_form_nattestlang = val
|
|
},
|
|
update_lookup_nattestlang(state, val) {
|
|
state.lookup_nattestlang = val
|
|
},
|
|
update_lookupnattestlang(state, val) {
|
|
state.lookupnattestlang = val
|
|
},
|
|
update_startdate(state,val){
|
|
state.startdate = val
|
|
},
|
|
update_enddate(state,val){
|
|
state.enddate = 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("nattest/update_save_status", 3, { root: true })
|
|
context.commit("nattest/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("nattest/update_save_status", 2, { root: true })
|
|
context.commit("nattest/update_save_error_message", resp.message, { root: true })
|
|
context.commit("nattest/update_alert_success", true, { root: true })
|
|
|
|
context.commit("update_dialog_form_nattestlang", false)
|
|
var msg = "Bahan " + prm.nattestname + " sudah update dong"
|
|
context.commit("nattest/update_msg_success", msg, { root: true })
|
|
context.commit("nattest/update_alert_success", true, { root: true })
|
|
context.dispatch("lookup", {
|
|
id: prm.nattestid
|
|
})
|
|
}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_nattestlang", 1)
|
|
try {
|
|
let resp = await api.lookup(one_token(),prm.id)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_nattestlang", 3)
|
|
} else {
|
|
context.commit("update_lookup_nattestlang", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_nattestlangs", data.records)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_nattestlang", 3)
|
|
}
|
|
},
|
|
async lookupnattestlang(context, prm) {
|
|
context.commit("update_lookupnattestlang", 1)
|
|
try {
|
|
let resp = await api.lookupnattestlang(one_token(),prm.id,prm.search, prm.current_page)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookupnattestlang", 3)
|
|
} else {
|
|
context.commit("update_lookupnattestlang", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("nattest/update_nattests", data, { root: true })
|
|
// context.commit("nattest/update_shownattests", data, { root: true })
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookupnattestlang", 3)
|
|
}
|
|
},
|
|
async lookupnattestlanghide(context, prm) {
|
|
context.commit("update_lookupnattestlang", 1)
|
|
try {
|
|
let resp = await api.lookupnattestlanghide(one_token(),prm.id,prm.search, prm.current_page)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookupnattestlang", 3)
|
|
} else {
|
|
context.commit("update_lookupnattestlang", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("nattest/update_nattests", data, { root: true })
|
|
// context.commit("nattest/update_shownattests", data, { root: true })
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookupnattestlang", 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("nattest/update_save_status", 3, { root: true })
|
|
context.commit("nattest/update_save_error_message", resp.message, { root: true })
|
|
} else {
|
|
context.commit("nattest/update_save_status", 2, { root: true })
|
|
context.commit("nattest/update_save_error_message", resp.message, { root: true })
|
|
context.commit("nattest/update_alert_success", true, { root: true })
|
|
|
|
//context.commit("update_dialog_form_schedule_promise", false)
|
|
var msg = "Mou "+prm.name+" dari nattest " + prm.nattestname + " sudah dihapus dong"
|
|
context.commit("nattest/update_msg_success", msg, { root: true })
|
|
context.commit("nattest/update_alert_success", true, { root: true })
|
|
context.dispatch("lookup", {
|
|
id: prm.nattestid
|
|
})
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_save_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
} |