<template>
    <div>
        <el-form :model="form" label-width="120px">
            <el-form-item label="ID">
                <el-input v-model="form.id"></el-input>
            </el-form-item>
            <el-form-item label="文件类型" prop="lx">
                <el-select v-model="form.imgType" placeholder="请选择文件类型">
                    <el-option v-for="dict in dict.type.tplx" :key="dict.value" :label="dict.label"
                        :value="dict.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="图片url">
                <el-input v-model="form.img"></el-input>
            </el-form-item>
            <el-form-item label="经度">
                <el-input v-model="form.latitude"></el-input>
            </el-form-item>
            <el-form-item label="纬度">
                <el-input v-model="form.longitude"></el-input>
            </el-form-item>
            <el-form-item label="项目ID">
                <el-input v-model="form.xmId"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleSubmit">提交</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { addxmtl } from '@/api/ManageApi/index';
import ImageUpload from '@/components/ImageUpload';

export default {
    components: { ImageUpload },
    dicts: ['tplx'],
    data() {
        return {
            form: {
                createBy: '',
                createTime: '',
                id: 0,
                img: '',
                imgType: 0,
                latitude: '',
                longitude: '',
                remark: '',
                updateBy: '',
                updateTime: '',
                xmId: 0,
            },
        };
    },
    methods: {
        handleFileUploaded(fileUrl) {
            this.form.img = fileUrl;
        },
        handleSubmit() {
            addxmtl(this.form)
                .then((response) => {
                    if (response.code === 200) {
                        this.$message.success('新增成功');
                        this.resetForm();
                    } else {
                        this.$message.error('新增失败');
                    }
                })
                .catch((error) => {
                    console.error('新增失败:', error);
                    this.$message.error('新增失败');
                });
        },
        resetForm() {
            this.form = {
                createBy: '',
                createTime: '',
                id: 0,
                img: '',
                imgType: 0,
                latitude: '',
                longitude: '',
                remark: '',
                updateBy: '',
                updateTime: '',
                xmId: 0,
            };
        },
    },
};
</script>