246 lines
8.0 KiB
JavaScript
246 lines
8.0 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
startDate: moment(new Date()).format('YYYY-MM-DD'),
|
|
endDate: moment(new Date()).format('YYYY-MM-DD'),
|
|
loading: false,
|
|
search: "",
|
|
setupList: [],
|
|
selectedSetup: {},
|
|
orderList: [],
|
|
url: '',
|
|
errorMsg: '',
|
|
snackbarSuccess: false,
|
|
snackbarError: false,
|
|
successMsg: '',
|
|
total: 0,
|
|
page: 1,
|
|
url: "",
|
|
dialogConfirmation: false,
|
|
note: "",
|
|
selectedPatient: {},
|
|
status: [
|
|
"Semua", 'Aktif', 'Void'
|
|
],
|
|
selectedStatus: 'Semua',
|
|
type: [
|
|
'cpone', 'log'
|
|
],
|
|
selectedType: 'cpone',
|
|
tmpListData: [],
|
|
listData: [],
|
|
|
|
},
|
|
mutations: {
|
|
update_listData(state, val) {
|
|
state.listData = val
|
|
},
|
|
update_tmpListData(state, val) {
|
|
state.tmpListData = val
|
|
},
|
|
update_selectedType(state, val) {
|
|
state.selectedType = val
|
|
},
|
|
update_type(state, val) {
|
|
state.type = val
|
|
},
|
|
update_selectedStatus(state, val) {
|
|
state.selectedStatus = val
|
|
},
|
|
update_selectedPatient(state, val) {
|
|
state.selectedPatient = val
|
|
},
|
|
update_dialogConfirmation(state, val) {
|
|
state.dialogConfirmation = val
|
|
},
|
|
update_note(state, val) {
|
|
state.note = val
|
|
},
|
|
update_url(state, val) {
|
|
state.url = val
|
|
},
|
|
update_startDate(state, val) {
|
|
state.startDate = val
|
|
},
|
|
update_endDate(state, val) {
|
|
state.endDate = val
|
|
},
|
|
update_loading(state, val) {
|
|
state.loading = val
|
|
},
|
|
update_search(state, val) {
|
|
state.search = val
|
|
},
|
|
update_orderList(state, val) {
|
|
state.orderList = val
|
|
},
|
|
update_url(state, val) {
|
|
state.url = val
|
|
},
|
|
update_setupList(state, val) {
|
|
state.setupList = val
|
|
},
|
|
update_selectedSetup(state, val) {
|
|
state.selectedSetup = val
|
|
},
|
|
update_errorMsg(state, val) {
|
|
state.errorMsg = val
|
|
},
|
|
update_snackbarSuccess(state, val) {
|
|
state.snackbarSuccess = val
|
|
},
|
|
update_snackbarError(state, val) {
|
|
state.snackbarError = val
|
|
},
|
|
update_successMsg(state, val) {
|
|
state.successMsg = val
|
|
},
|
|
update_total(state, val) {
|
|
state.total = val
|
|
},
|
|
update_page(state, val) {
|
|
state.page = val
|
|
},
|
|
},
|
|
actions: {
|
|
async getListData(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {}
|
|
prm.token = one_token()
|
|
let resp = await api.getListData(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.commit("update_tmpListData", resp.data ?? [])
|
|
context.commit("update_listData", resp.data.cpone ?? [])
|
|
context.commit("update_selectedType", 'cpone')
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e.message)
|
|
context.commit("update_snackbarError", true)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async getsetup(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {}
|
|
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)
|
|
context.commit("update_snackbarError", false)
|
|
} else {
|
|
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
|
|
context.commit("update_setupList", resp.data.records)
|
|
if (resp.data.records.length > 0) {
|
|
context.commit("update_selectedSetup", resp.data.records[0])
|
|
context.dispatch("search");
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e.message)
|
|
context.commit("update_snackbarError", false)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async search(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {}
|
|
prm.token = one_token()
|
|
prm.startDate = context.state.startDate
|
|
prm.endDate = context.state.endDate
|
|
prm.search = context.state.search
|
|
prm.setup = context.state.selectedSetup.Mgm_McuID
|
|
prm.page = context.state.page
|
|
prm.status = context.state.selectedStatus
|
|
|
|
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)
|
|
|
|
context.commit("update_orderList", resp.data.records)
|
|
context.commit("update_total", resp.data.total)
|
|
context.commit("update_url", resp.data.url)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e.message)
|
|
context.commit("update_snackbarError", true)
|
|
console.log(e)
|
|
}
|
|
},
|
|
async voidOrder(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {}
|
|
prm.token = one_token()
|
|
prm.id = context.state.selectedPatient.orderID
|
|
prm.reason = context.state.note
|
|
|
|
|
|
let resp = await api.voidOrder(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)
|
|
|
|
await context.dispatch("search")
|
|
context.commit("update_dialogConfirmation", false)
|
|
context.commit("update_note", "")
|
|
context.commit("update_successMsg", "Berhasil void order")
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_selectedPatient", {})
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e.message)
|
|
context.commit("update_snackbarError", true)
|
|
console.log(e)
|
|
}
|
|
},
|
|
|
|
}
|
|
}
|