index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <dg-table
  3. style="width: 100%"
  4. row-key="id"
  5. lazy
  6. border
  7. :data="table"
  8. :tree-props="treeProp"
  9. :load="load"
  10. :pagination="false"
  11. v-bind="$attrs"
  12. v-on="$listeners"
  13. >
  14. <template v-for="(item, indexs) in headerData">
  15. <dg-table-column :key="indexs" v-bind="item">
  16. <!-- <template v-if="item.state" slot-scope="scope">
  17. <span>{{ converterText(scope.row, item) }}</span>
  18. </template> -->
  19. </dg-table-column>
  20. </template>
  21. <slot />
  22. </dg-table>
  23. </template>
  24. <script>
  25. import * as api from "@/api/statistics-manage";
  26. export default {
  27. name: "lTreeTable",
  28. props: {
  29. url: {
  30. tpye: String,
  31. require: true
  32. },
  33. treeProp: {
  34. type: Object,
  35. default: () => ({
  36. hasChildren: "isParent",
  37. children: "children",
  38. isLeaf(data) {
  39. return data.isParent !== true;
  40. }
  41. })
  42. },
  43. headerData: {
  44. type: Array,
  45. default: () => []
  46. },
  47. searchForm: {
  48. type: Object,
  49. default: () => {}
  50. }
  51. },
  52. data() {
  53. return {
  54. table: []
  55. };
  56. },
  57. computed: {
  58. searchFormComputed() {
  59. return this.searchForm;
  60. }
  61. },
  62. methods: {
  63. load({ id, isParent, parent }, treeNode, resolve) {
  64. const { url } = this;
  65. this.searchFormComputed.isInit = false;
  66. this.searchFormComputed.orgId = id;
  67. if (isParent === true || parent === true) {
  68. api[url](this.searchFormComputed)
  69. .then(res => {
  70. resolve(res);
  71. })
  72. .catch(err => {
  73. resolve([]);
  74. });
  75. }
  76. }
  77. },
  78. created() {
  79. const that = this;
  80. const { url } = that;
  81. const { searchForm } = that;
  82. console.log(searchForm);
  83. api[url](searchForm || {})
  84. .then(res => {
  85. that.table = res;
  86. })
  87. .catch(err => {
  88. that.table = [];
  89. });
  90. }
  91. };
  92. </script>