<!--  -->
<template>
    <div>
        <HcTable :column="basetableColumn" :datas="basetableData" :isIndex="false" >
        </HcTable>
        <HcCard actionUi="text-center" class="mt-4">
            <template #extra>
                <HcNewSwitch :datas="tabTab" :keys="tabKey" @change="tabChange" :round="false" />
            </template>
            <HcTable :isIndex="false" :column="tableColumn" :datas="tableData">
                <template #deptId="{ row, index }">
                    <el-select v-model="row.deptId" block placeholder="请选择" disabled>
                        <el-option v-for="item in departMent" :label="item.deptName" :value="item.id" />
                    </el-select>
                </template>
                <template #costType="{ row, index }">
                    <el-select v-model="row.costType" block placeholder="请选择" disabled>
                        <el-option v-for="item in costTypeList" :label="item.dictName" :value="item.dictValue" />
                    </el-select>
                </template>
                <template #projectProcess="{ row, index }">
                    <el-select v-model="row.projectProcess" block placeholder="请选择" disabled>
                        <el-option v-for="item in processList" :label="item.name" :value="item.id" />
                    </el-select>
                </template>
                <template #budgetType="{ row, index }">
                    <el-select v-model="row.budgetType" disabled>
                        <el-option v-for="item in budgetTypeList" :label="item.dictName" :value="item.dictValue" />
                    </el-select>
                </template>
                <template #taskDetail="{ row, index }" >
                    <el-select v-model="row.taskDetail" :getdata="budgetTypeChange(row?.budgetType, index)" disabled>
                        <el-option v-for="item in taskDetailList[index]" :label="item.dictName" :value="item.dictValue" />
                    </el-select>
                </template>
                <template #budgetDays="{ row, index }" >
                    <el-input v-model="row.budgetDays" disabled/>
                </template>
                <template #postType="{ row, index }" >
                    <el-select v-model="row.postType" disabled>
                        <el-option v-for="item in postTypeList" :label="item.dictName" :value="item.id" />
                    </el-select>
                </template>

                <template #staffCount="{ row, index }" >
                    <el-input v-model="row.staffCount"  disabled/>
                </template>
                <template #budgetStaffCost="{ row, index }" >
                    <el-input v-model="row.budgetStaffCost" disabled />
                </template>
                <template #budgetTravelExpense="{ row, index }">
                    <el-input v-model="row.budgetTravelExpense" disabled/>
                </template>
                <template #outsourceUnitPrice="{ row, index }">
                    <el-input v-model="row.outsourceUnitPrice" disabled/>
                </template>
                <template #outsourcePeopleCount="{ row, index }">
                    <el-input v-model="row.outsourcePeopleCount" disabled/>
                </template>
                <template #outsourceCountMoney="{ row, index }">
                    <el-input v-model="row.outsourceCountMoney" disabled />
                </template>
                <template #otherBudgetMoney="{ row, index }">
                    <el-input v-model="row.otherBudgetMoney" disabled/>
                </template>
                <template #budgetCountMoney="{ row, index }">
                    <el-input v-model="row.budgetCountMoney" disabled/>
                </template>
                <template #budgetRemark="{ row, index }">
                    <el-input v-model="row.budgetRemark" disabled/>
                </template>
                <template #key15="{ row, index }">
                    <el-input v-model="row.key15" disabled />
                </template>
       
            </HcTable>
        </HcCard>
    </div>
</template>

<script setup>
import { ref, watch, onActivated } from 'vue'
import { getProjectList,getdepartmentList } from "~api/other";
import { getArrValue } from "js-fast-way";
import costApi from '~api/project/cost.js';

onActivated(() => {

  
})
//参数
const props = defineProps({
    otherInfo: {
        type: Object,
        default: {}
    }
})
const otherInfo = ref(props.otherInfo)
//监听
watch(() => [
    props.otherInfo,
], ([otherInfo]) => {
    console.log(otherInfo, 'otherInfo');
    getdepartmentListData()
    getCostTypeDict()
    getProcessList(otherInfo?.projectId)
    getPostDict()
    getBudgetTypeList()

    constructUnitData.value=otherInfo?.constructUnit||[]
    bulidUnitData.value=otherInfo?.buildUnit||[]
    supervisorUnitData.value=otherInfo?.supervisorUnit||[]
    tabKey.value='construction'
    tableData.value=constructUnitData.value
    basetableData.value=[
        {
            projectName: otherInfo?.projectName,
            projectCostTotal: otherInfo?.projectCostTotal,
            devCostTotal: otherInfo?.devCostTotal,
            businessCostTotal: otherInfo?.businessCostTotal,
            marketCostTotal: otherInfo?.marketCostTotal,
            maintainCostTotal: otherInfo?.maintainCostTotal,
            outsourceCostTotal: otherInfo?.outsourceCostTotal,
            manageCostTotal: otherInfo?.manageCostTotal,
        }
    ]

})
const basetableColumn = [
    { key: 'projectName', name: '项目名称' },
    { key: 'projectCostTotal', name: '成本测算总额' },
    { key: 'devCostTotal', name: '研发部成本总额' },
    { key: 'businessCostTotal', name: '业务部成本总金额：' },
    { key: 'marketCostTotal', name: '市场部成本总金额：' },
    { key: 'maintainCostTotal', name: '维护部成本总金额：' },
    { key: 'outsourceCostTotal', name: '外包劳务成本总金额：' },
    { key: 'manageCostTotal', name: '管理费成本总金额：' },

]
const basetableData = ref([
   
])

