<template>
    <HcCard>
        <template #header>
            <div class="w-36">
                <el-select v-model="searchForm.projectType" block clearable placeholder="项目类型" size="large">
                    <el-option v-for="item in projectType" :label="item.name" :value="item.key"/>
                </el-select>
            </div>
            <div class="w-40 ml-2">
                <el-select v-model="searchForm.user" block clearable placeholder="预算制订人" size="large">
                    <el-option v-for="item in users" :label="item.name" :value="item.key"/>
                </el-select>
            </div>
            <div class="w-52 ml-2">
                <el-select v-model="searchForm.project" block clearable placeholder="项目名称" size="large">
                    <el-option v-for="item in projectName" :label="item.name" :value="item.key"/>
                </el-select>
            </div>
            <div class="ml-4">
                <el-button type="primary" @click="searchClick" size="large">
                    <HcIcon name="search-2"/>
                    <span>搜索</span>
                </el-button>
            </div>
            <div class="ml-2">
                <el-button size="large" @click="resetClick">
                    <HcIcon name="close-circle"/>
                    <span>重置</span>
                </el-button>
            </div>
        </template>
        <template #extra>
            <el-button size="large" type="primary" hc-btn @click="addRowClick">
                <HcIcon name="add"/>
                <span>新增项目预算</span>
            </el-button>
        </template>

        <HcTable :isIndex="false" :column="tableColumn" :datas="tableData" :loading="tableLoading">
            <template #action="{row,index}">
                <el-button plain size="small" type="primary" @click="editRowClick(row)">编辑</el-button>
                <el-button plain size="small" type="danger">删除</el-button>
            </template>
        </HcTable>

        <template #action>
            <HcPages :pages="searchForm" @change="pageChange"/>
        </template>
    </HcCard>
</template>

<script setup>
import {ref} from "vue";
import {useRouter} from 'vue-router'

const router = useRouter()

//项目类型
const projectType = ref([
    {name: '二级路', key: '二级路'},
    {name: '国道', key: '国道'},
    {name: '水利水电', key: '水利水电'},
    {name: '市政', key: '市政'},
])

//报销人
const users = ref([
    {name: '张三', key: '张三'},
    {name: '李四', key: '李四'}
])

//项目名称
const projectName = ref([
    {name: '陈油路', key: '陈油路'},
    {name: '奉建路', key: '奉建路'}
])


//搜索表单
const searchForm = ref({
    projectType: null, user: null, project: null,
    current: 1, size: 20, total: 0
})

//搜索
const searchClick = () => {
    searchForm.value.current = 1;
    getTableData()
}

//重置搜索表单
const resetClick = () => {
    searchForm.value = {current: 1, size: 20, total: 0}
}

//分页被点击
const pageChange = ({current, size}) => {
    searchForm.value.current = current
    searchForm.value.size = size
    getTableData()
}

//获取数据
const tableLoading = ref(false)
const tableColumn = [
    {key: 'key', name: '编号', width: '100', align: 'center'},
    {key: 'key1', name: '项目名称'},
    {key: 'key2', name: '预算制订人'},
    {key: 'key3', name: '总成本预算', width: '140', align: 'center'},
    {key: 'key4', name: '目前已用预算', width: '140', align: 'center'},
    {key: 'key5', name: '剩余预算总额', width: '140', align: 'center'},
    {key: 'key6', name: '项目负责人', width: '140', align: 'center'},
    {key: 'action', name: '操作', width: '130', align: 'center'},
]
const tableData = ref([
    {id: 1, key: 'YS-01', key1: 'xxxx', key2: 'xxxx', key3: '65632', key4: '35654', key5: '12312', key6: 'xxxx'},
    {id: 2, key: 'YS-01', key1: 'xxxx', key2: 'xxxx', key3: '65632', key4: '35654', key5: '12312', key6: 'xxxx'},
    {id: 3, key: 'YS-01', key1: 'xxxx', key2: 'xxxx', key3: '65632', key4: '35654', key5: '12312', key6: 'xxxx'},
    {id: 4, key: 'YS-01', key1: 'xxxx', key2: 'xxxx', key3: '65632', key4: '35654', key5: '12312', key6: 'xxxx'},
    {id: 5, key: 'YS-01', key1: 'xxxx', key2: 'xxxx', key3: '65632', key4: '35654', key5: '12312', key6: 'xxxx'},
    {id: 6, key: 'YS-01', key1: 'xxxx', key2: 'xxxx', key3: '65632', key4: '35654', key5: '12312', key6: 'xxxx'},
])

const getTableData = () => {

}


//编辑预算
const editRowClick = (row) => {
    router.push({
        name: 'project-budget-form',
        query: {
            id: row.id
        }
    })
}

//新增预算
const addRowClick = () => {
    router.push({
        name: 'project-budget-form'
    })
}
</script>
