|
|
@@ -0,0 +1,118 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import { onMounted } from 'vue'
|
|
|
+import RegularPage from '@/components/RegularPage.vue'
|
|
|
+
|
|
|
+import { type BaseTableColumns, MessagePlugin } from 'tdesign-vue-next'
|
|
|
+import { useSearchable } from '@/composables/useSearchable'
|
|
|
+import { deleteProduct } from '@/api/product'
|
|
|
+import type { Product } from '@/model/product'
|
|
|
+import ProductDialog from '@/pages/product/components/ProductDialog.vue'
|
|
|
+import ImagePreviewer from '@/components/ImagePreviewer.vue'
|
|
|
+import type { PetVariety, SearchPetVarietyFilter } from '@/model/pet-variety'
|
|
|
+import { deletePetVariety, searchPetVarieties } from '@/api/petVariety'
|
|
|
+import PetVarietyDialog from '@/pages/pet-variety/components/PetVarietyDialog.vue'
|
|
|
+const { data, loading, pagination, onPageChange, fetchData } = useSearchable<
|
|
|
+ SearchPetVarietyFilter,
|
|
|
+ PetVariety
|
|
|
+>(searchPetVarieties)
|
|
|
+
|
|
|
+const columns: BaseTableColumns = [
|
|
|
+ {
|
|
|
+ title: '品种名称',
|
|
|
+ colKey: 'name',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '创建时间',
|
|
|
+ colKey: 'createdTime',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ colKey: 'operation',
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
+onMounted(fetchData)
|
|
|
+
|
|
|
+
|
|
|
+const productDialogVisible = ref(false)
|
|
|
+
|
|
|
+const editData = ref<PetVariety | null>(null)
|
|
|
+
|
|
|
+const handleEdit = (data: PetVariety) => {
|
|
|
+ editData.value = data
|
|
|
+ productDialogVisible.value = true
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const handleDelete = async (id: string) => {
|
|
|
+ loading.value = true
|
|
|
+ try {
|
|
|
+ await deletePetVariety(id)
|
|
|
+ await fetchData()
|
|
|
+ await MessagePlugin.success('删除成功')
|
|
|
+ } catch (e) {
|
|
|
+ await MessagePlugin.error('删除失败')
|
|
|
+ }finally {
|
|
|
+ loading.value = false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const handleSuccess = async () => {
|
|
|
+ await fetchData()
|
|
|
+ productDialogVisible.value = false
|
|
|
+ editData.value = null
|
|
|
+}
|
|
|
+
|
|
|
+const handleClose = () => {
|
|
|
+ editData.value = null
|
|
|
+}
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <RegularPage title="宠物品种">
|
|
|
+ <template #right-area>
|
|
|
+ <TButton @click="productDialogVisible = true">添加品种</TButton>
|
|
|
+ </template>
|
|
|
+ <TTable
|
|
|
+ class="w-full h-full"
|
|
|
+ row-key="id"
|
|
|
+ height="92%"
|
|
|
+ table-layout="auto"
|
|
|
+ :data="data"
|
|
|
+ :loading="loading"
|
|
|
+ :columns="columns"
|
|
|
+ cell-empty-content="-"
|
|
|
+ :paginationAffixedBottom="true"
|
|
|
+ :pagination="{
|
|
|
+ total: pagination.total,
|
|
|
+ current: pagination.page,
|
|
|
+ pageSize: pagination.size,
|
|
|
+ onChange: onPageChange
|
|
|
+ }"
|
|
|
+ >
|
|
|
+
|
|
|
+ <template #operation="{ row }">
|
|
|
+ <TSpace :size="1">
|
|
|
+ <TButton variant="text" size="small" theme="primary" @click="() => handleEdit(row)"
|
|
|
+ >编辑</TButton
|
|
|
+ >
|
|
|
+ <t-popconfirm
|
|
|
+ theme="default"
|
|
|
+ content="确定删除此品种吗?"
|
|
|
+ @confirm="() => handleDelete(row.id)"
|
|
|
+ >
|
|
|
+ <TButton variant="text" size="small" theme="danger">删除</TButton>
|
|
|
+ </t-popconfirm>
|
|
|
+ </TSpace>
|
|
|
+ </template>
|
|
|
+ </TTable>
|
|
|
+ <PetVarietyDialog v-model:visible="productDialogVisible" :data="editData" @success="handleSuccess" @close="handleClose"></PetVarietyDialog>
|
|
|
+ </RegularPage>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+
|
|
|
+</style>
|