tab-mannager.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class="bg-white p-2 table_box" >
  3. <el-table :data="tableData" border class="mt-4" stripe :header-cell-style="headerStyle" :row-class-name="tableRowClassName" style="height: 90%;"
  4. >
  5. <el-table-column v-for="item in tableColData" align="center"
  6. :prop="item.id"
  7. :label="item.name"
  8. :key="item.name"
  9. >
  10. <el-table-column v-for="item1 in item.children" align="center"
  11. :prop="item1.id"
  12. :label="item1.name"
  13. :key="item1.name">
  14. </el-table-column>
  15. </el-table-column>
  16. </el-table>
  17. </div>
  18. </template>
  19. <script setup>
  20. import {ref, watch,nextTick} from "vue";
  21. const props = defineProps({
  22. cur: {
  23. type: [String,Number],
  24. default: ''
  25. },
  26. })
  27. const tabsKey = ref(props.cur)
  28. //监听
  29. watch(() => [
  30. props.cur,
  31. ], ([key]) => {
  32. tabsKey.value = key
  33. console.log(key)
  34. })
  35. const tableData=ref([
  36. {time:'一月',beginremain:'2000'},
  37. {time:'二月',market:'2000',precost:1000,realcost: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. {time:'十一月',beginremain:'2000'},
  47. {time:'十二月',beginremain:'2000'},
  48. {time:'总计',beginremain:'2000'},
  49. ])
  50. const tableColData=ref([
  51. {
  52. id:'time',
  53. name: '时间',
  54. children:[
  55. {
  56. id:'time',
  57. name: '时间',
  58. children:[]
  59. },
  60. ]
  61. },
  62. {
  63. id: 'peopleCost',
  64. name: '人工成本',
  65. children:[
  66. {
  67. id: 'precost',
  68. name: '预算支出'
  69. },
  70. {
  71. id: 'realcost',
  72. name: '实际支出'
  73. },
  74. ]
  75. },
  76. {
  77. id: 'manngercost',
  78. name: '管理成本',
  79. children:[
  80. {
  81. id: 'precost',
  82. name: '预算支出'
  83. },
  84. {
  85. id: 'realcost',
  86. name: '实际支出'
  87. },
  88. ]
  89. },
  90. ])
  91. //合并
  92. const headerStyle=({ row, column, rowIndex, columnIndex })=>{
  93. const comStyle = {fontSize:"16px" ,background: "rgb(214, 225, 255)",color:'black'}
  94. // 1.1 让第0行的第0列跨2行
  95. if (rowIndex === 0 && columnIndex === 0) {
  96. nextTick(() => {
  97. document
  98. .getElementsByClassName(column.id)[0]
  99. .setAttribute("rowSpan", 2);
  100. return comStyle;
  101. });
  102. }
  103. // 1.2 被覆盖的进行隐藏
  104. if (rowIndex === 1 && (columnIndex == 0 )) {
  105. return {
  106. display: "none",
  107. ...comStyle,
  108. };
  109. }
  110. return comStyle;
  111. }
  112. //指定行颜色
  113. const tableRowClassName=({ row, rowIndex }) =>{
  114. if (rowIndex ===12) {
  115. return 'warm-row';
  116. }
  117. }
  118. </script>
  119. <style scoped lang="scss">
  120. </style>