tab-mannager.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. import mainApi from '~api/static/actual.js'
  23. import { getArrValue } from 'js-fast-way'
  24. const props = defineProps({
  25. cur: {
  26. type: [String, Number],
  27. default: '',
  28. },
  29. checkyear:{
  30. type: [String, Number],
  31. default: '',
  32. },
  33. })
  34. const tabsKey = ref(props.cur)
  35. const year = ref('')
  36. //监听
  37. watch(() => [
  38. props.cur,
  39. props.checkyear,
  40. ], ([key, checkyear]) => {
  41. tabsKey.value = key
  42. console.log(key, 'key')
  43. year.value = checkyear
  44. if (key === 'mannager') {
  45. console.log('获部门计划')
  46. budgetAndPracticalByManage()
  47. }
  48. })
  49. const tableData = ref([])
  50. //获取部门统计
  51. const budgetAndPracticalByManage = async () => {
  52. const { error, code, data } = await mainApi.budgetAndPracticalByManage(
  53. { year:year.value },
  54. )
  55. //判断状态
  56. if (!error && code === 200) {
  57. tableData.value = getArrValue(data)
  58. } else {
  59. tableData.value = []
  60. }
  61. }
  62. const tableColData = ref([
  63. {
  64. id:'time',
  65. name: '时间',
  66. children:[
  67. {
  68. id:'time',
  69. name: '时间',
  70. children:[],
  71. },
  72. ],
  73. },
  74. {
  75. id: 'peopleCost',
  76. name: '人工成本',
  77. children:[
  78. {
  79. id: 'disburse1',
  80. name: '预算支出',
  81. },
  82. {
  83. id: 'disburse2',
  84. name: '实际支出',
  85. },
  86. ],
  87. },
  88. {
  89. id: 'manngercost',
  90. name: '管理成本',
  91. children:[
  92. {
  93. id: 'disburse3',
  94. name: '预算支出',
  95. },
  96. {
  97. id: 'disburse4',
  98. name: '实际支出',
  99. },
  100. ],
  101. },
  102. ])
  103. //合并
  104. const headerStyle = ({ column, rowIndex, columnIndex })=>{
  105. const comStyle = { fontSize:'16px', background: 'rgb(214, 225, 255)', color:'black' }
  106. // 1.1 让第0行的第0列跨2行
  107. if (rowIndex === 0 && columnIndex === 0) {
  108. nextTick(() => {
  109. document
  110. .getElementsByClassName(column.id)[0]
  111. .setAttribute('rowSpan', 2)
  112. return comStyle
  113. })
  114. }
  115. // 1.2 被覆盖的进行隐藏
  116. if (rowIndex === 1 && (columnIndex === 0 )) {
  117. return {
  118. display: 'none',
  119. ...comStyle,
  120. }
  121. }
  122. return comStyle
  123. }
  124. //指定行颜色
  125. const tableRowClassName = ({ rowIndex }) =>{
  126. if (rowIndex === 12) {
  127. return 'warm-row'
  128. }
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. </style>