userSelectCompon.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <!-- @hide="popoverHide" -->
  3. <el-popover
  4. ref="reference"
  5. placement="bottom-start"
  6. :width="width?width:'400'"
  7. trigger="click"
  8. :disabled="disab"
  9. >
  10. <el-tabs v-model="activeName" :width="width?width:'400'" type="card" @tab-click="handleClick">
  11. <el-input v-model="checkLabel" size="mini" placeholder="请输入搜索内容" :disabled="disab">
  12. <i slot="suffix" class="el-icon-edit el-input__icon" />
  13. </el-input>
  14. <el-tab-pane label="按组织" name="1" style="height: 300px; overflow-y:auto;">
  15. <el-tree v-loading="loading" ref="tree_1" :default-expanded-keys="expandedKeys" :default-checked-keys="selectValue" :data="data_1" show-checkbox node-key="id" empty-text="没有数据了" :props="defaultProps" :filter-node-method="filterNode" @check="handleNodeChange" />
  16. </el-tab-pane>
  17. <el-tab-pane label="按岗位" name="2" style="height: 300px; overflow-y:auto;">
  18. <el-tree v-loading="loading" ref="tree_2" :default-expanded-keys="expandedKeys" :default-checked-keys="selectValue" :data="data_2" show-checkbox node-key="id" empty-text="没有数据了" :props="defaultProps" :filter-node-method="filterNode" @check="handleNodeChange" />
  19. </el-tab-pane>
  20. <el-tab-pane label="我的下属" name="3" style="height: 300px; overflow-y:auto;">
  21. <el-tree v-loading="loading" ref="tree_3" :default-expanded-keys="expandedKeys" :default-checked-keys="selectValue" :data="data_3" show-checkbox node-key="id" empty-text="没有数据了" :props="defaultProps" :filter-node-method="filterNode" @check="handleNodeChange" />
  22. </el-tab-pane>
  23. <el-tab-pane label="我的部门" name="4" style="height: 300px; overflow-y:auto;">
  24. <el-tree v-loading="loading" ref="tree_4" :default-expanded-keys="expandedKeys" :default-checked-keys="selectValue" :data="data_4" show-checkbox node-key="id" empty-text="没有数据了" :props="defaultProps" :filter-node-method="filterNode" @check="handleNodeChange" />
  25. </el-tab-pane>
  26. </el-tabs>
  27. <div slot="reference" data-v-51add840="" style="width: 100%;" class="col-input el-col el-col-20" @click="search">
  28. <div data-v-51add840="" class="el-form-item">
  29. <div class="el-form-item__content">
  30. <div data-v-51add840="" class="el-select">
  31. <div class="el-input el-input--suffix is-focus">
  32. <input v-model="selectLabel" type="text" autocomplete="off" placeholder="请选择人员" readonly class="el-input__inner">
  33. <span class="el-input__suffix">
  34. <span class="el-input__suffix-inner">
  35. <i :class="classType==1?class_up:class_dow" style="" />
  36. </span>
  37. </span>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </el-popover>
  44. </template>
  45. <script>
  46. export default {
  47. props: {
  48. defaultSelect: Array,
  49. width: String,
  50. multiple: Boolean,
  51. disab: Boolean,
  52. groupId: String,
  53. parentData: String
  54. },
  55. data() {
  56. return {
  57. loading: false,
  58. classType: 1,
  59. checkLabel: '',
  60. selectLabel: '',
  61. selectValue: [],
  62. labels: [],
  63. selectTree: [],
  64. expandedKeys: ['0'],
  65. activeName: '1',
  66. class_up: 'el-select__caret el-input__icon el-icon-arrow-up',
  67. class_dow: 'el-select__caret el-input__icon el-icon-arrow-up is-reverse',
  68. data_1: [],
  69. data_2: [],
  70. data_3: [],
  71. data_4: [],
  72. defaultProps: {
  73. children: 'children',
  74. label: 'label'
  75. }
  76. }
  77. },
  78. watch: {
  79. checkLabel(val) {
  80. this.$refs['tree_' + this.activeName].filter(val)
  81. }
  82. },
  83. mounted() {
  84. this.selectValue = this.defaultSelect;
  85. this.initData();
  86. },
  87. methods: {
  88. initData: function(){
  89. // this.getTreeDate();
  90. this.initTreeDate();
  91. },
  92. search: function() {
  93. if (this.classType === 1) {
  94. this.classType = 2
  95. } else {
  96. this.classType = 1
  97. }
  98. },
  99. handleClick: function() {
  100. this.getTreeDate()
  101. },
  102. handleNodeChange: function(data, checked, indeterminate) {
  103. if (!this.multiple) {
  104. if (checked) {
  105. this.$refs['tree_' + this.activeName].setCheckedKeys([])
  106. this.$refs['tree_' + this.activeName].setChecked(data, true)
  107. if (data.children == null) {
  108. this.selectValue = [data.id]
  109. this.labels = [data.label]
  110. }
  111. }
  112. } else {
  113. if (this.selectValue.indexOf(data.id) > -1) {
  114. this.selectValue = this.selectValue.filter(item => item !== data.id)
  115. this.labels = this.labels.filter(item => item !== data.label)
  116. }
  117. if (data.children != null && data.children.length > 0) {
  118. this.deleteSelect(data.children)
  119. }
  120. }
  121. this.popoverHide()
  122. },
  123. deleteSelect(data) {
  124. data.forEach(it => {
  125. if (it.children != null && it.children.length > 0) {
  126. this.deleteSelect(it.children)
  127. }
  128. this.selectValue = this.selectValue.filter(item => item !== it.id)
  129. this.labels = this.labels.filter(item => item !== it.label)
  130. })
  131. },
  132. popoverHide: function() {
  133. const sectd = this.$refs['tree_' + this.activeName].getCheckedNodes()
  134. const seachId = []
  135. const seachVal = []
  136. sectd.forEach(element => {
  137. if (element.selectType && this.selectValue.indexOf(element.id) === -1) {
  138. seachId.push(element.id)
  139. seachVal.push(element.label)
  140. }
  141. })
  142. if (seachVal.length > 0) {
  143. seachVal.forEach(ii => {
  144. this.labels.push(ii)
  145. })
  146. }
  147. this.selectLabel = this.labels.toString()
  148. if (seachId.length > 0) {
  149. seachId.forEach(ij => {
  150. this.selectValue.push(ij)
  151. })
  152. }
  153. if (this.parentData) {
  154. const parent = {
  155. selectValue: this.selectValue,
  156. parentData: this.parentData
  157. }
  158. this.$emit('selectValue', parent)
  159. } else {
  160. this.$emit('selectValue', this.selectValue)
  161. }
  162. },
  163. // 数据回显
  164. popoverShow: function() {
  165. const sectd = this.$refs['tree_' + this.activeName].getCheckedNodes()
  166. const seachVal = []
  167. sectd.forEach(element => {
  168. if (element.selectType) {
  169. seachVal.push(element.label)
  170. }
  171. })
  172. if (seachVal.length > 0) {
  173. seachVal.forEach(ii => {
  174. this.labels.push(ii)
  175. })
  176. }
  177. this.selectLabel = this.labels.toString();
  178. },
  179. filterNode: function(value, data) {
  180. if (!value) return true
  181. return data.label.indexOf(value) !== -1
  182. },
  183. // 获取树级数据
  184. getTreeDate: function() {
  185. this.loading = true;
  186. const postData = {
  187. groupType: this.activeName,
  188. groupId: this.groupId
  189. }
  190. this['data_' + this.activeName] = []
  191. const _this = this;
  192. this.baseUserRequest('getUserListGroupType', postData).then((res) => {
  193. if (res.data) {
  194. _this['data_' + this.activeName] = res.data.data
  195. }
  196. _this.loading = false
  197. this.$nextTick(() => {
  198. this.popoverHide()
  199. })
  200. }).catch(() => {
  201. })
  202. },
  203. initTreeDate: function() {
  204. this.loading = true;
  205. const postData = {
  206. groupType: this.activeName,
  207. groupId: this.groupId
  208. }
  209. this['data_' + this.activeName] = []
  210. const _this = this;
  211. this.baseUserRequest('getUserListGroupType', postData).then((res) => {
  212. if (res.data) {
  213. _this['data_' + this.activeName] = res.data.data
  214. }
  215. _this.loading = false
  216. this.$nextTick(() => {
  217. this.popoverShow();
  218. })
  219. }).catch(() => {
  220. })
  221. },
  222. // getData(data) {
  223. // data.map(item => {
  224. // this.getLeadKeys(item)
  225. // })
  226. // },
  227. // getLeadKeys(node) {
  228. // if (node.children && node.children.length > 0) {
  229. // node.disabled = true
  230. // node.children.forEach(item => {
  231. // this.getLeadKeys(item)
  232. // })
  233. // } else {
  234. // if (node.selectType) {
  235. // node.disabled = false
  236. // } else {
  237. // node.disabled = true
  238. // }
  239. // }
  240. // },
  241. baseUserRequest(opUrl, postData) {
  242. return this.$channel.globleRequest('FrameExclusiveUserController', opUrl, postData, 'project')
  243. }
  244. }
  245. }
  246. </script>