mixin.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. export default (params) => { // 导出混入对象
  2. const { //树分类过滤参数
  3. treeTypeNum=2
  4. } = params;
  5. return {
  6. data() {
  7. return {
  8. /**Split 开始 */
  9. ztreeNodes: [],
  10. leftSplitWidth: 20,
  11. rightSplitWidth: 80,
  12. ztreeObj: null,
  13. ztreeSetting: {
  14. check: {
  15. enable: false,
  16. },
  17. data: {
  18. simpleData: {
  19. enable: true,
  20. pIdKey: "parentId",
  21. },
  22. },
  23. view: {
  24. showIcon: false,
  25. },
  26. },
  27. currentTreeNode: null,
  28. //----ztreeLeft end---------
  29. }
  30. },
  31. created() {
  32. this.findLeftTreeData(); // 获取机构树的数据
  33. },
  34. mounted() {
  35. //用像素初始化左边的split的宽度
  36. this.changeTreeWidth(240); // 初始化树的宽度
  37. },
  38. methods: {
  39. changeTreeWidth(widthVal) {
  40. // 初始化树的宽度
  41. this.leftSplitWidth = Math.ceil(
  42. (widthVal / this.$refs.elMain.$el.clientWidth) * 100
  43. );
  44. this.rightSplitWidth = 100 - this.leftSplitWidth;
  45. },
  46. findLeftTreeData: function () {
  47. this.$api.dept.findTree().then((res) => {
  48. // console.log(treeTypeNum);
  49. this.treeDataRecursion(res.data, treeTypeNum);
  50. this.ztreeNodes = res.data;
  51. });
  52. },
  53. //树过滤五级机构递归
  54. treeDataRecursion(data, num, one) {
  55. data = data || this.ztreeNodes;
  56. one = one || 0;
  57. one++;
  58. for (let i = 0; i < data.length; i++) {
  59. if (data[i].comlevel == 5 && (data[i].managementSource != num)) {
  60. data.splice(i, 1);
  61. i = i - 1;
  62. } else {
  63. this.treeDataRecursion(data[i].children, num, one);
  64. }
  65. }
  66. },
  67. }
  68. }
  69. }