<template>
    <div class="default-main">
        <TableHeader :showReset="false">
            <template #select>


                <!-- <el-radio-group v-model.trim="tableStore.table.params.versionType" @change="tableStore.index()">
                    <el-radio-button label="web" value="WEB" />
                    <el-radio-button label="app" value="APP" />

                </el-radio-group> -->
            </template>
            <template #operation>
                <el-button type="primary" icon="el-icon-Plus" @click="addMenu">新增版本</el-button>
            </template>
        </TableHeader>
        <Table ref="tableRef" />
        <el-dialog width="600px" v-model.trim="dialogVisible" title="新增版本">
            <el-form :inline="false" :model="form" label-width="auto" class="form-one">
                <el-form-item label="版本号">
                    <el-input maxlength="32" show-word-limit v-model.trim="form.appVersion" placeholder="请输入版本号" />
                </el-form-item>
                <el-form-item label="整改内容">
                    <el-input maxlength="300" type="textarea" show-word-limit v-model.trim="form.content"
                        placeholder="请输入整改内容" />
                </el-form-item>
                <el-form-item label="发布类型">

                    <el-select v-model.trim="form.sev" placeholder="请选择发布类型">
                        <el-option label="优化" :value="0" />
                        <el-option label="bug调整" :value="1" />
                    </el-select>
                </el-form-item>
                <el-form-item label="版本类型">

                    <el-select v-model.trim="form.versionType" placeholder="please select your zone">
                        <el-option label="web" value="WEB" />
                        <el-option label="app" value="APP" />
                    </el-select>
                </el-form-item>
            </el-form>

            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="submit">确认</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { useDictData } from '@/stores/dictData'
import { ElMessage } from 'element-plus'
import { addVersion } from '@/api/systerm'
import router from '@/router/index'
const dialogVisible = ref(false)
const form = ref({
    appVersion: '',
    content: '',
    versionType: '',
    sev: '',
})
const tableStore = new TableStore({
    url: '/cs-system-boot/appVersion/getAllData',
    method: 'POST',
    showPage: false,
    paramsPOST: true,
    column: [
        {
            title: '序号', width: 80, formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '版本号', field: 'versionName', width: '150' },

        { title: '创建时间', field: 'createTime', width: '220' },
        {
            title: '发布类型', field: 'sev', formatter: (row,) => {
                return row.cellValue == 0 ? '优化' : 'bug调整'
            },
            width: '150'
        },
        { title: '整改内容', field: 'content' },




    ],
})
tableStore.table.params.versionType = 'WEB'
provide('tableStore', tableStore)

onMounted(async () => {
    tableStore.index()
    // await queryByCode('Direct_Connected_Device').then((res) => {
    //     queryByid(res.data.id).then((res) => {
    //         DevTypeOptions.value = res.data
    //     })
    // })
    // tableStore.table.params.devType = ''
})
const submit = () => {
    addVersion(form.value).then(res => {
        ElMessage.success('新增成功')
        tableStore.index()
        dialogVisible.value = false
        router.go(0)
    })
}
const addMenu = () => {
    dialogVisible.value = true
    form.value.appVersion = tableStore.table.data[0].versionName || ''
    form.value.content = ''
    form.value.sev = tableStore.table.data[0].sev || 0
    form.value.versionType = tableStore.table.data[0].versionType || 'WEB'
}

</script>
