|
|
@@ -15,18 +15,18 @@
|
|
|
<div class="row full-width q-mt-md q-col-gutter-sm">
|
|
|
<StateSelect
|
|
|
v-model="form.state"
|
|
|
- class="col-6"
|
|
|
+ class="col-3"
|
|
|
outlined
|
|
|
label="Estado / UF"
|
|
|
:initial-id="editStateId"
|
|
|
/>
|
|
|
|
|
|
- <UnitSelect
|
|
|
- v-model="form.unit"
|
|
|
- class="col-6"
|
|
|
+ <UnitMultiSelect
|
|
|
+ v-model="form.units"
|
|
|
+ class="col-9"
|
|
|
outlined
|
|
|
- label="Unidade"
|
|
|
- :initial-id="editUnitId"
|
|
|
+ label="Unidades"
|
|
|
+ :initial-ids="editUnitIds"
|
|
|
/>
|
|
|
|
|
|
<UserTypeSelect
|
|
|
@@ -151,7 +151,7 @@ import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
|
|
|
import DefaultInput from "src/components/defaults/DefaultInput.vue";
|
|
|
import AvatarImageComponent from "src/components/shared/AvatarImageComponent.vue";
|
|
|
import StateSelect from "src/components/selects/StateSelect.vue";
|
|
|
-import UnitSelect from "src/components/selects/UnitSelect.vue";
|
|
|
+import UnitMultiSelect from "src/components/selects/UnitMultiSelect.vue";
|
|
|
import UserTypeSelect from "src/components/selects/UserTypeSelect.vue";
|
|
|
import { useInputRules } from "src/composables/useInputRules";
|
|
|
import { useSubmitHandler } from "src/composables/useSubmitHandler";
|
|
|
@@ -169,13 +169,13 @@ const showPassword = ref(false);
|
|
|
const showPasswordConfirm = ref(false);
|
|
|
|
|
|
const editStateId = ref(null);
|
|
|
-const editUnitId = ref(null);
|
|
|
+const editUnitIds = ref([]);
|
|
|
|
|
|
const isEdit = computed(() => !!route.params.id);
|
|
|
|
|
|
const form = ref({
|
|
|
state: null,
|
|
|
- unit: null,
|
|
|
+ units: [],
|
|
|
user_type: null,
|
|
|
cpf: null,
|
|
|
name: null,
|
|
|
@@ -200,7 +200,7 @@ onMounted(async () => {
|
|
|
form.value.cpf = user.cpf;
|
|
|
form.value.user_type = user.user_type;
|
|
|
editStateId.value = user.state_id ?? null;
|
|
|
- editUnitId.value = user.unit_id ?? null;
|
|
|
+ editUnitIds.value = user.units?.map((u) => u.id) ?? [];
|
|
|
if (user.avatar_url) {
|
|
|
avatarRef.value?.setImageUrl(user.avatar_url);
|
|
|
}
|
|
|
@@ -214,7 +214,7 @@ function buildFormData() {
|
|
|
|
|
|
if (avatarFile.value) fd.append("avatar", avatarFile.value);
|
|
|
if (form.value.state?.value) fd.append("state_id", form.value.state.value);
|
|
|
- if (form.value.unit?.value) fd.append("unit_id", form.value.unit.value);
|
|
|
+ form.value.units?.forEach((u) => fd.append("unit_ids[]", u.value));
|
|
|
if (form.value.user_type) fd.append("user_type", form.value.user_type);
|
|
|
if (form.value.cpf) fd.append("cpf", form.value.cpf);
|
|
|
|
|
|
@@ -231,7 +231,8 @@ function buildUpdateData() {
|
|
|
|
|
|
if (avatarFile.value) fd.append("avatar", avatarFile.value);
|
|
|
if (form.value.state?.value) fd.append("state_id", form.value.state.value);
|
|
|
- if (form.value.unit?.value) fd.append("unit_id", form.value.unit.value);
|
|
|
+ // Sempre envia unit_ids[] para sincronizar (array vazio limpa todas as unidades)
|
|
|
+ (form.value.units ?? []).forEach((u) => fd.append("unit_ids[]", u.value));
|
|
|
if (form.value.user_type) fd.append("user_type", form.value.user_type);
|
|
|
if (form.value.cpf) fd.append("cpf", form.value.cpf);
|
|
|
if (form.value.name) fd.append("name", form.value.name);
|