tab-decost.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="bg-white p-2 table_box" >
  3. <el-table :data="tableData" border class="mt-4" :header-cell-style="headerStyle" stripe :row-class-name="tableRowClassName" style="height: 90%;">
  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:'二月',market:'2000',precost:1000,realcost: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. {time:'十二月',beginremain:'2000'},
  47. {time:'总计',beginremain:'2000'},
  48. ])
  49. const tableColData=ref([
  50. {
  51. id:'time',
  52. name: '时间',
  53. children:[
  54. { id:'time',
  55. name: '时间',}
  56. ]
  57. },
  58. {
  59. id: 'market',
  60. name: '市场部',
  61. children:[
  62. {
  63. id: 'precost',
  64. name: '预算支出'
  65. },
  66. {
  67. id: 'realcost',
  68. name: '实际支出'
  69. },
  70. ]
  71. },
  72. {
  73. id: 'technology',
  74. name: '研发部',
  75. children:[
  76. {
  77. id: 'precost',
  78. name: '预算支出'
  79. },
  80. {
  81. id: 'realcost',
  82. name: '实际支出'
  83. },
  84. ]
  85. },
  86. {
  87. id: 'implement',
  88. name: '实施部',
  89. children:[
  90. {
  91. id: 'precost',
  92. name: '预算支出'
  93. },
  94. {
  95. id: 'realcost',
  96. name: '实际支出'
  97. },
  98. ]
  99. },
  100. {
  101. id: 'maintenance',
  102. name: '维修部',
  103. children:[
  104. {
  105. id: 'precost',
  106. name: '预算支出'
  107. },
  108. {
  109. id: 'realcost',
  110. name: '实际支出'
  111. },
  112. ]
  113. },
  114. {
  115. id: 'mannager',
  116. name: '管理中心',
  117. children:[
  118. {
  119. id: 'precost',
  120. name: '预算支出'
  121. },
  122. {
  123. id: 'realcost',
  124. name: '实际支出'
  125. },
  126. ]
  127. },
  128. ])
  129. //合并
  130. const headerStyle=({ row, column, rowIndex, columnIndex })=>{
  131. const comStyle = {fontSize:"16px" ,background: "rgb(214, 225, 255)",color:'black'}
  132. // 1.1 让第0行的第0列跨2行
  133. if (rowIndex === 0 && columnIndex === 0) {
  134. nextTick(() => {
  135. document
  136. .getElementsByClassName(column.id)[0]
  137. .setAttribute("rowSpan", 2);
  138. return comStyle;
  139. });
  140. }
  141. // 1.2 被覆盖的进行隐藏
  142. if (rowIndex === 1 && (columnIndex == 0 )) {
  143. return {
  144. display: "none",
  145. ...comStyle,
  146. };
  147. }
  148. return comStyle;
  149. }
  150. //指定行颜色
  151. const tableRowClassName=({ row, rowIndex }) =>{
  152. if (rowIndex ===12) {
  153. return 'warm-row';
  154. }
  155. }
  156. const costcheck=ref('1')
  157. </script>
  158. <style scoped lang="scss">
  159. </style>