<template>
	<view class="examList-box">
        <view class="examList-import" @click.stop="ImportInformation">
            <van-icon name="plus" />
            <text>导入考试信息</text>
        </view>
		<view class="examList activeOne" v-for="(item,index) in dataList" :key="index">
            <view class="examList-center-box" @click="examDetails(item.ExamId)">
                <view class="examList-center-line"></view>
                <view class="examList-center flex">
                    <view class="examList-left">
                        <view class="examList-name">{{item.ExamName}}</view>
                        <view class="examList-state flex">
                            <van-icon name="clock-o" />
                            <view class="examList-state-text">{{item.CreateTime}}</view>
                        </view>
                    </view>
                    <view class="examList-right flex">
                        <view class="homework-score flex">
                            <view class="homework-score-title">人数</view>
                            <view class="homework-score-num flex">
                                {{item.StuNum}}
                            </view>
                        </view>
                        <view class="homework-score flex">
                            <view class="homework-score-title">平均得分</view>
                            <view class="homework-score-num flex">
                                {{item.AvgScore}}
                            </view>
                        </view>
                    </view>
                </view>
                <view class="examList-center-hint flex">
                   <view class="examList-hint-left flex">
                        <van-icon name="warning" />
                        <view>
                            导入失败(学员信息不匹配)可点击查看具体情况
                        </view>
                   </view>
                   <view class="examList-hint-right">
                       <view @click.stop="clickReimport(item)">重新导入</view>
                   </view>
                </view>
            </view>
            
        </view>
        <van-popup :show="show" :round="true">
            <view class="examList-popup-box">
                <van-icon class="examList-popup-closure" name="cross" @click="show=false"/>
                <view class="examList-popup-title">导入考试信息</view>
                <view class="examList-popup-content">
                    <input v-model="uploadParm.ExamName" class="examList-popup-name" placeholder="请输入考试名称">
                    <van-uploader
                    class="examList-popup-fil-box flex"
                    multiple
                    accept=".excel"
                    preview-size="120rpx"
                    @after-read="customUpload"
                    >
                    <view class="examList-popup-fil">
                       <van-image class="img" width="32rpx" height="32rpx" fit="cover"
				src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1653639041000_305.png" />
                    选择文件 
                    </view>
                    </van-uploader>
                </view>
            </view>
        </van-popup>
	</view>
</template>
<script>
	import {
		reactive,
		toRefs,
		onMounted,
		getCurrentInstance,
		inject
	} from "vue";
    import { uploadFile } from "@/utils/index";
	export default {
		props: {
			dataList:[]
		},
		components: {},
		setup(props) {
            let {
				proxy
			} = getCurrentInstance();
			let data = reactive({
				userData:{},//用户信息
				showPhone: false,
				showLogin: false, //多次点击
                show:false,
                uploadParm: {
                    // Uid:726615,
                    // CourseId:44977497,
                    Uid:0,
                    CourseId:0,
                    ExamName:'考试测试530'
                },
                fileList:[],
                Msg:{
                    PageIndex: 1,
                    PageSize: 10,
                    ExamName:''
                },
                dataList: props.dataList

			});
            let methods = {
                examDetails(item){
                    uni.reLaunch({
                        url: '/pages/index/examDetails?examId=' + item
					});
                },
                // 重新导入
                clickReimport(item){
                    data.uploadParm = {
                        Uid:item.ExamId,
                        CourseId:item.CourseId,
                        ExamName: item.ExamName
                    }
                },
                ImportInformation(){
                    data.show = true
                },
                uploadFilesBefore(){
                    
                },
                // 添加导入
                customUpload(event){
                    let host = ''
                    if (process.env.NODE_ENV === "development") {
                        host = 'http://192.168.10.36:8082/api'
                    } else {
                        host = 'https://eduapi.oytour.com/api'
                    }
                    const { file } = event.detail;
                    
                    if(file[0].url.indexOf('xls')==-1||file[0].url.indexOf('xlsx')==-1){
                        uni.showToast({
                            title:'请上传xls、xlsx格式的文件',
                            icon:'none',
	                        duration: 500
                        })
                        return
                    }
					
                    uni.uploadFile({
                        url: host + '/Upload/UploadStuExamScore',
                        filePath: file[0].url,
                        name: 'file',
                        formData: {
							myfile:file[0],
							params:JSON.stringify(data.uploadParm)
						},
                        success(res) {
                            uni.hideLoading();
                            uni.showToast({
                                title: res.Code ==1?'导入成功': '导入失败',
                                icon:'none',
                                duration: 500
                            })
                        },
                        fail(err) {
                            console.log("uploadErr", err)
                        }
	                });
                    // uploadFile(params, file, (res) => {
                    //     uni.showModal({
                    //         title:res.Message
                    //     })
                    // });
                    // return
                    
                }
            };
			let that = methods;
			return {
				...toRefs(data),
                ...methods
			};
		},
        onLoad(){
            
        },
        onShow() {
            
		}
	};
