hesabixCore/webUI/src/views/acc/component/notes.vue

210 lines
6.3 KiB
Vue
Raw Normal View History

2025-03-21 14:20:43 +03:30
<script lang="ts">
2025-03-29 16:33:41 +03:30
import { defineComponent } from 'vue';
2025-03-21 14:20:43 +03:30
import axios from 'axios';
export default defineComponent({
2025-03-29 16:33:41 +03:30
name: 'Notes',
2025-03-21 14:20:43 +03:30
props: {
stat: Object,
code: String,
2025-03-29 16:33:41 +03:30
typeNote: String,
2025-03-21 14:20:43 +03:30
},
2025-03-29 16:33:41 +03:30
data() {
2025-03-21 14:20:43 +03:30
return {
2025-03-29 16:33:41 +03:30
dialog: false, // برای باز و بسته کردن دیالوگ
loading: false,
2025-03-21 14:20:43 +03:30
items: [],
des: '',
2025-03-29 16:33:41 +03:30
snackbar: false, // برای نمایش اسنک‌بار
snackbarText: '', // متن پیام اسنک‌بار
snackbarColor: 'success', // رنگ اسنک‌بار (success, error)
};
},
mounted() {
this.loadData();
2025-03-21 14:20:43 +03:30
},
methods: {
loadData() {
this.loading = true;
2025-03-29 16:33:41 +03:30
axios
.post('/api/notes/list', {
type: this.$props.typeNote,
code: this.$props.code,
})
.then((response) => {
this.items = response.data;
this.$props.stat.count = response.data.length;
this.loading = false;
});
2025-03-21 14:20:43 +03:30
},
remove(id) {
this.loading = true;
2025-03-29 16:33:41 +03:30
axios.post(`/api/notes/remove/${id}`).then((response) => {
2025-03-21 14:20:43 +03:30
this.loading = false;
2025-03-29 16:33:41 +03:30
this.items = this.items.filter(item => item.id !== id); // حذف از لیست محلی
this.$props.stat.count = this.items.length; // به‌روزرسانی تعداد
this.snackbarText = 'یادداشت با موفقیت حذف شد.';
this.snackbarColor = 'success';
this.snackbar = true;
}).catch((error) => {
this.loading = false;
this.snackbarText = 'خطایی در حذف یادداشت رخ داد.';
this.snackbarColor = 'error';
this.snackbar = true;
console.error('خطا:', error);
});
2025-03-21 14:20:43 +03:30
},
save() {
2025-03-29 16:33:41 +03:30
if (this.des.trim() === '') {
this.snackbarText = 'شرح الزامی است.';
this.snackbarColor = 'error';
this.snackbar = true;
} else {
2025-03-21 14:20:43 +03:30
this.loading = true;
2025-03-29 16:33:41 +03:30
axios
.post('/api/notes/add', {
des: this.des,
type: this.$props.typeNote,
code: this.$route.params.id,
})
.then((response) => {
this.loading = false;
// اضافه کردن یادداشت جدید به لیست محلی
this.items.unshift({
id: response.data.id, // فرض می‌کنیم سرور id رو برمی‌گردونه
des: this.des,
});
this.$props.stat.count = this.items.length; // به‌روزرسانی تعداد
this.snackbarText = 'یادداشت با موفقیت ثبت شد.';
this.snackbarColor = 'success';
this.snackbar = true;
this.des = ''; // ریست کردن ورودی
})
.catch((error) => {
this.loading = false;
this.snackbarText = 'خطایی در ثبت یادداشت رخ داد.';
this.snackbarColor = 'error';
this.snackbar = true;
console.error('خطا:', error);
2025-03-21 14:20:43 +03:30
});
}
2025-03-29 16:33:41 +03:30
},
2025-03-21 14:20:43 +03:30
},
2025-03-29 16:33:41 +03:30
});
2025-03-21 14:20:43 +03:30
</script>
<template>
2025-03-29 16:33:41 +03:30
<!-- دکمه در تولبار -->
<v-btn icon color="warning" class="ml-2" @click="dialog = true">
<v-badge :content="items.length.toString()" color="dark">
<v-icon>mdi-note</v-icon>
</v-badge>
<v-tooltip activator="parent" location="bottom">یادداشتها</v-tooltip>
</v-btn>
<!-- دیالوگ یادداشتها -->
<v-dialog v-model="dialog" max-width="600" persistent>
<v-card>
<v-toolbar color="toolbar" flat dark>
<v-toolbar-title>
<v-icon color="warning" left>mdi-note</v-icon>
یادداشتها
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon @click="dialog = false">
<v-icon>mdi-close</v-icon>
</v-btn>
</v-toolbar>
<v-card-text>
<!-- فرم افزودن یادداشت -->
<v-row>
<v-col cols="12">
<v-text-field
v-model="des"
label="شرح"
placeholder="شرح یادداشت"
outlined
class="mt-2"
:disabled="loading"
@keyup.enter="save"
:loading="loading"
></v-text-field>
<v-btn
color="success"
@click="save"
class="mt-2"
:loading="loading"
>
<v-icon left>mdi-content-save</v-icon>
ثبت یادداشت
</v-btn>
</v-col>
</v-row>
<v-divider class="my-4"></v-divider>
<!-- لیست یادداشتها با اسکرول -->
<v-row>
<v-col cols="12">
<h5 class="text-primary">یادداشتهای ثبتشده</h5>
<v-list
max-height="300"
class="overflow-y-auto"
>
<v-list-item
v-for="item in items"
:key="item.id"
class="my-1"
>
<v-list-item-title class="d-flex align-center">
<span>{{ item.des }}</span>
<v-spacer></v-spacer>
<v-btn
icon
variant="plain"
:disabled="loading"
@click="remove(item.id)"
>
<v-icon color="error">mdi-trash-can</v-icon>
<v-tooltip activator="parent" location="top">حذف</v-tooltip>
</v-btn>
</v-list-item-title>
</v-list-item>
<v-list-item v-if="items.length === 0">
<v-list-item-title class="text-muted text-center">
یادداشتی موجود نیست
</v-list-item-title>
</v-list-item>
</v-list>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-dialog>
<!-- اسنکبار برای نمایش پیامها -->
<v-snackbar
v-model="snackbar"
:color="snackbarColor"
timeout="3000"
location="top"
>
{{ snackbarText }}
<template v-slot:actions>
<v-btn
color="white"
variant="text"
@click="snackbar = false"
>
بستن
</v-btn>
</template>
</v-snackbar>
2025-03-21 14:20:43 +03:30
</template>
2025-03-29 16:33:41 +03:30
<style scoped>
.overflow-y-auto {
overflow-y: auto;
}
</style>