<template>
    <div v-loading="!isAfterRender" element-loading-text="加载中..." class="hc-full">
        <hc-table
            v-if="isAfterRender" :column="tableColumn" :datas="tableData" :index-style="{ width: 60 }" is-check
            :check-style="{ fixed: true, width: 29 }" class="hc-project-list-table" @selection-change="tableCheckChange"
        >
            <template #name="{ row }">
                <el-link type="primary" @click="rowNameClick(row)">{{ row.name }}</el-link>
            </template>
            <template #investYearRate="{ row }">
                <span v-if="row.investYearRate">{{ row.investYearRate }}</span>
                <span v-else>/</span>
            </template>
            <template #yearlyInvest="{ row }">
                <span v-if="row.yearlyInvest">{{ row.yearlyInvest }}</span>
                <span v-else>/</span>
            </template>
            <template #investYear="{ row }">
                <span v-if="row.investYear">{{ row.investYear }}</span>
                <span v-else>/</span>
            </template>
            <template #yearlyInvestRate="{ row }">
                <span v-if="row.yearlyInvestRate">{{ row.yearlyInvestRate }}</span>
                <span v-else>/</span>
            </template>
            <template #action="{ row }">
                <el-link v-if="isAdminAuth" type="warning" @click="completion(row)">项目完成情况</el-link>
                <el-link type="primary" @click="examine(row)">查看</el-link>
                <el-link v-if="isAdminAuth" v-del-com:[delTableItem]="row" type="danger">删除</el-link>
                <el-link v-if="!isAdminAuth" type="warning" @click="projectStatus(row)">项目情况</el-link>
                <!-- el-link v-yes-com:[deriveTableItem]="row" type="success">导出</el-link -->
            </template>
        </hc-table>

        <!-- 查看详情 -->
        <hc-drawer v-model="isDrawer" to-id="hc-main-box" is-close>
            <hc-card class="hc-project-list-drawer" :scrollbar="true">
                <template #header>
                    <div class="flex-1 text-center text-[24px] font-bold">项目详情</div>
                </template>
                <HcInfoTable>
                    <tr>
                        <hc-info-table-td is-title width="10%" center>项目阶段</hc-info-table-td>
                        <hc-info-table-td center width="40%">{{ rowDetail?.projectStageName }}</hc-info-table-td>
                        <hc-info-table-td is-title width="10%" center>项目类型</hc-info-table-td>
                        <hc-info-table-td center width="40%">{{ rowDetail?.projectTypeName }}</hc-info-table-td>
                    </tr>
                    <tr>
                        <hc-info-table-td is-title width="10%" center>项目名称</hc-info-table-td>
                        <hc-info-table-td center width="40%">{{ rowDetail?.name }}</hc-info-table-td>
                        <hc-info-table-td is-title width="10%" center>建设规模</hc-info-table-td>
                        <hc-info-table-td center width="40%">{{ rowDetail?.buildScaleName }}</hc-info-table-td>
                    </tr>
                </HcInfoTable>
                <HcInfoTable class="mt-[-1px]">
                    <tr>
                        <hc-info-table-td is-title width="10%" center>计划开工年</hc-info-table-td>
                        <hc-info-table-td center width="15%">{{ rowDetail?.startYear }}</hc-info-table-td>
                        <hc-info-table-td is-title width="10%" center>计划完工年</hc-info-table-td>
                        <hc-info-table-td center width="15%">{{ rowDetail?.endYear }}</hc-info-table-td>
                        <hc-info-table-td is-title width="10%" center>总投资</hc-info-table-td>
                        <hc-info-table-td center width="40%">{{ rowDetail?.allInvestMoney }}</hc-info-table-td>
                    </tr>
                </HcInfoTable>
                <HcInfoTable class="mt-[-1px]">
                    <tr>
                        <hc-info-table-td is-title width="10%" center>交通强国建设试点任务</hc-info-table-td>
                        <hc-info-table-td center width="40%">{{ rowDetail?.isPilotPlan === 1 ? '是' : '否' }}</hc-info-table-td>
                        <hc-info-table-td is-title width="10%" center>责任单位</hc-info-table-td>
                        <hc-info-table-td center width="40%">{{ rowDetail?.dutyUnit }}</hc-info-table-td>
                    </tr>
                </HcInfoTable>
                <div class="hc-project-list-drawer-year">
                    <el-scrollbar>
                        <div class="relative p-2 pt-3">
                            <hc-card-item class="year-detail">
                                <template #header>
                                    <div class="flex-1 text-center text-[14px]">
                                        <HcDropdown v-model="yearKey" :datas="yearData.list" text="年" :props="{ key: 'planYear', label: 'planYear' }" @change="yearChange" />
                                    </div>
                                </template>
                                <el-table v-if="yearData.list && yearData.list.length > 0" :data="yearData.list[yearIndex].list" border class="w-full" :span-method="tableYearMethod">
                                    <el-table-column prop="planQuarterName" label="季度" width="100" align="center" />
                                    <el-table-column prop="planMonthName" class-name="line" width="120" align="center">
                                        <template #header>
                                            <div class="hc-table-th-line">
                                                <span class="left">月份</span>
                                                <span class="right">完成情况</span>
                                            </div>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="投资情况(亿元)" align="center">
                                        <el-table-column prop="planInvestMoney" label="计划完成投资额" width="100" align="center" />
                                        <el-table-column prop="investMoney" label="当月完成投资额" width="100" align="center" />
                                        <el-table-column prop="investUnfinishedMoney" label="与计划投资的差距" width="100" align="center" />
                                    </el-table-column>
                                    <el-table-column label="建设情况" align="center">
                                        <el-table-column prop="yearlyTarget" label="年度主要目标任务" width="100" align="center" />
                                        <el-table-column prop="workPlan" label="工作计划" width="100" align="center" />
                                        <el-table-column prop="workProgress" label="当月重大进展" align="center" />
                                        <el-table-column prop="workProgressAll" label="累计进展计划" align="center" />
                                        <el-table-column prop="planRatio" label="工作总体形象进度(%)" width="100" align="center" />
                                    </el-table-column>
                                </el-table>
                                <HcInfoTable v-if="yearData.list && yearData.list.length > 0" class="mt-[-1px]">
                                    <tr>
                                        <hc-info-table-td is-title width="128px" center>全年完成投资</hc-info-table-td>
                                        <hc-info-table-td center width="100px">{{ yearData.list[yearIndex].yearlyInvest || "-" }}</hc-info-table-td>
                                        <hc-info-table-td is-title width="100px" center>存在问题</hc-info-table-td>
                                        <hc-info-table-td center>{{ yearData.list[yearIndex]?.questionable || '-' }}</hc-info-table-td>
                                        <hc-info-table-td is-title width="100px" center>工作建议</hc-info-table-td>
                                        <hc-info-table-td center>{{ yearData.list[yearIndex]?.workAdvise || '-' }}</hc-info-table-td>
                                    </tr>
                                    <tr>
                                        <hc-info-table-td is-title width="128px" center>开工累计完成投资</hc-info-table-td>
                                        <hc-info-table-td center width="100px">{{ yearData.list[yearIndex].investYearAll || "-" }}</hc-info-table-td>
                                        <hc-info-table-td is-title width="100px" center>联系人</hc-info-table-td>
                                        <hc-info-table-td center>{{ yearData.list[yearIndex]?.linkman || '-' }}</hc-info-table-td>
                                        <hc-info-table-td is-title width="100px" center>联系电话</hc-info-table-td>
                                        <hc-info-table-td center>{{ yearData.list[yearIndex]?.phone || '-' }}</hc-info-table-td>
                                    </tr>
                                </HcInfoTable>
                            </hc-card-item>
                        </div>
                    </el-scrollbar>
                </div>
            </hc-card>
        </hc-drawer>

        <!-- 项目完成情况 -->
        <hc-drawer v-model="isCompletionDrawer" to-id="hc-main-box" is-close>
            <hc-card class="hc-project-list-drawer" is-action-btn :scrollbar="true">
                <template #header>
                    <div class="flex-1 text-center text-[24px] font-bold">项目完成情况</div>
                </template>
                <HcInfoTable>
                    <tr>
                        <hc-info-table-td is-title width="30px" center>项目名称</hc-info-table-td>
                        <hc-info-table-td center>{{ rowDetail?.name }}</hc-info-table-td>
                        <hc-info-table-td is-title width="30px" center>建设规模</hc-info-table-td>
                        <hc-info-table-td center>{{ rowDetail?.buildScaleName }}</hc-info-table-td>
                    </tr>
                </HcInfoTable>
                <div class="hc-project-list-drawer-year detail">
                    <el-scrollbar>
                        <div class="relative p-2 pt-3">
                            <hc-card-item class="year-detail edit">
                                <template #header>
                                    <div class="flex-1 text-center text-[14px]">
                                        <HcDropdown v-model="yearKey" :datas="yearData.list" text="年" :props="{ key: 'planYear', label: 'planYear' }" @change="yearChange" />
                                    </div>
                                </template>
                                <el-table v-if="yearData.list && yearData.list.length > 0" :data="yearData.list[yearIndex].list" border class="w-full" :span-method="tableYearMethod1">
                                    <el-table-column prop="planQuarterName" label="季度" width="100" align="center" />
                                    <el-table-column prop="planMonthName" class-name="line" width="120" align="center">
                                        <template #header>
                                            <div class="hc-table-th-line">
                                                <span class="left">月份</span>
                                                <span class="right">完成情况</span>
                                            </div>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="投资情况(亿元)" align="center">
                                        <el-table-column prop="planInvestMoney" label="计划完成投资额" width="100" align="center">
                                            <template #default="{ row }">
                                                <hc-body>
                                                    <hc-table-input v-model="row.planInvestMoney" disabled />
                                                </hc-body>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="investMoney" label="当月完成投资额" width="100" align="center">
                                            <template #default="{ row, $index }">
                                                <hc-body>
                                                    <!-- <hc-table-input v-model="row.investMoney" /> -->
                                                    <el-input v-model="row.investMoney" clearable :formatter="formatInput" :disabled="(yearData.list[yearIndex].isCanFill === 1 ? false : true) || !row.planInvestMoney" @change="changeInvestMoney($event, row, $index)" />
                                                </hc-body>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="investUnfinishedMoney" label="与计划投资的差距" width="100" align="center">
                                            <template #default="{ row }">
                                                <hc-body>
                                                    <hc-table-input v-model="row.investUnfinishedMoney" disabled />
                                                </hc-body>
                                            </template>
                                        </el-table-column>
                                    </el-table-column>
                                    <el-table-column label="建设情况" align="center">
                                        <el-table-column prop="workPlan" label="工作计划" width="100" align="center">
                                            <template #default="{ row }">
                                                <hc-body>
                                                    <hc-table-input v-model="row.workPlan" type="textarea" disabled resize="none" />
                                                </hc-body>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="workProgress" label="当月重大进展" align="center">
                                            <template #default="{ row }">
                                                <hc-body>
                                                    <hc-table-input v-model="row.workProgress" type="textarea" resize="none" :disabled="(yearData.list[yearIndex].isCanFill === 1 ? false : true) || !row.workPlan" />
                                                </hc-body>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="workProgressAll" label="累计进展情况" align="center">
                                            <template #default="{ row }">
                                                <hc-body>
                                                    <hc-table-input v-model="row.workProgressAll" type="textarea" resize="none" :disabled="(yearData.list[yearIndex].isCanFill === 1 ? false : true) || !row.workPlan" />
                                                </hc-body>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="planRatio" label="工作总体形象进度(%)" width="100" align="center">
                                            <template #default="{ row, $index }">
                                                <hc-body>
                                                    <!-- <hc-table-input v-model="row.planRatio" :disabled="yearData.list[yearIndex].isCanFill === 1 ? false : true" /> -->
                                                    <el-input v-model="row.planRatio" :disabled="(yearData.list[yearIndex].isCanFill === 1 ? false : true) || !row.workPlan" :formatter="formatInput" @change="changePlanRatio($enent, row, $index)" />
                                                </hc-body>
                                            </template>
                                        </el-table-column>
                                    </el-table-column>
                                </el-table>
                                <HcInfoTable v-if="yearData.list && yearData.list.length > 0" class="mt-[-1px]">
                                    <tr>
                                        <hc-info-table-td is-title width="30px" center>存在问题</hc-info-table-td>
                                        <hc-info-table-td center>
                                            <el-input v-model="yearData.list[yearIndex].questionable" type="textarea" resize="none" :disabled="yearData.list[yearIndex].isCanFill === 1 ? false : true" />
                                        </hc-info-table-td>
                                        <hc-info-table-td is-title width="30px" center>工作建议</hc-info-table-td>
                                        <hc-info-table-td center>
                                            <el-input v-model=" yearData.list[yearIndex].workAdvise" type="textarea" resize="none" :disabled="yearData.list[yearIndex].isCanFill === 1 ? false : true" />
                                        </hc-info-table-td>
                                    </tr>
                                    <tr>
                                        <hc-info-table-td is-title width="30px" center>联系人</hc-info-table-td>
                                        <hc-info-table-td center>
                                            <el-input v-model="yearData.list[yearIndex].linkman " :disabled="yearData.list[yearIndex].isCanFill === 1 ? false : true" />
                                        </hc-info-table-td>
                                        <hc-info-table-td is-title width="30px" center>联系电话</hc-info-table-td>
                                        <hc-info-table-td center>
                                            <el-input v-model="yearData.list[yearIndex].phone" :disabled="yearData.list[yearIndex].isCanFill === 1 ? false : true" />
                                        </hc-info-table-td>
                                    </tr>
                                </HcInfoTable>
                            </hc-card-item>
                        </div>
                    </el-scrollbar>
                </div>
                <template #action>
                    <el-button type="info" @click="isCompletionDrawer = false">取消</el-button>
                    <el-button type="warning" :loading="saveCompleLoading" @click="saveComplete">保存</el-button>
                </template>
            </hc-card>
        </hc-drawer>

        <!-- 项目情况 -->
        <hc-dialog v-model="isStatusShow" widths="60rem" title="项目情况" is-table :footer="false" @close="statusClose">
            <div class="project-status-dialog relative h-390px">
                <hc-card-item title="项目投资情况">
                    <HcStatusCharts :datas="{ a: [150, 100, 240, 100], b: [100, 160, 280, 120] }" />
                </hc-card-item>
            </div>
            <div class="project-status-dialog relative mt-14px">
                <hc-card-item title="项目进度情况">
                    <hc-table :column="statusColumn" :datas="statusData" :is-index="false" />
                </hc-card-item>
            </div>
        </hc-dialog>
    </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue'
