index.vue 5.8 KB

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