<template>
    <div>
        <el-card class="box-card" style="max-width: 500px;margin:20px auto">
            <el-form :model="formData" :rules="rules" ref="form" label-width="170px" label-position="right" size="small" style="max-width: 500px;">
                 <el-form-item prop="remark1" label="">
                    <template>
                        <el-button style="float: right;" type="text">如需定制特效/讲解员请联系管理员</el-button>
                    </template>

                </el-form-item>
                <el-form-item prop="remark1" label="特效名称">
                    <template>
                        <el-select v-model="formData.remark1" clearable placeholder="特效">
                            <el-option label="Effect001" value="Effect001"></el-option>
                            <el-option label="Effect002" value="Effect002"></el-option>
                            <el-option label="Effect003" value="Effect003"></el-option>
                        </el-select>
                    </template>

                </el-form-item>
                <el-form-item prop="remark2" label="模型出场方式">
                    <template>
                        <el-select v-model="formData.remark2" clearable placeholder="出场方式">
                            <el-option label="直接出现" value="1"></el-option>
                            <el-option label="渐变" value="2"></el-option>
                            <el-option label="从上方进入" value="3"></el-option>
                            <el-option label="从下方进入" value="4"></el-option>
                        </el-select>
                    </template>
                </el-form-item>
                <el-form-item prop="remark3" label="模型名称">
                    <template>
                        <el-select v-model="formData.remark3" clearable placeholder="模型名称">
                            <el-option label="Role001" value="Role001"></el-option>
                            <el-option label="Role002" value="Role002"></el-option>
                            <el-option label="Role003" value="Role003"></el-option>
                            <el-option label="Role004" value="Role004"></el-option>
                        </el-select>
                    </template>
                </el-form-item>
                <el-form-item prop="remark4" label="是否打招呼">
                    <template>
                        <el-select v-model="formData.remark4" clearable placeholder="是否打招呼">
                            <el-option label="是" value="0"></el-option>
                            <el-option label="否" value="1"></el-option>
                        </el-select>
                    </template>
                </el-form-item>
                <el-form-item prop="remark5" label="讲解员模式">
                    <template>
                        <el-select v-model="formData.remark5" clearable placeholder="讲解员模式">
                            <el-option label="实景" value="1"></el-option>
                            <el-option label="菲实景" value="2"></el-option>
                        </el-select>
                    </template>
                </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-form-item>
            </el-form>
        </el-card>
    </div>
</template>
<script>
import formValidator from '../formValidator'

export default {
    name: 'ArContentTemplateStep2',

    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.ArContentTemplateStep2Id) {
            this.$http.get({
                url: '/arContentChild/getOne',
                data: {
                    id: this.$route.query.ArContentTemplateStep2Id
                }
            }).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.arContentId) {
                this.formData.arContentId = this.$route.query.arContentId;
            }
        }




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

                if (res.data.length > 0) {
                    res.data.forEach(item => {
                        this.arContentIdOptions.push({ label: item.name, value: item.id });
                    })
                }
            }
        });
    },
    data() {
        return {
            saving: false,
            formData: {
                type: 1,
                remark1: 'Effect001',
                remark2: '1',
                remark3: 'Role001',
                remark4: '0',
                remark5: '1',
            },
            rules: {
            },
            arContentIdOptions: [],
            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 ? '/arContentChild/update' : '/arContentChild/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: '/arContentChild/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>
