vueMultipleDept.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div>
  3. <div class="bionicClass" @mouseenter="handleMouse(true)" @mouseleave="handleMouse(false)">
  4. <div @click.stop="showVisible(true)">
  5. <div class="bionicClassText" v-if="selectedDept.length <= 0">全部部门</div>
  6. <div v-else>
  7. <el-tag @click.stop="" type="info" size="small" closable @close="deteleItem(0)">{{ selectedDeptLabel[0]
  8. }}</el-tag>
  9. <el-tag @click.stop="" type="info" size="small" v-if="selectedDeptLabel.length > 1">+ {{
  10. selectedDeptLabel.length - 1 }}</el-tag>
  11. </div>
  12. </div>
  13. <div class="bionicClassIcon" v-if="showIocn && clearable">
  14. <el-link icon="el-icon-circle-close" type="info" :underline="false" @click.stop="clearItem()"></el-link>
  15. </div>
  16. </div>
  17. <el-dialog title="选择部门" :visible.sync="deptVisible" width="700px" top="60px" append-to-body
  18. :before-close="handleClose">
  19. <div class="selectDepartment">
  20. <el-input placeholder="请输入部门" v-model.trim="filterText" clearable @clear="echartDepartment(false)" @keyup.enter.native="echartDepartment(filterText ? true : false)">
  21. <el-button slot="append" icon="el-icon-search" @click="echartDepartment(true)"></el-button>
  22. </el-input>
  23. <div class="flex1 padding1">
  24. <el-tree class="filter-tree" node-key="id" :data="treeData" :props="defaultProps" show-checkbox
  25. :filter-node-method="treeDatafilterNode" default-expand-all @check-change="handleCheckChange"
  26. ref="treeDataComtent">
  27. <span class="custom-tree-node" slot-scope="{ node, data }">
  28. <span v-if="node.data.children">
  29. <TranslationOpenDataText type='departmentName' :openid='node.label'>
  30. </TranslationOpenDataText>
  31. </span>
  32. <span v-else>
  33. <TranslationOpenDataText type='userName' :openid='node.label'></TranslationOpenDataText>
  34. </span>
  35. </span>
  36. </el-tree>
  37. </div>
  38. </div>
  39. <span slot="footer" class="dialog-footer">
  40. <el-button @click="deptVisible = false">取 消</el-button>
  41. <el-button type="primary" @click="determineDept()">确 定</el-button>
  42. </span>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. name: '',
  49. components: {},
  50. props: {
  51. modelValue: {
  52. type: Array,
  53. default: () => []
  54. },
  55. defaultProps: {
  56. children: 'children',
  57. label: 'label'
  58. },
  59. selectType: { // 0 人员/部门, 1 人员搜索 2部门搜索
  60. type: String,
  61. default: () => '0'
  62. },
  63. clearable: {
  64. type: Boolean,
  65. default: () => true
  66. },
  67. },
  68. data() {
  69. return {
  70. user: JSON.parse(sessionStorage.getItem("user")),
  71. selectedDept: [],
  72. selectedDeptValue: [],
  73. selectedDeptLabel: [],
  74. filterText: '',
  75. filterKeyNode: [],
  76. treeData: [],
  77. treeDataCopy: [],
  78. deptVisible: false,
  79. treeDataLoading: false,
  80. showIocn: false
  81. }
  82. },
  83. computed: {},
  84. watch: {},
  85. created() { },
  86. mounted() {
  87. this.getDeptData()
  88. },
  89. model: {
  90. prop: 'modelValue',
  91. event: 'getValue'
  92. },
  93. methods: {
  94. determineDept() {
  95. const dataNodes = this.$refs.treeDataComtent.getCheckedNodes()
  96. this.selectedDept = dataNodes
  97. this.selectedDeptValue = dataNodes.map(item => item.id)
  98. this.selectedDeptLabel = dataNodes.map(item => item.label)
  99. this.updateModelValue()
  100. this.showVisible(false)
  101. },
  102. deteleItem(index, flag = false) {
  103. const deteleNumber = flag ? this.selectedDept.length : 1
  104. this.selectedDept.splice(index, deteleNumber)
  105. this.selectedDeptValue.splice(index, deteleNumber)
  106. this.selectedDeptLabel.splice(index, deteleNumber)
  107. this.updateModelValue()
  108. },
  109. clearItem() {
  110. this.selectedDept = []
  111. this.selectedDeptValue = []
  112. this.selectedDeptLabel = []
  113. this.updateModelValue()
  114. },
  115. echartDepartment(flag = true) {
  116. if (this.user.userNameNeedTranslate != '1') {
  117. this.$refs.treeDataComtent.filter(this.filterText);
  118. return
  119. }
  120. if (flag) { // 清空
  121. this.filterKeyNode = this.$refs.treeDataComtent.getCheckedKeys()
  122. }
  123. this.getDeptData(true)
  124. },
  125. setTreeDataKeyNode(array) {
  126. setTimeout(() => {
  127. this.$refs.treeDataComtent.setCheckedKeys(array);
  128. }, 300)
  129. },
  130. updateModelValue() {
  131. this.$emit('getValue', this.selectedDeptValue);
  132. this.$emit('change', this.selectedDeptValue);
  133. },
  134. treeDatafilterNode(value, data) {
  135. if (!value) return true;
  136. return data.label.indexOf(value) !== -1;
  137. },
  138. showVisible(flag) {
  139. this.deptVisible = flag
  140. if (flag) {
  141. this.setTreeDataKeyNode(this.modelValue || []);
  142. }
  143. },
  144. handleCheckChange() {
  145. let keys = this.$refs.treeDataComtent.getCheckedKeys()
  146. if (keys.length > 0) {
  147. this.filterKeyNode = [...this.filterKeyNode, keys[keys.length - 1]]
  148. }
  149. },
  150. getDeptData(flag = false, str) {
  151. this.treeDataLoading = true
  152. this.http.post("/department/listAllMemb", {
  153. queryType: this.selectType,
  154. keyword: this.filterText,
  155. cursor: ''
  156. }, res => {
  157. this.treeDataLoading = false
  158. this.treeData = JSON.parse(JSON.stringify(res.data.data || res.data))
  159. this.treeDataCopy = JSON.parse(JSON.stringify(res.data.data || res.data))
  160. flag ? this.$refs.treeDataComtent.setCheckedKeys(this.filterKeyNode) : ''
  161. }, err => {
  162. this.treeDataLoading = false
  163. })
  164. },
  165. handleMouse(flag) {
  166. this.showIocn = flag
  167. },
  168. },
  169. }
  170. </script>
  171. <style scoped lang='scss'>
  172. .selectDepartment {
  173. height: 56vh;
  174. display: flex;
  175. flex-direction: column;
  176. .flex1 {
  177. flex: 1;
  178. overflow: auto;
  179. }
  180. .padding1 {
  181. margin: 10px;
  182. }
  183. }
  184. .bionicClass {
  185. background-color: #FFF;
  186. background-image: none;
  187. border-radius: 4px;
  188. border: 1px solid #DCDFE6;
  189. box-sizing: border-box;
  190. color: #606266;
  191. display: inline-block;
  192. height: 40px;
  193. line-height: 40px;
  194. outline: 0;
  195. padding: 0 15px;
  196. -webkit-transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
  197. transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
  198. width: 350px;
  199. position: relative;
  200. cursor: pointer;
  201. .bionicClassIcon {
  202. position: absolute;
  203. top: 50%;
  204. right: 15px;
  205. transform: translateY(-50%);
  206. color: "#606266";
  207. z-index: 10;
  208. }
  209. .bionicClassText {
  210. color: #C0C4CC;
  211. }
  212. }
  213. .el-dialog {
  214. display: flex;
  215. flex-direction: column;
  216. margin: 0 !important;
  217. position: absolute;
  218. top: 50%;
  219. left: 50%;
  220. transform: translate(-50%, -50%);
  221. max-height: calc(100% - 200px);
  222. max-width: calc(100% - 30px);
  223. }
  224. .el-dialog .el-dialog__body {
  225. flex: 1;
  226. overflow: auto;
  227. }
  228. </style>
  229. <style>
  230. .bionicClassIcon .el-icon-circle-close {
  231. color: #C0C4CC !important;
  232. }
  233. </style>