MyTable.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div>
  3. <el-table
  4. :data="tableData"
  5. border
  6. style="width: 100%"
  7. highlight-current-row
  8. element-loading-text="数据加载中..."
  9. @selection-change="handlerSelectChange"
  10. @select="handlerSelect"
  11. @select-all="handlerSelectAll"
  12. >
  13. <el-table-column
  14. label="序号"
  15. v-if="hasIndex"
  16. type="index"
  17. align="center"
  18. width="100"
  19. >
  20. </el-table-column>
  21. <el-table-column
  22. v-if="hasSelect"
  23. type="selection"
  24. width="38"
  25. ></el-table-column>
  26. <el-table-column v-if="hasExpand" type="expand" width="38">
  27. <template slot-scope="props">
  28. <my-form :formList="getList(props.row)"> </my-form>
  29. </template>
  30. </el-table-column>
  31. <el-table-column
  32. v-for="(item, index) in tableConfigArr"
  33. :key="index"
  34. :prop="item.prop"
  35. :label="item.label"
  36. align="center"
  37. :sortable="item.sortable"
  38. >
  39. <div slot-scope="scope">
  40. <slot v-if="item.slot" :name="item.slot" :row="scope.row"> </slot>
  41. <template v-else>
  42. <div>{{ scope.row[item.prop] }}</div>
  43. </template>
  44. </div>
  45. </el-table-column>
  46. </el-table>
  47. </div>
  48. </template>
  49. <script>
  50. export default {
  51. name: "my-form",
  52. props: {
  53. tableData: {
  54. type: Array,
  55. require: true,
  56. default: function () {
  57. return [];
  58. },
  59. },
  60. tableConfigArr: {
  61. type: Array,
  62. default: function () {
  63. return [];
  64. },
  65. },
  66. hasSelect: {
  67. type: Boolean,
  68. default: function () {
  69. return false;
  70. },
  71. },
  72. hasIndex: {
  73. type: Boolean,
  74. default: function () {
  75. return false;
  76. },
  77. },
  78. hasExpand: {
  79. type: Boolean,
  80. default: function () {
  81. return false;
  82. },
  83. },
  84. },
  85. data() {
  86. return {
  87. title: "变少",
  88. dialogFormVisible: false,
  89. };
  90. },
  91. computed: {
  92. getList() {
  93. return function (data) {
  94. let arr = [];
  95. for (let i in data) {
  96. let json = {};
  97. json[i] = data[i];
  98. json.type = "text";
  99. arr.push(json);
  100. }
  101. return arr;
  102. };
  103. },
  104. },
  105. methods: {
  106. handlerSelectAll(val) {
  107. this.$emit("handlerSelectAll", val);
  108. },
  109. handlerSelect(value, obj) {
  110. // 选中项
  111. this.$emit("handlerSelect", value);
  112. },
  113. handlerSelectChange(value) {
  114. this.$emit("handlerSelectChange", value);
  115. },
  116. edit(data) {
  117. console.log(data, "122122");
  118. this.dialogFormVisible = true;
  119. },
  120. deleteData(data) {
  121. console.log(data, "000000");
  122. },
  123. handleSumbit(data) {
  124. console.log(data, "我是子组件pop传来的");
  125. this.dialogFormVisible = data;
  126. },
  127. },
  128. mounted() {
  129. console.log(this.tableConfigArr);
  130. },
  131. };
  132. </script>
  133. <style lang="scss" scoped>
  134. </style>