417 lines
17 KiB
JavaScript
417 lines
17 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
// is add kalau true maka add baru kalau false maka sispkan ke header yang sudah ada
|
|
|
|
import * as api from "../api/email.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
isAdd: true,
|
|
loading: false,
|
|
errorMsg: '',
|
|
snackbarSuccess: false,
|
|
snackbarError: false,
|
|
successMsg: '',
|
|
setupList: [],
|
|
selectedSetup: {},
|
|
startDate: moment(new Date()).format('YYYY-MM-DD'),
|
|
endDate: moment(new Date()).format('YYYY-MM-DD'),
|
|
search: "",
|
|
statusDetail: [{ 'text': "Semua", "value": "A" }, { 'text': "Sudah Dikirm", "value": "Y" }, { 'text': "Belum Dikirim", "value": "NO" }, { 'text': "Proses", "value": "N" }],
|
|
selectedStatusDetail: 'A',
|
|
orderList: [],
|
|
page: 1,
|
|
totalPage: 1,
|
|
selectedData: [],
|
|
dialogAdd: false,
|
|
receiver: '',
|
|
note: '',
|
|
totalData: 0,
|
|
totalEmail: 0,
|
|
totalNotEmail: 0,
|
|
totalError: 0,
|
|
},
|
|
mutations: {
|
|
update_totalError(state, val) {
|
|
state.totalError = val
|
|
},
|
|
update_totalNotEmail(state, val) {
|
|
state.totalNotEmail = val
|
|
},
|
|
update_totalEmail(state, val) {
|
|
state.totalEmail = val
|
|
},
|
|
update_totalData(state, val) {
|
|
state.totalData = val
|
|
},
|
|
update_receiver(state, val) {
|
|
state.receiver = val
|
|
},
|
|
update_note(state, val) {
|
|
state.note = val
|
|
},
|
|
update_dialogAdd(state, val) {
|
|
state.dialogAdd = val
|
|
},
|
|
update_selectedData(state, val) {
|
|
state.selectedData = val
|
|
},
|
|
update_errorMsg(state, val) {
|
|
state.errorMsg = val
|
|
},
|
|
update_isAdd(state, val) {
|
|
state.isAdd = val
|
|
},
|
|
update_snackbarSuccess(state, val) {
|
|
state.snackbarSuccess = val
|
|
},
|
|
update_snackbarError(state, val) {
|
|
state.snackbarError = val
|
|
},
|
|
update_successMsg(state, val) {
|
|
state.successMsg = val
|
|
},
|
|
update_loading(state, val) {
|
|
state.loading = val
|
|
},
|
|
update_startDate(state, val) {
|
|
state.startDate = val
|
|
},
|
|
update_endDate(state, val) {
|
|
state.endDate = val
|
|
},
|
|
|
|
update_selectedSetup(state, val) {
|
|
state.selectedSetup = val
|
|
},
|
|
update_setupList(state, val) {
|
|
state.setupList = val
|
|
},
|
|
update_orderList(state, val) {
|
|
state.orderList = val
|
|
},
|
|
update_totalPage(state, val) {
|
|
state.totalPage = val
|
|
},
|
|
update_page(state, val) {
|
|
state.page = val
|
|
},
|
|
|
|
update_search(state, val) {
|
|
state.search = val
|
|
},
|
|
update_selectedStatusDetail(state, val) {
|
|
state.selectedStatusDetail = val
|
|
},
|
|
},
|
|
actions: {
|
|
async getsetup(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
}
|
|
let resp = await api.getsetup(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
}
|
|
if (resp.data.records.length > 0) {
|
|
context.commit("update_selectedSetup", resp.data.records[0])
|
|
context.commit("update_startDate", resp.data.records[0].Mgm_McuStartDate)
|
|
context.commit("update_endDate", resp.data.records[0].Mgm_McuEndDate)
|
|
|
|
|
|
// context.dispatch("search")
|
|
context.dispatch("getdetail")
|
|
}
|
|
context.commit("update_setupList", resp.data.records)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async search(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
startDate: context.state.startDateHeader,
|
|
endDate: context.state.endDateHeader,
|
|
setupID: context.state.selectedSetup.Mgm_McuID,
|
|
page: context.state.headerPage,
|
|
}
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
}
|
|
|
|
context.commit("update_emailHeader", resp.data.records)
|
|
context.commit("update_headerTotal", resp.data.total)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async getdetail(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
let prm = {
|
|
token: one_token(),
|
|
startDate: context.state.startDate,
|
|
endDate: context.state.endDate,
|
|
status: context.state.selectedStatusDetail,
|
|
search: context.state.search,
|
|
setupID: context.state.selectedSetup.Mgm_McuID,
|
|
page: context.state.page,
|
|
}
|
|
let resp = await api.getdetail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = resp.data.records;
|
|
let selectedData = context.state.selectedData;
|
|
|
|
|
|
if (selectedData.length > 0 && data.length > 0) {
|
|
for (let i = 0; i < data.length; i++) {
|
|
const element = data[i];
|
|
let foundItem = selectedData.find((e) => e.orderID === element.orderID);
|
|
const index = selectedData.findIndex((e) => e.orderID === element.orderID);
|
|
if (foundItem) {
|
|
data[i].patientEmail = selectedData[index].patientEmail;
|
|
}
|
|
}
|
|
|
|
}
|
|
context.commit("update_orderList", data)
|
|
context.commit("update_totalPage", resp.data.total)
|
|
context.commit("update_totalData", resp.data.totalAll)
|
|
context.commit("update_totalEmail", resp.data.totalSend)
|
|
context.commit("update_totalError", resp.data.totalError)
|
|
context.commit("update_totalNotEmail", resp.data.totalNotSend)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async sendemail(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
let prm = {
|
|
token: one_token(),
|
|
data: context.state.selectedData,
|
|
setupID: context.state.selectedSetup.Mgm_McuID,
|
|
}
|
|
let resp = await api.sendemail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
context.dispatch("getdetail")
|
|
context.commit("update_dialogAdd", false)
|
|
context.commit("update_successMsg", 'Berhasil menyimpan data')
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_selectedData", [])
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async saveemail(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let email = 0;
|
|
if (
|
|
!(Object.keys(context.state.selectedEmail).length === 0 &&
|
|
context.state.selectedEmail.constructor === Object)
|
|
) {
|
|
email = context.state.selectedEmail.emailID;
|
|
}
|
|
let prm = {
|
|
token: one_token(),
|
|
data: context.state.selectedData,
|
|
receiver: context.state.receiver,
|
|
note: context.state.note,
|
|
setupID: context.state.selectedSetup.Mgm_McuID,
|
|
emailID: email,
|
|
}
|
|
let resp = await api.saveemail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
context.commit("update_selectedStatusDetail", 'Y')
|
|
context.dispatch("search")
|
|
context.dispatch("getdetail", 0)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
context.commit("update_successMsg", 'Berhasil menyerahkan hasil')
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_dialogAdd", false)
|
|
context.commit("update_isAdd", false)
|
|
context.commit("update_receiver", '')
|
|
context.commit("update_note", '')
|
|
context.commit("update_selectedData", [])
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async deleteemaildetail(context, id) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
let prm = {
|
|
token: one_token(),
|
|
detailID: id,
|
|
}
|
|
let resp = await api.deleteemaildetail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
} else {
|
|
context.commit("update_selectedStatusDetail", 'Y')
|
|
context.dispatch("search")
|
|
context.dispatch("getdetail", 0)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
context.commit("update_successMsg", 'Berhasil Hapus hasil')
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_dialogAdd", false)
|
|
context.commit("update_isAdd", false)
|
|
context.commit("update_receiver", '')
|
|
context.commit("update_note", '')
|
|
context.commit("update_selectedData", [])
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async lookup_type(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
try {
|
|
let resp = await api.lookup_type(one_token())
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_types", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
},
|
|
async pay(context, prm) {
|
|
context.commit("update_lookup_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.pay(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let data = {
|
|
records: resp.data.records.types,
|
|
total: resp.data.total
|
|
}
|
|
let xnumber = resp.data.records.data.numberx
|
|
let id = resp.data.records.data.idx
|
|
context.commit("update_types", data)
|
|
context.commit("update_last_payments", prm.payments)
|
|
context.commit("update_idx", id)
|
|
context.commit("update_total_payment", 0)
|
|
context.commit("update_paynumber", "Pembayaran nomor <span style='color:red'>" + xnumber + "</span> telah berhasil")
|
|
context.commit("update_dialog_pay_success", true)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
},
|
|
async delete_note(context, prm) {
|
|
context.commit("update_lookup_status", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp = await api.delete_note(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let xmsg = "Nota nomor <span style='color:red'>" + prm.nota.note_number + "</span> telah dihapus"
|
|
context.commit("update_msg_delete", xmsg)
|
|
context.commit("update_note_delete", '')
|
|
context.commit("update_nota_delete", {})
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
}
|
|
}
|
|
}
|