<template>
    <div class="box">
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card shadow="hover" class="mgb20">
                    <div class="flex-between">
                        <div class="per_title" v-preventReClick @click="goback()">
                            <i class="el-icon-arrow-left"></i>
                            <span class="per_back">返回</span>
                            <span class="per_school">修改分数</span>
                        </div>
                        <div>
                            <el-button type="success" size="small" round class="mag" v-preventReClick @click="saveAdd('form')">预览</el-button>
                            <el-button type="primary" size="small" round class="mag" v-preventReClick @click="saveAdd('form')">发布成绩</el-button>
                        </div>
                    </div>              
                </el-card>

                <div id="wrap">
                    <h6 style="text-align: center;font-size: 20px">实验成绩报告</h6>
                    <div class="flex-center mgb20 user_header">
                        <p class="addhr_tag"></p>
                        <span>基本信息</span>
                    </div>

                    <div>
                        <el-table :data="infoData" class="info-table" style="margin-bottom: 40px" header-align="center">
                            <el-table-column prop="userName" label="学生姓名" align="center">
                            </el-table-column>
                            <el-table-column prop="workNumber" label="学生学号" align="center">
                            </el-table-column>
                            <el-table-column prop="className" label="学生班级" align="center">
                            </el-table-column>
                            <el-table-column prop="teacherName" label="指导老师" align="center">
                            </el-table-column>
                            <el-table-column prop="period" label="实验学时" align="center">
                            </el-table-column>
                            <el-table-column prop="laboratory" label="实验室名称" align="center">
                            </el-table-column>
                            <el-table-column prop="startTime" label="实验时间" align="center">
                            </el-table-column>
                            <el-table-column prop="score" label="实验成绩" align="center">
                            </el-table-column>
                        </el-table>
                    </div>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 实验项目名称</p>
                    </div>
                    <el-input v-model="form.projectName" type="textarea" rows="5" disabled></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 实验目的</p>
                    </div>
                    <el-input v-model="form.purpose" type="textarea" rows="5" disabled></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 实验原理</p>
                    </div>
                    <el-input v-model="form.principle" type="textarea" rows="5" disabled></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 实验器材（设备、元器件）</p>
                    </div>
                    <el-input v-model="form.equipment" type="textarea" rows="5" disabled></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 实验步骤</p>
                    </div>
                    <el-input v-model="form.step" type="textarea" rows="5" disabled></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title">实验数据</p>
                        <!-- <span>得分：50/60</span> -->
                    </div>
                    <el-table :data="sjData" class="table" stripe header-align="center">
                        <el-table-column type="index" width="100" label="序号" align="center">
                            <template slot-scope="scope">
                                {{scope.$index + 1}}
                            </template>
                        </el-table-column>
                        <el-table-column prop="judgmentPointsName" label="考核点" align="center">
                        </el-table-column>
                        <el-table-column prop="StudentAnswers" label="学生答案" align="center">
                        </el-table-column>
                        <el-table-column prop="ReferenceAnswer" label="参考答案" align="center">
                        </el-table-column>
                        <el-table-column prop="score" label="得分" align="center">
                        </el-table-column>
                    </el-table>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 实验数据及结果分析</p>
                    </div>
                    <el-table :data="expData" stripe header-align="center" class="mat20">
                        <el-table-column type="index" width="100" label="序号" align="center"></el-table-column>
                        <el-table-column prop="ename" label="代码" align="center"></el-table-column>
                        <el-table-column prop="name" label="合约名称" align="center"></el-table-column>
                        <el-table-column prop="tradingDirection" label="方向(买/卖)" align="center"></el-table-column>
                        <el-table-column prop="entrustNumber" label="持仓/可用" align="center"></el-table-column>
                        <el-table-column prop="entrustPrice" label="均价/现价" align="center"></el-table-column>
                        <el-table-column prop="floatingPl" label="浮动盈亏" align="center"></el-table-column>
                        <el-table-column prop="preFreezingMargin" label="保证金" align="center"></el-table-column>
                        <el-table-column prop="tradeTime" label="最后交易日" align="center"></el-table-column>
                        <el-table-column prop="status" label="持仓状态" align="center"></el-table-column>
                        <el-table-column prop="createTime" label="开仓时间" align="center"></el-table-column>
                        <el-table-column prop="updateTime" label="平仓时间" align="center"></el-table-column>
                    </el-table>
                    <el-input style="margin-top: 20px" v-model="form.analysis" type="textarea" rows="5" disabled></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 实验结论</p>
                    </div>
                    <el-input type="textarea" v-model="form.conclusion" rows="5"></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 总结及心得体会</p>
                    </div>
                    <el-input type="textarea" v-model="form.summarize" rows="5"></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 对本实验过程及方法、手段的改进建议</p>
                    </div>
                    <el-input type="textarea" rows="5" v-model="form.improvement"></el-input>
                </div>

                <div class="mgb20">
                    <div class="meta-title-wrap">
                        <p class="meta-title"><i class="el-icon-discount"></i> 老师评语</p>
                    </div>
                    <el-input type="textarea" rows="5" v-model="form.comment"></el-input>
                </div>

                <el-card shadow="hover" class="mgb20">
                    <p class="mgb20">教师签名</p>
                    <div class="mgb20">
                        <el-radio v-model="autograph" label="1">不使用</el-radio>
                        <el-radio v-model="autograph" label="2">已有签名</el-radio>
                        <el-radio v-model="autograph" label="3">重新上传</el-radio>
                    </div>
                    <el-row>
                        <el-col :span="6">
                            <template v-if="autograph == 2">
                                <el-select v-model="signId" placeholder="请选择签名" size="mini" @change="signChange">
                                    <el-option
                                    v-for="item in signList"
                                    :key="item.id"
                                    :label="item.signatureName"
                                    :value="item.id"
                                    >
                                    </el-option>
                                </el-select>
                                <img class="sign-img" :src="signSrc" alt="">
                                <div>
                                    <el-button size="mini" type="danger" @click="delSign">删除</el-button>
                                </div>
                            </template>
                            <template v-else-if="autograph == 3">
                                <el-upload
                                :data="{userId: userId}"
                                :limit="1"
                                :action="api.uploadSignature"
                                list-type="picture-card"
                                :on-remove="handleRemove"
                                :on-exceed="handleExceed"
                                :on-success="uploadSuccess">
                                <i class="el-icon-plus"></i>
                                </el-upload>
                            </template>
                        </el-col>
                    </el-row>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    export default {
        data (){
            return {
                userId: this.$store.state.userLoginId,
                stuId: this.$route.query.stuId,
                studentName: this.$route.query.studentName,
                class: this.$route.query.class,
                id: this.$route.query.id,
                infoData: [],
                accountData: [],
                analysisContent: '',
                showData: '1',
                autograph: '1',
                form: {
                    projectName: '',
                    period: '',
                    userName: '',
                    content: '',
                    conclusion: '',
                    score: '',
                },
                pages: 1,
                ipVisible: false,
                configId : this.$store.state.configId,
                keyword: '',
                fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}],
                isEdit: false,
                signList: [],
                signId: '',
                sjData: [],
                expData: []
            }
        },
        mounted(){
            this.getData()
            this.getSgin()
        },
        methods: {
            getData(){
                let data = {
                    reportId: this.id,
                    userId: this.stuId,
                }
                this.$get(this.api.getReport,data).then(res => {
                    let report = res.data.experimentalReportEntity
                    let steps = []
                    for(let i in report){
                        if(i.includes('steps') && report[i]) steps.push(JSON.parse(report[i]))
                    }
                    this.form = report
                    this.expData = report.steps9 ? JSON.parse(report.steps9).recordsData: []

                    let score = res.data.score
                    let answerList = []
                    for(let i in res.data.userAnswersList){
                        answerList = answerList.concat(res.data.userAnswersList[i])
                    }
                    let sjData = []
                    answerList.map(n => {
                        if(n.type == 1){
                            this.$post(this.api.queryItem,n.levelThree)
                            .then((res) => {
                                n.levelFour = res.subject.find(e => e.id == n.levelFour).itemDescription
                                console.log(11,n)
                            }).catch((err) => {})
                        }
                    })
                    setTimeout(() => {
                        score.map(n => {
                            let item = answerList.find(e => e.tradingJudgmentPointsId == n.tradingJudgmentPointsId)
                            sjData.push({
                                judgmentPointsName: item.judgmentPointsName,
                                userAnswers: n.userAnswers,
                                referenceAnswer: item.levelFour,
                                score: n.score
                            })
                        })
                    },500)

                    this.sjData = sjData
                    this.infoData.push({
                        workNumber: report.workNumber,
                        className: this.class != 'undefined' ? this.class : '',
                        teacherName: report.teacherName,
                        period: report.period,
                        laboratory: report.laboratory,
                        startTime: report.creationTime,
                        score: report.score,
                        userName: this.studentName
                    })
                }).catch(res => {})
            },
            getSgin(){
                let data = {
                    userId: this.userId
                }
                this.$get(this.api.querySignature,data).then(res => {
                    this.signList = res.data
                    this.signId = res.data[0].id
                    this.signSrc = res.data[0].signatureUrl
                }).catch(res => {})
            },
            signChange(){
                this.signSrc = this.signList.find(n => n.id == this.signId).signatureUrl
                console.log(22,this.signSrc)
            },
            delSign(){
                let data = {
                    id: this.signId
                }
                this.$post(this.api.daleteSignature,data).then(res => {
                    this.$message.success('删除成功')
                    this.getSgin()
                }).catch(res => {})
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            saveAdd(){
                let data = {
                    systemId: this.configId,
                    systemName: this.form.systemName,
                    systemType: this.form.systemType,
                    systemAttribution: this.form.systemAttribution,
                }
                if(this.configId){
                    this.$post(this.api.updateServiceConfig,data).then((res) => {
                            this.$message.success('编辑成功');
                            this.$router.back()
                        }).catch((res) => {
                    })
                }else{
                    this.$post(this.api.updateServiceConfig,data).then((res) => {
                            this.$message.success('添加成功');
                            this.$router.back()
                        }).catch((res) => {
                    })
                }
            },
            editMsg(){
                this.isEdit = true
            },
            handleExceed(files, fileList) {
                this.$message.warning(
                    `当前限制选择 1 个文件，如需更换，请删除上一个文件再重新选择！` 
                );
            },
            uploadSuccess(res,file){
                if(res.status == 200){
                    this.$message.success('上传成功')
                    this.getSgin()
                }else{
                    this.$message.error(res.errmessage)
                }
            },
            goback() {
                this.$confirm('确定返回？未更新的信息将不会保存。', '提示', {
                    type: 'warning'
                })
                .then(() => {
                    this.$router.back()
                })
                .catch(() => {});
            }
        }
    }
