Flatten nested repos
This commit is contained in:
182
test/vuex/one-report-v6/modules/report.js
Normal file
182
test/vuex/one-report-v6/modules/report.js
Normal file
@@ -0,0 +1,182 @@
|
||||
// 1 => LOADING
|
||||
// 2 => DONE
|
||||
// 3 => ERROR
|
||||
import * as api from "../api/report.js"
|
||||
window.api = api
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
loading: false,
|
||||
reports: [],
|
||||
report: {},
|
||||
error: '',
|
||||
details: [],
|
||||
detail: [],
|
||||
loading_detail: false,
|
||||
error_detail: '',
|
||||
params: [],
|
||||
total_params: 0,
|
||||
total_filter_params: 0,
|
||||
search_status: 0,
|
||||
current_page: 1,
|
||||
get_data_status: 0,
|
||||
get_data_error_message: '',
|
||||
reportautocompletes: [],
|
||||
autocomplete_status: 0
|
||||
},
|
||||
mutations: {
|
||||
update_loading(state, status) {
|
||||
state.loading = status
|
||||
},
|
||||
update_reports(state, val) {
|
||||
state.reports = val
|
||||
},
|
||||
update_report(state, report) {
|
||||
state.report = report
|
||||
},
|
||||
update_error(state, val) {
|
||||
state.error = val
|
||||
},
|
||||
update_details(state, val) {
|
||||
state.details = val
|
||||
},
|
||||
update_detail(state, data) {
|
||||
state.detail = data.detail
|
||||
},
|
||||
update_loading_detail(state, val) {
|
||||
state.loading_detail = val
|
||||
},
|
||||
update_error_detail(state, val) {
|
||||
state.error_detail = val
|
||||
},
|
||||
update_params(state, val) {
|
||||
state.params = val
|
||||
},
|
||||
update_total_params(state, val) {
|
||||
state.total_params = val
|
||||
},
|
||||
update_total_filter_params(state, val) {
|
||||
state.total_filter_params = val
|
||||
},
|
||||
update_current_page(state, val) {
|
||||
state.current_page = val
|
||||
},
|
||||
update_get_data_status(state, val) {
|
||||
state.get_data_status = val
|
||||
},
|
||||
update_get_data_error_message(state, val) {
|
||||
state.get_data_error_message = val
|
||||
},
|
||||
update_reportdropdowns(state, val) {
|
||||
state.reportdropdowns = val
|
||||
},
|
||||
update_reportdropdown(state, val) {
|
||||
state.reportdropdown = val
|
||||
},
|
||||
update_reportautocompletes(state, val) {
|
||||
state.reportautocompletes = val
|
||||
},
|
||||
update_autocomplete_status(state, val) {
|
||||
state.autocomplete_status = val
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async list(context, prm) {
|
||||
context.commit("update_loading", true)
|
||||
try {
|
||||
let resp = await api.list(prm)
|
||||
if (resp.statusText != "OK") {
|
||||
context.commit("update_loading", false)
|
||||
context.commit("update_error", resp.message)
|
||||
} else {
|
||||
context.commit("update_loading", false)
|
||||
context.commit("update_error", "")
|
||||
context.commit("update_reports", resp.data.data.records)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_loading", false)
|
||||
context.commit("update_error", e.message)
|
||||
}
|
||||
},
|
||||
async lookupparam(context, prm) {
|
||||
context.commit("update_loading", true)
|
||||
try {
|
||||
prm.token = one_token()
|
||||
let resp = await api.lookupparam(prm)
|
||||
if (resp.statusText != "OK") {
|
||||
context.commit("update_loading", false)
|
||||
context.commit("update_error", resp.message)
|
||||
} else {
|
||||
context.commit("update_loading", false)
|
||||
context.commit("update_error", "")
|
||||
let data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total,
|
||||
total_filter: resp.data.total_filter
|
||||
}
|
||||
|
||||
context.commit("update_params", resp.data.data.records)
|
||||
context.commit("update_total_params", resp.data.data.total)
|
||||
context.commit("update_total_filter_params", resp.data.data.total_filter)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_loading", false)
|
||||
context.commit("update_error", e.message)
|
||||
}
|
||||
},
|
||||
async detail(context, id) {
|
||||
context.commit("update_loading_detail", true)
|
||||
try {
|
||||
let resp = await api.detail(id)
|
||||
//console.log(resp)
|
||||
if (resp.statusText != "OK") {
|
||||
context.commit("update_loading_detail", false)
|
||||
context.commit("update_error_detail", resp.message)
|
||||
} else {
|
||||
context.commit("update_loading_detail", false)
|
||||
context.commit("update_error_detail", "")
|
||||
var arrOrders = resp.data.data.records
|
||||
arrOrders.forEach((value, index) => {
|
||||
arrOrders[index]["items"] = []
|
||||
if(value.R_InputTypeName === 'dropdown'){
|
||||
var sp = value.R_ReportDetailSourceSp
|
||||
context.dispatch("listdropdown",{sp:sp,index: index})
|
||||
}
|
||||
});
|
||||
context.commit("update_details", arrOrders)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_loading_detail", false)
|
||||
context.commit("update_error_detail", e.message)
|
||||
}
|
||||
},
|
||||
async listdropdown(context, param) {
|
||||
context.commit("update_get_data_status", 1)
|
||||
try {
|
||||
let resp = await api.listdropdown(param.sp)
|
||||
//disimpan dalam report detail
|
||||
let arrOrders = context.state.details
|
||||
arrOrders[param.index].items = resp
|
||||
context.commit("update_details",arrOrders)
|
||||
} catch (e) {
|
||||
context.commit("update_get_data_status", 3)
|
||||
context.commit("update_get_data_error_message", e.message)
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
async listautocomplete(context, prm) {
|
||||
context.commit("update_autocomplete_status", 1)
|
||||
try {
|
||||
let resp = await api.listautocomplete(prm)
|
||||
context.commit("update_autocomplete_status", 2)
|
||||
let arrOrders = context.state.details
|
||||
arrOrders[prm.index].items = resp.data
|
||||
context.commit("update_details",arrOrders)
|
||||
} catch (e) {
|
||||
context.commit("update_autocomplete_status", 3)
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user