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

296 lines
9.9 KiB
JavaScript

// 1 => LOADING
// 2 => DONE
// 3 => ERROR
import * as api from "../api/deliveryorder.js"
export default {
namespaced: true,
state: {
last_id: -1,
act: 'new',
lookup_deliveryorder: 0,
lookup_error_message: '',
deliveryorders: [],
total_deliveryorders: 0,
total_filter_deliveryorders: 0,
startdate: moment(new Date()).format('DD-MM-YYYY'),
selected_deliveryorder: {
name: ""
},
save_status: 0,
save_error_message: '',
dialog_form_deliveryorder: false,
dialog_edit_form_deliveryorder: false,
alert_success: false,
msg_success: "",
show_all: 'N',
errors: [],
deliveryordertypes: [],
deliveryordertype: {},
branchs: [],
branch: {},
destinations: [],
destination: {},
worklists: [],
worklist: {},
couriers: [],
courier: {},
get_data_status: 0,
get_data_error_message: '',
cities: [],
deliveryorderdetail_address: {},
autocomplete_status: 0,
search_status: 0,
autocitys:[],
autocity:{},
autodistricts:[],
autodistrict:{},
autokelurahans:[],
autokelurahan:{},
nonlabs: [],
selected_nonlab: {},
current_page: 1,
x_search: '',
isexternal: 'N',
dialog_form_viewresult: false,
deliveryorderdetailresults: []
},
mutations: {
update_dialog_form_viewresult(state, val) {
state.dialog_form_viewresult = val
},
update_deliveryorderdetailresults(state, data) {
state.deliveryorderdetailresults = data
},
update_isexternal(state, val) {
state.isexternal = val
},
update_x_search(state, val) {
state.x_search = val
},
update_current_page(state, val) {
state.current_page = val
},
update_last_id(state, val) {
state.last_id = val
},
update_act(state, val) {
state.act = val
},
update_errors(state, val) {
state.errors = val
},
update_show_all(state, val) {
state.show_all = val
},
update_startdate(state, val) {
state.startdate = val
},
update_lookup_error_message(state, status) {
state.lookup_error_message = status
},
update_lookup_deliveryorder(state, status) {
state.lookup_deliveryorder = status
},
update_deliveryorders(state, data) {
state.deliveryorders = data.records
state.total_deliveryorders = data.total
state.total_filter_deliveryorders = data.total_filter
},
update_selected_deliveryorder(state, val) {
state.selected_deliveryorder = val
},
update_save_status(state, val) {
state.save_status = val
},
update_save_error_message(state, val) {
state.save_error_message = val
},
update_dialog_form_deliveryorder(state, val) {
state.dialog_form_deliveryorder = val
},
update_dialog_edit_form_deliveryorder(state, val) {
state.dialog_edit_form_deliveryorder = val
},
update_alert_success(state, val) {
state.alert_success = val
},
update_msg_success(state, val) {
state.msg_success = val
},
update_deliveryordertypes(state, data) {
state.deliveryordertypes = data
},
update_deliveryordertype(state, val) {
state.deliveryordertype = val
},
update_branchs(state, data) {
state.branchs = data
},
update_branch(state, val) {
state.branch = val
},
update_destinations(state, data) {
state.destinations = data
},
update_destination(state, val) {
state.destination = val
},
update_worklists(state, data) {
state.worklists = data
},
update_worklist(state, val) {
state.worklist = val
},
update_couriers(state, data) {
state.couriers = data
},
update_courier(state, val) {
state.courier = val
},
update_autocitys(state,data){
state.autocitys = data
},
update_autocity(state,val){
state.autocity = val
},
update_autodistricts(state,data){
state.autodistricts = data
},
update_autodistrict(state,val){
state.autodistrict = val
},
update_autokelurahans(state,data){
state.autokelurahans = data
},
update_autokelurahan(state,val){
state.autokelurahan = 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_cities(state, val) {
state.cities = val
},
update_deliveryorderdetail_address(state, val) {
state.deliveryorderdetail_address = val
},
update_autocomplete_status(state, val) {
state.autocomplete_status = val
},
update_districts(state, val) {
state.districts = val
},
update_district_address(state, val) {
state.district_address = val
},
update_kelurahans(state, val) {
state.kelurahans = val
},
update_kelurahan_address(state, val) {
state.kelurahan_address = val
},
update_instruments(state, data) {
state.instruments = data
},
update_instrument(state, val) {
state.instrument = val
},
update_autotemplates(state, data) {
state.autotemplates = data
},
update_autotemplate(state, val) {
state.autotemplate = val
},
update_nonlabs(state, val) {
state.nonlabs = val
},
update_selected_nonlab(state, val) {
state.selected_nonlab = val
}
},
actions: {
async lookupbyname(context, prm) {
context.commit("update_lookup_deliveryorder", 1)
try {
prm.token = one_token()
let resp = await api.lookupbyname(prm)
if (resp.status != "OK") {
context.commit("update_lookup_deliveryorder", 3)
context.commit("update_lookup_error_message", resp.message)
} else {
context.commit("update_lookup_deliveryorder", 2)
context.commit("update_lookup_error_message", "")
let data = {
records: resp.data.records,
total: resp.data.total,
total_filter: resp.data.total_filter,
branchid: resp.data.branchid,
branchname: resp.data.branchname
}
context.commit("update_deliveryorders", data)
console.log(data.branchname)
context.commit("update_branchs", [{
M_BranchID: data.branchid,
M_BranchName: data.branchname
}])
context.commit("update_branch", {
M_BranchID: data.branchid,
M_BranchName: data.branchname
})
if (prm.lastid === -1) {
// context.commit("update_selected_deliveryorder", data.records[0])
var pat = data.records[0]
context.dispatch("deliveryorderdetail/lookupbyid", {
id: pat.id,
current_page: 1,
lastid: -1
}, {
root: true
})
} else {
//context.commit("update_selected_deliveryorder", data.records[prm.lastid])
var pat = data.records[prm.lastid]
context.dispatch("deliveryorderdetail/lookupbyid", {
id: pat.id,
current_page: 1,
lastid: -1
}, {
root: true
})
}
}
} catch (e) {
context.commit("update_lookup_deliveryorder", 3)
context.commit("update_lookup_error_message", e.message)
}
},
async lookupresultbyid(context, prm) {
context.commit("update_save_status", 1)
try {
prm.token = one_token()
let resp = await api.lookupresultbyid(prm)
if (resp.status != "OK") {
context.commit("update_save_status", 3)
} else {
context.commit("update_save_status", 2)
let data = {
records: resp.data.records,
total: resp.data.total
}
context.commit("update_deliveryorderdetailresults", data.records)
console.log(data.records)
// context.commit("update_total_data", data.total)
}
} catch (e) {
context.commit("update_save_status", 3)
}
}
}
}