import mainApi from '~api/project/project'
import { getArrValue, getObjValue } from 'js-fast-way'
import BigNumber from 'bignumber.js'
import dayjs from 'dayjs'
import HcStatusCharts from './components/charts.vue'

const props = defineProps({
    isAdmin: {
        type: Boolean,
        default: false,
    },
    loading: {
        type: Boolean,
        default: false,
    },
    datas: {
        type: Array,
        default: () => ([]),
    },
    planYear: {
        type: String,
        default: '',
    },
})

//事件
const emit = defineEmits(['tap', 'completion', 'examine', 'del', 'export', 'check', 'change'])

//监听权限
const isAdminAuth = ref(props.isAdmin)
watch(() => props.isAdmin, (admin) => {
    isAdminAuth.value = admin
})
//分页搜索的年份
const planYearData = ref(props.planYear)
watch(() => props.planYear, (year) => {
   
    
    planYearData.value = year
  
    

})
//渲染完成
const currentYear = ref('')
const isAfterRender = ref(false)
onMounted(() => {
    //表格太复杂，渲染较慢，等页面先加载完成，再渲染表格，不然会卡住一下不动。
    //因为表头涉及到年份，如果年份很多，那么会更卡。
    currentYear.value = new dayjs().format('YYYY')
 
    
    setTimeout(() => {
        isAfterRender.value = true
    }, 200)
})

