<template>
    <div>
        <a-modal :visible="visible" @ok="handOK" :confirmLoading="confirmLoading" @cancel="handCancle" width="900px"
            :maskClosable="false" :destroyOnClose="true">
            <template slot="title">
                下载
            </template>
            <div class="modal-box" style="padding:0">
                <a-form :form="form" @submit="handOK" layout="horizontal">
                    <a-form-item label="文件类型：" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
                        <a-radio-group style="display: flex;flex-direction: column;" v-decorator="['id',{rules: [{ required: true, message: '请选择下载的文件类型!' }]
                }]">
                            <a-radio v-if="record.fileId" :value="'fileId'">试卷文件</a-radio>
                            <a-radio v-if="record.fullPaperFileId" :value="'fullPaperFileId'">试卷包含答案解析文件</a-radio>
                            <a-radio v-if="record.answerFileId" :value="'answerFileId'">试卷答案解析</a-radio>
                            <a-radio v-if="record.answerSheetFileId" :value="'answerSheetFileId'">答题卡</a-radio>
                        </a-radio-group>
                    </a-form-item>
                </a-form>
            </div>
        </a-modal>
    </div>
</template>
<script>
    import { FileReadFile } from '@/api/api'
    import { download } from '@/utils/tools'
    export default {
        data() {
            return {
                confirmLoading: false,
                visible: false,
                form: this.$form.createForm(this),
                record: {}
            };
        },
        mounted() {

        },
        methods: {
            showModal(record) {
                this.record = record;
                this.visible = true;
            },
            //表单确认
            handOK(e) {
                e.preventDefault();
                this.form.validateFields((err, values) => {
                    if (!err) {
                        this.confirmLoading = true;
                        console.log(values, 'values')
                        let data = {
                            id: this.record[values.id]
                        }
                        console.log(data, 'data')
                        FileReadFile(data).then(res => {
                            download(res)
                            this.confirmLoading = false;
                            this.handCancle();
                        }).catch(err => {
                            this.confirmLoading = true;
                        })

                    }
                })
            },
            handCancle() {
                this.visible = false;
            }
        },
    };
</script>
<style scoped>
    .ant-radio-wrapper {
        margin-top: 10px;
    }
</style>