Initial import
This commit is contained in:
272
one-ui/system/one-inject-price/modules/holiday.js
Normal file
272
one-ui/system/one-inject-price/modules/holiday.js
Normal file
@@ -0,0 +1,272 @@
|
||||
// 1 => LOADING
|
||||
// 2 => DONE
|
||||
// 3 => ERROR
|
||||
import * as api from "../api/holiday.js"
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
couriers: [],
|
||||
type: [],
|
||||
selectedType: '',
|
||||
loading: false,
|
||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
yearFilter: moment(new Date()).format('YYYY'),
|
||||
year: moment(new Date()).format('YYYY'),
|
||||
name: "",
|
||||
curr_page: 1,
|
||||
total: 0,
|
||||
error_dialog: false,
|
||||
error_message: "",
|
||||
is_courier: [],
|
||||
snackbar: false,
|
||||
snackbar_msg: "",
|
||||
holidays: [],
|
||||
dialogForm: false,
|
||||
name: '',
|
||||
desc: '',
|
||||
selectedHoliday: {},
|
||||
dialog_delete: false
|
||||
// selected_courier: {},
|
||||
// current_page: 1,
|
||||
// last_id: -1,
|
||||
// x_search: "",
|
||||
// search_status: 0,
|
||||
|
||||
// // dropdown courier
|
||||
// namecouriers: [],
|
||||
// namecourier: {},
|
||||
|
||||
// autocomplete_status: 0,
|
||||
// save_status: 0,
|
||||
// error_message: "",
|
||||
// dialog_error: false,
|
||||
// alert_error: false,
|
||||
// msg_success: "",
|
||||
// alert_success: false,
|
||||
// get_data_status:0,
|
||||
// filter_branch: [],
|
||||
// selected_filter_branch: {},
|
||||
// filter_kurir: [],
|
||||
// selected_filter_kurir: {},
|
||||
// filter_status: [],
|
||||
// selected_filter_status: {},
|
||||
},
|
||||
mutations: {
|
||||
update_selectedHoliday(state, val) {
|
||||
state.selectedHoliday = val
|
||||
},
|
||||
update_dialog_delete(state, val) {
|
||||
state.dialog_delete = val
|
||||
},
|
||||
update_desc(state, val) {
|
||||
state.desc = val
|
||||
},
|
||||
update_dialogForm(state, val) {
|
||||
state.dialogForm = val
|
||||
},
|
||||
update_year(state, val) {
|
||||
state.year = val
|
||||
},
|
||||
update_yearFilter(state, val) {
|
||||
state.yearFilter = val
|
||||
},
|
||||
update_date(state, val) {
|
||||
state.date = val
|
||||
},
|
||||
update_type(state, val) {
|
||||
state.type = val
|
||||
},
|
||||
update_selectedType(state, val) {
|
||||
state.selectedType = val
|
||||
},
|
||||
update_couriers(state, val) {
|
||||
state.couriers = val
|
||||
},
|
||||
update_total(state, val) {
|
||||
state.total = val;
|
||||
},
|
||||
update_loading(state, val) {
|
||||
state.loading = val;
|
||||
},
|
||||
update_error_message(state, val) {
|
||||
state.error_message = val;
|
||||
},
|
||||
update_name(state, val) {
|
||||
state.name = val;
|
||||
},
|
||||
update_curr_page(state, val) {
|
||||
state.curr_page = val;
|
||||
},
|
||||
update_is_courier(state, val) {
|
||||
state.is_courier = val;
|
||||
},
|
||||
update_snackbar(state, val) {
|
||||
state.snackbar = val;
|
||||
},
|
||||
update_snackbar_msg(state, val) {
|
||||
state.snackbar_msg = val;
|
||||
},
|
||||
update_error_dialog(state, val) {
|
||||
state.error_dialog = val;
|
||||
},
|
||||
update_holidays(state, val) {
|
||||
state.holidays = val;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async gettype(context) {
|
||||
context.commit("update_loading", true)
|
||||
try {
|
||||
// prm.token = one_token();
|
||||
var param = {
|
||||
"token": one_token(),
|
||||
}
|
||||
let resp = await api.gettype(param);
|
||||
if (resp.status !== "OK") {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_dialog", true);
|
||||
context.commit("update_error_message", resp);
|
||||
} else {
|
||||
context.commit("update_loading", false);
|
||||
console.log(resp.data);
|
||||
context.commit("update_type", resp.data)
|
||||
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_dialog", true);
|
||||
context.commit("update_error_message", error);
|
||||
}
|
||||
},
|
||||
async search(context) {
|
||||
context.commit("update_loading", true)
|
||||
try {
|
||||
// prm.token = one_token();
|
||||
var param = {
|
||||
"year": context.state.yearFilter,
|
||||
"token": one_token(),
|
||||
}
|
||||
let resp = await api.search(param);
|
||||
if (resp.status !== "OK") {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_dialog", true);
|
||||
context.commit("update_error_message", resp);
|
||||
} else {
|
||||
context.commit("update_loading", false);
|
||||
console.log(resp.data);
|
||||
context.commit("update_holidays", resp.data)
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_dialog", true);
|
||||
context.commit("update_error_message", error);
|
||||
}
|
||||
},
|
||||
async add(context) {
|
||||
context.commit("update_loading", true)
|
||||
try {
|
||||
let prm = {};
|
||||
|
||||
prm.token = one_token();
|
||||
prm.name = context.state.name;
|
||||
prm.year = context.state.year;
|
||||
prm.date = context.state.date;
|
||||
prm.type = context.state.selectedType;
|
||||
prm.description = context.state.desc;
|
||||
|
||||
// prm.userID = one_user();
|
||||
let resp = await api.add(prm);
|
||||
if (resp.status !== "OK") {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_message", resp);
|
||||
context.commit("update_error_dialog", true);
|
||||
} else {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_snackbar", true);
|
||||
context.commit("update_dialogForm", false);
|
||||
context.commit("update_snackbar_msg", "Berhasil Menambahkan hari libur");
|
||||
console.log(resp.data);
|
||||
// var tempCourrier = JSON.stringify(context.state.is_courier);
|
||||
// var arrCourier = JSON.parse(tempCourrier);
|
||||
// arrCourier.push(prm.userID);
|
||||
// context.commit("update_is_courier", arrCourier);
|
||||
context.dispatch("search");
|
||||
}
|
||||
} catch (error) {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_message", error);
|
||||
context.commit("update_error_dialog", true);
|
||||
}
|
||||
},
|
||||
async edit(context) {
|
||||
context.commit("update_loading", true)
|
||||
try {
|
||||
let prm = {};
|
||||
|
||||
prm.token = one_token();
|
||||
prm.name = context.state.name;
|
||||
prm.year = context.state.year;
|
||||
prm.date = context.state.date;
|
||||
prm.type = context.state.selectedType;
|
||||
prm.description = context.state.desc;
|
||||
prm.id = context.state.selectedHoliday.id;
|
||||
|
||||
// prm.userID = one_user();
|
||||
let resp = await api.edit(prm);
|
||||
if (resp.status !== "OK") {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_message", resp);
|
||||
context.commit("update_error_dialog", true);
|
||||
} else {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_snackbar", true);
|
||||
context.commit("update_dialogForm", false);
|
||||
context.commit("update_snackbar_msg", "Berhasil edit hari libur");
|
||||
console.log(resp.data);
|
||||
// var tempCourrier = JSON.stringify(context.state.is_courier);
|
||||
// var arrCourier = JSON.parse(tempCourrier);
|
||||
// arrCourier.push(prm.userID);
|
||||
// context.commit("update_is_courier", arrCourier);
|
||||
context.dispatch("search");
|
||||
}
|
||||
} catch (error) {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_message", error);
|
||||
context.commit("update_error_dialog", true);
|
||||
}
|
||||
},
|
||||
async deleteData(context) {
|
||||
context.commit("update_loading", true)
|
||||
try {
|
||||
let prm = {}
|
||||
prm.token = one_token();
|
||||
prm.id = context.state.selectedHoliday.id;
|
||||
// prm.userID = one_user();
|
||||
let resp = await api.deleteData(prm);
|
||||
if (resp.status !== "OK") {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_message", resp);
|
||||
context.commit("update_error_dialog", true);
|
||||
} else {
|
||||
context.commit("update_loading", false);
|
||||
console.log(resp.data);
|
||||
context.commit("update_snackbar", true);
|
||||
context.commit("update_dialog_delete", false);
|
||||
context.commit("update_snackbar_msg", "Berhasil Menghapus libur");
|
||||
// var tempCourrier = JSON.stringify(context.state.is_courier);
|
||||
// var arrCourier = JSON.parse(tempCourrier);
|
||||
// arrCourier.filter((e) => e === prm.courierID);
|
||||
// context.commit("update_is_courier", arrCourier);
|
||||
context.dispatch("search");
|
||||
}
|
||||
} catch (error) {
|
||||
context.commit("update_loading", false);
|
||||
context.commit("update_error_message", error);
|
||||
context.commit("update_error_dialog", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user