Files
FE_CPONE/test/vuex/one-process-ref-receive-sample-v7/modules/deliveryorder.js
2026-04-27 10:13:31 +07:00

183 lines
7.0 KiB
JavaScript

// 1 => LOADING
// 2 => DONE
// 3 => ERROR
import * as api from "../api/deliveryorder.js"
export default {
namespaced: true,
state: {
act: 'new',
loading: false,
error: '',
deliveryorders: [],
total: 0,
total_filter: 0,
show_all: false,
last_id: -1,
selected_deliveryorder: {
name: ""
},
loading_details: false,
error_details: '',
details:[],
total_details : 0,
total_details_filter : 0,
show_all_details: false,
last_id_details: -1,
x_search: '',
init_date: moment().format("YYYY-MM-DD"),
xcek: 0
},
mutations: {
update_xcek(state, val) {
state.xcek = val
},
update_init_date(state, val) {
state.init_date = val
},
update_x_search(state, val) {
state.x_search = val
},
update_last_id(state, val) {
state.last_id = val
},
update_show_all(state, val) {
state.show_all = val
},
update_error(state, val) {
state.error = val
},
update_loading(state, val) {
state.loading = val
},
update_deliveryorders(state, data) {
state.deliveryorders = data.records
state.total= data.total
state.total_filter= data.total_filter
},
update_error_details(state, val) {
state.error_details = val
},
update_last_id_details(state, val) {
state.last_id_details = val
},
update_show_all_details(state, val) {
state.show_all_details = val
},
update_error_details(state, val) {
state.error_details = val
},
update_loading_detail(state, val) {
state.loading = val
},
update_selected_deliveryorder(state, val) {
state.selected_deliveryorder = val
}
},
actions: {
async lookup(context, prm) {
context.commit("update_loading", true)
try {
prm.token = one_token()
let resp = await api.lookup(prm)
if (resp.status != "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
}
if (prm.lastid === -1) {
var pat = data.records[0]
context.commit("update_selected_deliveryorder", pat)
context.commit("update_deliveryorders", data)
context.dispatch("sample/selected", {id: pat.id},{root: true})
context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
} else {
var pat = data.records[prm.lastid]
context.commit("update_selected_deliveryorder", pat)
context.commit("update_deliveryorders", data)
context.dispatch("sample/selected", {id: pat.id},{root: true})
context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
}
}
} catch (e) {
context.commit("update_loading", false)
context.commit("update_error", e.message)
}
},
async lookupbybarcode(context, prm) {
context.commit("update_loading", true)
try {
prm.token = one_token()
let resp = await api.lookupbybarcode(prm)
if (resp.status != "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
}
if (prm.lastid === -1) {
var pat = data.records[0]
context.commit("update_selected_deliveryorder", pat)
var cek = context.state.xcek
console.log('cek di modules')
console.log(cek)
if(cek === 0){
context.dispatch("sample/selected", {
id: pat.id,
barcode: prm.search
}, {
root: true
})
}
context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
} else {
var pat = data.records[prm.lastid]
context.commit("update_selected_deliveryorder", pat)
context.dispatch("sample/selected", {id: pat.id, barcode: prm.search},{root: true})
context.dispatch("deliveryorderdetail/lookup", {id: pat.id, current_page : 1},{root: true})
}
}
} catch (e) {
context.commit("update_loading", false)
context.commit("update_error", e.message)
}
},
async detail(context, prm) {
context.commit("update_loading_details", true)
try {
prm.token = one_token()
let resp = await api.detail(prm)
if (resp.status != "OK") {
context.commit("update_loading_details", false)
context.commit("update_lookup_error_details", resp.message)
} else {
context.commit("update_loading_details", false)
context.commit("update_lookup_error_details", "")
let data = {
records: resp.data.records,
total: resp.data.total,
total_filter: resp.data.total_filter
}
context.commit("update_details", data)
}
} catch (e) {
context.commit("update_lookup_details", false)
context.commit("update_lookup_error_details", e.message)
}
}
}
}