tab-month.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="bg-white p-2 table_box" >
  3. <el-table :data="tableData" border class="mt-4" :header-cell-style="headerStyle">
  4. <el-table-column v-for="item in tableColData" align="center"
  5. :prop="item.id"
  6. :label="item.name"
  7. :key="item.name"
  8. >
  9. <el-table-column v-for="item1 in item.children" align="center"
  10. :prop="item1.id"
  11. :label="item1.name"
  12. :key="item1.name">
  13. </el-table-column>
  14. </el-table-column>
  15. </el-table>
  16. </div>
  17. </template>
  18. <script setup>
  19. import {ref, watch,nextTick} from "vue";
  20. const props = defineProps({
  21. cur: {
  22. type: [String,Number],
  23. default: ''
  24. },
  25. })
  26. const tabsKey = ref(props.cur)
  27. //监听
  28. watch(() => [
  29. props.cur,
  30. ], ([key]) => {
  31. tabsKey.value = key
  32. console.log(key)
  33. })
  34. const tableData=ref([
  35. {time:'二月',beginremain:'2000'},
  36. {time:'三月',beginremain:'2000'},
  37. {time:'四月',beginremain:'2000'},
  38. {time:'五月',beginremain:'2000'},
  39. {time:'六月',beginremain:'2000'},
  40. {time:'七月',beginremain:'2000'},
  41. {time:'八月',beginremain:'2000'},
  42. {time:'九月',beginremain:'2000'},
  43. {time:'十月',beginremain:'2000'},
  44. {time:'十一月',beginremain:'2000'},
  45. {time:'十二月',beginremain:'2000'},
  46. ])
  47. const tableColData=ref([
  48. {
  49. id:'time',
  50. name: '时间',
  51. children:[
  52. {
  53. id:'time',
  54. name: '时间',
  55. }
  56. ]
  57. },
  58. {
  59. id: 'beginremain',
  60. name: '年初每月收支预算',
  61. children:[
  62. {
  63. id: 'beginremain',
  64. name: '收入'
  65. },
  66. {
  67. id: 'beginremain',
  68. name: '支出'
  69. },
  70. ]
  71. },
  72. {
  73. id: 'beginremain',
  74. name: '每月计划收支预算',
  75. children:[
  76. {
  77. id: 'beginremain',
  78. name: '收入'
  79. },
  80. {
  81. id: 'beginremain',
  82. name: '支出'
  83. },
  84. ]
  85. },
  86. {
  87. id: 'beginremain',
  88. name: '实际每月收支',
  89. children:[
  90. {
  91. id: 'beginremain',
  92. name: '收入'
  93. },
  94. {
  95. id: 'beginremain',
  96. name: '支出'
  97. },
  98. ]
  99. },
  100. ])
  101. //合并
  102. const headerStyle=({ row, column, rowIndex, columnIndex })=>{
  103. const comStyle = { backgroundColor: "" };
  104. // 1.1 让第0行的第0列跨2行
  105. if (rowIndex === 0 && columnIndex === 0) {
  106. nextTick(() => {
  107. document
  108. .getElementsByClassName(column.id)[0]
  109. .setAttribute("rowSpan", 2);
  110. return comStyle;
  111. });
  112. }
  113. // 1.2 被覆盖的进行隐藏
  114. if (rowIndex === 1 && (columnIndex == 0 )) {
  115. return {
  116. display: "none",
  117. ...comStyle,
  118. };
  119. }
  120. return comStyle;
  121. }
  122. const costcheck=ref('1')
  123. </script>
  124. <style scoped lang="scss">
  125. </style>