<template>
    <div class="bg-white p-2 table_box">
        <el-table :data="tableData" border class="mt-4" stripe :header-cell-style="headerStyle" :row-class-name="tableRowClassName" style="height: 90%;">
            <el-table-column
                v-for="item in tableColData" :key="item.name"
                align="center"
                :prop="item.id"
                :label="item.name"
            >
                <el-table-column
                    v-for="item1 in item.children" :key="item1.name"
                    align="center"
                    :prop="item1.id"
                    :label="item1.name"
                />
            </el-table-column>
        </el-table>
    </div>
</template>

<script setup>
import { nextTick, ref, watch } from 'vue'
import mainApi from '~api/static/actual.js'
import { getArrValue } from 'js-fast-way'


const props = defineProps({
cur: {
  type: [String, Number],
  default: '',
},
checkyear:{
  type: [String, Number],
  default: '',
},
})

const tabsKey = ref(props.cur)
const year = ref('')
//监听
watch(() => [
props.cur,
props.checkyear,
], ([key, checkyear]) => {
tabsKey.value = key
console.log(key, 'key')
year.value = checkyear
  if (key === 'mannager') {
    console.log('获部门计划')
    budgetAndPracticalByManage()
  }
})


const tableData = ref([])
//获取部门统计
const budgetAndPracticalByManage = async () => {
    const { error, code, data } = await mainApi.budgetAndPracticalByManage(
     { year:year.value },
    )
    //判断状态
    if (!error && code === 200) {
      tableData.value = getArrValue(data)
  
    } else {
      tableData.value = []
    }
}
const tableColData = ref([
  {
    id:'time',
    name: '时间',
    children:[
    {
        id:'time',
        name: '时间',
        children:[],
    },
    ],
  },
  
 {
        id: 'peopleCost',
        name: '人工成本',
        children:[
            {
            id: 'disburse1',
            name: '预算支出',
            },
            {
            id: 'disburse2',
            name: '实际支出',
            },
    
        ],
    },
    {
        id: 'manngercost',
        name: '管理成本',
        children:[
            {
            id: 'disburse3',
            name: '预算支出',
            },
            {
            id: 'disburse4',
            name: '实际支出',
            },
    
        ],
    },

    
])
//合并

const headerStyle = ({ column, rowIndex, columnIndex })=>{
  const comStyle = { fontSize:'16px', background: 'rgb(214, 225, 255)', color:'black' }
      // 1.1 让第0行的第0列跨2行
      if (rowIndex === 0 && columnIndex === 0) {
        nextTick(() => {
          document
            .getElementsByClassName(column.id)[0]
            .setAttribute('rowSpan', 2)
          return comStyle
        })
      }
      // 1.2 被覆盖的进行隐藏
      if (rowIndex === 1 && (columnIndex === 0 )) {
        return {
          display: 'none',
          ...comStyle,
        }
      }

      return comStyle
}

   //指定行颜色
   const tableRowClassName = ({ rowIndex }) =>{
      if (rowIndex === 12) {
        return 'warm-row'
      }
 }
</script>

<style scoped lang="scss">

</style>
