index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <!-- TODO @zange:挪到 product 下,建个 category 包,挪进去哈; -->
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入名称"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  23. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  24. <el-button
  25. type="primary"
  26. plain
  27. @click="openForm('create')"
  28. v-hasPermi="['crm:product-category:create']"
  29. >
  30. <Icon icon="ep:plus" class="mr-5px" /> 新增
  31. </el-button>
  32. </el-form-item>
  33. </el-form>
  34. </ContentWrap>
  35. <!-- 列表 -->
  36. <ContentWrap>
  37. <el-table v-loading="loading" :data="list" row-key="id" default-expand-all>
  38. <el-table-column label="名称" align="center" prop="name" />
  39. <el-table-column
  40. label="创建时间"
  41. align="center"
  42. prop="createTime"
  43. :formatter="dateFormatter"
  44. width="180px"
  45. />
  46. <el-table-column label="操作" align="center">
  47. <template #default="scope">
  48. <el-button
  49. link
  50. type="primary"
  51. @click="openForm('update', scope.row.id)"
  52. v-hasPermi="['crm:product-category:update']"
  53. >
  54. 编辑
  55. </el-button>
  56. <el-button
  57. link
  58. type="danger"
  59. @click="handleDelete(scope.row.id)"
  60. v-hasPermi="['crm:product-category:delete']"
  61. >
  62. 删除
  63. </el-button>
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. </ContentWrap>
  68. <!-- 表单弹窗:添加/修改 -->
  69. <ProductCategoryForm ref="formRef" @success="getList" />
  70. </template>
  71. <script setup lang="ts">
  72. import { dateFormatter } from '@/utils/formatTime'
  73. import download from '@/utils/download'
  74. import * as ProductCategoryApi from '@/api/crm/productCategory'
  75. import ProductCategoryForm from './ProductCategoryForm.vue'
  76. import { handleTree } from '@/utils/tree'
  77. defineOptions({ name: 'CrmProductCategory' })
  78. const message = useMessage() // 消息弹窗
  79. const { t } = useI18n() // 国际化
  80. const loading = ref(true) // 列表的加载中
  81. const list = ref<any[]>([]) // 列表的数据
  82. const queryParams = reactive({
  83. name: null
  84. })
  85. const queryFormRef = ref() // 搜索的表单
  86. /** 查询列表 */
  87. const getList = async () => {
  88. loading.value = true
  89. try {
  90. const data = await ProductCategoryApi.getProductCategoryList(queryParams)
  91. list.value = handleTree(data, 'id', 'parentId')
  92. } finally {
  93. loading.value = false
  94. }
  95. }
  96. /** 搜索按钮操作 */
  97. const handleQuery = () => {
  98. getList()
  99. }
  100. /** 重置按钮操作 */
  101. const resetQuery = () => {
  102. queryFormRef.value.resetFields()
  103. handleQuery()
  104. }
  105. /** 添加/修改操作 */
  106. const formRef = ref()
  107. const openForm = (type: string, id?: number) => {
  108. formRef.value.open(type, id)
  109. }
  110. /** 删除按钮操作 */
  111. const handleDelete = async (id: number) => {
  112. try {
  113. // 删除的二次确认
  114. await message.delConfirm()
  115. // 发起删除
  116. await ProductCategoryApi.deleteProductCategory(id)
  117. message.success(t('common.delSuccess'))
  118. // 刷新列表
  119. await getList()
  120. } catch {}
  121. }
  122. /** 初始化 **/
  123. onMounted(() => {
  124. getList()
  125. })
  126. </script>