index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  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 label="分类状态" prop="status">
  21. <el-select
  22. v-model="queryParams.status"
  23. placeholder="请选择分类状态"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="dict.value"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  37. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  38. <el-button
  39. type="primary"
  40. plain
  41. @click="openForm('create')"
  42. v-hasPermi="['system:product-classify:create']"
  43. >
  44. <Icon icon="ep:plus" class="mr-5px" /> 新增
  45. </el-button>
  46. <el-button type="danger" plain @click="toggleExpandAll">
  47. <Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
  48. </el-button>
  49. </el-form-item>
  50. </el-form>
  51. </ContentWrap>
  52. <!-- 列表 -->
  53. <ContentWrap>
  54. <el-table
  55. v-loading="loading"
  56. :data="list"
  57. row-key="id"
  58. :default-expand-all="isExpandAll"
  59. v-if="refreshTable"
  60. >
  61. <el-table-column prop="name" label="分类名称" />
  62. <el-table-column prop="name" label="分类编码" />
  63. <el-table-column prop="sort" label="排序" />
  64. <el-table-column prop="status" label="状态">
  65. <template #default="scope">
  66. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column
  70. label="创建时间"
  71. align="center"
  72. prop="createTime"
  73. width="180"
  74. :formatter="dateFormatter"
  75. />
  76. <el-table-column label="操作" align="center">
  77. <template #default="scope">
  78. <el-button
  79. link
  80. type="primary"
  81. @click="openForm('update', scope.row.id)"
  82. v-hasPermi="['system:product-classify:update']"
  83. >
  84. 修改
  85. </el-button>
  86. <el-button
  87. link
  88. type="danger"
  89. @click="handleDelete(scope.row.id)"
  90. v-hasPermi="['system:product-classify:delete']"
  91. >
  92. 删除
  93. </el-button>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. </ContentWrap>
  98. <!-- 表单弹窗:添加/修改 -->
  99. <ProductClassifyForm ref="formRef" @success="getList" />
  100. </template>
  101. <script lang="ts" setup>
  102. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  103. import { dateFormatter } from '@/utils/formatTime'
  104. import { handleTree } from '@/utils/tree'
  105. import * as ProductClassifyApi from '@/api/pms/productclassify'
  106. import ProductClassifyForm from './ProductClassifyForm.vue'
  107. defineOptions({ name: 'IotProductClassify' })
  108. const message = useMessage() // 消息弹窗
  109. const { t } = useI18n() // 国际化
  110. const loading = ref(true) // 列表的加载中
  111. const list = ref() // 列表的数据
  112. const queryParams = reactive({
  113. pageNo: 1,
  114. pageSize: 100,
  115. name: undefined,
  116. status: undefined
  117. })
  118. const queryFormRef = ref() // 搜索的表单
  119. const isExpandAll = ref(true) // 是否展开,默认全部展开
  120. const refreshTable = ref(true) // 重新渲染表格状态
  121. // const userList = ref<UserApi.UserVO[]>([]) // 用户列表
  122. /** 查询分类列表 */
  123. const getList = async () => {
  124. loading.value = true
  125. try {
  126. const data = await ProductClassifyApi.IotProductClassifyApi.getIotProductClassifyPage(queryParams)
  127. list.value = handleTree(data)
  128. } finally {
  129. loading.value = false
  130. }
  131. }
  132. /** 展开/折叠操作 */
  133. const toggleExpandAll = () => {
  134. refreshTable.value = false
  135. isExpandAll.value = !isExpandAll.value
  136. nextTick(() => {
  137. refreshTable.value = true
  138. })
  139. }
  140. /** 搜索按钮操作 */
  141. const handleQuery = () => {
  142. getList()
  143. }
  144. /** 重置按钮操作 */
  145. const resetQuery = () => {
  146. queryParams.pageNo = 1
  147. queryFormRef.value.resetFields()
  148. handleQuery()
  149. }
  150. /** 添加/修改操作 */
  151. const formRef = ref()
  152. const openForm = (type: string, id?: number) => {
  153. formRef.value.open(type, id)
  154. }
  155. /** 删除按钮操作 */
  156. const handleDelete = async (id: number) => {
  157. try {
  158. // 删除的二次确认
  159. await message.delConfirm()
  160. // 发起删除
  161. await ProductClassifyApi.IotProductClassifyApi.deleteIotProductClassify(id)
  162. message.success(t('common.delSuccess'))
  163. // 刷新列表
  164. await getList()
  165. } catch {}
  166. }
  167. /** 初始化 **/
  168. onMounted(async () => {
  169. await getList()
  170. // 获取用户列表
  171. //userList.value = await UserApi.getSimpleUserList()
  172. })
  173. </script>