231 lines
7.1 KiB
Vue
231 lines
7.1 KiB
Vue
<script>
|
|
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
|
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
|
import {ref} from "vue";
|
|
import {authenticatedRequest} from "@/components/session/authenticatedRequest.vue";
|
|
|
|
/**
|
|
* Local vehicle conditions cache
|
|
* @type {ref<null>}
|
|
*/
|
|
export const vehicle_conditions_cache = ref(null);
|
|
|
|
/**
|
|
* The SelfServeVehicleConditions object
|
|
*/
|
|
export const SelfServeVehicleConditions = {
|
|
meta: {
|
|
title: "Køretøjsbetingelser",
|
|
icon: "fas fa-car-side",
|
|
description: "Oversigt over køretøjsbetingelser (Svar på spørgsmål)",
|
|
endpoint: "/department/selfserve/vehicle/conditions",
|
|
labels: {
|
|
single: "køretøjsbetingelse",
|
|
multiple: "køretøjsbetingelser"
|
|
}
|
|
},
|
|
columns: {
|
|
id: {
|
|
label: "ID",
|
|
type: "number",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
}
|
|
},
|
|
department: {
|
|
label: "Afdeling",
|
|
type: "number",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
}
|
|
},
|
|
lane: {
|
|
label: "Bane",
|
|
type: "number",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
}
|
|
},
|
|
customer_id: {
|
|
label: "Kunde ID",
|
|
type: "number",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
}
|
|
},
|
|
reg: {
|
|
label: "Registreringsnummer",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: true,
|
|
onchange: async (event, helpers) => {
|
|
const reg = event.target.value;
|
|
if (reg && reg.length > 2) {
|
|
try {
|
|
const status = await SessionUser.objects.vehicles.functions.getVehicleStatus(reg);
|
|
if (status && status.customer_id) {
|
|
helpers.setFieldValue('customer_id', status.customer_id);
|
|
}
|
|
} catch (e) {
|
|
console.error("Could not fetch vehicle status", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
question: {
|
|
label: "Spørgsmål",
|
|
type: "select",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
},
|
|
options: async (lockedValues = {}) => {
|
|
const departmentId = lockedValues.department || lockedValues.department_id;
|
|
const questions = await SessionUser.objects.self_serve_questions.get.all(
|
|
departmentId ? { department: parseInt(departmentId) } : {}
|
|
);
|
|
|
|
const [departments, products] = await Promise.all([
|
|
SessionUser.objects.departments.get.all(),
|
|
SessionUser.objects.products.get.all()
|
|
]);
|
|
|
|
return questions.map(q => {
|
|
const departmentName = departments.find(d => parseInt(d.id) === parseInt(q.department))?.name || q.department;
|
|
const productName = products.find(p => parseInt(p.id) === parseInt(q.product))?.name || q.product;
|
|
return {
|
|
...q,
|
|
name: `${departmentName}-${q.lane}-${productName}: ${q.question}`
|
|
};
|
|
});
|
|
},
|
|
parse: (id) => {
|
|
return SessionUser.objects.self_serve_questions.functions.getQuestionText(id);
|
|
}
|
|
},
|
|
value: {
|
|
label: "Værdi",
|
|
type: "boolean",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
}
|
|
},
|
|
created_at: {
|
|
label: "Oprettet",
|
|
type: "datetime",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
}
|
|
}
|
|
},
|
|
add: async (department, lane, customer_id, reg, question, value, options = {}) => {
|
|
const safeOptions = {};
|
|
const normalizedVehicleType = parseInt(options.vehicle_type ?? options.vehicle_type_id);
|
|
|
|
if (!Number.isNaN(normalizedVehicleType) && normalizedVehicleType > 0) {
|
|
safeOptions.vehicle_type = normalizedVehicleType;
|
|
}
|
|
|
|
return ObjectsGlobal.add.object(SelfServeVehicleConditions.meta.endpoint, {
|
|
department: parseInt(department),
|
|
lane: parseInt(lane),
|
|
customer_id: parseInt(customer_id),
|
|
reg: reg,
|
|
question: parseInt(question),
|
|
value: value === "true" || value === true,
|
|
...safeOptions,
|
|
activate_machine: false,
|
|
sync_relay_state: false
|
|
});
|
|
},
|
|
set: {
|
|
department: async (id, department) => {
|
|
return ObjectsGlobal.set.column(SelfServeVehicleConditions.meta.endpoint, id, "department", parseInt(department));
|
|
},
|
|
lane: async (id, lane) => {
|
|
return ObjectsGlobal.set.column(SelfServeVehicleConditions.meta.endpoint, id, "lane", parseInt(lane));
|
|
},
|
|
customer_id: async (id, customer_id) => {
|
|
return ObjectsGlobal.set.column(SelfServeVehicleConditions.meta.endpoint, id, "customer_id", parseInt(customer_id));
|
|
},
|
|
reg: async (id, reg) => {
|
|
return ObjectsGlobal.set.column(SelfServeVehicleConditions.meta.endpoint, id, "reg", reg);
|
|
},
|
|
question: async (id, question) => {
|
|
return ObjectsGlobal.set.column(SelfServeVehicleConditions.meta.endpoint, id, "question", parseInt(question));
|
|
},
|
|
value: async (id, value) => {
|
|
return ObjectsGlobal.set.column(SelfServeVehicleConditions.meta.endpoint, id, "value", value === "true" || value === true);
|
|
}
|
|
},
|
|
get: {
|
|
all: async (filters = {}) => {
|
|
return ObjectsGlobal.get.objects(SelfServeVehicleConditions.meta.endpoint, filters);
|
|
},
|
|
single: async (id) => {
|
|
return ObjectsGlobal.get.object(SelfServeVehicleConditions.meta.endpoint, id);
|
|
},
|
|
previewAllowed: async (laneId, reg, vehicleTypeId, options = {}) => {
|
|
const params = {
|
|
lane_id: parseInt(laneId),
|
|
reg: reg,
|
|
};
|
|
|
|
const normalizedVehicleTypeId = parseInt(vehicleTypeId);
|
|
if (!Number.isNaN(normalizedVehicleTypeId) && normalizedVehicleTypeId > 0) {
|
|
params.vehicle_type = normalizedVehicleTypeId;
|
|
}
|
|
|
|
return authenticatedRequest("/department/selfserve/vehicle/allowed", "GET", params, null, null, options)
|
|
.then((response) => response.data.data || response.data);
|
|
},
|
|
washSummary: async (params, options) => {
|
|
return authenticatedRequest("/department/selfserve/washes/summary", "GET", params || {}, null, null, options || {})
|
|
.then((response) => response.data.data || response.data);
|
|
}
|
|
},
|
|
delete: async (id) => {
|
|
return ObjectsGlobal.delete.object(SelfServeVehicleConditions.meta.endpoint, id);
|
|
},
|
|
functions: {
|
|
showDeleteObjectForm: (id, onAfterSubmit = null) => {
|
|
return ObjectsGlobal.showDeleteObjectForm(SelfServeVehicleConditions, id, onAfterSubmit);
|
|
},
|
|
},
|
|
/**
|
|
* Show the create object form
|
|
* @param initialData
|
|
* @param onAfterSubmit
|
|
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
|
*/
|
|
showCreateObjectForm: (initialData = {}, onAfterSubmit = null) => {
|
|
return ObjectsGlobal.showCreateObjectForm(SelfServeVehicleConditions, onAfterSubmit, initialData);
|
|
},
|
|
/**
|
|
* Show the edit object field form
|
|
* @param id
|
|
* @param column
|
|
* @param value
|
|
* @param onAfterSubmit
|
|
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
|
*/
|
|
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null) => {
|
|
return ObjectsGlobal.showEditObjectFieldForm(
|
|
SelfServeVehicleConditions,
|
|
id,
|
|
column,
|
|
value,
|
|
onAfterSubmit
|
|
);
|
|
}
|
|
};
|
|
</script>
|