<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="name" label="名称">
                <el-input v-model="formData.name" :disabled="'name'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="type" label="类别">
                <el-input v-model="formData.type" :disabled="'type'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="ownedLandMarkId" label="所属地标ID">
                <template>
                    <el-select v-model="formData.ownedLandMarkId" clearable placeholder="请选择" :disabled="'ownedLandMarkId'==subColumn">
                        <el-option v-for="item in ownedLandMarkIdOptions" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </template>
            </el-form-item>
            <el-form-item prop="arContentGroupId" label="AR内容组ID">
                <el-input v-model="formData.arContentGroupId" :disabled="'arContentGroupId'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="arKitPosX" label="ArKit坐标X">
                <el-input v-model="formData.arKitPosX" :disabled="'arKitPosX'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="arKitPosY" label="ArKit坐标Y">
                <el-input v-model="formData.arKitPosY" :disabled="'arKitPosY'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="arKitPosZ" label="ArKit坐标Z">
                <el-input v-model="formData.arKitPosZ" :disabled="'arKitPosZ'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="arKitScale" label="ArKit缩放">
                <el-input v-model="formData.arKitScale" :disabled="'arKitScale'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="arKitAngle" label="ArKit角度">
                <el-input v-model="formData.arKitAngle" :disabled="'arKitAngle'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="arKitShowLenth" label="ArKit一定距离显示">
                <el-input v-model="formData.arKitShowLenth" :disabled="'arKitShowLenth'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="gyroPosX" label="Gyro坐标X">
                <el-input v-model="formData.gyroPosX" :disabled="'gyroPosX'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="gyroPosY" label="Gyro坐标Y">
                <el-input v-model="formData.gyroPosY" :disabled="'gyroPosY'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="gyroPosZ" label="Gyro坐标Z">
                <el-input v-model="formData.gyroPosZ" :disabled="'gyroPosZ'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="gyroPosScale" label="Gyro缩放">
                <el-input v-model="formData.gyroPosScale" :disabled="'gyroPosScale'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="gyroPosAngle" label="Gyro角度">
                <el-input v-model="formData.gyroPosAngle" :disabled="'gyroPosAngle'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="gyroPosShowLenth" label="Gyro一定距离显示">
                <el-input v-model="formData.gyroPosShowLenth" :disabled="'gyroPosShowLenth'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="vuforiaImageInfoAreaMarking" label="Gyro绑定识别图区域标记编号">
                <el-input v-model="formData.vuforiaImageInfoAreaMarking" :disabled="'vuforiaImageInfoAreaMarking'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="remark1" label="模型X">
                <el-input v-model="formData.remark1" :disabled="'remark1'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="remark2" label="模型Y">
                <el-input v-model="formData.remark2" :disabled="'remark2'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="remark3" label="模型Z">
                <el-input v-model="formData.remark3" :disabled="'remark3'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="remark4" label="显示镜头前">
                <el-input v-model="formData.remark4" :disabled="'remark4'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="remark5" label="备注5">
                <el-input v-model="formData.remark5" :disabled="'remark5'==subColumn"></el-input>
            </el-form-item>
            <el-form-item prop="remark6" label="备注6">
                <el-input v-model="formData.remark6" :disabled="'remark6'==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: '/aimPlaceContent/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;
            }
        }




        this.$http.get({
            url: '/landMark/all'
        }).then(res => {
            if (res.success) {

                if (res.data.length > 0) {
                    res.data.forEach(item => {
                        this.ownedLandMarkIdOptions.push({ label: item.mapName, value: String(item.id) });
                    })
                }
            }
        });
    },
    data() {
        return {
            saving: false,
            formData: {},
            rules: {
            },
            ownedLandMarkIdOptions: [],
            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 ? '/aimPlaceContent/update' : '/aimPlaceContent/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: '/aimPlaceContent/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>
