vueMultipleDept.vue 8.1 KB

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