// 1 => LOADING // 2 => DONE // 3 => ERROR import * as api from "../api/email.js" export default { namespaced: true, state: { loading: false, error: '', format:'', }, mutations: { update_loading(state, val) { state.loading= val }, update_error(state, val) { state.error= val }, update_format(state, val) { state.format = val }, }, actions: { async get(context, trx) { context.commit("update_loading", true) try { let type= context.rootState.sample.typeresult.id let prm = {orderID : trx.trx_id, type: type, token: one_token() } context.commit("update_format", '') let resp = await api.get(prm) context.commit("update_loading", false) if (resp.status != "OK") { context.commit("update_error", resp.message) } else { context.commit("update_error", "") let dt = resp.data if (dt.length > 0 ) { let format = dt[0].T_EmailNonLabFormat context.commit("update_format", format) } } } catch (e) { context.commit("update_error", e.message) } }, async save(context, prm) { context.commit("update_loading", true) try { prm.token = one_token() context.commit("update_format", '') let resp = await api.save(prm) context.commit("update_loading", false) if (resp.status != "OK") { context.commit("update_error", resp.message) } else { context.commit("update_error", "") let format = prm.format context.commit("update_format", format) } } catch (e) { context.commit("update_error", e.message) } }, } }