<template>
    <hc-card class="hc-project-collect-gist-list">
        <template #header>
            <div class="relative ml-3 w-[300px]">
                <hc-search-input v-model="searchForm.queryValue" text="搜索" color="#151921" @search="searchClick">
                    <template #prepend>
                        <el-select v-model="searchForm.year" placeholder="年份" clearable style="width: 80px">
                            <el-option label="2023" value="2023" />
                            <el-option label="2024" value="2024" />
                        </el-select>
                    </template>
                </hc-search-input>
            </div>
        </template>
        <template #extra>
            <div class="w-[120px]">
                <el-select v-model="searchForm.key1" filterable clearable block placeholder="项目阶段" @change="searchClick">
                    <el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </div>
            <el-button v-del-com:[delTableItem] type="danger" class="ml-2" :disabled="tableCheckKeys.length <= 0">批量删除</el-button>
            <el-button type="warning" class="ml-2" @click="importClick">导入</el-button>
            <el-button v-yes-com:[deriveTableItem] type="primary" class="ml-2" :disabled="tableCheckKeys.length <= 0">批量导出</el-button>
        </template>
        <HcTableList ref="tableRef" is-admin @tap="rowNameClick" @check="tableCheck" />
        <template #action>
            <hc-pages :pages="searchForm" @change="pageChange" />
        </template>

        <!-- 导入 -->
        <hc-dialog v-model="isImportShow" widths="24rem" title="项目数据导入" :footer="false" @close="modalImportClose">
            <hc-form-upload
                v-model="importFile" class="hc-form-drop-upload"
                :options="{ num: 0, type: 'list', drop: true }"
                :upload="{ options: uploadOptions }"
            />
            <div class="hc-flex mt-5">
                <span class="mr-2">模板下载:</span>
                <el-button color="#20C98B" size="small" class="text-white">点击下载</el-button>
            </div>
        </hc-dialog>
    </hc-card>
</template>

<script setup>
import { ref } from 'vue'
import HcTableList from '../modules/gist-list.vue'

//事件
const emit = defineEmits(['edit'])

const tableRef = ref(null)

//项目阶段
const stateOptions = ref([{ value: '1', label: '新开工项目' }, { value: '2', label: '建成项目' }, { value: '3', label: '在建项目' }])

//搜索条件
const searchForm = ref({ queryValue: '', year: '', current: 1, size: 20, total: 0 })
const searchClick = () => {

}

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

//表格被选择
const tableCheckKeys = ref([])
const tableCheck = (row) => {
    tableCheckKeys.value = row
}

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

//批量删除
const delTableItem = () => {
    tableRef.value?.batchRemove()
}

//批量导出
const deriveTableItem = () => {
    tableRef.value?.batchExport()
}

//项目数据导入
const isImportShow = ref(false)
const importFile = ref([])
const uploadOptions = {
    accept: '.xls,.xlsx',
    accept_tip: '请选择Excel文件',
}
const importClick = () => {
    isImportShow.value = true
}

//关闭项目数据导入弹窗
const modalImportClose = () => {
    isImportShow.value = false
}
</script>