//表头
const tableColumn = ref([
   
    { key: 'projectTypeName', name: '项目类型', width: 120, align: 'center' },
    { key: 'projectStageName', name: '项目阶段', width: 120, align: 'center' },
    { key: 'name', name: '项目名称' },
    { key: 'buildScaleName', name: '建设规模', width: 120, align: 'center' },
    { key: 'startYear', name: '开工年', width: 100, align: 'center' },
    { key: 'endYear', name: '完工年', width: 100, align: 'center' },
    { key: 'allInvestMoney', name: '总投资（亿元）', width: 100, align: 'center' },
 

  
    { key: 'investYearAll', name: '项目累计完成投资（亿元）', width: 100, align: 'center' },
    { key: 'investYearRate', name: '累计完成投资率', width: 100, align: 'center' },
    { key: 'yearlyInvest', name: '今年计划投资（亿元）', width: 100, align: 'center' },
    { key: 'investYear', name: '今年累计投资完成（亿元）', width: 100, align: 'center' },
    { key: 'yearlyInvestRate', name: '今年投资完成率', width: 100, align: 'center' },
       { key: 'dutyUnit', name: '责任单位' },
 
   /*{ key: 'fourteenFiveInvest', name: '\“十四五”\'计划投资（亿元)' },
   { key: 'isFocusProjectName', name: '市级重点项目' },
   { key: 'finishedInvestMoney', name: '完成投资金额(亿元)' },
   { key: 'finishedFillRatio', name: '完成情况填写比例(%)' },
   { key: 'leaderUnit', name: '牵头单位' },
   { key: 'assistUnit', name: '配合单位' },*/
    { key: 'action', name: '操作', width: isAdminAuth.value ? 220 : 150, fixed:'right', align: 'center' },
])

