190 lines
7.2 KiB
JavaScript
190 lines
7.2 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/fisik.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
last_id: -1,
|
|
current_page: 1,
|
|
lookup_fisik: 0,
|
|
lookup_error_message: '',
|
|
fisiks: [],
|
|
total_fisiks: 0,
|
|
total_filter_fisiks: 0,
|
|
selected_fisik: {},
|
|
x_search: '',
|
|
dialog_fisik: false,
|
|
act: 'new',
|
|
save_status: 2,
|
|
loading_save: false,
|
|
error_message: "",
|
|
alert_error: false,
|
|
dialog_error: false,
|
|
msg_success: "",
|
|
alert_success: false,
|
|
},
|
|
mutations: {
|
|
update_lookup_fisik(state, status) {
|
|
state.lookup_fisik = status
|
|
},
|
|
update_lookup_error_message(state, status) {
|
|
state.lookup_error_message = status
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
},
|
|
update_fisiks(state, data) {
|
|
state.fisiks = data.records
|
|
state.total_fisiks = data.total
|
|
state.total_filter_fisiks = data.total_filter
|
|
},
|
|
update_selected_fisik(state, val) {
|
|
state.selected_fisik = val
|
|
},
|
|
update_x_search(state, val) {
|
|
state.x_search = val
|
|
},
|
|
update_dialog_fisik(state, val) {
|
|
state.dialog_fisik = val
|
|
},
|
|
update_act(state, val) {
|
|
state.act = val
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_loading_save(state, val) {
|
|
state.loading_save = val
|
|
},
|
|
update_error_message(state, val) {
|
|
state.error_message = val
|
|
},
|
|
update_alert_error(state, val) {
|
|
state.alert_error = val;
|
|
},
|
|
update_dialog_error(state, val) {
|
|
state.dialog_error = val
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val;
|
|
},
|
|
},
|
|
actions: {
|
|
async lookupbyname(context, prm) {
|
|
context.commit("update_lookup_fisik", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.lookupbyname(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_fisik", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_fisik", 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_fisiks", data)
|
|
if (prm.lastid === -1) {
|
|
var pat = data.records[0]
|
|
console.log("pat", data.records)
|
|
context.commit("update_selected_fisik", data.records[0])
|
|
// console.log(prm.user)
|
|
context.dispatch("fisikdetail/lookup", {
|
|
id: pat.id,
|
|
code: '',
|
|
name: '',
|
|
current_page: 1,
|
|
lastid: -1
|
|
}, {
|
|
root: true
|
|
})
|
|
// if (prm.user != "") {
|
|
// context.dispatch("fisikdetail/lookup", {
|
|
// id: pat.id,
|
|
// code: '',
|
|
// name: '',
|
|
// current_page: 1,
|
|
// lastid: -1
|
|
// }, {
|
|
// root: true
|
|
// })
|
|
// }
|
|
}else{
|
|
var pat = data.records[prm.lastid]
|
|
context.commit("update_selected_fisik", data.records[prm.lastid])
|
|
context.dispatch("fisikdetail/lookup", {
|
|
id: pat.id,
|
|
code: '',
|
|
name: '',
|
|
current_page: 1,
|
|
lastid: -1
|
|
}, {
|
|
root: true
|
|
})
|
|
// if (prm.user != "") {
|
|
// context.dispatch("fisikdetail/lookup", {
|
|
// id: pat.id,
|
|
// code: '',
|
|
// name: '',
|
|
// current_page: 1,
|
|
// lastid: -1
|
|
// }, {
|
|
// root: true
|
|
// })
|
|
// }
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_fisik", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
},
|
|
|
|
async addfisik(context, prm) {
|
|
context.commit("update_save_status", 1)
|
|
try {
|
|
context.commit("update_loading_save", true)
|
|
prm.token = one_token()
|
|
let resp = await api.addfisik(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status", 3)
|
|
context.commit("update_loading_save", false)
|
|
context.commit("update_error_message", resp.message)
|
|
context.commit("update_alert_error", true)
|
|
context.commit("update_dialog_error", true)
|
|
} else {
|
|
context.commit("update_save_status", 2)
|
|
context.commit("update_loading_save", false)
|
|
context.commit("update_error_message", "")
|
|
context.commit("update_dialog_error", false)
|
|
let data = resp.data
|
|
var msg = "Fisik template " + prm.name + " berhasil disimpan"
|
|
context.commit("update_msg_success", msg)
|
|
context.commit("update_alert_success", true)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_dialog_fisik", false)
|
|
context.dispatch("lookupbyname",{
|
|
fisikname: "",
|
|
current_page: 1,
|
|
lastid: -1
|
|
})
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading_save", false)
|
|
context.commit("update_error_message", e.message)
|
|
context.commit("update_alert_error", true)
|
|
}
|
|
},
|
|
}
|
|
} |