<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="remark" label="策划备注">
                <el-input v-model="formData.remark" :disabled="'remark'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="mapType" label="地图类型">
                <el-input v-model="formData.mapType" :disabled="'mapType'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="mapName" label="地图名称">
                <el-input v-model="formData.mapName" :disabled="'mapName'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="mapSprite" label="缩略图">
                <el-input v-model="formData.mapSprite" :disabled="'mapSprite'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="anchorImageGroupName" label="识别图信息">
                <el-input v-model="formData.anchorImageGroupName" :disabled="'anchorImageGroupName'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="defaultMode" label="模式">
                <el-input v-model="formData.defaultMode" :disabled="'defaultMode'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="vuforiaDataName" label="识别图数据名称">
                <el-input v-model="formData.vuforiaDataName" :disabled="'vuforiaDataName'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="mapInfo" label="地图信息">
                <el-input v-model="formData.mapInfo" :disabled="'mapInfo'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="mapWidth" label="地图高">
                <el-input v-model="formData.mapWidth" :disabled="'mapWidth'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="mapHeight" label="地图高">
                <el-input v-model="formData.mapHeight" :disabled="'mapHeight'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="mapRate" label="比率">
                <el-input v-model="formData.mapRate" :disabled="'mapRate'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="showInPanel" label="是否显示">
                <el-input v-model="formData.showInPanel" :disabled="'showInPanel'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="latitude" label="经度">
                <el-input v-model="formData.latitude" :disabled="'latitude'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="longitude" label="纬度">
                <el-input v-model="formData.longitude" :disabled="'longitude'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="radiantRange" label="辐射范围">
                <el-input v-model="formData.radiantRange" :disabled="'radiantRange'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="city" label="城市">
                <el-input v-model="formData.city" :disabled="'city'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                        <el-form-item>
                <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
                <el-button @click="onDelete" v-if="formData.id" type="danger">删除</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.column) {
                this.subColumn = this.$route.query.column.split(',')[1];
                this.subValue = this.$route.query.column.split(',')[0];
            }

            if (this.$route.query.id) {
                this.$http.get({
                    url: '/marketMap/getOne',
                    data: {
                        id: this.$route.query.id
                    }
                }).then(res => {
                    if (res.success) {

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                        this.formData = res.data;

                    if (this.$route.query.column) {
                        this.formData[this.subColumn] = this.subValue;
                    }
                    }
                })
            }else {
                if (this.$route.query.column) {
                    this.formData[this.subColumn] = this.subValue;
                }
            }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
        data() {
            return {
                saving: false,
                formData: {},
                rules: {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
                                                                                                                                                                                            subColumn: '',
            subValue: '',
        }
        },
        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 ? '/marketMap/update' : '/marketMap/save',
                    data: data
                }).then(res => {
                    if (res.success) {
                        this.$message.success('成功');
                        this.$router.go(-1);
                    } else {
                        this.$message.warning('失败')
                    }
                });
            },
            onDelete() {
                this.$alert('删除将无法恢复，确认要删除么？', '警告', { type: 'error' }).then(() => {
                    return this.$http.post({
                    url: '/marketMap/del',
                    data: { id: this.formData.id }
                    })
                }).then(() => {
                    this.$message.success('删除成功');
                    this.$router.go(-1);
                }).catch(action => {
                    if (action === 'cancel') {
                        this.$message.info('删除取消');
                    } else {
                        this.$message.error('删除失败');
                    }
                })
            },
        }
    }
</script>
<style lang="less" scoped>
</style>
