<template>
    <div class="main-container">
        <el-card class="box-card !border-none" shadow="never">

            <div class="flex justify-between items-center">
                <span class="text-lg">{{pageName}}</span>
                <el-button type="primary" @click="addEvent">
                    {{ t('addAaaaaaaaaaa') }}
                </el-button>
            </div>

            <el-card class="box-card !border-none my-[10px] table-search-wrap" shadow="never">
                <el-form :inline="true" :model="aaaaaaaaaaaTable.searchParam" ref="searchFormRef">
                    
                    <el-form-item>
                        <el-button type="primary" @click="loadAaaaaaaaaaaList()">{{ t('search') }}</el-button>
                        <el-button @click="resetForm(searchFormRef)">{{ t('reset') }}</el-button>
                    </el-form-item>
                </el-form>
            </el-card>

            <div class="mt-[10px]">
                <el-table :data="aaaaaaaaaaaTable.data" size="large" v-loading="aaaaaaaaaaaTable.loading">
                    <template #empty>
                        <span>{{ !aaaaaaaaaaaTable.loading ? t('emptyData') : '' }}</span>
                    </template>
                     <el-table-column :label="t('url1')" width="100" align="left">
                        <template #default="{ row }">
                            <el-avatar v-if="row.url1" :src="img(row.url1)" />
                            <el-avatar v-else icon="UserFilled" />
                        </template>
                    </el-table-column>
                    <el-table-column prop="url2" :label="t('url2')" min-width="120" :show-overflow-tooltip="true"/>
                    
                    <el-table-column prop="url3" :label="t('url3')" min-width="120" :show-overflow-tooltip="true"/>
                    
                    <el-table-column :label="t('operation')" fixed="right" min-width="120">
                       <template #default="{ row }">
                           <el-button type="primary" link @click="editEvent(row)">{{ t('edit') }}</el-button>
                           <el-button type="primary" link @click="deleteEvent(row.id)">{{ t('delete') }}</el-button>
                       </template>
                    </el-table-column>

                </el-table>
                <div class="mt-[16px] flex justify-end">
                    <el-pagination v-model:current-page="aaaaaaaaaaaTable.page" v-model:page-size="aaaaaaaaaaaTable.limit"
                        layout="total, sizes, prev, pager, next, jumper" :total="aaaaaaaaaaaTable.total"
                        @size-change="loadAaaaaaaaaaaList()" @current-change="loadAaaaaaaaaaaList" />
                </div>
            </div>

            <edit ref="editAaaaaaaaaaaDialog" @complete="loadAaaaaaaaaaaList" />
        </el-card>
    </div>
</template>

<script lang="ts" setup>
import { reactive, ref, watch } from 'vue'
import { t } from '@/lang'
import { useDictionary } from '@/app/api/dict'
import { getAaaaaaaaaaaList, deleteAaaaaaaaaaa } from '@/app/api/aaaaaaaaaaa'
import { img } from '@/utils/common'
import { ElMessageBox,FormInstance } from 'element-plus'
import Edit from '@/app/views/aaaaaaaaaaa/components/aaaaaaaaaaa-edit.vue'
import { useRoute } from 'vue-router'
const route = useRoute()
const pageName = route.meta.title;

let aaaaaaaaaaaTable = reactive({
    page: 1,
    limit: 10,
    total: 0,
    loading: true,
    data: [],
    searchParam:{
      
    }
})

const searchFormRef = ref<FormInstance>()

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

// 字典数据
    

/**
 * 获取测试列表
 */
const loadAaaaaaaaaaaList = (page: number = 1) => {
    aaaaaaaaaaaTable.loading = true
    aaaaaaaaaaaTable.page = page

    getAaaaaaaaaaaList({
        page: aaaaaaaaaaaTable.page,
        limit: aaaaaaaaaaaTable.limit,
         ...aaaaaaaaaaaTable.searchParam
    }).then(res => {
        aaaaaaaaaaaTable.loading = false
        aaaaaaaaaaaTable.data = res.data.data
        aaaaaaaaaaaTable.total = res.data.total
    }).catch(() => {
        aaaaaaaaaaaTable.loading = false
    })
}
loadAaaaaaaaaaaList()

const editAaaaaaaaaaaDialog: Record<string, any> | null = ref(null)

/**
 * 添加测试
 */
const addEvent = () => {
    editAaaaaaaaaaaDialog.value.setFormData()
    editAaaaaaaaaaaDialog.value.showDialog = true
}

/**
 * 编辑测试
 * @param data
 */
const editEvent = (data: any) => {
    editAaaaaaaaaaaDialog.value.setFormData(data)
    editAaaaaaaaaaaDialog.value.showDialog = true
}

/**
 * 删除测试
 */
const deleteEvent = (id: number) => {
    ElMessageBox.confirm(t('aaaaaaaaaaaDeleteTips'), t('warning'),
        {
            confirmButtonText: t('confirm'),
            cancelButtonText: t('cancel'),
            type: 'warning',
        }
    ).then(() => {
        deleteAaaaaaaaaaa(id).then(() => {
            loadAaaaaaaaaaaList()
        }).catch(() => {
        })
    })
}

    

const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.resetFields()
    loadAaaaaaaaaaaList()
}
</script>

<style lang="scss" scoped>
/* 多行超出隐藏 */
.multi-hidden {
		word-break: break-all;
		text-overflow: ellipsis;
		overflow: hidden;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
</style>
