import * as api from "../api/queue.js" export default { namespaced: true, state: { start_date: moment(new Date()).format('YYYY-MM-DD'), end_date: moment(new Date()).add(14, 'd').format('YYYY-MM-DD'), Keyword: "", current_page: 1, total_page: 0, snackbar: false, snackbar_msg: "", dialog_error: false, dialog_follow_up: false, dialog_error_msg: "", isLoading: false, fuLoading: false, subServices: [], queueList: [], status: [{ "id": "0", "name": "All" }, { "id": "Y", "name": "Sudah Follow Up" }, { "id": "X", "name": "Belum Follow Up" }], selectedStatus: { "id": "0", "name": "All" }, selectedSubService: { "id": "0", "name": "All" } }, mutations: { update_isLoading(state, val) { state.isLoading = val; }, update_start_date(state, val) { state.start_date = val; }, update_end_date(state, val) { state.end_date = val; }, update_keyword(state, val) { state.Keyword = val; }, update_current_page(state, val) { state.current_page = val; }, update_total_page(state, val) { state.total_page = val; }, update_snackbar(state, val) { state.snackbar = val; }, update_snackbar_msg(state, val) { state.snackbar_msg = val; }, update_dialog_error(state, val) { state.dialog_error = val; }, update_dialog_error_msg(state, val) { state.dialog_error_msg = val; }, update_subServices(state, val) { state.subServices = val; }, update_selectedSubService(state, val) { state.selectedSubService = val; }, update_queueList(state, val) { state.queueList = val; }, update_dialog_follow_up(state, val) { state.dialog_follow_up = val; }, update_fuLoading(state, val) { state.fuLoading = val; }, update_status(state, val) { state.status = val; }, update_selectedStatus(state, val) { state.selectedStatus = val; }, }, actions: { async getsubservice(context) { try { let resp = await api.getSubService({ "token": one_token() }); if (resp.status != "OK") { context.commit("update_dialog_error", true) context.commit("update_dialog_error_msg", resp.message) } else { context.commit("update_dialog_error_msg", "") console.log(resp); context.commit("update_subServices", resp.data) } } catch (e) { context.commit("update_dialog_error", true) context.commit("update_dialog_error_msg", e.message) console.log(e) } }, async search(context) { context.commit("update_isLoading", true) try { var param = { "token": one_token(), "start_date": context.state.start_date, "end_date": context.state.end_date, "subService": context.state.selectedSubService.id, "keyword": context.state.Keyword, "status": context.state.selectedStatus.id, "page": context.state.current_page } let resp = await api.search(param) if (resp.status != "OK") { context.commit("update_dialog_error", true) context.commit("update_dialog_error_msg", resp.message) context.commit("update_isLoading", false) } else { context.commit("update_queueList", resp.data.data) context.commit("update_total_page", resp.data.total_page) context.commit("update_isLoading", false) } } catch (e) { context.commit("update_dialog_error", true) context.commit("update_dialog_error_msg", e.message) context.commit("update_isLoading", false) console.log(e) } }, async followUp(context, prm) { context.commit("update_fuLoading", true) try { var param = { "token": one_token(), "queue_id": prm.id, "msg": prm.note, } let resp = await api.followup(param) if (resp.status != "OK") { context.commit("update_dialog_error", true) context.commit("update_dialog_error_msg", resp.message) context.commit("update_fuLoading", false) } else { context.commit("update_fuLoading", false) context.commit("update_dialog_follow_up", false) context.commit("update_snackbar_msg", "Follow Up " + prm.name + " Berhasil") context.commit("update_snackbar", true) context.dispatch("search") } } catch (e) { context.commit("update_dialog_error", true) context.commit("update_dialog_error_msg", e.message) context.commit("update_fuLoading", false) console.log(e) } }, } }