selectUser.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="hui-flex hui-dialog">
  3. <div class="hui-flex-box">
  4. <div class="change-user-box">
  5. <div class="change-part">
  6. <div class="part-breadcrumb">
  7. <div class="part-breadcrumb-item" v-for="(item,index) in breadcrumb" :key="index"
  8. @click="breadcrumbClick(item,index)">
  9. {{item.name}}
  10. <i class="iconfont huifont-xiala-right" v-if="index < breadcrumb.length-1"></i>
  11. </div>
  12. </div>
  13. <el-checkbox class="check-all" v-model="checkAll" @change="checkChange" v-if="!maxLen">
  14. 全选
  15. </el-checkbox>
  16. <div class="part-user no-box" v-if="partList.length === 0 && userList.length === 0">
  17. <el-empty width="100"></el-empty>
  18. </div>
  19. <div class="part-user" v-else>
  20. <el-checkbox-group v-model="checkedBox" @change="testCheckedAll">
  21. <el-checkbox v-for="(item,index) in partList" :label="item.id" :key="-item.id" disabled>
  22. <div class="user-box">
  23. <div class="user-avatar">
  24. <i class="iconfont huifont-bumen"></i>
  25. </div>
  26. <div class="user-name">{{item.name}}</div>
  27. <div class="part-button" @click="openPart(item)">展开</div>
  28. </div>
  29. </el-checkbox>
  30. <el-checkbox v-for="(item,index) in userList" :label="item.id" :key="item.id"
  31. @change="selectUser" :disabled="returnDisabled(item)">
  32. <div class="user-box">
  33. <div class="user-avatar">
  34. <avatar :user="item" :size="12"></avatar>
  35. </div>
  36. <div class="user-name">{{item.name}}</div>
  37. </div>
  38. </el-checkbox>
  39. </el-checkbox-group>
  40. </div>
  41. </div>
  42. <div class="change-user">
  43. <div class="change-user-operation">
  44. <div class="change-user-count">
  45. 已选择:{{checkedUserList.length}}名用户
  46. </div>
  47. <div class="change-user-clear" @click="clearAll">清空</div>
  48. </div>
  49. <div class="change-user-list no-box" v-if="checkedUserList.length === 0">
  50. <el-empty width="100"></el-empty>
  51. </div>
  52. <div class="change-user-list" v-else>
  53. <div class="change-user-item user-box" v-for="(item,index) in checkedUserList" :label="item.id"
  54. :key="item.id">
  55. <div class="user-avatar">
  56. <avatar :user="item" :size="12"></avatar>
  57. </div>
  58. <div class="user-name">
  59. <div>{{item.name}}</div>
  60. <p>{{item.partName}}</p>
  61. </div>
  62. <div class="user-delete" @click="deleteUser(item)">
  63. <i class="iconfont huifont-guanbi"></i>
  64. </div>
  65. <div class="user-line" v-if="index < checkedUserList.length-1"></div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="hui-dialog-submit">
  72. <el-button size="small" @click="$emit('callback')">取 消</el-button>
  73. <el-button size="small" type="primary" @click="submit">保 存</el-button>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import {
  79. getPartList
  80. } from '@/api/organization'
  81. export default {
  82. props: ['list', 'type', 'maxLen'],
  83. data() {
  84. return {
  85. checkAll: false,
  86. partList: [],
  87. allUserList: [],
  88. userList: [],
  89. checkedBox: [],
  90. breadcrumb: [{
  91. id: 0,
  92. name: '部门'
  93. }],
  94. checkedUserList: [],
  95. partId: ''
  96. }
  97. },
  98. mounted() {
  99. this.init();
  100. },
  101. methods: {
  102. init() {
  103. getPartList(this.$store.getters.organization.id, -1).then(res => {
  104. if (res.state) {
  105. this.returnChildren(res.data); //获取总员工数列表
  106. this.partList = res.data;
  107. this.breadcrumb[0]['node'] = this.partList;
  108. if (this.list && this.list.length > 0) {
  109. this.checkedBox = this.list.map(node => node.id);
  110. this.checkedUserList = this.list;
  111. }
  112. }
  113. })
  114. },
  115. returnChildren(data) {
  116. data.forEach(item => {
  117. if (item.children && item.users) {
  118. let obj = item.users.map(res => {
  119. return {
  120. id: res.id,
  121. name: res.name,
  122. partName: item.name,
  123. partId: item.id,
  124. portrait: res.portrait
  125. };
  126. })
  127. this.allUserList = this.allUserList.concat(obj);
  128. }
  129. if (item.children && item.children.length > 0) this.returnChildren(item.children);
  130. });
  131. },
  132. returnDisabled(item) {
  133. if (this.maxLen === this.checkedBox.length) {
  134. if (this.checkedBox.filter(node => node === item.id).length > 0) return false;
  135. return true;
  136. }
  137. return false;
  138. },
  139. checkChange(val) {
  140. if (this.userList.length === 0) return;
  141. if (val) {
  142. let data = this.checkedBox;
  143. this.checkedBox = Array.from(new Set(data.concat(this.userList.map(node => node.id))));
  144. } else {
  145. let ids = this.userList.map(node => node.id);
  146. for (var i = 0; i < ids.length; i++) {
  147. let boxIndex = this.checkedBox.findIndex(node => node === ids[i]);
  148. this.checkedBox.splice(boxIndex, 1);
  149. }
  150. }
  151. this.selectUser();
  152. },
  153. selectUser() {
  154. this.checkedUserList = this.checkedBox.map(node => {
  155. return this.allUserList.filter(user => user.id === node)[0];
  156. })
  157. },
  158. deleteUser(item) {
  159. let boxIndex = this.checkedBox.findIndex(node => node === item.id);
  160. this.checkedBox.splice(boxIndex, 1);
  161. this.selectUser();
  162. this.testCheckedAll();
  163. },
  164. clearAll() {
  165. this.checkedBox = [];
  166. this.selectUser();
  167. this.testCheckedAll();
  168. },
  169. openPart(data) {
  170. this.breadcrumb.push({
  171. id: data.id,
  172. name: data.name,
  173. node: data
  174. });
  175. this.filterList(data);
  176. },
  177. filterList(data) {
  178. this.partList = data.children;
  179. this.partId = data.id;
  180. this.userList = this.allUserList.filter(node => node.partId === data.id);
  181. this.testCheckedAll();
  182. },
  183. testCheckedAll() {
  184. if (this.userList.length === 0) return this.checkAll = false;
  185. let checkedCount = this.checkedBox.filter(node => this.userList.filter(res => res.id === node).length > 0)
  186. .length;
  187. this.checkAll = checkedCount === this.userList.length;
  188. },
  189. breadcrumbClick(item, index) {
  190. if (index === this.breadcrumb.length - 1) return;
  191. this.breadcrumb = this.breadcrumb.slice(0, index + 1);
  192. if (item.id === 0) {
  193. this.userList = [];
  194. return this.partList = item.node;
  195. }
  196. this.filterList(this.breadcrumb[this.breadcrumb.length - 1].node);
  197. },
  198. submit() {
  199. this.$emit('callback', this.checkedUserList);
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss">
  205. .change-user-box {
  206. width: 100%;
  207. height: 100%;
  208. display: flex;
  209. .no-box {
  210. display: flex;
  211. align-items: center;
  212. justify-content: center;
  213. border-top: 1px solid $--border-color-light;
  214. }
  215. .change-part {
  216. flex: 1;
  217. border-right: 1px solid $--border-color-light;
  218. height: 100%;
  219. display: flex;
  220. flex-direction: column;
  221. .part-breadcrumb {
  222. display: flex;
  223. flex-wrap: wrap;
  224. padding: 20px;
  225. .part-breadcrumb-item {
  226. display: flex;
  227. align-items: center;
  228. opacity: 0.5;
  229. cursor: pointer;
  230. i {
  231. font-size: 14px;
  232. padding: 0 5px;
  233. }
  234. }
  235. .part-breadcrumb-item:last-child {
  236. opacity: 1;
  237. }
  238. }
  239. .check-all {
  240. padding: 0px 20px 10px 20px;
  241. }
  242. .part-user {
  243. flex: 1;
  244. overflow-y: auto;
  245. padding: 0 20px 10px 20px;
  246. .el-checkbox-group {
  247. .el-checkbox {
  248. display: flex;
  249. align-items: center;
  250. height: 48px;
  251. }
  252. .el-checkbox__input.is-disabled+span.el-checkbox__label {
  253. cursor: pointer;
  254. }
  255. .el-checkbox {
  256. margin-right: 0;
  257. }
  258. .el-checkbox__label {
  259. flex: 1;
  260. }
  261. }
  262. }
  263. }
  264. .user-box {
  265. display: flex;
  266. align-items: center;
  267. .user-avatar {
  268. width: 32px;
  269. height: 32px;
  270. background: $--color-primary;
  271. border-radius: 50%;
  272. margin-right: 10px;
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. overflow: hidden;
  277. i {
  278. font-size: 20px;
  279. color: $--color-white;
  280. }
  281. }
  282. .user-name {
  283. flex: 1;
  284. width: 0;
  285. p {
  286. font-size: 12px;
  287. opacity: 0.6;
  288. }
  289. }
  290. .part-button {
  291. color: $--color-primary;
  292. }
  293. .user-delete {
  294. width: 24px;
  295. height: 24px;
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. cursor: pointer;
  300. border-radius: 2px;
  301. i {
  302. margin-top: 2px;
  303. opacity: 0.5;
  304. font-size: 14px;
  305. }
  306. }
  307. .user-delete:hover {
  308. color: $--color-danger;
  309. }
  310. }
  311. .change-user {
  312. flex: 1;
  313. height: 100%;
  314. display: flex;
  315. flex-direction: column;
  316. .change-user-operation {
  317. padding: 20px;
  318. display: flex;
  319. justify-content: space-between;
  320. .change-user-clear {
  321. color: $--color-danger;
  322. cursor: pointer;
  323. }
  324. }
  325. .change-user-list {
  326. flex: 1;
  327. height: 0;
  328. overflow-y: auto;
  329. padding: 0 20px 14px 20px;
  330. .change-user-item {
  331. height: 48px;
  332. position: relative;
  333. .user-line {
  334. width: 2px;
  335. background-color: rgba(255, 255, 255, 0.2);
  336. position: absolute;
  337. top: 40px;
  338. bottom: -8px;
  339. left: 15px;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. </style>