index.vue 3.5 KB

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