index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <a-row :gutter="10">
  3. <a-col :xs="24" :sm="24" :md="24" :lg="5" :xl="5">
  4. <a-card :bordered="false" :loading="cardLoading">
  5. <a-tree
  6. v-if="treeData.length > 0"
  7. v-model:expandedKeys="defaultExpandedKeys"
  8. :tree-data="treeData"
  9. :field-names="treeFieldNames"
  10. @select="treeSelect"
  11. />
  12. <a-empty :image="Empty.PRESENTED_IMAGE_SIMPLE" />
  13. </a-card>
  14. </a-col>
  15. <a-col :xs="24" :sm="24" :md="24" :lg="19" :xl="19">
  16. <a-card :bordered="false" style="margin-bottom: 10px">
  17. <a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form" :model="searchFormState">
  18. <a-row :gutter="24">
  19. <a-col :span="8">
  20. <a-form-item name="searchKey" label="名称关键词">
  21. <a-input v-model:value="searchFormState.searchKey" placeholder="请输入组织名称关键词" />
  22. </a-form-item>
  23. </a-col>
  24. <a-col :span="8">
  25. <a-button type="primary" @click="table.refresh(true)">
  26. <template #icon><SearchOutlined /></template>
  27. 查询
  28. </a-button>
  29. <a-button class="snowy-buttom-left" @click="reset">
  30. <template #icon><redo-outlined /></template>
  31. 重置
  32. </a-button>
  33. </a-col>
  34. </a-row>
  35. </a-form>
  36. </a-card>
  37. <a-card :bordered="false">
  38. <s-table
  39. ref="table"
  40. :columns="columns"
  41. :data="loadData"
  42. :expand-row-by-click="true"
  43. :alert="options.alert.show"
  44. bordered
  45. :row-key="(record) => record.id"
  46. :row-selection="options.rowSelection"
  47. >
  48. <template #operator class="table-operator">
  49. <a-space>
  50. <a-button type="primary" @click="formRef.onOpen(undefined, searchFormState.parentId)">
  51. <template #icon><plus-outlined /></template>
  52. 新增
  53. </a-button>
  54. <xn-batch-delete :selectedRowKeys="selectedRowKeys" @batchDelete="deleteBatchOrg" />
  55. </a-space>
  56. </template>
  57. <template #bodyCell="{ column, record }">
  58. <template v-if="column.dataIndex === 'category'">
  59. {{ $TOOL.dictTypeData('ORG_CATEGORY', record.category) }}
  60. </template>
  61. <template v-if="column.dataIndex === 'action'">
  62. <a @click="formRef.onOpen(record)">编辑</a>
  63. <a-divider type="vertical" />
  64. <a-popconfirm title="删除此组织与下级组织吗?" @confirm="removeOrg(record)">
  65. <a-button type="link" danger size="small">删除</a-button>
  66. </a-popconfirm>
  67. </template>
  68. </template>
  69. </s-table>
  70. </a-card>
  71. </a-col>
  72. </a-row>
  73. <Form ref="formRef" @successful="table.refresh()" />
  74. </template>
  75. <script setup name="sysOrg">
  76. import { Empty } from 'ant-design-vue'
  77. import { isEmpty } from 'lodash-es'
  78. import orgApi from '@/api/organization/organization'
  79. import Form from './form.vue'
  80. const columns = [
  81. {
  82. title: '组织名称',
  83. dataIndex: 'name'
  84. },
  85. // {
  86. // title: '分类',
  87. // dataIndex: 'category'
  88. // },
  89. {
  90. title: '排序',
  91. dataIndex: 'sortCode',
  92. width: 100
  93. },
  94. {
  95. title: '操作',
  96. dataIndex: 'action',
  97. align: 'center',
  98. width: '150px'
  99. }
  100. ]
  101. const selectedRowKeys = ref([])
  102. // 列表选择配置
  103. const options = {
  104. alert: {
  105. show: false,
  106. clear: () => {
  107. selectedRowKeys.value = ref([])
  108. }
  109. },
  110. rowSelection: {
  111. onChange: (selectedRowKey, selectedRows) => {
  112. selectedRowKeys.value = selectedRowKey
  113. }
  114. }
  115. }
  116. // 定义tableDOM
  117. const table = ref(null)
  118. const formRef = ref()
  119. const searchFormRef = ref()
  120. const searchFormState = ref({})
  121. // 默认展开的节点
  122. const defaultExpandedKeys = ref([])
  123. const treeData = ref([])
  124. // 替换treeNode 中 title,key,children
  125. const treeFieldNames = { children: 'children', title: 'name', key: 'id' }
  126. const cardLoading = ref(true)
  127. // 表格查询 返回 Promise 对象
  128. const loadData = (parameter) => {
  129. loadTreeData()
  130. return orgApi.orgPage(Object.assign(parameter, searchFormState.value)).then((res) => {
  131. return res
  132. })
  133. }
  134. // 重置
  135. const reset = () => {
  136. searchFormRef.value.resetFields()
  137. table.value.refresh(true)
  138. }
  139. // 加载左侧的树
  140. const loadTreeData = () => {
  141. orgApi.orgTree().then((res) => {
  142. cardLoading.value = false
  143. if (res !== null) {
  144. treeData.value = res
  145. if (isEmpty(defaultExpandedKeys.value)) {
  146. // 默认展开2级
  147. treeData.value.forEach((item) => {
  148. // 因为0的顶级
  149. if (item.parentId === '0') {
  150. defaultExpandedKeys.value.push(item.id)
  151. // 取到下级ID
  152. if (item.children) {
  153. item.children.forEach((items) => {
  154. defaultExpandedKeys.value.push(items.id)
  155. })
  156. }
  157. }
  158. })
  159. }
  160. }
  161. })
  162. }
  163. // 点击树查询
  164. const treeSelect = (selectedKeys) => {
  165. if (selectedKeys.length > 0) {
  166. searchFormState.value.parentId = selectedKeys.toString()
  167. } else {
  168. delete searchFormState.value.parentId
  169. }
  170. table.value.refresh(true)
  171. }
  172. // 删除
  173. const removeOrg = (record) => {
  174. let params = [
  175. {
  176. id: record.id
  177. }
  178. ]
  179. orgApi.orgDelete(params).then(() => {
  180. table.value.refresh(true)
  181. })
  182. }
  183. // 批量删除
  184. const deleteBatchOrg = (params) => {
  185. orgApi.orgDelete(params).then(() => {
  186. table.value.clearRefreshSelected()
  187. })
  188. }
  189. </script>
  190. <style scoped>
  191. .ant-form-item {
  192. margin-bottom: 0 !important;
  193. }
  194. .primaryAdd {
  195. margin-right: 10px;
  196. }
  197. .snowy-buttom-left {
  198. margin-left: 8px;
  199. }
  200. </style>