<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-72 ml-2">
                <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="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="warning" hc-btn @click="draftsClick">
                <HcIcon name="draft"/>
                <span>草稿箱(1)</span>
            </el-button>
            <el-button size="large" type="primary" hc-btn @click="addRowClick">
                <HcIcon name="add"/>
                <span>新增支付记录</span>
            </el-button>
        </template>

        <HcTable :column="tableColumn" :datas="tableData" :loading="tableLoading">
            <template #key="{row}">
                <span class="text-blue" @click="rowNameTap(row)">{{row.key}}</span>
            </template>
            <template #action="{row,index}">
                <el-button size="small" type="primary">撤销</el-button>
            </template>
        </HcTable>

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

        <!--草稿箱-->
        <HcDialog bgColor="#ffffff" isToBody isTable :footer="false" :show="draftsModal" title="草稿箱(1)" widths="62rem" @close="draftsCloseClick">
            <el-alert title="3个月内未更新的草稿将被自动删除" type="warning" show-icon />
            <div style="position: relative;height: calc(100% - 44px);">
                <HcTable :isIndex="false" :column="tableDraftsColumn" :datas="tableDraftsData">
                    <template #action="{row,index}">
                        <el-button size="small" type="primary">继续编辑</el-button>
                        <el-button size="small" type="danger">删除</el-button>
                    </template>
                </HcTable>
            </div>
        </HcDialog>
    </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 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: 'key1', name: '申请时间', minWidth: '160'},
    {key: 'key2', name: '收款人', minWidth: '160'},
    {key: 'key3', name: '收款金额', width: '160', align: 'center'},
    {key: 'key4', name: '收款用途', width: '160', align: 'center'},
    {key: 'key5', name: '审批结果', width: '160', align: 'center'},
    {key: 'key6', name: '审批状态', width: '140', align: 'center'},
    {key: 'key7', name: '报销时间', width: '160', align: 'center'},
    {key: 'key8', name: '创建人', width: '140', align: 'center'},
    {key: 'key9', name: '创建时间', width: '160', align: 'center'},
    {key: 'action', name: '操作', width: '90', align: 'center', fixed: 'right'},
]
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 rowNameTap = (row) => {

}

//新增
const addRowClick = () => {
    router.push({
        name: 'expense-paymentRequest-record'
    })
}

//草稿箱
const draftsModal = ref(false)
const draftsClick = () => {
    draftsModal.value = true
}
const draftsCloseClick = () => {
    draftsModal.value = false
}

//草稿箱数据
const tableDraftsColumn = [
    {key: 'key1', name: '标题'},
    {key: 'key2', name: '更新时间', width: '200'},
    {key: 'action', name: '操作', width: '170', align: 'center'},
]
const tableDraftsData = ref([{id: 1, key1: 'xxxx', key2: 'xxxx'}, {id: 2, key1: 'xxxx', key2: 'xxxx'}, {id: 3, key1: 'xxxx', key2: 'xxxx'}])

</script>
