<template>
    <el-dialog v-model="dialogFormVisible" 
    :show-close="false" 
    :title="dialogTitle" width="340" 
    :close-on-press-escape="false" :close-on-click-modal="false" >
        <div>
            <el-input v-model="addEditMsg.GName" 
            placeholder="请输入分组名称">
            </el-input>
            <el-input class="q-pt-lg" type="Number" v-model="addEditMsg.SortNum" 
            placeholder="排序">
            </el-input>
        </div>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="close">取消</el-button>
            <el-button type="primary" @click="setGroup" :loading="setLoading">
              确认
            </el-button>
          </div>
        </template>
      </el-dialog>
</template>
<script lang="ts" setup>
    import { reactive, ref, onMounted, watch} from "vue";
    import { ElLoading, ElMessage, ElMessageBox } from "element-plus";
    import CloudDiskService from '@/services/CloudDiskService'
    import { ApiResult } from "@/configs/axios";
    const dialogFormVisible = ref(true)
    const dialogTitle = ref('')
    const setLoading = ref(false)
    // const addEditMsg = reactive({
    //     Id: '',
    //     GName: '',
    //     SortNum: null,
    // })
    const props = defineProps({
        dialogType: {
            type: Number,
            required: true,
        },
        addEditMsg: {
            type: Object,
            required: '',
        },
    })
    const emit = defineEmits<{
        (event: 'close'): void,
        (event: 'success'): void,
    }>()
    dialogTitle.value = props.dialogType==1?'新增分组名称':'编辑分组名称'
    const close = () =>{
        dialogFormVisible.value = false
        emit('close')
    }
    const setGroup = async () =>{
        if(!props.addEditMsg.GName) return ElMessage.warning({
            showClose: true,
            message: `请输入分组名称`,
        })
        setLoading.value = true
        let pageRes = await CloudDiskService.SetPPTCloudGroup(props.addEditMsg);
        if (pageRes.data.resultCode==ApiResult.SUCCESS) {
            dialogFormVisible.value = false
            emit('success')
        }
        setLoading.value = false
    }
</script>