132 lines
4.7 KiB
JavaScript
132 lines
4.7 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/service.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
services: [],
|
|
selected_service: {},
|
|
total_service: 0,
|
|
current_page: 1,
|
|
pagination:{
|
|
descending:'asc',
|
|
sortBy:'HS_WhatsAppID'
|
|
},
|
|
date: moment(new Date()).format('YYYY-MM-DD'),
|
|
search_status: false,
|
|
last_id: -1,
|
|
alert_success: false,
|
|
msg_success: "",
|
|
error_message: "",
|
|
alert_error: false,
|
|
dialog_error: false
|
|
},
|
|
mutations: {
|
|
update_services(state, val) {
|
|
state.services = val
|
|
},
|
|
update_selected_service(state, val) {
|
|
state.selected_service = val
|
|
},
|
|
update_total_service(state, val) {
|
|
state.service = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_pagination(state, val) {
|
|
state.pagination = val
|
|
},
|
|
update_date(state, val) {
|
|
state.date = val
|
|
},
|
|
update_search_status(state, val) {
|
|
state.search_status = val
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val;
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
},
|
|
update_error_message(state, val) {
|
|
state.error_message = val
|
|
},
|
|
update_alert_error(state, val) {
|
|
state.alert_error = val;
|
|
},
|
|
update_dialog_error(state, data) {
|
|
state.dialog_error = data
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context) {
|
|
context.commit("update_search_status", true)
|
|
try {
|
|
var prm = {
|
|
token: one_token(),
|
|
current_page: context.state.current_page,
|
|
date: context.state.date,
|
|
sortBy: context.state.pagination.sortBy,
|
|
sortStatus: context.state.pagination.descending
|
|
}
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status", false)
|
|
console.log(resp.message)
|
|
} else {
|
|
context.commit("update_search_status", false)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("update_services", data.records)
|
|
context.commit("update_total_service", data.total)
|
|
if (context.state.last_id == -1) {
|
|
if (resp.data && resp.data.records.length > 0) {
|
|
context.commit("update_selected_service", resp.data.records[0])
|
|
}
|
|
} else {
|
|
let idx = _.findIndex(resp.data.records, function (o) {
|
|
return o.HS_WhatsAppID == context.state.update_selected_service.HS_WhatsAppID
|
|
});
|
|
if (idx >= 0) {
|
|
context.commit("update_selected_service", resp.data.records[idx]);
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", false)
|
|
}
|
|
},
|
|
|
|
async resend(context, prm) {
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.resend(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_error_message", resp.message)
|
|
context.commit("update_alert_error", true)
|
|
context.commit("update_dialog_error", true)
|
|
} else {
|
|
context.commit("update_dialog_error", false)
|
|
let data = resp.data
|
|
var msg = "Berhasil dikirim ulang"
|
|
context.commit("update_msg_success", msg)
|
|
context.commit("update_alert_success", true)
|
|
context.dispatch("search")
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_dialog_error", true)
|
|
context.commit("update_error_message", resp.e)
|
|
context.commit("update_alert_error", true)
|
|
}
|
|
}
|
|
}
|
|
} |