index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div>
  3. <el-card class="!border-none mt-4" shadow="never" v-loading="pager.loading">
  4. <div>
  5. <el-button v-perms="['goods:category:add']" type="primary" @click="handleAdd()">
  6. <template #icon>
  7. <icon name="el-icon-Plus"/>
  8. </template>
  9. 新增
  10. </el-button>
  11. </div>
  12. <el-table class="mt-4" size="large" :data="pager.lists">
  13. <el-table-column type="selection" width="55"/>
  14. <el-table-column
  15. label="分类名称"
  16. prop="name"
  17. min-width="120"
  18. show-tooltip-when-overflow
  19. />
  20. <el-table-column label="商品数" prop="number" min-width="120"/>
  21. <!-- <el-table-column label="状态" min-width="120">-->
  22. <!-- <template #default="{ row }">-->
  23. <!-- <el-switch-->
  24. <!-- v-perms="['article:cate:change']"-->
  25. <!-- v-model="row.isShow"-->
  26. <!-- :active-value="1"-->
  27. <!-- :inactive-value="0"-->
  28. <!-- @change="changeStatus(row.id, row.isShow)"-->
  29. <!-- />-->
  30. <!-- </template>-->
  31. <!-- </el-table-column>-->
  32. <el-table-column label="排序" prop="sort" min-width="120"/>
  33. <el-table-column label="操作" width="120" fixed="right">
  34. <template #default="{ row }">
  35. <el-button
  36. v-perms="['goods:category:edit']"
  37. type="primary"
  38. link
  39. @click="handleEdit(row)"
  40. >
  41. 编辑
  42. </el-button>
  43. <el-button
  44. v-perms="['goods:category:delete']"
  45. type="danger"
  46. link
  47. @click="handleDelete(row.id)"
  48. >
  49. 删除
  50. </el-button>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. <div class="flex justify-end mt-4">
  55. <pagination v-model="pager" @change="getLists"/>
  56. </div>
  57. </el-card>
  58. <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false"/>
  59. </div>
  60. </template>
  61. <script lang="ts" setup name="articleColumn">
  62. import {usePaging} from '@/hooks/usePaging'
  63. import feedback from '@/utils/feedback'
  64. import EditPopup from './edit.vue'
  65. import {goodsCategoryDelete, goodsCategoryEdit, goodsCategoryPage} from "@/api/goods/category";
  66. const editRef = shallowRef<InstanceType<typeof EditPopup>>()
  67. const showEdit = ref(false)
  68. const {pager, getLists} = usePaging({
  69. fetchFun: goodsCategoryPage
  70. })
  71. const handleAdd = async () => {
  72. showEdit.value = true
  73. await nextTick()
  74. editRef.value?.open('add')
  75. }
  76. const handleEdit = async (data: any) => {
  77. showEdit.value = true
  78. await nextTick()
  79. editRef.value?.open('edit')
  80. editRef.value?.setFormData(data)
  81. }
  82. const handleDelete = async (id: number) => {
  83. await feedback.confirm('确定要删除?')
  84. await goodsCategoryDelete({id, isDelete: 1})
  85. feedback.msgSuccess('删除成功')
  86. getLists()
  87. }
  88. const changeStatus = async (id: number, isShow: number) => {
  89. try {
  90. await goodsCategoryEdit({id, isShow})
  91. feedback.msgSuccess('修改成功')
  92. getLists()
  93. } catch (error) {
  94. getLists()
  95. }
  96. }
  97. getLists()
  98. </script>