<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="marketId" label="所属商圈">
                <el-input v-model="formData.marketId" :disabled="'marketId'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="boxName" label="地图名称">
                <el-input v-model="formData.boxName" :disabled="'boxName'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="typeId" label="显示类型">
                <el-input v-model="formData.typeId" :disabled="'typeId'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="typeName" label="类型">
                <el-input v-model="formData.typeName" :disabled="'typeName'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="posX" label="坐标X">
                <el-input v-model="formData.posX" :disabled="'posX'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="posY" label="坐标Y">
                <el-input v-model="formData.posY" :disabled="'posY'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="posZ" label="坐标Z">
                <el-input v-model="formData.posZ" :disabled="'posZ'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="scale" label="缩放">
                <el-input v-model="formData.scale" :disabled="'scale'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="angle" label="角度">
                <el-input v-model="formData.angle" :disabled="'angle'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="showLenth" label="一定距离显示">
                <el-input v-model="formData.showLenth" :disabled="'showLenth'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="parentImageName" label="所属图片">
                <el-input v-model="formData.parentImageName" :disabled="'parentImageName'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="androidPosX" label="android坐标X">
                <el-input v-model="formData.androidPosX" :disabled="'androidPosX'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="androidPosY" label="android坐标Y">
                <el-input v-model="formData.androidPosY" :disabled="'androidPosY'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="androidPosZ" label="android坐标Z">
                <el-input v-model="formData.androidPosZ" :disabled="'androidPosZ'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="androidScale" label="android缩放">
                <el-input v-model="formData.androidScale" :disabled="'androidScale'==subColumn"></el-input>
            </el-form-item>
                                                                                                                                                                                                                                                                                                                            <el-form-item prop="androidAngle" label="android角度">
                <el-input v-model="formData.androidAngle" :disabled="'androidAngle'==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: '/marketMapBox/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 ? '/marketMapBox/update' : '/marketMapBox/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: '/marketMapBox/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>
