index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <CtFilter :items="formItems" @reset="handleReset" @search="handleSearch">
  3. <template #appendBtn>
  4. <v-btn class="ml-3 elevation-5" color="#00897B" @click="handleAdd">
  5. <v-icon left>mdi-plus</v-icon>
  6. {{ t('common.add') }}
  7. </v-btn>
  8. </template>
  9. </CtFilter>
  10. <v-card class="pa-5 card-box mt-3">
  11. <CtTable
  12. :items="items"
  13. :headers="headers"
  14. :loading="loading"
  15. :showPage="true"
  16. :total="total"
  17. :page-info="pageInfo"
  18. itemKey="id"
  19. :isTools="false"
  20. @pageHandleChange="handleChangePage"
  21. >
  22. <template #status="{ item }">
  23. <v-chip :color="item.status === '0' ? 'success' : 'error'" size="small" label>{{ item.statusName }}</v-chip>
  24. </template>
  25. <template #actions="{ item }">
  26. <v-btn variant="text" color="primary" @click="handleEdit(item)">编辑</v-btn>
  27. <v-btn variant="text" color="error" @click="handleDel(item)">删除</v-btn>
  28. </template>
  29. </CtTable>
  30. </v-card>
  31. <CtDialog :visible="show" :widthType="2" :title="editItem ? '编辑院系' : '新增院系'" @close="show = false" @submit="handleSubmit">
  32. <FormPage ref="formPageRef" :editItem="editItem" />
  33. </CtDialog>
  34. </template>
  35. <script setup>
  36. defineOptions({ name: 'organization' })
  37. import { ref } from 'vue'
  38. import { useI18n } from '@/hooks/web/useI18n'
  39. import Confirm from '@/plugins/confirm'
  40. import Snackbar from '@/plugins/snackbar'
  41. import { formatDate } from '@/utils/date'
  42. import { deleteOrganization, getOrganizationPage } from '@/api/school'
  43. import FormPage from './FormPage.vue'
  44. const { t } = useI18n()
  45. const total = ref(10)
  46. const items = ref([])
  47. const show = ref(false)
  48. const loading = ref(false)
  49. const formPageRef = ref()
  50. const editItem = ref(null)
  51. // 检索框
  52. const formItems = ref({
  53. options: [
  54. {
  55. type: 'text',
  56. key: 'name',
  57. value: '',
  58. label: '院系名称',
  59. clearable: true,
  60. hideDetails: true,
  61. width: 200
  62. }
  63. ]
  64. })
  65. const query = ref({
  66. name: null
  67. })
  68. const pageInfo = ref({
  69. pageNo: 1,
  70. pageSize: 10,
  71. type: 0
  72. })
  73. const headers = [
  74. { title: '院系名称', key: 'name', align: 'left', sortable: false },
  75. { title: '创建时间', key: 'createTime', value: (e) => formatDate(e.createTime), sortable: false },
  76. { title: t('common.actions'), key: 'actions', sortable: false }
  77. ]
  78. // 列表
  79. const getPage = async () => {
  80. loading.value = true
  81. try {
  82. const res = await getOrganizationPage({ ...pageInfo.value, ...query.value })
  83. items.value = res.list || []
  84. total.value = res.total
  85. } finally {
  86. loading.value = false
  87. }
  88. }
  89. // 检索
  90. const handleSearch = (obj) => {
  91. pageInfo.value.pageNo = 1
  92. query.value = obj
  93. getPage()
  94. }
  95. // 重置
  96. const handleReset = (obj) => {
  97. pageInfo.value.pageNo = 1
  98. query.value = obj
  99. getPage()
  100. }
  101. // 新增
  102. const handleAdd = () => {
  103. editItem.value = null
  104. show.value = true
  105. }
  106. // 编辑
  107. const handleEdit = (item) => {
  108. editItem.value = item
  109. show.value = true
  110. }
  111. // 新增、编辑提交
  112. const handleSubmit = async () => {
  113. await formPageRef.value.submit()
  114. show.value = false
  115. getPage()
  116. }
  117. // 删除
  118. const handleDel = async (item) => {
  119. Confirm(t('common.confirmTitle'), '是否确定删除?').then(async () => {
  120. await deleteOrganization(item.id)
  121. Snackbar.success('删除成功')
  122. getPage()
  123. })
  124. }
  125. // 分页
  126. const handleChangePage = (index) => {
  127. pageInfo.value.pageNo = index
  128. getPage()
  129. }
  130. getPage()
  131. </script>