<template>
    <div>
        <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small"
                 style="max-width: 500px;">
                                                                                                                    <el-form-item prop="facedName" label="朝向">
                <el-input v-model="formData.facedName"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                        <el-form-item prop="rank" label="排序">
                <el-input v-model="formData.rank"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                    <el-form-item>
                <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
                <el-button @click="$router.go(-1)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    import formValidator from '../formValidator'

    export default {
        created() {
            if (this.$route.query.id) {
                this.$http.get({
                    url: '/facedInfo/getOne',
                    data: {
                        id: this.$route.query.id
                    }
                }).then(res => {
                    if (res.success) {
                        this.formData = res.data;
                    }
                })
            }
        },
        data() {
            return {
                saving: false,
                formData: {},
                rules: {
                                                                                                        facedName:
                    [
                        {required: true, message: '请输入 朝向', trigger: 'blur'},
                                            ],
                                                                },
        }
        },
        methods: {
            onSave() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.submit();
                    } else {
                        return false;
                    }
                });
            },
            submit() {
                var data = JSON.parse(JSON.stringify(this.formData));
                this.$http.post({
                    url: this.formData.id ? '/facedInfo/update' : '/facedInfo/save',
                    data: data
                }).then(res => {
                    if (res.success) {
                        this.$message.success('成功');
                        this.$router.go(-1);
                    } else {
                        this.$message.warning('失败')
                    }
                });
            }
        }
    }
</script>
<style lang="less" scoped>
</style>