</script>

<style lang="scss" scoped>
    .box{
        padding: 0 50px;
        background-color: #fff;
    }
    /deep/.el-textarea.is-disabled .el-textarea__inner{
        background-color: #ebfafd;
    }
    #wrap{
        /deep/.info-table{
        border: 0;
        th{
            background-color: #fff !important;
            .cell{
                color: #444;
            }
        }
        tr{
            border: 0;
        }
        tr:hover,tr:hover>td{
            background-color: #c6f2f8 !important;
        }
        td{
            border: {
                left: 4px solid #fff;
                right: 4px solid #fff;
            }
            &:first-child{
                border-left: 0;
            }
            &:last-child{
                border-right: 0;
            }
            background-color: #c6f2f8;
            border-bottom: 0;
        }
        }
        /deep/.table th{
            background-color: #a2a2a2 !important;
        }
    }
    
    /deep/.cell{
        font-size: 12px;
    }
    /deep/.el-row{
        padding-top: 20px;
        margin: 0 !important;
    }
    .form-item{
        display: flex;
        align-items: center;
    }
    .form-item .el-input{
        width: auto;
    }
    .form-item span{
        margin-right: 10px;
    }
    .meta-title-wrap{
        display: flex;
        justify-content: space-between;
        align-items: center;
        span{
            font-size: 13px;
            color: #444;
        }
    }
    .flex-between{
        span{
            font-size: 13px;
            color: #444;
        }
    }
    .meta-title{
        display: flex;
        align-items: center;
        padding: 10px 20px;
        margin-bottom: 10px;
        font-size: 16px;
        color: #fff;
        background-color: #9278FF;
        i{
            margin-right: 10px;
        }
    }
    .step-title{
        margin-bottom: 10px;
        font-size: 16px;
        color: #9278ff;
    }
    .bd-title{
        padding-top: 20px;
        border-top: 1px dashed #ccc;
    }
    .sign-img{
        max-width: 200px;
        margin-top: 10px;
    }
</style>