ソースを参照

ajustes avaliacao: max 5 files, so permite anexar foto em avaliaca negativa, nao tava exibindo foto do avaliado, pré-seleciona favorito se ja era antes

Gustavo Zanatta 1 週間 前
コミット
1a65929fa3
1 ファイル変更33 行追加4 行削除
  1. 33 4
      src/components/dashboard/ScheduleRatingDialog.vue

+ 33 - 4
src/components/dashboard/ScheduleRatingDialog.vue

@@ -24,7 +24,14 @@
           class="q-mb-sm"
           size="64px"
         >
+          <img
+            v-if="photoUrl"
+            style="object-fit: cover"
+            :src="photoUrl"
+          />
+
           <span
+            v-else
             class="full-width full-height flex flex-center"
             style="font-size: 20px; border-radius: 50%;"
             :style="avatarStyle"
@@ -102,7 +109,10 @@
         />
       </q-card-section>
 
-      <q-card-section class="q-pt-xs q-pb-xs q-px-lg">
+      <q-card-section
+        v-if="isNegative"
+        class="q-pt-xs q-pb-xs q-px-lg"
+      >
         <input
           ref="photoInputRef"
           accept="image/jpeg,image/png,image/webp"
@@ -133,7 +143,7 @@
           </div>
 
           <div
-            v-if="photos.length < 5"
+            v-if="photos.length < MAX_PHOTOS"
             class="photo-add"
             @click="photoInputRef.click()"
           >
@@ -217,6 +227,8 @@ const { t } = useI18n()
 const $q = useQuasar()
 const store = userStore()
 
+const MAX_PHOTOS = 5
+
 const stars = ref(0)
 const selectedTagIds = ref([])
 const comment = ref(null)
@@ -235,6 +247,13 @@ const avatarStyle = computed(() => {
 
 const isNegative = computed(() => stars.value > 0 && stars.value <= 2)
 
+const photoUrl = computed(() =>
+  props.schedule.customer_photo
+  ?? props.schedule.client_photo
+  ?? props.schedule.client?.profile_media?.url
+  ?? null
+)
+
 const initials = computed(() =>
   getFirstName(props.schedule.client_name)?.slice(0, 2).toUpperCase() ?? '??'
 )
@@ -242,7 +261,7 @@ const initials = computed(() =>
 const onPhotosSelected = (event) => {
   const files = Array.from(event.target.files)
 
-  const remaining = 5 - photos.value.length
+  const remaining = MAX_PHOTOS - photos.value.length
 
   files.slice(0, remaining).forEach(file => {
     photos.value.push(file)
@@ -256,6 +275,16 @@ const onStarsChange = () => {
   selectedTagIds.value = []
 
   blockClient.value = false
+
+  if (!isNegative.value) clearPhotos()
+}
+
+const clearPhotos = () => {
+  photoPreviews.value.forEach(preview => URL.revokeObjectURL(preview))
+
+  photos.value = []
+
+  photoPreviews.value = []
 }
 
 const removePhoto = (idx) => {
@@ -292,7 +321,7 @@ const submit = async () => {
       block_provider: false,
       block_client: isNegative.value && blockClient.value,
       favorite_provider: false,
-      photos: photos.value,
+      photos: isNegative.value ? photos.value : [],
     })
 
     onDialogOK(true)