<template>
    <div>
        <el-card class="box-card" style="margin-top:20px;">
            <el-container>
                <el-aside width="300px">
                    <el-form :model="formData" :rules="rules" ref="form" label-width="120px" label-position="right" size="small">
                        <el-form-item prop="remark1" label="标题">
                            <el-input v-model="formData.remark1"></el-input>
                        </el-form-item>
                        <el-form-item prop="remark2" label="内容">
                            <el-input v-model="formData.remark2"></el-input>
                        </el-form-item>
                        <el-form-item prop="remark3" label="语音">
                            <el-input v-model="formData.remark3"></el-input>
                        </el-form-item>
                        <el-form-item prop="remark4" label="按键内容">
                            <el-input v-model="formData.remark4"></el-input>
                        </el-form-item>
                        <el-form-item prop="remark5" label="图片">
                            <el-input v-model="formData.remark5"></el-input>
                        </el-form-item>
                        <el-form-item prop="remark6" label="下一个位置X">
                            <el-input v-model="formData.remark6" :disabled="'remark6'==subColumn"></el-input>
                        </el-form-item>
                        <el-form-item prop="remark7" label="下一个位置Y">
                            <el-input v-model="formData.remark7" :disabled="'remark7'==subColumn"></el-input>
                        </el-form-item>
                        <el-form-item prop="remark8" label="下一个位置Z">
                            <el-input v-model="formData.remark8" :disabled="'remark8'==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>

                </el-aside>
                <el-main>
                    <div class="boxmodle">
                        <div class="left">
                            讲解员{{ArContentTemplateStep2.remark3}}
                        </div>
                        <div class="right">
                            <div class="title">
                                {{formData.remark1}}
                            </div>
                            <div class="content">
                                {{formData.remark2}}
                            </div>
                            <div class="img">
                                {{formData.remark5}}
                            </div>

                            <div class="btn">
                                <el-button type="primary" size="mini" plain>{{formData.remark4||'无内容'}}</el-button>
                            </div>
                        </div>

                    </div>
                </el-main>
            </el-container>
            <el-row>
                <el-button type="primary" plain @click=" next();">跳过这一步</el-button>

            </el-row>
        </el-card>
    </div>
</template>
<script>
import formValidator from '../formValidator'

export default {
    name: 'ArContentTemplateStep4',
    props: {

    },

    created() {

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

                    if (res.data) {
                        this.formData = res.data;
                    }


                }
            })
        }

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


                }
            })
        }




        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: {
                // arContentId: 3,
                type: 3,
            },
            rules: {
            },
            arContentIdOptions: [],
            subColumn: '',
            subValue: '',
            ArContentTemplateStep2: {}
        }
    },
    methods: {
        onSave() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        next() {
            this.$emit('saveInfo', 1)
        },
        submit() {
            var data = JSON.parse(JSON.stringify(this.formData));
            data.arContentId = this.$route.query.arContentId
            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.formData = {
                    type: 3
                }

            }).catch(action => {
                if (action === 'cancel') {

                } else {
                    this.$message.error('删除失败');
                }
            })
        },
    }
}
</script>
<style lang="less" scoped>
.boxmodle {
    width: 700px;
    // height: 500px;
    border: 1px dashed #ccc;
    display: flex;
    padding: 20px 0;
    align-items: center;
    justify-content: center;
    .left {
        border: 1px dashed #ccc;
        width: 300px;
        height: 300px;
        margin-right: 20px;

        display: flex;
        justify-content: center;
        align-items: center;
    }
    .right {
        width: 350px;

        .title {
            text-align: center;
            line-height: 60px;
            height: 60px;
        }

        .content {
            height: 145px;
            border: 1px dashed #ccc;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .img {
            height: 145px;
            border: 1px dashed #ccc;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 10px;
        }

        .btn {
            height: 50px;
            margin-top: 10px;
            text-align: right;
        }
    }
}
</style>
