<template>
    <div class="feedbackDetail">
        <el-form ref="form" label-width="80px">
            <el-form-item label="游戏名称:">
                <p>{{feedbackInfo.gameAlias}}</p>
            </el-form-item>

            <el-form-item label="联系方式:">
                <el-tag>{{contactType(feedbackInfo.userContactType)}}
                </el-tag> <p>{{feedbackInfo.userContact}}</p>
            </el-form-item>

            <el-form-item label="问题描述:">
                <p>{{feedbackInfo.content}}</p>
            </el-form-item>

            <el-form-item label="游戏截图:">
                <viewer :images="feedbackInfo.imageUrlList">
                    <img v-for="(src,index) in feedbackInfo.imageUrlList" :src="src" :key="index"
                         style="width: 100px; height: 100px" fill>
                </viewer>
            </el-form-item>

            <div class="">
                <el-button @click="handelReturn">返 回</el-button>
                <el-button type="primary" @click="handelComplete" v-show="feedbackInfo && feedbackInfo.state===0">完 成
                </el-button>
            </div>


        </el-form>
    </div>
</template>

<script>
    import feedbackApi from '@/api/feedback'

    export default {
        name: "feedbackDetail",
        data() {
            return {
                params: {},
                page:{},
                feedbackInfo: {},
                contactOption: [
                    {text: '微信', value: 0, inputType: 'text'},
                    {text: 'QQ', value: 1, inputType: 'number'},
                    {text: '手机号', value: 2, inputType: 'tel'},
                    {text: '邮箱', value: 3, inputType: 'email'}
                ],
            }
        },
        mounted() {
            this.params = this.$route.params.params;
            this.page = this.$route.params.page;
            this.feedbackInfo.id = this.$route.params.id;
            this.getFeedbackDetail()
        },
        methods: {
            getFeedbackDetail() {
                feedbackApi.getFeedbackById(this.feedbackInfo.id).then(res => {
                    this.feedbackInfo = res;
                    let imageUrls = this.feedbackInfo.imageUrl;
                    if (imageUrls && imageUrls.length) {
                        this.feedbackInfo.imageUrlList = imageUrls.split(',')
                    }
                    console.log(this.feedbackInfo);
                })
            },
            handelReturn() {
                this.$router.push({
                    name: 'feedbackList',
                    params: {
                        params: this.params,
                        page:this.page
                    }
                })
            },
            handelComplete() {
                this.$confirm('您确定已经完成该条反馈信息了吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    feedbackApi.updateFeedback({id: this.feedbackInfo.id, state: 1}).then(res => {
                        this.$message({
                            type: 'success',
                            message: '已完成!'
                        });
                        this.handelReturn()
                    });

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            },
            contactType(type) {
                return this.contactOption.find(f => f.value == type).text
            },
        }
    }
</script>

<style lang="less" scoped>
    .feedbackDetail {
        padding: 20px 20px 50px;
    }
</style>