353 lines
12 KiB
JavaScript
353 lines
12 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/queue.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
screen: 'setting',
|
|
loading: false,
|
|
stationList: [],
|
|
selectedStation: [],
|
|
branchList: [],
|
|
selectedBranch: {},
|
|
title: '',
|
|
errorMsg: '',
|
|
snackbarError: false,
|
|
queueList: [],
|
|
setupList: [],
|
|
selectedSetup: {},
|
|
onSite: false,
|
|
onSiteMcuID: [],
|
|
statusFO: [],
|
|
dataTicket: {},
|
|
dataPatient: {},
|
|
statusStation: [],
|
|
selectedStatusStation: {},
|
|
statusDone: 'N'
|
|
},
|
|
mutations: {
|
|
update_statusDone(state, val) {
|
|
state.statusDone = val;
|
|
},
|
|
update_dataPatient(state, val) {
|
|
state.dataPatient = val;
|
|
},
|
|
update_selectedStatusStation(state, val) {
|
|
state.selectedStatusStation = val;
|
|
},
|
|
update_statusStation(state, val) {
|
|
state.statusStation = val;
|
|
},
|
|
update_statusFO(state, val) {
|
|
state.statusFO = val;
|
|
},
|
|
update_dataTicket(state, val) {
|
|
state.dataTicket = val;
|
|
},
|
|
update_onSiteMcuID(state, val) {
|
|
state.onSiteMcuID = val;
|
|
},
|
|
update_onSite(state, val) {
|
|
state.onSite = val;
|
|
},
|
|
update_setupList(state, val) {
|
|
state.setupList = val;
|
|
},
|
|
update_selectedSetup(state, val) {
|
|
state.selectedSetup = val;
|
|
},
|
|
update_screen(state, val) {
|
|
state.screen = val;
|
|
},
|
|
update_queueList(state, val) {
|
|
state.queueList = val;
|
|
},
|
|
update_loading(state, val) {
|
|
state.loading = val;
|
|
},
|
|
update_stationList(state, val) {
|
|
state.stationList = val;
|
|
},
|
|
update_selectedStation(state, val) {
|
|
state.selectedStation = val;
|
|
},
|
|
update_branchList(state, val) {
|
|
state.branchList = val;
|
|
},
|
|
update_selectedBranch(state, val) {
|
|
state.selectedBranch = val;
|
|
},
|
|
update_title(state, val) {
|
|
state.title = val;
|
|
},
|
|
update_errorMsg(state, val) {
|
|
state.errorMsg = val;
|
|
},
|
|
update_snackbarError(state, val) {
|
|
state.snackbarError = val;
|
|
},
|
|
},
|
|
actions: {
|
|
async getStation(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
let resp = await api.getStation()
|
|
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
|
|
}
|
|
let dataLocal = localStorage.getItem("queue-west");
|
|
let local = JSON.parse(dataLocal);
|
|
if (dataLocal != null) {
|
|
context.commit("update_title", local.title)
|
|
context.commit("update_selectedStation", local.station)
|
|
context.commit("update_onSite", local.onSite)
|
|
|
|
|
|
|
|
}
|
|
|
|
context.commit("update_stationList", resp.data.records)
|
|
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
async getbranch(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
let resp = await api.getbranch()
|
|
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
|
|
}
|
|
let dataLocal = localStorage.getItem("queue-west");
|
|
let local = JSON.parse(dataLocal);
|
|
if (dataLocal != null) {
|
|
|
|
context.commit("update_selectedBranch", local.branch)
|
|
}
|
|
|
|
context.commit("update_branchList", resp.data.records)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
async getAntrian(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
;
|
|
let selectedStation = context.state.selectedStation;
|
|
|
|
let arrStationID = [];
|
|
|
|
selectedStation.forEach(element => {
|
|
arrStationID.push(element.stationID);
|
|
});
|
|
|
|
let station = arrStationID.join(',')
|
|
// "arrStationID": "7",
|
|
// "branchID": "3",
|
|
// "onSite": "Y",
|
|
// "setupID": "201"
|
|
let prm = {
|
|
arrStationID: station,
|
|
branchID: context.state.selectedBranch.M_BranchID,
|
|
onSite: context.state.onSite ? 'Y' : 'N',
|
|
setupID: context.state.onSite ? context.state.selectedSetup.Mgm_McuID : '0'
|
|
};
|
|
|
|
|
|
let resp = await api.getAntrian(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
|
|
}
|
|
console.log('Call api result')
|
|
console.log(prm)
|
|
context.commit("update_queueList", resp.data)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
async getTicket(context, code) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
|
|
|
|
|
|
let resp = await api.getTicket(code)
|
|
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)
|
|
if (resp.data) {
|
|
context.commit("update_dataTicket", resp.data)
|
|
context.commit("update_statusFO", resp.data.statusFO)
|
|
context.commit("update_statusStation", resp.data.statusStation)
|
|
context.commit("update_statusDone", 'N')
|
|
context.commit("update_selectedStatusStation", {})
|
|
if (resp.data.statusStation.length > 0) {
|
|
context.commit("update_dataPatient", resp.data.statusStation[0])
|
|
let countDone = 0;
|
|
resp.data.statusStation.forEach(element => {
|
|
if (element.T_SamplingQueueStatusName === 'Call' ||
|
|
element.T_SamplingQueueStatusName === 'Process'
|
|
) {
|
|
context.commit("update_selectedStatusStation", element)
|
|
}
|
|
if (element.T_SamplingQueueStatusName === 'Done') {
|
|
countDone = countDone + 1;
|
|
}
|
|
});
|
|
if (countDone === resp.data.statusStation.length) {
|
|
context.commit("update_statusDone", 'Y')
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
async getSetup(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let branchID = context.state.selectedBranch.M_BranchID;
|
|
|
|
let resp = await api.getSetup(branchID)
|
|
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
|
|
}
|
|
let dataLocal = localStorage.getItem("queue-west");
|
|
let local = JSON.parse(dataLocal);
|
|
context.commit("update_setupList", resp.data.records)
|
|
if (dataLocal != null) {
|
|
context.commit("update_selectedSetup", local.setup)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
async getsetuponsite(context) {
|
|
context.commit("update_loading", true)
|
|
try {
|
|
|
|
|
|
let resp = await api.getsetuponsite()
|
|
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
|
|
}
|
|
let strMcuID = resp.data.records.mcuID
|
|
|
|
let arrMcuID = strMcuID.split(',')
|
|
context.commit("update_onSiteMcuID", arrMcuID)
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
}
|
|
}
|