<template>
    <div>
        <el-card class="box-card" style="max-width: 500px;margin:20px auto">
            <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small" style="max-width: 500px;">

                <el-form-item prop="groupId" label="内容组ID">
                    <el-input v-model="formData.groupId" :disabled="'groupId'==subColumn"></el-input>
                </el-form-item>
                <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-select placeholder="类别" size="small" v-model="formData.type" class="filter-item">
                        <el-option label="普通虚拟讲解员" value="1001">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item prop="remark1" label="备注1">
                    <el-input v-model="formData.remark1" :disabled="'remark1'==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-item prop="text" label="文字">
                        <el-input v-model="formData.text" :disabled="'text'==subColumn"></el-input>
                    </el-form-item> -->
                <!-- <el-form-item prop="image" label="图片">
                        <el-input v-model="formData.image" :disabled="'image'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="url" label="URL">
                        <el-input v-model="formData.url" :disabled="'url'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="voice" label="音频">
                        <el-input v-model="formData.voice" :disabled="'voice'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="movie" label="视频">
                        <el-input v-model="formData.movie" :disabled="'movie'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="model" label="模型">
                        <el-input v-model="formData.model" :disabled="'model'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="cfile" label="文本文件">
                        <el-input v-model="formData.cfile" :disabled="'cfile'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="resourceSize" label="资源大小（M）">
                        <el-input v-model="formData.resourceSize" :disabled="'resourceSize'==subColumn"></el-input>
                    </el-form-item> -->

                <!-- <el-form-item prop="remark2" label="备注2">
                        <el-input v-model="formData.remark2" :disabled="'remark2'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="remark3" label="备注3">
                        <el-input v-model="formData.remark3" :disabled="'remark3'==subColumn"></el-input>
                    </el-form-item>
                    <el-form-item prop="remark4" label="备注4">
                        <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>
        </el-card>

    </div>
</template>
<script>
import formValidator from '../formValidator'

export default {
    name: 'ArContent',
    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.arContentId) {
            this.$http.get({
                url: '/arContent/getOne',
                data: {
                    id: this.$route.query.arContentId
                }
            }).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,
            rules: {
            },
            subColumn: '',
            subValue: '',
            formData: {
                type:'1001'
            }
        }
    },
    computed: {
    },
    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 ? '/arContent/update' : '/arContent/save',
                data: data
            }).then(res => {
                if (res.success) {
                    this.$message.success('成功');
                    if (this.formData.id) {
                        this.$emit('next', res.data)
                    }
                    else {
                        this.$emit('saveInfo', res.data)
                    }
                } else {
                    this.$message.warning('失败')
                }
            });
        },
        onDelete() {
            this.$alert('删除将无法恢复，确认要删除么？', '警告', { type: 'error' }).then(() => {
                return this.$http.post({
                    url: '/arContent/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>
