EmployeeSelector.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <template>
  2. <div>
  3. <div class="employee_selector_box">
  4. <el-row :gutter="10">
  5. <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11" class="scroller-box one">
  6. <div class="search-box">
  7. <div class="search flex-box" style="margin-bottom: 7px;"><el-input v-model="keyword" placeholder="请输入姓名" clearable></el-input></div>
  8. <div class="search flex-box" v-if="can_select_dept">
  9. <el-cascader
  10. v-model="dept_id"
  11. ref="dept"
  12. :options="dept_list"
  13. :props="{ checkStrictly: true, value: 'id', label: 'name', children: '_child' }"
  14. clearable
  15. filterable
  16. placeholder="全公司"
  17. ></el-cascader>
  18. </div>
  19. </div>
  20. <div class="flex-box-end" style="padding: 10px;border-bottom: 1px solid #f1f1f1;height: 40px;box-sizing: border-box;">
  21. <el-checkbox v-if="isChecKedAll && multi" v-model="checked" @change="checkedChange" :indeterminate="indeterminate">全选</el-checkbox>
  22. </div>
  23. <el-scrollbar :style="{ height: can_select_dept ? '310px' : '350px' }" :native="false" v-loading="table_loading">
  24. <div class="choose_left">
  25. <div class="persons_box" v-if="list.length > 0">
  26. <div class="employee_cell_a" v-for="(item, index) in list" :key="index">
  27. <div
  28. class="employee_cell flex-box flex-v-ce"
  29. v-if="can_select_employee && item.name.indexOf(keyword) >= 0"
  30. @click.prevent.stop="select_employee(item)"
  31. >
  32. <div class="employee_checkbox"><el-checkbox v-model="item.checked"></el-checkbox></div>
  33. <img :src="item.img_url" width="30" height="30" class="imgUrl" v-if="item.img_url">
  34. <div class="imgUrl" v-else style="background: #238DFA;color: #fff;">{{item.name.substring(item.name.length-2)}}</div>
  35. <div class="employee_name">{{ item.name }}</div>
  36. </div>
  37. </div>
  38. </div>
  39. <div v-else class="fontColorF" style="text-align: center;margin-top: 50px;">暂无可选人员</div>
  40. </div>
  41. </el-scrollbar>
  42. </el-col>
  43. <el-col :xs="2" :sm="2" :md="2" :lg="2" :xl="2" class="col-line"><span style="opacity: 0;">空</span></el-col>
  44. <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11" class="scroller-box">
  45. <div class="option-box flex-box flex-v-ce">
  46. <div class="fontColorF flex-1" v-show="multi">已选择{{ employee_selected_list.length }}个员工</div>
  47. <el-button type="type" @click="clear_data()">清空</el-button>
  48. </div>
  49. <el-scrollbar wrap-class="column-wrapper scrollable-items-container" :native="false" style="height: 390px;">
  50. <div class="choose_right">
  51. <div class="employee_cell flex-box flex-v-ce" v-for="(item, index) in dept_selected_list" :key="index">
  52. <div class="employee_name">{{ item.dept_name }}</div>
  53. <div class="employee_delete"><el-button type="default" size="mini" @click="dept_cancel(item)" icon="el-icon-close" circle></el-button></div>
  54. </div>
  55. <div class="flex-box-ce employee_cell2" v-for="(item, index) in employee_selected_list" :key="index">
  56. <div class="flex-box-ce flex-1">
  57. <img :src="item.img_url" width="30" height="30" style="margin-right: 8px;" class="imgUrl" v-if="item.img_url">
  58. <div class="imgUrl" v-else style="background: #238DFA;color: #fff;margin-right: 8px;">{{item.name.substring(item.name.length-2)}}</div>
  59. <div class="userName font-flex-word">{{ item.name }}</div>
  60. </div>
  61. <i class="el-icon-error deleteUser" v-if="!item.is_creator || !createDimness" @click="employee_cancel(item, true)"></i>
  62. </div>
  63. </div>
  64. </el-scrollbar>
  65. </el-col>
  66. </el-row>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. // import Item from './Item'
  72. // import VirtualList from 'vue-virtual-scroll-list'
  73. export default {
  74. props: {
  75. can_select_dept: {
  76. //指定是否能选择部门
  77. type: Boolean,
  78. default: true
  79. },
  80. can_select_employee: {
  81. //指定是否能选择员工
  82. type: Boolean,
  83. default: true
  84. },
  85. selected: {
  86. //已经选择的员工和部门
  87. type: Object,
  88. default: () => {
  89. return {
  90. employee: [],
  91. dept: []
  92. };
  93. }
  94. },
  95. multi: {
  96. //指定员工是否能多选
  97. type: Boolean,
  98. default: true
  99. },
  100. dept_multi: {
  101. //指定部门是否能多选
  102. type: Boolean,
  103. default: true
  104. },
  105. employee_list: {
  106. //指定显示的员工列表,注意:传值后组件的员工数据将不是统一向服务器获取的,而是指定的员工列表,格式是:[{id: 1, name: “张三”, img_url: “”}]
  107. type: Array,
  108. default: () => {
  109. return [];
  110. }
  111. },
  112. close_clear_data: {
  113. //关闭时是否清空选择的数据
  114. type: Boolean,
  115. default: true
  116. },
  117. max: {
  118. //当multi为true时,用来限制选择人数,0不生效
  119. type: Number,
  120. default: 0
  121. },
  122. user_no_select: {
  123. //是否能选择创始人
  124. type: Boolean,
  125. default: true
  126. },
  127. isChecKedAll: {
  128. //是否能全人员
  129. type: Boolean,
  130. default: true
  131. },
  132. my_no_select: {
  133. //当前设置人的id,过滤某位人员,一般为自己
  134. type: Number,
  135. default: 0
  136. },
  137. isCreatorSelect: {
  138. //当employee_list为空时,依然显示空值而不是显示人员列表
  139. type: Boolean,
  140. default: false
  141. },
  142. use_Administrator_list: {
  143. //未指定员工并请求人员接口时,保留管理员,过滤员工
  144. type: Boolean,
  145. default: false
  146. },
  147. createDimness: {
  148. //组织架构设置上级专用-不清除创始人
  149. type: Boolean,
  150. default: false
  151. }
  152. },
  153. name: 'EmployeeSelector',
  154. data() {
  155. let selected = JSON.parse(JSON.stringify(this.selected));
  156. let user_no_select = JSON.parse(JSON.stringify(this.user_no_select));
  157. return {
  158. table_loading: false,
  159. employee_selected_list: selected.employee,
  160. dept_selected_list: selected.dept,
  161. employee_selected: [],
  162. dept_selected: [],
  163. com_height: '100%',
  164. list: [], //人员列表
  165. dept_name: '', //部门名称
  166. dept_id: 0, //部门ID
  167. pid: 0, //部门ID实传
  168. dept_list: [], //部门列表
  169. dept_list_arr: [], //收集的部门
  170. keyword: '', //搜索值
  171. checked: false, //是否全选
  172. indeterminate: false,
  173. not_user: user_no_select,
  174. all_list: []
  175. };
  176. },
  177. watch: {
  178. dept_id(val) {
  179. if (val.length > 1) {
  180. this.pid = val[val.length - 1];
  181. } else {
  182. this.pid = val[0];
  183. }
  184. this.$nextTick(() => {
  185. this.$refs.dept.dropDownVisible = false;
  186. this.get_user_list();
  187. this.checked = false;
  188. });
  189. },
  190. selected(val) {
  191. let selected = JSON.parse(JSON.stringify(val));
  192. this.employee_selected = [];
  193. this.dept_selected = [];
  194. this.employee_selected_list = selected.employee;
  195. this.dept_selected_list = selected.dept;
  196. for (let i in selected.employee) {
  197. this.employee_selected.push(selected.employee[i].id);
  198. }
  199. for (let i in selected.dept) {
  200. this.dept_selected.push(selected.dept[i].dept_id);
  201. }
  202. },
  203. //搜索
  204. keyword(val) {
  205. this.checked = false;
  206. }
  207. },
  208. methods: {
  209. //全选择
  210. checkedChange(val) {
  211. if (val) {
  212. for (let i in this.list) {
  213. this.$set(this.list[i], 'checked', true);
  214. }
  215. this.$nextTick(() => {
  216. let employeeSelectedList = JSON.parse(JSON.stringify(this.employee_selected_list));
  217. let employeeSelectedIds = [],
  218. total = 0;
  219. employeeSelectedList.forEach(element => {
  220. employeeSelectedIds.push(element.id);
  221. });
  222. for (const i in this.list) {
  223. if (employeeSelectedIds.includes(this.list[i].id)) {
  224. total += 1;
  225. } else {
  226. this.employee_selected_list.push(this.list[i]);
  227. }
  228. }
  229. this.list.length == total ? (this.indeterminate = true) : (this.indeterminate = false);
  230. });
  231. } else {
  232. this.clear_data();
  233. }
  234. },
  235. //添加或移除已添加的员工
  236. employee_cancel(item) {
  237. this.employee_selected_list.map((arr, index) => {
  238. if (arr.id == item.id) {
  239. this.employee_selected_list.splice(index, 1);
  240. }
  241. });
  242. this.list.map((arr, index) => {
  243. if (arr.id == item.id) {
  244. this.$set(arr, 'checked', false);
  245. }
  246. });
  247. },
  248. //获取部门
  249. get_dept_list() {
  250. this.$axios('get', '/api/department/tree').then(res => {
  251. this.dept_list = this.getTreeData(res.data.data.list);
  252. });
  253. },
  254. // 递归判断列表,把最后的children设为undefined
  255. getTreeData(data) {
  256. for (var i = 0; i < data.length; i++) {
  257. if (data[i]._child.length < 1) {
  258. // children若为空数组,则将children设为undefined
  259. data[i]._child = undefined;
  260. } else {
  261. // children若不为空数组,则继续 递归调用 本方法
  262. this.getTreeData(data[i]._child);
  263. }
  264. }
  265. return data;
  266. },
  267. //选择部门
  268. dept_cancel(item) {
  269. this.dept_selected.splice(this.dept_selected.indexOf(item.id), 1);
  270. let delete_index = -1;
  271. for (let i in this.dept_selected_list) {
  272. if (this.dept_selected.indexOf(this.dept_selected_list[i].id) < 0) {
  273. delete_index = i;
  274. }
  275. }
  276. if (delete_index >= 0) {
  277. this.dept_selected_list.splice(delete_index, 1);
  278. for (let i in this.dept_list) {
  279. if (this.dept_list[i].dept_id == item.id) {
  280. this.$set(this.dept_list[i], 'checked', false);
  281. }
  282. }
  283. }
  284. },
  285. //选择员工
  286. select_employee(item) {
  287. if (item.checked) {
  288. item.checked = false;
  289. this.employee_cancel(item);
  290. } else {
  291. if (!this.multi) {
  292. this.employee_selected = [];
  293. this.employee_selected_list = [];
  294. for (let i in this.list) {
  295. this.$set(this.list[i], 'checked', false);
  296. }
  297. }
  298. if (this.max > 0 && this.employee_selected_list.length == this.max && this.multi) {
  299. this.$message.error('最多只能选择' + this.max + '人');
  300. return false;
  301. }
  302. this.employee_selected.push(item.id);
  303. this.employee_selected_list.push({
  304. id: item.id,
  305. name: item.name,
  306. img_url: item.img_url
  307. });
  308. item.checked = true;
  309. }
  310. },
  311. clear_data() {
  312. this.employee_selected = [];
  313. if(this.createDimness){
  314. this.employee_selected_list = this.employee_selected_list.filter(x => x.is_creator);
  315. }else{
  316. this.employee_selected_list = [];
  317. }
  318. this.dept_selected = [];
  319. this.dept_selected_list = [];
  320. this.checked = false;
  321. for (let i in this.list) {
  322. this.$set(this.list[i], 'checked', false);
  323. }
  324. for (let i in this.dept_list) {
  325. this.$set(this.dept_list[i], 'checked', false);
  326. }
  327. },
  328. close() {
  329. if (this.close_clear_data) {
  330. this.employee_selected = [];
  331. this.employee_selected_list = [];
  332. this.dept_selected = [];
  333. this.dept_selected_list = [];
  334. for (let i in this.list) {
  335. this.$set(this.list[i], 'checked', false);
  336. }
  337. for (let i in this.dept_list) {
  338. this.$set(this.dept_list[i], 'checked', false);
  339. }
  340. }
  341. },
  342. confirm() {
  343. this.$emit('confirm', {
  344. employee: this.employee_selected_list,
  345. dept: this.dept_selected_list
  346. });
  347. this.close();
  348. },
  349. filtration() {
  350. //获取员工列表,限制已禁用的员工
  351. this.$axios('get', '/api/employee/index', { dept_id: this.pid, page: 0, page_size: 3000,is_official:1 })
  352. .then(res => {
  353. if (res.data.code == 1) {
  354. let list = res.data.data.list;
  355. let data = [];
  356. // list.forEach((item, index) => {
  357. // if (item.is_official == 1) {
  358. // data.push(item);
  359. // }
  360. // });
  361. this.userdatars(list);
  362. } else {
  363. this.userdatars();
  364. }
  365. })
  366. .catch(() => {
  367. this.userdatars();
  368. });
  369. },
  370. userdatars(userlist) {
  371. var employee_selected_list = this.employee_selected_list;
  372. let list = this.employee_list;
  373. if (userlist) {
  374. list = [...userlist].filter(x => [...list].some(y => y.id === x.id));
  375. }
  376. list.map(item => {
  377. item['checked'] = false;
  378. for (var i in employee_selected_list) {
  379. //判断传进来的员工是否是员工集合里的,是就设为已点击状态
  380. if (employee_selected_list[i].id == item.id) {
  381. item['checked'] = true;
  382. }
  383. }
  384. });
  385. this.list = list;
  386. this.table_loading = false;
  387. },
  388. //获取员工详情
  389. get_user_list() {
  390. this.table_loading = true;
  391. var that = this;
  392. var employee_selected_list = this.employee_selected_list;
  393. if (this.employee_list.length > 0 || this.isCreatorSelect) {
  394. this.filtration();
  395. return false;
  396. }
  397. this.list = [];
  398. this.$axios('get', '/api/employee/index', { dept_id: this.pid, keywords: this.keyword, page: 0, page_size: 3000,is_official:1 })
  399. .then(res => {
  400. var employee = res.data.data.list || [];
  401. if (this.use_Administrator_list) {
  402. //使用管理员列表
  403. employee = this.useAdministratorList(employee);
  404. }
  405. var userAll = [];
  406. employee.forEach((item, i) => {
  407. if (!this.not_user && item.is_creator == 1) {
  408. //过滤创始人
  409. return null;
  410. } else if (this.my_no_select == item.id) {
  411. //过滤掉当前设置人
  412. return null;
  413. } else if (item.id) {
  414. userAll.push(item);
  415. }
  416. // 前端先隐藏过滤未开启的人员的功能
  417. // } else if (item.is_official == 1) {
  418. // userAll.push(item);
  419. // }
  420. });
  421. userAll.map(item => {
  422. item['checked'] = false;
  423. for (var i in employee_selected_list) {
  424. //判断传进来的员工是否是员工集合里的,是就设为已点击状态
  425. if (employee_selected_list[i].id == item.id) {
  426. item['checked'] = true;
  427. }
  428. }
  429. });
  430. that.list = userAll;
  431. })
  432. .finally(() => {
  433. that.table_loading = false;
  434. });
  435. },
  436. useAdministratorList(list) {
  437. //过滤掉普通员工,返回管理员
  438. let arr = [];
  439. list.forEach((item, i) => {
  440. if (
  441. item.employee_detail.role_list.findIndex(
  442. value => value.name == 'dept_manager' || value.name == 'creator' || value.name == 'point_manager' || value.name == 'admin'
  443. ) >= 0
  444. ) {
  445. arr.push(item);
  446. }
  447. });
  448. return arr;
  449. }
  450. },
  451. created() {
  452. var that = this;
  453. that.checked = false;
  454. setTimeout(() => {
  455. that.get_user_list();
  456. if (that.can_select_dept) {
  457. that.get_dept_list();
  458. }
  459. }, 200);
  460. }
  461. };
  462. </script>
  463. <style scoped>
  464. .deleteUser{
  465. font-size: 16px;
  466. padding: 8px;
  467. color: #777777;
  468. cursor: pointer;
  469. }
  470. .deleteUser:hover{
  471. color: #F56C6C;
  472. }
  473. .userName{
  474. width: 170px;
  475. }
  476. .employee_selector_box {
  477. width: 600px;
  478. padding: 20px;
  479. box-sizing: border-box;
  480. margin: 0 auto;
  481. }
  482. /* 搜索框 */
  483. .employee_selector_box .search {
  484. margin: 0 auto;
  485. width: 80%;
  486. }
  487. /* 左边框 */
  488. .employee_selector_box .choose_left {
  489. padding: 8px 10px;
  490. }
  491. .employee_selector_box .choose_left .employee_cell {
  492. border-bottom: 1px #f1f1f1 solid;
  493. }
  494. .employee_selector_box .choose_left .employee_checkbox {
  495. padding-left: 8px;
  496. }
  497. .employee_selector_box .choose_left .employee_img_url {
  498. padding-left: 8px;
  499. }
  500. .employee_selector_box .choose_left .employee_name {
  501. padding-left: 8px;
  502. }
  503. /* .employee_selector_box ::v-deep .el-scrollbar__thumb {
  504. width: 2px;
  505. margin: 15px 0 0 6px;
  506. background: #409eff;
  507. } */
  508. /* 右边距 */
  509. .employee_selector_box .option-box {
  510. padding: 14px;
  511. }
  512. .employee_selector_box .choose_right {
  513. padding: 8px 10px;
  514. }
  515. .employee_selector_box .choose_right .employee_delete .el-button {
  516. transform: scale(0.5);
  517. background: #c0c4cc;
  518. }
  519. .employee_selector_box .choose_right .employee_delete .el-button ::v-deep .el-icon-close {
  520. color: #fff;
  521. }
  522. .employee_selector_box .choose_right .employee_delete .el-button:active {
  523. background: #409eff;
  524. }
  525. .employee_selector_box .choose_right .employee_delete .el-button:active ::v-deep .el-icon-close {
  526. color: #fff;
  527. }
  528. .employee_selector_box .choose_right .employee_cell .employee_name {
  529. padding-left: 8px;
  530. }
  531. .employee_selector_box .choose_right .employee_cell .employee_img_url {
  532. padding-left: 8px;
  533. }
  534. /* 右边距 */
  535. .employee_cell2{
  536. padding: 8px 0;
  537. height: 50px;
  538. box-sizing: border-box;
  539. border-bottom: 1px #f1f1f1 solid;
  540. }
  541. .employee_selector_box ::v-deep .employee_cell {
  542. padding: 8px 0;
  543. height: 50px;
  544. box-sizing: border-box;
  545. }
  546. .employee_selector_box ::v-deep .employee_cell:hover {
  547. background: #ecf5ff;
  548. }
  549. .employee_cell {
  550. display: -webkit-inline-box;
  551. cursor: pointer;
  552. width: 100%;
  553. color: #606266;
  554. padding: 8px 0;
  555. background-color: transparent;
  556. border-bottom: 1px #f1f1f1 solid;
  557. }
  558. .employee_cell .employee_img_url {
  559. display: table-cell;
  560. vertical-align: middle;
  561. width: 30px;
  562. padding-left: 0px;
  563. }
  564. .employee_cell .employee_img_url img {
  565. width: 24px;
  566. height: 24px;
  567. border-radius: 50%;
  568. }
  569. .employee_cell .employee_checkbox {
  570. display: table-cell;
  571. vertical-align: middle;
  572. width: 30px;
  573. text-align: center;
  574. }
  575. .employee_cell .employee_name {
  576. display: table-cell;
  577. vertical-align: middle;
  578. color: #606266;
  579. }
  580. .employee_delete {
  581. display: table-cell;
  582. text-align: right;
  583. padding-right: 0px;
  584. }
  585. .employee_cell_a {
  586. display: block;
  587. }
  588. .employee_cell_a:hover {
  589. background-color: #ecf5ff;
  590. border-radius: 4px;
  591. }
  592. .dept_child_cell {
  593. display: table-cell;
  594. vertical-align: middle;
  595. }
  596. .dept_child_cell span {
  597. float: right;
  598. padding-right: 8px;
  599. }
  600. .dept_child_cell span:hover {
  601. color: #1c1c1c;
  602. }
  603. .dept_child_cell span:active {
  604. color: #1c1c1c;
  605. }
  606. .scroller-box {
  607. height: 440px;
  608. padding: 0px !important;
  609. background-color: #fdfdfd;
  610. border: 1px solid #eee;
  611. border-radius: 4px;
  612. overflow: hidden;
  613. }
  614. /* .scroller-box.one{
  615. height: 440px;
  616. } */
  617. .col-line {
  618. position: relative;
  619. height: 400px;
  620. }
  621. .col-line:before {
  622. content: ' ';
  623. width: 1px;
  624. height: 400px;
  625. position: absolute;
  626. top: 0;
  627. bottom: 0;
  628. left: 50%;
  629. background-color: #eee;
  630. }
  631. .search-box {
  632. background-color: #fff;
  633. padding: 10px 5px;
  634. border-bottom: 1px solid #eee;
  635. }
  636. .option-box {
  637. padding: 5px;
  638. background-color: #fff;
  639. border-bottom: 1px solid #eee;
  640. margin: 0 -5px;
  641. }
  642. .child_btn {
  643. color: #409eff;
  644. }
  645. .dept_path {
  646. margin: 10px 0;
  647. display: block;
  648. white-space: nowrap;
  649. overflow: auto;
  650. }
  651. /*滚动条的宽度*/
  652. .dept_path::-webkit-scrollbar {
  653. width: 5px;
  654. height: 5px;
  655. }
  656. /*外层轨道。可以用display:none让其不显示,也可以添加背景图片,颜色改变显示效果*/
  657. .dept_path::-webkit-scrollbar-track {
  658. width: 6px;
  659. background-color: #fff0;
  660. -webkit-border-radius: 2em;
  661. -moz-border-radius: 2em;
  662. border-radius: 2em;
  663. }
  664. /*滚动条的设置*/
  665. .dept_path::-webkit-scrollbar-thumb {
  666. background-color: #fff0;
  667. background-clip: padding-box;
  668. min-height: 28px;
  669. -webkit-border-radius: 2em;
  670. -moz-border-radius: 2em;
  671. border-radius: 2em;
  672. }
  673. /*滚动条移上去的背景*/
  674. .dept_path:hover::-webkit-scrollbar-thumb {
  675. background-color: rgba(144, 147, 153, 0.3);
  676. }
  677. .imgUrl{
  678. border-radius: 50%;
  679. height: 30px;
  680. width: 30px;
  681. box-sizing: border-box;
  682. text-align: center;
  683. line-height: 30px;
  684. font-size: 0.6rem;
  685. }
  686. </style>