<template>
    <div class="edit-view">
        <el-form
            :model="formData"
            :rules="rules"
            ref="form"
            label-width="55px"
            label-position="right"
            size="small"
            style="max-width: 500px;"
        >
            <el-form-item prop="city" label="城市">
                <el-input v-model="formData.city"></el-input>
            </el-form-item>
            <el-form-item prop="XSL" label="XSL">
                <el-input v-model="formData.XSL"></el-input>
            </el-form-item>
            <el-form-item prop="XTR" label="XTR">
                <el-input v-model="formData.XTR"></el-input>
            </el-form-item>
            <el-form-item prop="GKR" label="GKR">
                <el-input v-model="formData.GKR"></el-input>
            </el-form-item>
            <el-form-item prop="GKZ" label="GKZ">
                <el-input v-model="formData.GKZ"></el-input>
            </el-form-item>
            <el-form-item prop="MDR" label="MDR">
                <el-input v-model="formData.MDR"></el-input>
            </el-form-item>
            <el-form-item prop="RMR" label="RMR">
                <el-input v-model="formData.RMR"></el-input>
            </el-form-item>
            <el-form-item prop="MDZ" label="MDZ">
                <el-input v-model="formData.MDZ"></el-input>
            </el-form-item>
            <el-form-item prop="GXS" label="GXS">
                <el-input v-model="formData.GXS"></el-input>
            </el-form-item>
            <el-form-item prop="GXZ" label="GXZ">
                <el-input v-model="formData.GXZ"></el-input>
            </el-form-item>
            <el-form-item prop="GXL" label="GXL">
                <el-input v-model="formData.GXL"></el-input>
            </el-form-item>
            <el-form-item prop="MDE" label="MDE">
                <el-input v-model="formData.MDE"></el-input>
            </el-form-item>
            <el-form-item prop="MDL" label="MDL">
                <el-input v-model="formData.MDL"></el-input>
            </el-form-item>
            <el-form-item prop="JDS" label="JDS">
                <el-input v-model="formData.JDS"></el-input>
            </el-form-item>
            <el-form-item prop="DJE" label="DJE">
                <el-input v-model="formData.DJE"></el-input>
            </el-form-item>
            <el-form-item prop="ZXE" label="ZXE">
                <el-input v-model="formData.ZXE"></el-input>
            </el-form-item>
            <el-form-item prop="ZXZ" label="ZXZ">
                <el-input v-model="formData.ZXZ"></el-input>
            </el-form-item>
            <el-form-item prop="JDR" label="JDR">
                <el-input v-model="formData.JDR"></el-input>
            </el-form-item>
            <el-form-item prop="JDZ" label="JDZ">
                <el-input v-model="formData.JDZ"></el-input>
            </el-form-item>
            <el-form-item prop="QXL" label="QXL">
                <el-input v-model="formData.QXL"></el-input>
            </el-form-item>
            <el-form-item prop="QXE" label="QXE">
                <el-input v-model="formData.QXE"></el-input>
            </el-form-item>
            <el-form-item prop="GYR" label="GYR">
                <el-input v-model="formData.GYR"></el-input>
            </el-form-item>
            <el-form-item prop="CJR" label="CJR">
                <el-input v-model="formData.CJR"></el-input>
            </el-form-item>
            <el-form-item prop="CJL" label="CJL">
                <el-input v-model="formData.CJL"></el-input>
            </el-form-item>
            <el-form-item prop="CJZ" label="CJZ">
                <el-input v-model="formData.CJZ"></el-input>
            </el-form-item>
            <el-form-item prop="DML" label="DML">
                <el-input v-model="formData.DML"></el-input>
            </el-form-item>
            <el-form-item prop="YFL" label="YFL">
                <el-input v-model="formData.YFL"></el-input>
            </el-form-item>
            <el-form-item prop="JDL" label="JDL">
                <el-input v-model="formData.JDL"></el-input>
            </el-form-item>
            <el-form-item prop="YFL2" label="YFL2">
                <el-input v-model="formData.YFL2"></el-input>
            </el-form-item>
            <el-form-item prop="YKL" label="YKL">
                <el-input v-model="formData.YKL"></el-input>
            </el-form-item>
            <el-form-item prop="YGL" label="YGL">
                <el-input v-model="formData.YGL"></el-input>
            </el-form-item>
            <el-form-item prop="JZS" label="JZS">
                <el-input v-model="formData.JZS"></el-input>
            </el-form-item>
            <el-form-item prop="ZGS" label="ZGS">
                <el-input v-model="formData.ZGS"></el-input>
            </el-form-item>
            <el-form-item prop="JLE" label="JLE">
                <el-input v-model="formData.JLE"></el-input>
            </el-form-item>
            <el-form-item prop="JLL" label="JLL">
                <el-input v-model="formData.JLL"></el-input>
            </el-form-item>
            <el-form-item prop="BDL" label="BDL">
                <el-input v-model="formData.BDL"></el-input>
            </el-form-item>
            <el-form-item prop="DCL" label="DCL">
                <el-input v-model="formData.DCL"></el-input>
            </el-form-item>
            <el-form-item prop="FBL" label="FBL">
                <el-input v-model="formData.FBL"></el-input>
            </el-form-item>
            <el-form-item prop="JRL" label="JRL">
                <el-input v-model="formData.JRL"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="onSave" :loading="saving" type="primary">保存</el-button>
                <el-button @click="onDelete" :loading="saving" type="danger" v-if="formData.id">删除 </el-button>
                <el-button @click="$router.go(-1)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
export default {
    name: 'AnalyzeStateEdit',
    created() {
        if (this.$route.query.id) {
            this.$http
                .get('analyzeState/get/' + this.$route.query.id)
                .then(res => {
                    this.formData = res;
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        }
    },
    data() {
        return {
            saving: false,
            formData: {},
            rules: {}
        };
    },
    methods: {
        onSave() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        submit() {
            let data = { ...this.formData };

            this.saving = true;
            this.$http
                .post('/analyzeState/save', data, { body: 'json' })
                .then(res => {
                    this.saving = false;
                    this.$message.success('成功');
                    this.$router.go(-1);
                })
                .catch(e => {
                    console.log(e);
                    this.saving = false;
                    this.$message.error(e.error);
                });
        },
        onDelete() {
            this.$alert('删除将无法恢复，确认要删除么？', '警告', { type: 'error' })
                .then(() => {
                    return this.$http.post(`/analyzeState/del/${this.formData.id}`);
                })
                .then(() => {
                    this.$message.success('删除成功');
                    this.$router.go(-1);
                })
                .catch(e => {
                    if (e !== 'cancel') {
                        console.log(e);
                        this.$message.error(e.error);
                    }
                });
        }
    }
};
</script>
<style lang="less" scoped></style>
