index copy.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div class="p-4">
  3. <div class="zhiwei-header">
  4. <div class="zhiwei-title">职位管理</div>
  5. <div class="handle-btns">
  6. <a-button class="btn" type="primary" @click="addHandle">新增</a-button>
  7. <a-button class="btn" @click="editHandle">修改</a-button>
  8. <a-button class="btn" danger @click="delHandle">删除</a-button>
  9. </div>
  10. </div>
  11. <div class="zhiwei-body">
  12. <div class="structure-tree list-items">
  13. <div class="item-title">部门列表</div>
  14. <a-tree :replaceFields="replaceFields" :treeData="treeData" v-if="treeData" @select="nodeSelect"></a-tree>
  15. </div>
  16. <div class="posts-list list-items">
  17. <div class="item-title">职位列表</div>
  18. <div class="posts-box item-box">
  19. <div class="posts item" v-for="(item, index) in posts.data" :key="index">
  20. <span :class="{ 'chosed': item.departid === posts.currentId }" @click="chooseHandle(item, 'posts')">{{ item.departName }}</span>
  21. <span v-if="item.departid === posts.currentId" style="color: red;" @click="openDetailModal(item)">查看</span>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <ZhiweiDrawer :formData="formData" :drawerTitle="drawerTitle" @onSubmit="onSubmit" ref="drawerRef"></ZhiweiDrawer>
  27. <ZhiweiModal v-if="showModal" @closeModal="showModal = false" :positionDetail="positionDetail"/>
  28. </div>
  29. </template>
  30. <script>
  31. import { defineComponent, reactive, ref, toRefs, computed, onMounted, watch, createVNode } from 'vue';
  32. import ZhiweiDrawer from './ZhiweiDrawer.vue';
  33. import ZhiweiModal from './ZhiweiModal.vue';
  34. import { structureList, getPostsList, delPosts } from '/@/api/sys/zhiwei';
  35. import { message, Modal } from 'ant-design-vue';
  36. import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
  37. export default defineComponent({
  38. name: 'zhiwei',
  39. components: { ZhiweiDrawer, ZhiweiModal, ExclamationCircleOutlined },
  40. setup(props, { emit }) {
  41. const drawerRef = ref(null)
  42. const data = reactive({
  43. replaceFields: {
  44. children: 'children',
  45. title: 'name',
  46. key: 'id'
  47. },
  48. treeData: [],//单位列表树
  49. currentNode: "",//当前选中的树节点
  50. posts: {
  51. currentId: "",
  52. data: []
  53. },//职位数据
  54. formData: {
  55. departid: "",
  56. parentId: "",
  57. departName: "",
  58. orderId: 0,
  59. orgId: ""
  60. },
  61. drawerTitle: '新增职位',
  62. showModal:false,
  63. positionDetail:{}
  64. });
  65. /**
  66. * 点击树节点触发
  67. */
  68. const nodeSelect = (selectkey, { selectedNodes, node }) => {
  69. if (node.dataRef.departid === data.currentNode) {
  70. return;
  71. } else {
  72. data.currentNode = node.dataRef.departid
  73. }
  74. resetDatas()
  75. let params = {
  76. departmentId: node.dataRef.departid
  77. }
  78. getPostsList(params).then(res => {
  79. if (res.datas) {
  80. data.posts.data = res.datas
  81. !res.datas.length && message.info('该部门下无职位数据')
  82. }else{
  83. message.info('该部门下无职位数据')
  84. }
  85. })
  86. };
  87. const resetDatas = () => {
  88. data.posts.data = []
  89. data.posts.currentId = ""
  90. }
  91. const chooseHandle = (item) => {
  92. if (data.posts.currentId === item.departid) {
  93. return;
  94. }
  95. data.posts.currentId = item.departid
  96. }
  97. const openDetailModal = (item) => {
  98. data.positionDetail = item
  99. data.showModal = true
  100. }
  101. onMounted(() => {
  102. structureList().then(res => {
  103. res.length && (data.treeData = res)
  104. })
  105. });
  106. /**
  107. * 对职位的操作
  108. */
  109. const addHandle = () => {
  110. if (data.currentNode === "") {
  111. message.error('请先选择机构!')
  112. } else {
  113. data.formData = {
  114. departid: "",
  115. parentId: "",
  116. departName: "",
  117. orderId: data.posts.data.length + 1,
  118. orgId: data.currentNode
  119. }
  120. data.drawerTitle = '新增职位'
  121. drawerRef.value.showDrawer()
  122. }
  123. }
  124. const editHandle = () => {
  125. if (data.currentNode === "") {
  126. message.error('请先选择机构!')
  127. } else if (data.posts.currentId === "") {
  128. message.error('请先选择职位!')
  129. } else {
  130. data.posts.data.forEach(item => {
  131. if (item.departid === data.posts.currentId) {
  132. data.formData = {
  133. departid: data.posts.currentId,
  134. parentId: item.parentId,
  135. departName: item.departName,
  136. orderId: item.orderId
  137. }
  138. data.drawerTitle = '修改职位'
  139. drawerRef.value.showDrawer()
  140. }
  141. })
  142. }
  143. }
  144. const delHandle = () => {
  145. if (data.currentNode === "") {
  146. message.error('请先选择机构!')
  147. } else if (data.posts.currentId === "") {
  148. message.error('请先选择职位!')
  149. } else {
  150. Modal.confirm({
  151. title: '删除提示',
  152. icon: createVNode(ExclamationCircleOutlined),
  153. content: '确定删除岗位?',
  154. centered: true,
  155. okText: '确定',
  156. okType: 'danger',
  157. cancelText: '取消',
  158. onOk: (() => {
  159. let params = {
  160. orgId: data.currentNode,
  161. departid: data.posts.currentId
  162. }
  163. delPosts(params).then(res => {
  164. if (res.datas === 1) {
  165. message.success('操作成功')
  166. onSubmit(true)
  167. } else {
  168. message.error('操作失败')
  169. }
  170. })
  171. })
  172. });
  173. }
  174. }
  175. const onSubmit = (e) => {
  176. if (e) {
  177. data.posts.data = []
  178. data.posts.currentId = ""
  179. let params = {
  180. departmentId: data.currentNode
  181. }
  182. getPostsList(params).then(res => {
  183. if (res.datas) {
  184. data.posts.data = res.datas
  185. }
  186. })
  187. }
  188. }
  189. return {
  190. drawerRef,
  191. ...toRefs(data),
  192. nodeSelect,
  193. chooseHandle,
  194. addHandle,
  195. editHandle,
  196. delHandle,
  197. openDetailModal,
  198. onSubmit
  199. };
  200. },
  201. });
  202. </script>
  203. <style lang="less" scoped>
  204. .p-4 {
  205. height: 100%;
  206. .zhiwei-header {
  207. padding: 10px;
  208. width: 100%;
  209. height: 70px;
  210. background-color: #fff;
  211. display: flex;
  212. justify-content: space-between;
  213. align-items: center;
  214. .zhiwei-title {
  215. font-size: 16px;
  216. font-weight: 500;
  217. margin-left: 20px;
  218. user-select: none;
  219. }
  220. .handle-btns {
  221. margin-right: 20px;
  222. display: flex;
  223. .btn {
  224. margin-right: 10px;
  225. &:last-child {
  226. margin-right: 0;
  227. }
  228. }
  229. }
  230. }
  231. .zhiwei-body {
  232. margin-top: 20px;
  233. width: 100%;
  234. // height: 800px;
  235. height: calc(100% - 90px);
  236. display: flex;
  237. .list-items {
  238. margin-right: 20px;
  239. padding: 10px;
  240. height: 100%;
  241. overflow: auto;
  242. flex: 1;
  243. background-color: #fff;
  244. &:last-child {
  245. margin-right: 0;
  246. }
  247. .item-title {
  248. padding-left: 10px;
  249. height: 40px;
  250. line-height: 40px;
  251. font-size: 16px;
  252. background-color: #9eafe7;
  253. }
  254. .item-box {
  255. margin-top: 7px;
  256. .item {
  257. width: fit-content;
  258. height: 32px;
  259. display: flex;
  260. align-items: center;
  261. span {
  262. padding: 4px;
  263. cursor: pointer;
  264. user-select: none;
  265. &:hover {
  266. background-color: #f5f5f5;
  267. }
  268. margin-right: 30px;
  269. }
  270. .chosed {
  271. background-color: #dbedff;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. }
  278. </style>