</script>
<style scoped>
    .examList-hint-right view{
        padding: 16rpx 30rpx;
        background: #C91727;
        border-radius: 50rpx;
        color: #FFFFFF;
        font-size: 24rpx;
        font-weight: bold;
        letter-spacing: 1rpx;
    }
    .examList-hint-right{
        flex-shrink: 0;
        margin-left: 50rpx;
    }
    .examList-hint-left view{
        background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1653648241000_545.png')no-repeat center;
        background-size: 100% 100%;
        padding: 11rpx 0 11rpx 30rpx;
    }
    .examList-hint-left van-icon{
        font-size: 42rpx;
        margin-right: 10rpx;
    }
    .examList-hint-left{
        font-size: 22rpx;
        color: #C91727;
        letter-spacing: 1rpx; 
        align-items: center;
    }
    .examList-center-hint{
        justify-content: space-between;
        padding: 10rpx 0;
        border-top: 1rpx solid #F6F6F6;
        align-items: center;
    }
    .img {
        display: inline-block;
        position: relative;
        top: 6rpx;
        margin-right: 10rpx;
    }
    .examList-popup-fil{
        
    }
    .examList-popup-fil-box{
        display: flex;
        line-height: 88rpx;
        padding: 0 197rpx;
        border-radius: 44rpx;
        font-size: 30rpx;
        color: #FFFFFF;
        background: #C91727;
        margin-top: 27rpx;
        text-align: center;
    }
    .examList-popup-name{
        background-color: #FFFFFF;
        text-align: center;
        border: 1px solid #AAAAAA;
        height: 86rpx;
        line-height: 86rpx;
        padding: 0 10rpx;
        border-radius: 44rpx;
        font-size: 30rpx;
    }
    .examList-popup-title{
        width: 100%;
        text-align: center;
        font-size: 30rpx;
        font-weight: 500;
        margin-bottom: 73rpx;
        letter-spacing: 1rpx;
    }
    .examList-popup-closure{
        position: absolute;
        right: 31rpx;
        top: 31rpx;
        color: #282828;
        font-size: 38rpx;
    }
    .examList-popup-box{
        position: relative;
        width: 548rpx;
        padding: 48rpx 55rpx 98rpx 55rpx;
    }
    .homework-score-num view:last-child{
        font-size: 23rpx;
        margin-top: 25rpx;
    }
    .homework-score-num view:first-child{
        margin-right: 10rpx;
        font-size: 46rpx;
        font-weight: 800;
    }
    .homework-score-num{
        font-weight: 800;
        font-style: italic;
        font-size: 36rpx;
    }
    .homework-score-title{
        font-size: 20rpx;
        margin-bottom: 0rpx;
        font-weight: 400;
        letter-spacing: 1px;
        margin-bottom: 15rpx;
    }
    .homework-score:last-child{
        margin-right: 0rpx;
    }
    .homework-score{
        margin-right: 16rpx;
        flex-direction: column;
        justify-content: center;
    }
    .examList-right{
        height: 122rpx;
        background: #FCEEEF;
        padding: 23rpx 37rpx 15rpx 37rpx;
        border-radius: 30rpx;
        justify-content: space-between;
        flex-shrink: 0;
        margin-left: 11rpx;
        color: #CE8086;
    }
    .examList.activeOne .examList-state-text{
        color: #BEBEBE;
    }
    .examList-state-text{
        font-size: 20rpx;
        letter-spacing: 2px;
    }
    .examList-state van-icon{
        color: #DADADA;
        font-size: 24rpx;
        margin-right: 10rpx;
    }
    .examList-state{
        margin-top: 35rpx;
        font-size: 20rpx;
    }
    .examList.activeOne .examList-name{
        color: #282828;
    }
    .examList-name{
        height: 70rpx;
        font-size: 26rpx;
        word-break: break-all;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        margin-top: 9rpx;
        letter-spacing: 1px;
        font-weight: bold;
    }
    .examList-left{
        flex-grow: 1;
    }
    .examList-center{
        justify-content: space-between;
        padding: 0 0 20rpx 0;
    }
    .examList-center-line{
        width: 4rpx;
        height: 23rpx;
        background: #282828;
        position: absolute;
        left: 0;
        top: 46rpx;
    }
    .examList.activeOne .examList-center-box{
        background: #FFFFFF; 
    }
    .examList-center-box{
        flex-grow: 1;
        position: relative;
        border-radius: 30rpx;
        padding: 31rpx 40rpx 0 22rpx;
        margin-bottom: 50rpx;
        box-shadow: 0px 6px 29px 0px rgba(76, 76, 76, 0.09);
        border-radius: 30px;
    }
	.examList{
        margin: 0 50rpx;
    }
    .examList-import text{
        margin-left: 15rpx;
    }
    .examList-import{
        width: 247rpx;
        border: 1rpx solid #F2A1A8;
        background: #FFFFFF;
        line-height: 54rpx;
        padding: 0 38rpx;
        margin: auto;
        margin-bottom: 48rpx;
        border-radius: 50rpx;
        color: #F2A1A8;
        font-size: 24rpx;
        text-align: center;
    }
    .examList-box{
        
    }
</style>