//监听数据
const tableData = ref(props.datas)
watch(() => props.datas, (data) => {
    tableData.value = data
})
//表格被选择
const tableCheckKeys = ref([])
const tableCheckChange = (rows) => {
    tableCheckKeys.value = rows
    emit('check', rows)
}

//项目名称被点击
const rowNameClick = (row) => {
    emit('tap', row)
}

//项目完成情况
const isCompletionDrawer = ref(false)
const completion = (row) => {
    isCompletionDrawer.value = true
    
    emit('completion', row)
    getDetailData(row.id)
}

//查看
const rowDetail = ref({})
const isDrawer = ref(false)
const isDrawerType = ref('view')
const examine = (row) => {
    isDrawer.value = true
    isDrawerType.value = 'view'
    rowDetail.value = row
    getDetailData(row.id)
    // emit('examine', row)
}
const getDetailData = async (id) => {
    const { error, code, data, msg } = await mainApi.detailMore(id)
    if (error || code !== 200) {
        window.$message.error(msg ?? '获取数据失败')
        drawerCancel()
        return
    }
    //处理数据
    const res = getObjValue(data)
    const list = getArrValue(res.list)
    res.list = list
    rowDetail.value = res
    yearData.value = res
    //设置默认数据
    if (list.length > 0) {
        let isIndex = false
        for (let i = 0; i < list.length; i++) {
            const planYear = list[i].planYear.toString()
            if (planYear === planYearData.value) {
                yearKey.value = list[i].planYear
                yearIndex.value = i
                isIndex = true
                break
            } else if (planYearData.value > parseInt( Math.max(...list.map(item => parseInt(item.planYear))))) {
                yearKey.value = list[list.length - 1].planYear
                yearIndex.value = list.length - 1
                isIndex = true
            }
         
        
        }
        //默认值
        if (!isIndex) {
            yearIndex.value = 0
            yearKey.value = list[0].planYear
           
            
        }
    
            
            
    } else {
        yearIndex.value = -1
        yearKey.value = null
    }
}

