<template>
    <HcCard>
        <template #header>
            <div class="w-72">
                <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>
        </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: '外包类型', width: '140'},
    {key: 'key2', name: '关联项目', minWidth: '200'},
    {key: 'key3', name: '支付金额', width: '160', align: 'center'},
    {key: 'key4', name: '支付对方', width: '140', align: 'center'},
    {key: 'key5', name: '审批结果', width: '140', align: 'center'},
    {key: 'key6', name: '审批状态', width: '140', align: 'center'},
    {key: 'key7', name: '申请支付时间', width: '180', 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-outsourcing-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>