//类型tab数据和相关处理
const tabKey = ref('construction')
const tabTab = ref([
    { key: 'bulid', name: '施工单位成本' },
    { key: 'supervision', name: '监理单位成本' },
    { key: 'construction', name: '建设单位成本' }
]);
//测算表格数据
const constructUnitData=ref([])
const bulidUnitData=ref([])
const supervisorUnitData=ref([])

const tabChange = ({ key }) => {
    tabKey.value = key
    if(key=='supervision'){
        tableData.value=supervisorUnitData.value
    }else if(key=='construction'){
        tableData.value=constructUnitData.value
    }else if(key=='bulid'){
        tableData.value=bulidUnitData.value

    }

}
//成本测算表格
const tableColumn = [
    {key: 'deptId', name: '费用分摊部门', width: '160', align: 'center'},
    {key: 'costType', name: '费用分类', width: '160', align: 'center'},
    {key: 'projectProcess', name: '项目环节', width: '160', align: 'center'},
    {key: 'budgetType', name: '预算类型', width: '160', align: 'center'},
    {key: 'taskDetail', name: '任务明细', width: '160',  align: 'center'},
    {key: 'budgetDays', name: '预计工作量(小数/整数/天)', width: '160',  align: 'center'},
    {key: 'postType', name: '投入岗位类型(日单价)', width: '160', align: 'center'},
    {key: 'staffCount', name: '投入人员数量', width: '160', align: 'center'},
    {key: 'budgetStaffCost', name: '预计人工成本(元)', width: '160', align: 'center'},
    {key: 'budgetTravelExpense', name: '预计差旅费(元)', width: '160', align: 'center'},
    {key: 'outsourceUnitPrice', name: '外包单价', width: '160', align: 'center'},
    {key: 'outsourcePeopleCount', name: '外包数量', width: '160', align: 'center'},
    {key: 'outsourceCountMoney', name: '外包金额', width: '160', align: 'center'},
    {key: 'otherBudgetMoney', name: '其他预算金额', width: '160', align: 'center'},
    {key: 'budgetCountMoney', name: '总预算金额', width: '160', align: 'center'},
    {key: 'budgetRemark', name: '测算备注', width: '160', align: 'center'},
  
]
const tableData = ref([])//成本测算表格
//费用分摊部门
const departMent = ref([])
const getdepartmentListData = async () => {
    const {error, code, data} = await getdepartmentList({deptType:2})
    //判断状态
    if (!error && code === 200) {
        departMent.value = getArrValue(data)
    } else {
        departMent.value = []
    }
}
//获取费用分类
const costTypeList=ref([])
const getCostTypeDict=async(type)=>{
    const {error, code, data} = await costApi.getCostTypeDict()
    if (!error && code === 200) {
        costTypeList.value=getArrValue(data)

    } else {
        costTypeList.value={}
    }
}
//获取项目环节
const processList=ref([])
const getProcessList=async(projectId)=>{
    const {error, code, data} = await costApi.getProcessList({projectId:projectId})
    if (!error && code === 200) {
        processList.value=getArrValue(data)

    } else {
        processList.value={}
    }
}
//获取预算分类getSecondSubject
const budgetTypeList=ref([])
const getBudgetTypeList=async()=>{
    const {error, code, data} = await costApi.getSecondSubject()
    if (!error && code === 200) {
        budgetTypeList.value=getArrValue(data)
     

    } else {
        budgetTypeList.value={}
    }
}
//任务明细
const taskDetailList=ref({})
const budgetTypeChange=async(val,index)=>{
    let id=''
    budgetTypeList.value.forEach((ele)=>{
        if(ele.dictValue===val){
            id=ele.id
        }
    })
    if(id.length>0){
        const {error, code, data} = await costApi.getChlidList({parentId:id,type:1})
        if (!error && code === 200) {
            taskDetailList.value[index]=getArrValue(data)

        } else {
            taskDetailList.value[index]={}
        }
    }
   
}
//获取岗位分类postTypeList
const postTypeList=ref([])
const getPostDict=async(type)=>{
    const {error, code, data} = await costApi.getPostDict()
    if (!error && code === 200) {
        postTypeList.value=getArrValue(data)
    


    } else {
        postTypeList.value={}
    }
}
</script>
<style lang='scss' scoped></style>