//删除
const delTableItem = async ({ item }, resolve) => {
    const { error, code, msg } = await mainApi.del(item.id)
    if (!error && code === 200) {
        window.$message.success('删除成功')
        resolve()
        emit('change')
    } else {
        window.$message.error(msg ?? '删除失败')
        resolve()
    }
}
//关闭抽屉
const drawerCancel = () => {
    isDrawer.value = false
    isDrawerType.value = ''
    yearData.value = {}
    yearIndex.value = -1
    yearKey.value = null
}


//导出数据
const deriveTableItem = async ({ item }, resolve) => {
    /*const { error, val } = await mainApi.exportWorkfocus(item.id)
    if (error) {
        window.$message?.error('数据异常')
        resolve()
        return
    }
    await newDownBlob(val)*/
    window.$message?.error('暂未开放')
    resolve()
}

//年数据
const yearKey = ref('')
const yearData = ref({})
const yearIndex = ref(-1)
const yearChange = (_, index) => {
    yearIndex.value = index
}

//合并列或行
const tableYearMethod = ({ rowIndex, columnIndex }) => {
    return setSpanMethod(columnIndex, rowIndex)
}

//合并列或行
const tableYearMethod1 = ({ rowIndex, columnIndex }) => {
    return setSpanMethod(columnIndex, rowIndex, false)
}
const saveCompleLoading = ref(false)
const saveComplete = async ()=>{
    saveCompleLoading.value = true
        //发起请求
    const { error, code, msg } = await mainApi.updateProFin({
        ...yearData.value,
    })
    //判断状态
    saveCompleLoading.value = false
    if (!error && code === 200) {
        window.$message.success('操作成功')
        getDetailData(rowDetail.value.id)
        emit('change')
    } else {
        window.$message.error(msg ?? '操作失败')
    }
}


