<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form class="mb-[-16px] formtabel" :model="queryParams" inline>
                <el-form-item label-width="100px" label="主题" prop="title">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.title"
                        clearable
                        placeholder="请输入主题"
                    />
                </el-form-item>
                <el-form-item label-width="100px" label="">
                    <el-button class="el-btn" type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <div class="mt-4">
                <el-table :data="pager.lists" @cell-click="handleSelectionChange">
                    <el-table-column label="主题" prop="title" show-overflow-tooltip />
                    <el-table-column label="创建人" prop="admin_name" show-overflow-tooltip />
                    <el-table-column label="金额" prop="money" show-overflow-tooltip />
                    <el-table-column label="任务类型" prop="type_name" show-overflow-tooltip />
                    <el-table-column label="状态" show-overflow-tooltip>
                        <template #default="{ row }">
                            <span>{{ row.status == 1 ? '显示' : '隐藏' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="任务描述" prop="content" show-overflow-tooltip />
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup
            v-if="showEdit"
            ref="editRef"
            :dict-data="dictData"
            @success="getLists"
            @close="showEdit = false"
        />
    </div>
</template>

<script lang="ts" setup name="taskTemplateLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiTaskTemplateLists, apiTaskTemplateDelete } from '@/api/task_template'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
import { dictDataLists } from '@/api/setting/dict'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const datalist = ref([])
// 是否显示编辑框
const showEdit = ref(false)

// 查询条件
const queryParams = reactive({
    title: '',
    admin_id: '',
    money: '',
    type: '',
    status: '',
    content: ''
})
const statusdata = reactive([
    { id: 1, name: '显示' },
    { id: 2, name: '隐藏' }
])

// 选中数据
const selectData = ref<any[]>([])

const emits = defineEmits(['customEvent'])

// 表格选择后回调事件
const handleSelectionChange = (value: any) => {
    emits('customEvent', value)

    // selectData.value = val.map(({ id }) => id)
}

// 获取字典数据
const { dictData } = useDictData('')

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiTaskTemplateLists,
    params: queryParams
})

//任务类型接口
// dictDataLists({ type_id: 10 }).then((res) => {
//     datalist.value = res.lists
// })
getLists()
</script>
<style lang="scss" scoped>
.formtabel {
    .el-form-item {
        width: 20%;
        .el-btn {
            margin-left: 60px;
        }
    }
}
</style>
