|
|
@@ -23,6 +23,73 @@
|
|
|
type="number"
|
|
|
/>
|
|
|
|
|
|
+ <q-banner class="col-12 bg-blue-1 text-primary rounded-borders">
|
|
|
+ A duração padrão das aulas é de 2 horas e pode ser alterada se
|
|
|
+ necessário. É possível configurar no máximo dois dias.
|
|
|
+ </q-banner>
|
|
|
+
|
|
|
+ <DefaultInput
|
|
|
+ v-model="form.class_duration_hours"
|
|
|
+ label="Duração da Aula (horas)"
|
|
|
+ class="col-12"
|
|
|
+ type="number"
|
|
|
+ min="0.5"
|
|
|
+ max="24"
|
|
|
+ step="0.5"
|
|
|
+ />
|
|
|
+
|
|
|
+ <DefaultSelect
|
|
|
+ v-model="form.weekday"
|
|
|
+ label="1º Dia da Semana"
|
|
|
+ class="col-4"
|
|
|
+ :options="weekdays"
|
|
|
+ option-value="value"
|
|
|
+ option-label="label"
|
|
|
+ emit-value
|
|
|
+ map-options
|
|
|
+ clearable
|
|
|
+ />
|
|
|
+
|
|
|
+ <DefaultInput
|
|
|
+ v-model="form.start_time"
|
|
|
+ label="Horário Inicial"
|
|
|
+ class="col-4"
|
|
|
+ mask="##:##"
|
|
|
+ />
|
|
|
+
|
|
|
+ <DefaultInput
|
|
|
+ :model-value="firstEndTime"
|
|
|
+ label="Horário Final"
|
|
|
+ class="col-4"
|
|
|
+ disable
|
|
|
+ />
|
|
|
+
|
|
|
+ <DefaultSelect
|
|
|
+ v-model="form.second_weekday"
|
|
|
+ label="2º Dia da Semana"
|
|
|
+ class="col-4"
|
|
|
+ :options="secondWeekdayOptions"
|
|
|
+ option-value="value"
|
|
|
+ option-label="label"
|
|
|
+ emit-value
|
|
|
+ map-options
|
|
|
+ clearable
|
|
|
+ />
|
|
|
+
|
|
|
+ <DefaultInput
|
|
|
+ v-model="form.second_start_time"
|
|
|
+ label="Horário Inicial do 2º dia"
|
|
|
+ class="col-4"
|
|
|
+ mask="##:##"
|
|
|
+ />
|
|
|
+
|
|
|
+ <DefaultInput
|
|
|
+ :model-value="secondEndTime"
|
|
|
+ label="Horário Final do 2º dia"
|
|
|
+ class="col-4"
|
|
|
+ disable
|
|
|
+ />
|
|
|
+
|
|
|
<DefaultCurrencyInput
|
|
|
v-model="form.contract_register_value"
|
|
|
label="R$ Matrícula"
|
|
|
@@ -119,7 +186,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, computed, onMounted } from "vue";
|
|
|
+import { ref, computed, onMounted, watch } from "vue";
|
|
|
import { useDialogPluginComponent } from "quasar";
|
|
|
|
|
|
import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
|
@@ -151,6 +218,30 @@ const loading = ref(false);
|
|
|
|
|
|
const products = ref([]);
|
|
|
|
|
|
+const weekdays = [
|
|
|
+ { value: 1, label: "Segunda" },
|
|
|
+ { value: 2, label: "Terça" },
|
|
|
+ { value: 3, label: "Quarta" },
|
|
|
+ { value: 4, label: "Quinta" },
|
|
|
+ { value: 5, label: "Sexta" },
|
|
|
+ { value: 6, label: "Sábado" },
|
|
|
+ { value: 0, label: "Domingo" },
|
|
|
+];
|
|
|
+
|
|
|
+const trimTime = (time) => (time ? time.slice(0, 5) : null);
|
|
|
+
|
|
|
+const calculateEndTime = (startTime, durationHours) => {
|
|
|
+ if (!/^\d{2}:\d{2}$/.test(startTime ?? "")) return null;
|
|
|
+ const [hours, minutes] = startTime.split(":").map(Number);
|
|
|
+ if (hours > 23 || minutes > 59) return null;
|
|
|
+ const end =
|
|
|
+ (hours * 60 + minutes + Math.round(Number(durationHours) * 60)) %
|
|
|
+ (24 * 60);
|
|
|
+ return `${String(Math.floor(end / 60)).padStart(2, "0")}:${String(
|
|
|
+ end % 60,
|
|
|
+ ).padStart(2, "0")}`;
|
|
|
+};
|
|
|
+
|
|
|
const productOptions = computed(() =>
|
|
|
products.value.map((p) => ({
|
|
|
label: p.name,
|
|
|
@@ -165,9 +256,37 @@ const form = ref({
|
|
|
contract_register_value: props.package?.contract_register_value ?? null,
|
|
|
contract_value: props.package?.contract_value ?? null,
|
|
|
contrat_discount_value: props.package?.contrat_discount_value ?? null,
|
|
|
+ class_duration_hours:
|
|
|
+ (props.package?.class_duration_minutes ?? 120) / 60,
|
|
|
+ weekday: props.package?.weekday ?? null,
|
|
|
+ start_time: trimTime(props.package?.start_time),
|
|
|
+ second_weekday: props.package?.second_weekday ?? null,
|
|
|
+ second_start_time: trimTime(props.package?.second_start_time),
|
|
|
materials: [{ product_id: null, quantity: 1, price: null }],
|
|
|
});
|
|
|
|
|
|
+const secondWeekdayOptions = computed(() =>
|
|
|
+ weekdays.filter((day) => day.value !== form.value.weekday),
|
|
|
+);
|
|
|
+const firstEndTime = computed(() =>
|
|
|
+ calculateEndTime(form.value.start_time, form.value.class_duration_hours),
|
|
|
+);
|
|
|
+const secondEndTime = computed(() =>
|
|
|
+ calculateEndTime(
|
|
|
+ form.value.second_start_time,
|
|
|
+ form.value.class_duration_hours,
|
|
|
+ ),
|
|
|
+);
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => form.value.weekday,
|
|
|
+ (weekday) => {
|
|
|
+ if (form.value.second_weekday === weekday) {
|
|
|
+ form.value.second_weekday = null;
|
|
|
+ }
|
|
|
+ },
|
|
|
+);
|
|
|
+
|
|
|
const onProductSelected = (material) => {
|
|
|
const option = productOptions.value.find(
|
|
|
(o) => o.value === material.product_id,
|
|
|
@@ -189,6 +308,12 @@ onMounted(async () => {
|
|
|
|
|
|
if (props.package?.id) {
|
|
|
const pkg = await getUnitPackage(props.package.id);
|
|
|
+ form.value.class_duration_hours =
|
|
|
+ (pkg.class_duration_minutes ?? 120) / 60;
|
|
|
+ form.value.weekday = pkg.weekday ?? null;
|
|
|
+ form.value.start_time = trimTime(pkg.start_time);
|
|
|
+ form.value.second_weekday = pkg.second_weekday ?? null;
|
|
|
+ form.value.second_start_time = trimTime(pkg.second_start_time);
|
|
|
if (pkg.materials?.length) {
|
|
|
form.value.materials = pkg.materials.map((m) => ({
|
|
|
product_id: m.product_id,
|
|
|
@@ -210,6 +335,13 @@ const onOKClick = async () => {
|
|
|
contract_value: form.value.contract_value,
|
|
|
contract_register_value: form.value.contract_register_value,
|
|
|
contrat_discount_value: form.value.contrat_discount_value,
|
|
|
+ class_duration_minutes: Math.round(
|
|
|
+ Number(form.value.class_duration_hours) * 60,
|
|
|
+ ),
|
|
|
+ weekday: form.value.weekday,
|
|
|
+ start_time: form.value.start_time || null,
|
|
|
+ second_weekday: form.value.second_weekday,
|
|
|
+ second_start_time: form.value.second_start_time || null,
|
|
|
materials: validMaterials.map((m) => ({
|
|
|
product_id: m.product_id,
|
|
|
quantity: Number(m.quantity),
|