168 lines
5.1 KiB
Vue
168 lines
5.1 KiB
Vue
<script setup>
|
|
import axios from 'axios';
|
|
import { ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useQuasar } from 'quasar';
|
|
import { useRoute } from 'vue-router';
|
|
import { useArrayData } from 'src/composables/useArrayData';
|
|
import Paginate from 'src/components/PaginateData.vue';
|
|
import FetchData from 'components/FetchData.vue';
|
|
import TeleportSlot from 'components/ui/TeleportSlot.vue';
|
|
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
|
|
|
import { toDate } from 'src/filters';
|
|
|
|
const quasar = useQuasar();
|
|
const route = useRoute();
|
|
const { t } = useI18n();
|
|
const arrayData = useArrayData('ClaimRma');
|
|
|
|
const claim = ref();
|
|
const fetcher = ref();
|
|
|
|
const claimFilter = {
|
|
fields: ['rma'],
|
|
};
|
|
|
|
async function onFetch(data) {
|
|
claim.value = data;
|
|
|
|
const filter = {
|
|
include: {
|
|
relation: 'worker',
|
|
scope: {
|
|
include: {
|
|
relation: 'user',
|
|
},
|
|
},
|
|
},
|
|
order: 'created DESC',
|
|
where: {
|
|
code: claim.value.rma,
|
|
},
|
|
};
|
|
|
|
arrayData.applyFilter({ filter });
|
|
}
|
|
|
|
async function addRow() {
|
|
const formData = {
|
|
code: claim.value.rma,
|
|
};
|
|
|
|
await axios.post(`ClaimRmas`, formData);
|
|
await arrayData.refresh();
|
|
|
|
quasar.notify({
|
|
type: 'positive',
|
|
message: t('globals.rowAdded'),
|
|
icon: 'check',
|
|
});
|
|
}
|
|
|
|
function confirmRemove(id) {
|
|
quasar
|
|
.dialog({
|
|
component: VnConfirm,
|
|
})
|
|
.onOk(() => remove(id));
|
|
}
|
|
|
|
async function remove(id) {
|
|
await axios.delete(`ClaimRmas/${id}`);
|
|
await arrayData.refresh();
|
|
|
|
quasar.notify({
|
|
type: 'positive',
|
|
message: t('globals.rowRemoved'),
|
|
icon: 'check',
|
|
});
|
|
}
|
|
</script>
|
|
<template>
|
|
<fetch-data
|
|
:url="`Claims/${route.params.id}`"
|
|
:filter="claimFilter"
|
|
@on-fetch="onFetch"
|
|
auto-load
|
|
/>
|
|
<paginate data-key="ClaimRma" url="ClaimRmas">
|
|
<template #body="{ rows }">
|
|
<q-card class="card">
|
|
<template v-for="(row, index) of rows" :key="row.id">
|
|
<q-item class="q-pa-none items-start">
|
|
<q-item-section class="q-pa-md">
|
|
<q-list>
|
|
<q-item class="q-pa-none">
|
|
<q-item-section>
|
|
<q-item-label caption>
|
|
{{ t('claim.rma.user') }}
|
|
</q-item-label>
|
|
<q-item-label>
|
|
{{ row.worker.user.name }}
|
|
</q-item-label>
|
|
</q-item-section>
|
|
</q-item>
|
|
<q-item class="q-pa-none">
|
|
<q-item-section>
|
|
<q-item-label caption>
|
|
{{ t('claim.rma.created') }}
|
|
</q-item-label>
|
|
<q-item-label>
|
|
{{
|
|
toDate(row.created, {
|
|
timeStyle: 'medium',
|
|
})
|
|
}}
|
|
</q-item-label>
|
|
</q-item-section>
|
|
</q-item>
|
|
</q-list>
|
|
</q-item-section>
|
|
<q-card-actions vertical class="justify-between">
|
|
<q-btn
|
|
flat
|
|
round
|
|
color="orange"
|
|
icon="vn:bin"
|
|
@click="confirmRemove(row.id)"
|
|
>
|
|
<q-tooltip>{{ t('globals.remove') }}</q-tooltip>
|
|
</q-btn>
|
|
</q-card-actions>
|
|
</q-item>
|
|
<q-separator v-if="index !== rows.length - 1" />
|
|
</template>
|
|
</q-card>
|
|
</template>
|
|
</paginate>
|
|
|
|
<teleport-slot v-if="!quasar.platform.is.mobile" to="#header-actions">
|
|
<div class="row q-gutter-x-sm">
|
|
<q-btn @click="addRow()" icon="add" color="primary" dense rounded>
|
|
<q-tooltip bottom> {{ t('globals.add') }} </q-tooltip>
|
|
</q-btn>
|
|
<q-separator vertical />
|
|
</div>
|
|
</teleport-slot>
|
|
|
|
<teleport-slot to=".q-footer">
|
|
<q-tabs align="justify" inline-label narrow-indicator>
|
|
<q-tab @click="addRow()" icon="add_circle" :label="t('globals.add')" />
|
|
</q-tabs>
|
|
</teleport-slot>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
.q-toolbar {
|
|
background-color: $grey-9;
|
|
}
|
|
.sticky-page {
|
|
padding-top: 66px;
|
|
}
|
|
|
|
.q-page-sticky {
|
|
z-index: 2998;
|
|
}
|
|
</style>
|