popUpWindowForSelectingPersonnel.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogVisible" :width="width" :before-close="handleClose"
  3. @close="$emit('input', false)" append-to-body top="5.6vh">
  4. <div class="theContent">
  5. <div class="theContent-input">
  6. <el-input placeholder="请输入内容" ref="focusOnInput" v-model.trim="filterText" class="input-with-select"
  7. @keyup.enter.native="nameSearch()">
  8. <el-button slot="append" icon="el-icon-search" @click="nameSearch()"></el-button>
  9. </el-input>
  10. </div>
  11. <div class="theContent-tree">
  12. <el-tree :data="deptMembData" show-checkbox default-expand-all check-strictly node-key="id" ref="tree"
  13. highlight-current :props="defaultProps" @check-change="treeHandChange" :filter-node-method="filterNode" v-loading="selectPersonnelTreeLoading">
  14. <span class="custom-tree-node" slot-scope="{ node, data }">
  15. <span v-if="user.userNameNeedTranslate == '1'">
  16. <span v-if="node.data.children">
  17. <TranslationOpenDataText type='departmentName' :openid='node.label'></TranslationOpenDataText>
  18. </span>
  19. <span v-else>
  20. <TranslationOpenDataText type='userName' :openid='node.label'></TranslationOpenDataText>
  21. </span>
  22. </span>
  23. <span v-if="user.userNameNeedTranslate != '1'">
  24. {{ node.label }}
  25. </span>
  26. </span>
  27. </el-tree>
  28. </div>
  29. </div>
  30. <span slot="footer" class="dialog-footer">
  31. <el-button @click="handleClose">关闭</el-button>
  32. <el-button type="primary" @click="handleConfirm">确定</el-button>
  33. </span>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. export default {
  38. name: 'AbcdEfg',
  39. props: {
  40. value: {
  41. type: Boolean,
  42. required: true
  43. },
  44. title: {
  45. type: String,
  46. default: '选择人员'
  47. },
  48. width: {
  49. type: String,
  50. default: '800px'
  51. }
  52. },
  53. data() {
  54. return {
  55. dialogVisible: this.value,
  56. filterText: '',
  57. deptMembData: [],
  58. user: JSON.parse(sessionStorage.getItem("user")),
  59. permissions: JSON.parse(sessionStorage.getItem("permissions")),
  60. filterNodePersonnel: [],
  61. defaultProps: {
  62. children: 'children',
  63. label: 'label'
  64. },
  65. selectPersonnelTreeLoading: false,
  66. }
  67. },
  68. watch: {
  69. value(newVal) {
  70. this.dialogVisible = newVal
  71. if(newVal) {
  72. this.$nextTick(() => {
  73. this.$refs.focusOnInput.focus()
  74. })
  75. }
  76. },
  77. filterText(val) {
  78. if (this.user.userNameNeedTranslate != 1) {
  79. this.$refs.tree.filter(val);
  80. }
  81. }
  82. },
  83. mounted() {
  84. this.getDepartment()
  85. },
  86. methods: {
  87. nameSearch() {
  88. if (this.user.userNameNeedTranslate != 1) {
  89. this.$refs.tree.filter(this.filterText);
  90. } else {
  91. if (this.filterText != '') {
  92. this.selectPersonnelTreeLoading = true
  93. this.http.post("/user/getEmployeeList", {
  94. keyword: this.filterText,
  95. cursor: '',
  96. departmentId: -1,
  97. pageIndex: 1,
  98. pageSize: 1000
  99. },
  100. res => {
  101. this.selectPersonnelTreeLoading = false
  102. if (res.code == "ok") {
  103. this.filterNodePersonnel = res.data.records.map(item => item.name)
  104. this.$refs.tree.filter(this.filterText);
  105. } else {
  106. this.$message({
  107. message: res.msg,
  108. type: "error"
  109. });
  110. }
  111. },
  112. error => {
  113. this.selectPersonnelTreeLoading = false
  114. this.$message({
  115. message: error,
  116. type: "error"
  117. });
  118. });
  119. } else {
  120. this.getDepartment()
  121. }
  122. }
  123. },
  124. filterNode(value, data) {
  125. let { userNameNeedTranslate } = this.user
  126. if (!value) return true;
  127. if (userNameNeedTranslate != '1') {
  128. return data.label.indexOf(value) !== -1;
  129. } else {
  130. return this.filterNodePersonnel.some(item => item.includes(data.label))
  131. }
  132. },
  133. treeHandChange(val, flag) {
  134. const { id } = val
  135. if (flag) {
  136. this.$refs.tree.setCheckedKeys([]);
  137. this.$refs.tree.setCheckedKeys([id]);
  138. }
  139. },
  140. // 获取部门列表
  141. getDepartment() {
  142. this.selectPersonnelTreeLoading = true
  143. this.http.post("/department/listAllMemb", {},
  144. res => {
  145. this.selectPersonnelTreeLoading = false
  146. if (res.code == "ok") {
  147. var list = res.data;
  148. //设置员工到部门下面
  149. this.setUserToDept(list);
  150. this.deptMembData = list;
  151. } else {
  152. this.$message({
  153. message: res.msg,
  154. type: "error"
  155. });
  156. }
  157. },
  158. error => {
  159. this.selectPersonnelTreeLoading = false
  160. this.$message({
  161. message: error,
  162. type: "error"
  163. });
  164. });
  165. },
  166. setUserToDept(list) {
  167. for (var i in list) {
  168. if (list[i].children != null) {
  169. this.setUserToDept(list[i].children);
  170. }
  171. if (list[i].userList != null) {
  172. if (list[i].children == null) {
  173. list[i].children = [];
  174. }
  175. list[i].userList.forEach(element => {
  176. var obj = { id: element.id, label: element.name, parentId: element.departmentId, isUser: 1 };
  177. list[i].children.push(obj);
  178. });
  179. }
  180. }
  181. },
  182. handleClose() {
  183. this.dialogVisible = false
  184. this.$emit('input', false)
  185. },
  186. // 确定控件
  187. handleConfirm() {
  188. const arr = this.$refs.tree.getCheckedNodes()
  189. const item = arr[0] || {}
  190. if(!item.isUser) {
  191. this.$message({
  192. message: '请选择人员',
  193. type: "error"
  194. });
  195. return
  196. }
  197. const row = { ...item, value: item.id, label: item.label }
  198. this.$emit('confirm', row)
  199. this.handleClose()
  200. },
  201. // 设置树形控件的选中项
  202. setTreeCheckedKeys(keys) {
  203. this.$refs.tree.setCheckedKeys(keys);
  204. },
  205. }
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. .dialog-footer {
  210. text-align: right;
  211. }
  212. .theContent {
  213. height: 50vh;
  214. display: flex;
  215. flex-direction: column;
  216. .theContent-tree {
  217. flex: 1;
  218. padding-right: 15px;
  219. margin: 20px 0;
  220. overflow-y: auto;
  221. }
  222. }
  223. </style>