269 lines
10 KiB
JavaScript
269 lines
10 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/service.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
staffs:[],
|
|
selected_staff:{},
|
|
liststaff:[],
|
|
selected_liststaff:{},
|
|
listorder: [],
|
|
selected_orders: [],
|
|
current_page: 1,
|
|
total_page: 0,
|
|
errors:[],
|
|
transaction_date:moment(new Date()).format('DD-MM-YYYY'),
|
|
msg_error: '',
|
|
dialog_error: false,
|
|
save_hide: false,
|
|
trx_id:0,
|
|
get_data_status:0,
|
|
save_status: 0,
|
|
dialog_release: false,
|
|
msg_release: ""
|
|
},
|
|
mutations: {
|
|
update_staffs(state, val) {
|
|
state.staffs = val
|
|
},
|
|
update_selected_staff(state, val) {
|
|
state.selected_staff = val
|
|
},
|
|
update_liststaff(state, val) {
|
|
state.liststaff = val
|
|
},
|
|
update_selected_liststaff(state, val) {
|
|
state.officerHeaderDetail = val
|
|
},
|
|
update_deleted_liststaff(state, val) {
|
|
state.liststaff.splice(val, 1)
|
|
},
|
|
update_listorder(state, val) {
|
|
state.listorder = val
|
|
},
|
|
update_selected_orders(state, val) {
|
|
state.selected_orders = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = val
|
|
},
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_msg_error(state, val) {
|
|
state.msg_error = val
|
|
},
|
|
update_dialog_error(state, val) {
|
|
state.dialog_error = val
|
|
},
|
|
update_save_hide(state, val) {
|
|
state.save_hide = val
|
|
},
|
|
update_trx_id(state, val) {
|
|
state.trx_id = val
|
|
},
|
|
update_transaction_date(state, val) {
|
|
state.transaction_date = val
|
|
},
|
|
update_get_data_status(state, val) {
|
|
state.get_data_status = val
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_dialog_release(state, val) {
|
|
state.dialog_release = val
|
|
},
|
|
update_msg_release(state, val) {
|
|
state.msg_release = val
|
|
}
|
|
// end
|
|
},
|
|
actions: {
|
|
async getstaff(context,prm) {
|
|
context.commit("update_get_data_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.getstaff(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_error", resp.message)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_get_data_status",3)
|
|
} else {
|
|
context.commit("update_get_data_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_staffs",data.records)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_get_data_status",3)
|
|
}
|
|
},
|
|
|
|
async getorder(context,prm) {
|
|
context.commit("update_get_data_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.getorder(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_error", resp.message)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_get_data_status",3)
|
|
} else {
|
|
context.commit("update_get_data_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total_page: resp.data.total_page
|
|
}
|
|
context.commit("update_listorder", data.records)
|
|
context.commit("update_total_page", data.total_page)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_get_data_status",3)
|
|
}
|
|
},
|
|
|
|
async saveOrder(context,prm) {
|
|
context.commit("update_save_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.saveOrder(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_error", resp.message)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_save_status",3)
|
|
} else {
|
|
context.commit("update_save_status",2)
|
|
context.commit("update_transaction_date",moment(new Date()).format('DD-MM-YYYY'))
|
|
context.commit("update_listorder",[])
|
|
context.commit("update_selected_orders",[])
|
|
context.commit("update_selected_staff",{})
|
|
context.commit("update_liststaff",[])
|
|
|
|
context.commit("service/update_last_id", resp.data.id,{root:true})
|
|
if (prm.act === "new") {
|
|
var msg = "Pembuatan spk nomor " + resp.data.number + " berhasil dong ..."
|
|
} else {
|
|
var msg = "Perubahan spk nomor " + resp.data.number + " berhasil dong ..."
|
|
}
|
|
context.commit("service/update_msg_success", msg,{root:true})
|
|
context.commit("service/update_dialog_success", true,{root:true})
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_save_status",3)
|
|
}
|
|
},
|
|
|
|
async getorderbyid(context,prm) {
|
|
context.commit("update_get_data_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.getorderbyid(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_error", resp.message)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_get_data_status",3)
|
|
} else {
|
|
context.commit("update_get_data_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total_page: resp.data.total_page
|
|
}
|
|
context.commit("update_listorder", data.records)
|
|
context.commit("update_selected_orders", data.records)
|
|
context.commit("update_total_page", data.total_page)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_get_data_status",3)
|
|
}
|
|
},
|
|
|
|
async getstaffbyid(context,prm) {
|
|
context.commit("update_get_data_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.getstaffbyid(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_error", resp.message)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_get_data_status",3)
|
|
} else {
|
|
context.commit("update_get_data_status",2)
|
|
let data = {
|
|
records : resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_liststaff", data.records)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_get_data_status",3)
|
|
}
|
|
},
|
|
async removeOfficer(context, idx) {
|
|
context.commit('update_deleted_liststaff', idx);
|
|
context.commit("service/update_no_save", 1,{root:true})
|
|
},
|
|
|
|
async releaseOrder(context,prm) {
|
|
context.commit("update_save_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.releaseOrder(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_error", resp.message)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_save_status",3)
|
|
} else {
|
|
context.commit("update_save_status",2)
|
|
context.commit("service/update_last_id", resp.data.id,{root:true})
|
|
var msg = "Release dan register spk nomor " + prm.number + " berhasil dong ..."
|
|
context.commit("service/update_msg_success", msg,{root:true})
|
|
context.commit("service/update_dialog_success", true,{root:true})
|
|
context.commit("update_dialog_release", false)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_save_status",3)
|
|
}
|
|
},
|
|
|
|
async deleteOrder(context,prm) {
|
|
context.commit("update_save_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.deleteOrder(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_msg_error", resp.message)
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_save_status",3)
|
|
} else {
|
|
context.commit("update_save_status",2)
|
|
context.commit("update_transaction_date",moment(new Date()).format('DD-MM-YYYY'))
|
|
context.commit("update_listorder",[])
|
|
context.commit("update_total_page", 0)
|
|
context.commit("update_selected_orders",[])
|
|
context.commit("update_selected_staff",{})
|
|
context.commit("update_liststaff",[])
|
|
|
|
context.commit("service/update_last_id", 0, {root:true})
|
|
var msg = "Data spk nomor " + prm.number + " berhasil dihapus dong ..."
|
|
context.commit("service/update_msg_success", msg,{root:true})
|
|
context.commit("service/update_dialog_success", true,{root:true})
|
|
context.commit("service/update_dialog_confirmation_delete", false, {root:true})
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_save_status",3)
|
|
}
|
|
},
|
|
|
|
// end
|
|
|
|
}
|
|
} |