<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.contractType" block clearable placeholder="合同类型" size="large">
                    <el-option v-for="item in contractType" :label="item.name" :value="item.key"/>
                </el-select>
            </div>
            <div class="w-48 ml-2">
                <el-select v-model="searchForm.projectProcess" block clearable placeholder="项目进程" size="large">
                    <el-option v-for="item in projectProcess" :label="item.name" :value="item.key"/>
                </el-select>
            </div>
            <div class="w-36 ml-2">
                <el-select v-model="searchForm.date" block clearable placeholder="选择时间" size="large">
                    <el-option v-for="item in annuals" :label="item.name" :value="item.key"/>
                </el-select>
            </div>
            <div class="w-40 ml-2">
                <el-input v-model="searchForm.queryValue" clearable placeholder="请输入关键词" @keyup="keyUpEvent" size="large"/>
            </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 #key1="{row}">
                <span class="text-blue text-hover" @click="rowClick(row)">{{row.key1}}</span>
            </template>
            <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 contractType = ref([
    {name: '咨询服务+软件', key: '1'},
    {name: '软件', key: '2'},
    {name: '咨询服务', key: '3'},
    {name: '后期服务+软件', key: '4'},
    {name: '数字化扫描+软件', key: '5'},
])

//项目进程
const projectProcess = ref([
    {name: '商机-演示沟通', key: '1'},
    {name: '商机-成本核算及报价', key: '2'},
    {name: '合同-服务范围洽谈', key: '3'},
    {name: '产品-研发', key: '4'},
    {name: '产品-配置', key: '5'},
    {name: '产品-测试', key: '6'},
    {name: '产品-交付', key: '7'},
    {name: '实施-系统培训', key: '8'},
    {name: '实施-现场服务', key: '9'},
    {name: '实施-合同回款', key: '10'},
    {name: '项目验收', key: '11'},
])

//年度数据
const annuals = ref([
    {name: '2023年5月', key: '2023-05'},
    {name: '2022年4月', key: '2022-04'},
    {name: '2021年3月', key: '2021-03'}
])

//搜索表单
const searchForm = ref({
    projectType: null, contractType: null, projectProcess: null, date: null, queryValue: '',
    current: 1, size: 20, total: 0
})

//搜索框回车
const keyUpEvent = (event) => {
    if (event.key === "Enter") {
        searchForm.value.current = 1;
        getTableData()
    }
}

//搜索
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: '90', align: 'center'},
    {key: 'key1', name: '项目名称'},
    {key: 'key2', name: '项目进程', width: '160', align: 'center'},
    {key: 'key3', name: '项目开始日期', width: '160', align: 'center'},
    {key: 'key4', name: '项目类型', width: '140', align: 'center'},
    {key: 'key5', name: '合同类型', width: '140', align: 'center'},
    {key: 'key6', name: '合同额(W)', width: '100', align: 'center'},
    {key: 'key8', name: '负责人', width: '100', align: 'center'},
    {key: 'key7', name: '合同起止日期', width: '220', align: 'center'},
    {key: 'action', name: '操作', width: '130', align: 'center'},
]
const tableData = ref([
    {id: 1, key: 'GS-01', key1: '焦作至唐河高速公路方城至唐河段', key2: '研发-配置', key3: '2022-07-01', key4: '高速公路', key5: '软件合同', key6: '40', key8: '张三', key7: '2022-07-01 ~ 2022-04-01'},
    {id: 2, key: 'GS-01', key1: '焦作至唐河高速公路方城至唐河段', key2: '研发-配置', key3: '2022-07-01', key4: '高速公路', key5: '软件合同', key6: '40', key7: '2022-07-01 ~ 2022-04-01'},
    {id: 3, key: 'GS-01', key1: '焦作至唐河高速公路方城至唐河段', key2: '研发-配置', key3: '2022-07-01', key4: '高速公路', key5: '软件合同', key6: '40', key7: '2022-07-01 ~ 2022-04-01'},
])

const getTableData = () => {

}

//查看
const rowClick = (row) => {
    router.push({
        name: 'project-list-info',
        query: {
            id: row.id,
            type: 'view'
        }
    })
}

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

//新增预算
const addRowClick = () => {
    router.push({
        name: 'project-list-info',
        query: {
            type: 'add'
        }
    })
}
</script>
