departmentSelection.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="chooseSomeone">
  3. <div class="chooseSomeone_selsect">
  4. <van-search v-model.trim="selectValue" shape="round" background="#F4F4F4" placeholder="请输入" @search="onSearch"
  5. @input="onSearch"></van-search>
  6. </div>
  7. <div class="chooseSomeone_Con contentRoll">
  8. <div class="treeBox">
  9. <div class="treeBox_tree">
  10. <el-tree ref="tree" v-model="treeVal" show-checkbox node-key="id" :data="personnelTree" :props="defaultProps" check-strictly @check-change="treeHandChange"
  11. :filter-node-method="filterNode">
  12. <span class="custom-tree-node" slot-scope="{ node }">
  13. <span>
  14. {{ node.label }}
  15. </span>
  16. </span>
  17. </el-tree>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="chooseSomeone_btn">
  22. <van-button round type="info" size="small" style="width: 100%;" :loading="loadingBtn"
  23. @click="treeHandClick()">确定</van-button>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. isAdd: {
  31. type: Number,
  32. default: () => 1
  33. },
  34. },
  35. components: {},
  36. data() {
  37. return {
  38. selectValue: '',
  39. radioVal: '',
  40. groupVal: [],
  41. treeVal: [],
  42. // 人员数组
  43. personnelList: [],
  44. personnelTree: [],
  45. newPersonnelTree: [],
  46. defaultProps: {
  47. children: 'children',
  48. label: 'label'
  49. },
  50. loadingBtn: false, // 确定按钮loading
  51. };
  52. },
  53. computed: {},
  54. watch: {
  55. selectValue(val) {
  56. this.$refs.tree.filter(val);
  57. }
  58. },
  59. created() { },
  60. mounted() {
  61. this.getDepartmentPersonnel()
  62. },
  63. methods: {
  64. onSearch() {
  65. if (!this.selectValue) {
  66. return
  67. }
  68. },
  69. filterNode(value, data) {
  70. if (!value) return true;
  71. return data.label.indexOf(value) !== -1;
  72. },
  73. newGroupViewBackCli(flg, i) {
  74. this.newGroupViewBack = flg
  75. if (this.type != 1) {
  76. this.newGroupView = i
  77. this.$refs.tree.setCheckedKeys(this.groupVal)
  78. } else {
  79. this.getPeople()
  80. }
  81. },
  82. // 获取部门人员
  83. getDepartmentPersonnel() {
  84. this.$axios.post('/department/listAllMemb', {})
  85. .then(res => {
  86. if (res.code == "ok") {
  87. let list = res.data;
  88. this.personnelTree = list
  89. this.newPersonnelTree = JSON.parse(JSON.stringify(list))
  90. } else {
  91. this.$toast.clear();
  92. this.$toast.fail(res.msg);
  93. }
  94. }).catch(err => { this.$toast.clear(); });
  95. },
  96. treeHandChange(val, flag) {
  97. const { id } = val
  98. if(flag) {
  99. this.$refs.tree.setCheckedKeys([]);
  100. this.$refs.tree.setCheckedKeys([id]);
  101. }
  102. },
  103. treeHandClick() {
  104. let arr = this.$refs.tree.getCheckedNodes()
  105. if (arr.length <= 0) {
  106. this.$toast('请选择部门');
  107. return
  108. }
  109. let newArr = arr.map(item => {
  110. return {
  111. value: item.id,
  112. label: item.label || '',
  113. }
  114. })
  115. this.$emit('changeDepartmentSelection', newArr)
  116. }
  117. },
  118. };
  119. </script>
  120. <style scoped lang="less">
  121. * {
  122. box-sizing: border-box;
  123. }
  124. .textDepartmentName {
  125. color: #999;
  126. font-size: 14px;
  127. }
  128. .chooseSomeone {
  129. display: flex;
  130. flex-wrap: wrap;
  131. flex-direction: column;
  132. width: 100%;
  133. height: 100%;
  134. padding: 10px 15px 0px 15px;
  135. .chooseSomeone_selsect {
  136. .van-search__content {
  137. background-color: #fff;
  138. }
  139. }
  140. .treeBox {
  141. width: 100%;
  142. height: 100%;
  143. display: flex;
  144. flex-direction: column;
  145. .treeBox_tree {
  146. flex: 1;
  147. overflow-y: auto;
  148. padding: 10px;
  149. }
  150. .treeBox_tree_text {
  151. font-size: 14px;
  152. color: #999;
  153. display: flex;
  154. align-items: center;
  155. padding: 8px;
  156. .van-icon {
  157. margin-right: 6px;
  158. }
  159. }
  160. // 调整组件的默认样式
  161. .el-tree-node__content {
  162. height: 30px;
  163. }
  164. }
  165. .chooseSomeone_Con {
  166. flex: 1;
  167. background-color: #fff;
  168. border-radius: 10px;
  169. overflow-y: auto;
  170. padding: 10px;
  171. .chooseSomeoneo_group,
  172. .chooseSomeone_radio_group {
  173. .van-radio,
  174. .van-checkbox {
  175. width: 100%;
  176. padding: 10px;
  177. font-size: 16px;
  178. color: #333;
  179. border-bottom: 1px solid #F4F4F4;
  180. .van-radio__label {
  181. flex: 1 !important;
  182. }
  183. .van-checkbox__label {
  184. flex: 1 !important;
  185. }
  186. }
  187. .chooseSomeone_group_item,
  188. .chooseSomeone_radio_group_item {
  189. display: flex;
  190. justify-content: space-between;
  191. div:last-child {
  192. font-size: 12px;
  193. color: #999;
  194. width: 50%;
  195. text-align: right;
  196. }
  197. }
  198. }
  199. }
  200. .chooseSomeone_btn {
  201. display: flex;
  202. justify-content: space-between;
  203. align-items: center;
  204. height: 50px;
  205. .van-button {
  206. width: 48%;
  207. }
  208. }
  209. }
  210. </style>