<style lang="less" scoped>
.uploadEvaluation{
    width: 300px;
    float: left;
}
</style>
<template>
    <div>
        <div id="uploadEvaluation" class="uploadEvaluation">
            <label>學校編碼: {{ code }}</label>
            <Input placeholder="評測ID" v-model="id"></Input>
            <Upload action="" :before-upload="handleBeforeUpload" accept=".json" :show-upload-list="false">
                <Icon type="ios-folder" color="#606060" size="200" style="margin-top:60px;cursor:pointer;" @click="openUploadFile" />
            </Upload>
            <Button @click="send()">發送</Button>
        </div>
        <div style="width: 600px; height: 600px;float: left;overflow: auto;">
            <pre style="background-color: aliceblue;">
                {{ classResult }}
            </pre>
        </div>
  </div>
</template>

<script>
import { post } from '@/api/http'
	


export default {
  data() {
    return {
      file: null,
      code: this.$store.state.user.schoolCode,
      id: '',
      classResult: ''
    }
  },
  computed: {
  },
  methods: {
    initUpload() {
        this.file = null
    },
    openUploadFile() {
        this.initUpload()
    },
    handleBeforeUpload(file) {
        const fileExt = file.name.split('.').pop().toLocaleLowerCase()
        if (fileExt === 'json') {
            this.readFile(file)
            this.file = file
        } else {
            this.$Notice.warning({
                title: this.$t('stuAccount.importTips5'),
                desc: this.$t('stuAccount.importTips6') + file.name + this.$t('stuAccount.importTips7')
            })
        }
        return false
    },
    // 读取文件
    readFile(file) {
        var fReader = new FileReader()
        let _this = this
        fReader.onload = function (e) {
            console.log(JSON.parse(e.target.result))
            _this.classResult = JSON.parse(e.target.result)
        }
        fReader.readAsText(file);
    },
    send(){
        post('/analysis/importResult', {
            code: this.$store.state.user.schoolCode,
            id: this.id,
            classResult: this.classResult['classResult']
        }).then(res => {
            console.log(res, 'res')
        }, err => {
            console.log(err, 'err')
        })
    }
  }
}
</script>