const setSpanMethod = (column, row, isAllYear = true) => {
    if (column === 0) { //第一列
        const rows = [0, 3, 6, 9], irows = [1, 2, 4, 5, 7, 8, 10, 11]
        if (rows.indexOf(row) !== -1) {
            //主要季度隐藏
            return { rowspan: 3, colspan: 1 }
        } else if (irows.indexOf(row) !== -1) {
            //非主要的季度隐藏
            return { rowspan: 0, colspan: 0 }
        } else {
            return { rowspan: 1, colspan: 1 }
        }
    } else if (column === 2) { //第三列
        const rows = [0, 3, 6, 9], irows = [1, 2, 4, 5, 7, 8, 10, 11]
        if (rows.indexOf(row) !== -1) {
            //主要隐藏
            return { rowspan: 3, colspan: 1 }
        } else if (irows.indexOf(row) !== -1) {
            //非主要的隐藏
            return { rowspan: 0, colspan: 0 }
        } else {
            return { rowspan: 1, colspan: 1 }
        }
    } else if (column === 4) { //第五列
        const rows = [0, 3, 6, 9], irows = [1, 2, 4, 5, 7, 8, 10, 11]
        if (rows.indexOf(row) !== -1) {
            //主要隐藏
            return { rowspan: 3, colspan: 1 }
        } else if (irows.indexOf(row) !== -1) {
            //非主要的隐藏
            return { rowspan: 0, colspan: 0 }
        } else {
            return { rowspan: 1, colspan: 1 }
        }
    } else if (column === 5) { //第六列
        if (isAllYear) {
            if (row === 0) {
                return { rowspan: 12, colspan: 1 }
            } else if (row > 0 && row < 12) {
                return { rowspan: 0, colspan: 0 }
            } else {
                return { rowspan: 1, colspan: 1 }
            }
        } else {
            const rows = [0, 3, 6, 9], irows = [1, 2, 4, 5, 7, 8, 10, 11]
            if (rows.indexOf(row) !== -1) {
                //主要隐藏
                return { rowspan: 3, colspan: 1 }
            } else if (irows.indexOf(row) !== -1) {
                //非主要的隐藏
                return { rowspan: 0, colspan: 0 }
            } else {
                return { rowspan: 1, colspan: 1 }
            }
        }
    } else if (column === 6) { //第七列
        if (isAllYear) {
            const rows = [0, 3, 6, 9], irows = [1, 2, 4, 5, 7, 8, 10, 11]
            if (rows.indexOf(row) !== -1) {
                //主要隐藏
                return { rowspan: 3, colspan: 1 }
            } else if (irows.indexOf(row) !== -1) {
                //非主要的隐藏
                return { rowspan: 0, colspan: 0 }
            } else {
                return { rowspan: 1, colspan: 1 }
            }
        }
    }
}

const formatInput = (value)=>{
    // 移除非数字和小数点
    value = value.replace(/[^\d.]/g, '')

    // 将输入值转换为浮点数
    let floatValue = parseFloat(value)

    // 检查输入是否为数字且不小于0
    if (!isNaN(floatValue) && floatValue >= 0) {
    // 如果是数字且不小于0，则返回原始值
    return value
    } else {
        // 如果输入不符合要求，则返回空字符串
        return ''
    }
}
const changeInvestMoney = (val, row, index)=>{
    let table = yearData.value.list[yearIndex.value].list
    table.forEach((ele, index)=>{
        if (index === 0) {
            table[index].investMoneyAll = Number(table[index].investMoney )
        } else if (0 < index < 12) {
            // table[index].investMoneyAll = Number(table[index].investMoney ) + Number(table[index - 1].investMoneyAll)
            let a = Number( table[index].investMoney )
            let b = Number(table[index - 1].investMoneyAll)
            a = BigNumber(a)
            b = BigNumber(b)
            let c = a.plus(b).toNumber()
            table[index].investMoneyAll = c
        }
    })
}
const changePlanRatio = (val, row, index)=>{
    /*let table = yearData.value.list[yearIndex.value].list
    if (index > 0) {
        let topVal = Number(table[index - 1].planRatio)
        if (Number(row.planRatio) < topVal) {
            window.$message.warning('形象进度百分比:每季度应为增加情况，当月不得低于上月')
            row.planRatio = ''
        }
    } else if (index === 0) {
        let nextVal = Number(table[index + 1].planRatio)
        if (nextVal > 0 && Number(row.planRatio) > nextVal) {
            window.$message.warning('形象进度百分比:每季度应为增加情况，当月不得低于上月')
            row.planRatio = ''
        }
    }*/
}

