tab-mannager.vue 3.0 KB

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