Flatten nested repos
This commit is contained in:
164
test/vuex/one-md-packet/modules/packet_new.js
Normal file
164
test/vuex/one-md-packet/modules/packet_new.js
Normal file
@@ -0,0 +1,164 @@
|
||||
// 1 => LOADING
|
||||
// 2 => DONE
|
||||
// 3 => ERROR
|
||||
import * as api from "../api/packet.js"
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
|
||||
search_status: 0,
|
||||
search_error_message: '',
|
||||
|
||||
query_company: '',
|
||||
companies: [],
|
||||
selected_company: {},
|
||||
total_company: 0,
|
||||
|
||||
query_mou: '',
|
||||
mous: [],
|
||||
selected_mou: {},
|
||||
total_mou: 0,
|
||||
|
||||
total_packet: 0,
|
||||
new_packet: { amount:0, disc:0, discrp:0, sub_total:0, other:0, total:0, cito:'N'},
|
||||
edit_packet: false,
|
||||
dialog_packet: false,
|
||||
|
||||
state_edit: false
|
||||
},
|
||||
mutations: {
|
||||
|
||||
update_search_error_message(state, patient) {
|
||||
state.search_error_message = patient
|
||||
},
|
||||
|
||||
// MOU
|
||||
update_query_mou(state, q) {
|
||||
state.query_mou = q
|
||||
},
|
||||
|
||||
update_mous(state, d) {
|
||||
state.mous = d.records
|
||||
state.total_mou = d.total
|
||||
},
|
||||
|
||||
update_selected_mou(state, d) {
|
||||
state.selected_mou = d
|
||||
},
|
||||
|
||||
// COMPANY
|
||||
update_query_company(state, q) {
|
||||
state.query_company = q
|
||||
},
|
||||
|
||||
update_companies(state, d) {
|
||||
state.companies = d.records
|
||||
state.total_company = d.total
|
||||
},
|
||||
|
||||
update_selected_company(state, d) {
|
||||
state.selected_company = d
|
||||
|
||||
// update mous
|
||||
state.mous = d.mou
|
||||
state.selected_mou = {}
|
||||
state.total_mou = (d.mou ? d.mou.length : 0)
|
||||
},
|
||||
|
||||
update_search_status(state, val) {
|
||||
state.search_status = val
|
||||
},
|
||||
|
||||
update_errors(state, val) {
|
||||
state.errors = val
|
||||
},
|
||||
|
||||
update_dialog_packet(state, val) {
|
||||
state.dialog_packet = val
|
||||
},
|
||||
|
||||
update_state_edit(state, val) {
|
||||
state.state_edit = val
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async search_company(context) {
|
||||
|
||||
try {
|
||||
let resp = await api.search_company(one_token(), context.state.query_company)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_search_status", 3)
|
||||
context.commit("update_search_error_message", resp.message)
|
||||
} else {
|
||||
context.commit("update_search_status", 2)
|
||||
context.commit("update_search_error_message", "")
|
||||
let data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total
|
||||
}
|
||||
|
||||
context.commit("update_companies", data)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_search_status", 3)
|
||||
context.commit("update_search_error_message", e.message)
|
||||
}
|
||||
},
|
||||
|
||||
async search_mou(context) {
|
||||
|
||||
try {
|
||||
let resp = await api.search_mou(one_token(), context.state.selected_company.M_CompanyID, context.state.query_mou)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_search_status", 3)
|
||||
context.commit("update_search_error_message", resp.message)
|
||||
} else {
|
||||
context.commit("update_search_status", 2)
|
||||
context.commit("update_search_error_message", "")
|
||||
let data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total
|
||||
}
|
||||
|
||||
context.commit("update_mous", data)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_search_status", 3)
|
||||
context.commit("update_search_error_message", e.message)
|
||||
}
|
||||
},
|
||||
|
||||
async save(context, data) {
|
||||
|
||||
try {
|
||||
let resp
|
||||
if (data.edit)
|
||||
resp = await api.save(one_token(), JSON.stringify(data), true)
|
||||
else
|
||||
resp = await api.save(one_token(), JSON.stringify(data))
|
||||
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_search_status", 3)
|
||||
context.commit("update_search_error_message", resp.message)
|
||||
} else {
|
||||
context.commit("update_search_status", 2)
|
||||
context.commit("update_search_error_message", "")
|
||||
|
||||
context.dispatch("packet/search_packet", null, {root:true})
|
||||
context.commit('update_dialog_packet', false)
|
||||
|
||||
context.commit('packet/update_auto_selected_packet_id', resp.data, {root:true})
|
||||
context.commit("packet/update_query_company", context.state.selected_company.M_CompanyName, {root:true})
|
||||
context.commit('packet/update_companies', {records:[context.state.selected_company], total:1}, {root:true})
|
||||
context.commit('packet/update_selected_company', context.state.selected_company, {root:true})
|
||||
context.commit('packet/update_selected_mou', context.state.selected_mou, {root:true})
|
||||
context.dispatch('packet/search_packet', null, {root:true})
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_search_status", 3)
|
||||
context.commit("update_search_error_message", e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user