//项目情况
const isStatusShow = ref(false)
const statusColumn = [
    { key: 'key1', name: '月份', align: 'center' },
    { key: 'key2', name: '工作计划', align: 'center' },
    { key: 'key3', name: '当月重大进度', align: 'center' },
    { key: 'key4', name: '累计完成情况', align: 'center' },
    { key: 'key5', name: '工程总体形象进度(%)', align: 'center' },
]
const statusData = ref([
    { key1:'1月' }, { key1:'2月' }, { key1:'3月' }, { key1:'4月' }, { key1:'5月' }, { key1:'6月' },
    { key1:'7月' }, { key1:'8月' }, { key1:'9月' }, { key1:'10月' }, { key1:'11月' }, { key1:'12月' },
])
const projectStatus = (row) => {
    console.log(row)
    isStatusShow.value = true
}

//关闭弹窗
const statusClose = () => {
    isStatusShow.value = false
}
</script>

<style lang="scss">
.hc-project-list-table .el-table[hc].new {
    --el-table-header-bg-color: #101010;
    --el-table-header-text-color: #fff;
    --el-table-text-color: #101010;
    thead.is-group th.el-table__cell {
        background: var(--el-table-header-bg-color);
    }
    thead .el-table-fixed-column--left.el-table__cell,
    thead .el-table-fixed-column--right.el-table__cell {
        background: var(--el-table-header-bg-color) !important;
    }
    tbody .el-table-fixed-column--left.el-table__cell,
    tbody .el-table-fixed-column--right.el-table__cell {
        background: var(--el-table-tr-bg-color) !important;
    }
    .el-table__body tr.current-row>td.el-table__cell {
        background-color: var(--el-table-current-row-bg-color) !important;
    }
}
.hc-project-list-drawer-year {
    position: relative;
    border: 1px solid #dddddd;
    border-top: 0;
    height: calc(100% - 170px);
    &.detail {
        height: calc(100% - 34px);
    }
    .year-detail {
        padding: 14px;
        background: #f7f7f7;
        border-radius: 5px;
        .hc-card-item-header {
            border-bottom: 1px solid #ecebeb;
            padding-bottom: 10px;
            .item-header {
                justify-content: center;
            }
        }
        .el-table {
            --el-table-border-color: #dcdcdc;
            --el-table-header-text-color: #101010;
            --el-table-row-hover-bg-color: transparent;
        }
        .el-table th.el-table__cell.line {
            padding: 0;
            height: 100%;
            .cell {
                padding: 0;
                height: 100%;
                display: contents;
            }
            .hc-table-th-line {
                position: relative;
                height: 100%;
                font-size: 14px;
                display: contents;
                .left {
                    position: absolute;
                    bottom: 20px;
                    left: 12px;
                }
                .right {
                    position: absolute;
                    top: 18px;
                    right: 8px;
                    font-size: 13px;
                }
                &::after {
                    content: '';
                    position: absolute;
                    top: 51px;
                    left: -30px;
                    width: 180px;
                    height: 1px;
                    background: #dcdcdc;
                    transform: rotate(41deg);
                }
            }
        }
        &.edit .el-table--enable-row-transition .el-table__body td.el-table__cell {
            height: 60px;
        }
        .el-table .el-table__cell .cell {
            .hc-new-main-body_content {
                padding: 4px !important;
                .el-input, .el-textarea {
                    height: 100%;
                    .el-input__inner {
                        text-align: center;
                    }
                    .el-textarea__inner {
                        height: 100%;
                    }
                }
            }
        }
    }
}
.project-status-dialog .hc-card-item-box {
    background: #f8f8f8;
    .hc-card-item-header {
        color: #101010;
    }
}
</style>
