index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <!-- 弹出框 -->
  3. <el-popover placement="bottom-start" :disabled="disabled" v-model="visible">
  4. <!-- 选中的值 -->
  5. <div slot="reference" class="tags-box">
  6. <i
  7. v-if="sNodeList.length > 0 && !disabled"
  8. class="el-icon-circle-close close-icon"
  9. @click="clear"></i>
  10. <el-tag type="success" v-for="v in sNodeList" :key="v.id">{{v.name}}</el-tag>
  11. </div>
  12. <!-- 文本框 -->
  13. <el-input
  14. style="width: 100%; margin-bottom: 20px"
  15. v-model="queryForm.value"
  16. @input="serchTreeHandler"
  17. placeholder="请输入过滤值"
  18. ></el-input>
  19. <!-- 下拉框 -->
  20. <el-row :gutter="20" type="flex" align="middle">
  21. <el-col :span="14" :xs="24">
  22. <el-select
  23. :disabled="disable"
  24. v-model="queryForm.type"
  25. placeholder="请选择过滤机构类型"
  26. clearable
  27. @change="serchTreeHandler"
  28. >
  29. <el-option
  30. v-for="dict in dict.type.sys_org_type"
  31. :key="dict.value"
  32. :label="dict.label"
  33. :value="parseInt(dict.value)"
  34. ></el-option>
  35. </el-select>
  36. </el-col>
  37. <el-col :span="10" :xs="24">
  38. <el-checkbox v-if="!disable" v-model="checked">按过滤机构类型勾选</el-checkbox>
  39. </el-col>
  40. </el-row>
  41. <!-- 机构树 -->
  42. <div class="tree-box">
  43. <el-tree
  44. ref="tree"
  45. :data="orgTree"
  46. :props="defaultProps"
  47. node-key="id"
  48. show-checkbox
  49. :check-strictly="true"
  50. :expand-on-click-node="false"
  51. :default-checked-keys="nodes"
  52. :default-expanded-keys="nodes"
  53. @node-click="handleNodeClick"
  54. @check="onCheck"
  55. :filter-node-method="filterNode">
  56. </el-tree>
  57. </div>
  58. </el-popover>
  59. </template>
  60. <script>
  61. export default {
  62. dicts: ["sys_org_type"],
  63. props: {
  64. //默认选中的node
  65. defaultNode: {
  66. type: Array,
  67. default: () => [],
  68. required: false,
  69. },
  70. //行社机构
  71. hangsheTree: {
  72. type: Boolean,
  73. default: false,
  74. },
  75. defaultProps: {
  76. type: Object,
  77. default: () => {
  78. return {
  79. children: "children",
  80. label: "name",
  81. };
  82. },
  83. },
  84. //自定义请求
  85. customRequest: {
  86. type: Function,
  87. },
  88. //组件禁用
  89. disabled: {
  90. type: Boolean,
  91. default: false,
  92. required: false,
  93. },
  94. queryData: {
  95. type: Number,
  96. default: null,
  97. required: false,
  98. },
  99. // 机构类型筛选条件禁用
  100. disable: {
  101. type: Boolean,
  102. default: false,
  103. required: false,
  104. },
  105. },
  106. data() {
  107. return {
  108. //是否取消关联父子级
  109. strictly: true,
  110. //清除图标
  111. showClearable: false,
  112. //弹窗显示
  113. visible: false,
  114. //结构树
  115. orgTree: null,
  116. //过滤条件
  117. queryForm: {
  118. value: null,
  119. type: null,
  120. },
  121. //受否全选
  122. checked: false,
  123. //默认展示的node
  124. //defaultNode:[],
  125. //已选中的node
  126. sNodeList: [],
  127. nodes: [],
  128. };
  129. },
  130. mounted() {
  131. this.getDeptTree();
  132. },
  133. computed:{
  134. },
  135. watch: {
  136. defaultNode: {
  137. immediate: true,
  138. handler(n) {
  139. if(!n || n.length === 0)return;
  140. this.nodes = this.defaultNode;
  141. this.$nextTick(() => {
  142. let arr = [];
  143. this.defaultNode.forEach(v=>{
  144. let node = this.$refs.tree.getNode(v);
  145. arr.push(node.data)
  146. })
  147. this.sNodeList = arr;
  148. });
  149. },
  150. },
  151. checked: {
  152. handler(v) {
  153. if (v) {
  154. this.strictly = false;
  155. } else {
  156. this.strictly = true;
  157. }
  158. },
  159. },
  160. queryData: {
  161. handler(n) {
  162. if (n) {
  163. this.queryForm.type = parseInt(n);
  164. this.serchTreeHandler();
  165. }
  166. },
  167. // queryForm: {
  168. // deep: true,
  169. // handler(n, o) {
  170. // if(!n.value&&!n.type){
  171. // this.$refs.tree.filter({});
  172. // }else{
  173. // this.$refs.tree.filter(n);
  174. // }
  175. // },
  176. // },
  177. },
  178. // computed: {
  179. // defaultNode:
  180. // //pv: sync("value"),
  181. // },
  182. },
  183. methods: {
  184. clear() {
  185. this.sNodeList = [];
  186. this.$refs.tree.setCheckedKeys([]);
  187. this.$refs.tree.setCurrentKey(null);
  188. this.nodes = [];
  189. this.$emit("selectNode", JSON.stringify(this.sNodeList));
  190. },
  191. //筛选条件变化
  192. serchTreeHandler() {
  193. this.$refs.tree.filter(this.queryForm);
  194. },
  195. /** 查询机构下拉树结构 */
  196. getDeptTree() {
  197. if (this.customRequest) {
  198. this.customRequest().then((response) => {
  199. this.treeList = response.data;
  200. return
  201. });
  202. }
  203. this.orgTree = this.$store.getters.orgTree;
  204. if (this.hangsheTree) {
  205. this.orgTree = this.$store.getters.depTree;
  206. }
  207. },
  208. filterNode(value, data, node) {
  209. if (this.queryForm.value && this.queryForm.type) {
  210. return (
  211. data.name.indexOf(this.queryForm.value) !== -1 &&
  212. data.type == this.queryForm.type
  213. );
  214. }
  215. if (this.queryForm.value) {
  216. return data.name.indexOf(this.queryForm.value) !== -1;
  217. }
  218. if (this.queryForm.type) {
  219. return data.type == this.queryForm.type;
  220. }
  221. return true;
  222. },
  223. handleNodeClick() {
  224. },
  225. onCheck(data, checked, tree) {
  226. if (this.checked) {
  227. //当前按过滤机构类型勾选
  228. //递归查询
  229. this.recursionTreeHandler(this.queryForm.type, [data]);
  230. }
  231. // debugger;
  232. this.sNodeList = this.$refs.tree.getCheckedNodes();
  233. this.$emit("selectNode", JSON.stringify(this.sNodeList));
  234. },
  235. recursionTreeHandler(type, tree) {
  236. tree.forEach((item) => {
  237. if (type == item.type) {
  238. this.$refs.tree.setCheckedKeys([item.id])
  239. }
  240. });
  241. if (tree.children && tree.children.length > 0) {
  242. this.recursionTreeHandler(type, tree.children)
  243. } else {
  244. return;
  245. }
  246. },
  247. getSubOrgIdsByOrgType(topOrg, orgType, orgIdList) {
  248. if (!topOrg) return;
  249. if (topOrg.type == orgType) {
  250. orgIdList.push(topOrg);
  251. }
  252. if (topOrg.children && topOrg.children.length > 0) {
  253. topOrg.children.forEach((item) => {
  254. this.getSubOrgIdsByOrgType(item, orgType, orgIdList);
  255. });
  256. }
  257. },
  258. },
  259. model: {
  260. prop: "defaultNode",
  261. event: "selectNode",
  262. },
  263. };
  264. </script>
  265. <style scoped lang="scss">
  266. .tags-box {
  267. background-color: #fff;
  268. border-radius: 4px;
  269. border: 1px solid #dcdfe6;
  270. color: #606266;
  271. outline: 0;
  272. padding: 0 15px 0 5px;
  273. width: 100%;
  274. min-height: 40px;
  275. max-height: 40px;
  276. position: relative;
  277. overflow: hidden;
  278. display: inline-block;
  279. text-overflow: ellipsis;
  280. white-space: nowrap;
  281. cursor: pointer;
  282. > span {
  283. margin: 5px 10px;
  284. }
  285. &:hover {
  286. .close-icon {
  287. display: block;
  288. color: #666;
  289. }
  290. }
  291. .close-icon {
  292. position: absolute;
  293. top: 30%;
  294. right: 5px;
  295. display: none;
  296. cursor: pointer;
  297. }
  298. }
  299. .tree-box {
  300. margin-top: 20px;
  301. max-height: 300px;
  302. overflow: auto;
  303. border-radius: 4px;
  304. border: 1px solid #dcdfe6;
  305. }
  306. </style>