Flatten nested repos
This commit is contained in:
212
test/vuex/one-md-packet/modules/packet_copy.js
Normal file
212
test/vuex/one-md-packet/modules/packet_copy.js
Normal file
@@ -0,0 +1,212 @@
|
||||
// 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,
|
||||
default_company: {},
|
||||
|
||||
query_mou: '',
|
||||
mous: [],
|
||||
selected_mou: null,
|
||||
total_mou: 0,
|
||||
default_mou: {},
|
||||
|
||||
query_packet: '',
|
||||
packets: [],
|
||||
selected_packet: null,
|
||||
total_packet: 0,
|
||||
|
||||
dialog_copy: 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
|
||||
if (d) {
|
||||
state.mous = d.mou
|
||||
state.selected_mou = {}
|
||||
state.total_mou = d.mou.length
|
||||
} else {
|
||||
state.mous = []
|
||||
state.selected_mou = {}
|
||||
state.total_mou = 0
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// PRICE
|
||||
update_query_packet(state, q) {
|
||||
state.query_packet = q
|
||||
},
|
||||
|
||||
update_packets(state, d) {
|
||||
state.packets = d.records
|
||||
state.total_packet = d.total
|
||||
},
|
||||
|
||||
update_selected_packet(state, d) {
|
||||
state.selected_packet = d
|
||||
},
|
||||
|
||||
update_search_status(state, val) {
|
||||
state.search_status = val
|
||||
},
|
||||
|
||||
update_errors(state, val) {
|
||||
state.errors = val
|
||||
},
|
||||
|
||||
update_dialog_copy(state, val) {
|
||||
state.dialog_copy = 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 search_packet(context) {
|
||||
|
||||
try {
|
||||
let resp = await api.search_packet(one_token(), context.state.selected_mou.M_MouID, context.rootState.packet.selected_packet.T_PacketType, context.state.query_packet, true)
|
||||
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_packets", data)
|
||||
|
||||
// Auto selected after save
|
||||
if (context.state.auto_selected_packet_id) {
|
||||
for(let i in data.records)
|
||||
if (data.records[i].T_PacketID == context.state.auto_selected_packet_id)
|
||||
context.commit('update_selected_packet', data.records[i])
|
||||
}
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_search_status", 3)
|
||||
context.commit("update_search_error_message", e.message)
|
||||
}
|
||||
},
|
||||
|
||||
async save_copy(context) {
|
||||
|
||||
try {
|
||||
let source_id = context.state.selected_packet.T_PacketID
|
||||
let target_id = context.rootState.packet.selected_packet.T_PacketID
|
||||
|
||||
let resp = await api.save_copy(one_token(), source_id, target_id)
|
||||
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.commit('update_dialog_copy', false)
|
||||
context.dispatch('px/search_px', null, {root:true})
|
||||
|
||||
let x = context.rootState.packet.selected_packet
|
||||
x.T_PacketPrice = resp.data.packet_price
|
||||
x.T_PacketOriginalPrice = resp.data.total_price
|
||||
|
||||
context.commit('packet/update_selected_packet', x, {root:true})
|
||||
context.commit('test/update_state_add', false, {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