<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
			<el-form-item label="试卷名称" prop="PaperName">
				<el-input v-model="queryParams.PaperName" placeholder="请输入试卷名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="组卷方式" prop="ProduceWay">
				<el-select v-model="queryParams.ProduceWay" placeholder="请选择组卷方式" clearable>
					<el-option v-for="dict in dict.type.jxjy_ks_ctfs" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
					v-hasPermi="['system:PaperInfo:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
					v-hasPermi="['system:PaperInfo:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
					@click="handleDelete" v-hasPermi="['system:PaperInfo:remove']">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
					v-hasPermi="['system:PaperInfo:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="PaperInfoList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column align="center" label="序号" type="index" />
			<el-table-column label="试卷名称" align="center" prop="PaperName" width="600px" />
			<el-table-column label="出题方式" align="center" prop="ProduceWay">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.jxjy_ks_ctfs" :value="scope.row.ProduceWay" />
				</template>
			</el-table-column>
			<el-table-column label="试题数量" align="center" prop="TestCount" />
			<el-table-column label="试卷总分" align="center" prop="PaperMark" />
			<el-table-column label="创建日期" align="center" prop="CreateDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						>修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-view" @click="yvlan(scope.row)"
						 >预览</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						>删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />

		<!-- 添加或修改试卷对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="60vw" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="120px">
				<el-row :gutter="20">
					<el-col :span="24">
						<div style="font-weight: bold;padding: 10px;text-align: center;background-color: #67C23A;margin: 20px 0;">
							试卷基本设置
						</div>
					</el-col>
					<el-col :span="24">
						<el-form-item label="试卷名称：" prop="PaperName">
							<el-input v-model="form.PaperName" placeholder="请输入试卷名称" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="试卷类型：" prop="PaperType">
							<el-select v-model="form.PaperType" placeholder="请选择试卷类型 ">
								<el-option v-for="dict in dict.type.jxjy_ks_sjlx" :key="dict.value" :label="dict.label"
									:value="parseInt(dict.value)"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="出题方式：" prop="ProduceWay">
							<el-select v-model="form.ProduceWay" placeholder="请选择出题方式">
								<el-option v-for="dict in dict.type.jxjy_ks_ctfs" :key="dict.value" :label="dict.label"
									:value="parseInt(dict.value)"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="显示模式" prop="ShowModal">
							<el-select v-model="form.ShowModal" placeholder="请选择显示模式">
								<el-option v-for="dict in dict.type.jxjy_ks_xsms" :key="dict.value" :label="dict.label"
									:value="parseInt(dict.value)"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="答题时间" prop="ExamTime">
							<el-input v-model="form.ExamTime" placeholder="请输入答题时间" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="试卷总分" prop="PaperMark">
							<el-input v-model="form.PaperMark" placeholder="请输入试卷总分" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="通过分数" prop="PassMark">
							<el-input v-model="form.PassMark" placeholder="请输入通过分数" />
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="分数定义" prop="MarkDefine">
							<!-- <el-select v-model="form.MarkDefine" placeholder="请选择分数定义">
								<el-option label="忽略题库中试题分数，按题型指定分数折算" value="2"></el-option>
								<el-option label="使用题库中试题分数，将总分折算为试卷总分" value="1"></el-option>
							</el-select> -->
							<el-radio-group v-model="form.MarkDefine">
								<el-radio value="2" :label="2">忽略题库中试题分数，按题型指定分数折算</el-radio>
								<el-radio value="1"  :label="1">使用题库中试题分数，将总分折算为试卷总分</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<div style="font-weight: bold;padding: 10px;text-align: center;background-color: #67C23A;margin: 20px 0;">
							试卷选项
						</div>
					</el-col>
					<el-col :span="8">
						<el-form-item label="多次考试" prop="RepeatExam">
							<!-- <el-select v-model="form.RepeatExam" placeholder="请选择允许多次考"> -->

							<el-radio-group v-model="form.RepeatExam">
								<el-radio v-for="dict in dict.type.jxjy_sf" :key="dict.value" :label="parseInt(dict.value)"
									:value="dict.value">{{dict.label}}</el-radio>
							</el-radio-group>
							<!-- </el-select> -->
						</el-form-item>
					</el-col>
					<el-col :span="8" v-if="form.RepeatExam == 1">
						<el-form-item label="最多考试次数" prop="RepeatExamNum">
							<el-input v-model="form.RepeatExamNum" placeholder="请输入最多考试次数" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="查看考试结果" prop="SeeResult"> 
							<el-radio-group v-model="form.SeeResult">
								<el-radio v-for="dict in dict.type.jxjy_sf" :key="dict.value" :label="parseInt(dict.value)"
									:value="dict.value">{{dict.label}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="自动保存" prop="AutoSave">
							<div style="display: flex;align-items: center;">
								<el-input v-model="form.AutoSave" placeholder="请输入时间" style="width: 100px;" />分钟
								<span style="color: #F56C6C;margin-left: 10px;">
									注：0分钟不进行自动保存
								</span>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="多选给分规则" prop="MultipleRule">
							<el-radio-group v-model="form.MultipleRule">
								<el-radio v-for="dict in dict.type.jxjy_ks_dxgfgz" :key="dict.value"
									:label="parseInt(dict.value)">{{dict.label}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<div style="font-weight: bold;padding: 10px;text-align: center;background-color: #67C23A;margin: 20px 0;">
							试题策略<el-button size="mini" style="margin-left: 20px;" @click="addCelue">添加策略</el-button>
						</div>
					</el-col>
					<el-col :span="24">
						<el-table :data="form.paperPolicy" border style="width: 100%">
							<el-table-column label="培训类别" >
								<template slot-scope="scope">
									<dict-tag :options="dict.type.jxjy_zhuanye" :value="scope.row.SubjectID" />
								</template>
							</el-table-column>
							<el-table-column prop="name" label="专业" >
								<template slot-scope="scope">
									<dict-tag :options="dict.type.jxjy_ks_pxzy" :value="scope.row.LoreID" />
								</template>
							</el-table-column>
							<el-table-column prop="address" label="题型名称">
								<template slot-scope="scope">
									<dict-tag :options="dict.type.jxjy_ks_tx" :value="scope.row.TestTypeID" />
								</template>
							</el-table-column>
							<el-table-column prop="TestDiff1" label="易">
							</el-table-column>
							<el-table-column prop="TestDiff2" label="较易">
							</el-table-column>
							<el-table-column prop="TestDiff3" label="中等">
							</el-table-column>
							<el-table-column prop="TestDiff4" label="较难">
							</el-table-column>
							<el-table-column prop="TestDiff5" label="难">
							</el-table-column>
							<el-table-column prop="address" label="操作">
								<template slot-scope="scope">
									<el-button size="mini" type="text" icon="el-icon-edit" @click="xiugai(scope.row,scope.$index)" >修改</el-button>
									<el-button size="mini" type="text" icon="el-icon-delete" @click="shanchu(scope.row,scope.$index)" >删除</el-button>
								</template>
							</el-table-column>
						</el-table>
					</el-col>
					<el-col :span="24">
						<div style="font-weight: bold;padding: 10px;text-align: center;background-color: #67C23A;margin: 20px 0;">
							题型标题
						</div>
					</el-col>
					<el-col :span="24">
						<el-table :data="form.paperTestType" border style="width: 100%">
							<el-table-column prop="address" label="题型名称">
								<template slot-scope="scope">
									<dict-tag :options="dict.type.jxjy_ks_tx" :value="scope.row.TestTypeID" />
								</template>
							</el-table-column>
							<el-table-column prop="address" label="题型标题">
								<template slot-scope="scope">
									<el-form-item label-width="0" :prop="'paperTestType.'+ scope.$index +'.TestTypeTitle'" :rules="{required: true,message: '请填写题型标题',trigger: ['blur', 'change']}">
										<el-input v-model="scope.row.TestTypeTitle" placeholder="请输入通过分数" />
									</el-form-item>
								</template>
							</el-table-column>
							<el-table-column prop="TestDiff1" label="每题分数">
								<template slot-scope="scope">
									<el-form-item label-width="0" :prop="'paperTestType.'+scope.$index+'.TestTypeMark'" :rules="{required: true,message: '请填写每题分数',trigger: ['blur', 'change']}">
										<el-input v-model="scope.row.TestTypeMark" placeholder="请输入通过分数" />
									</el-form-item>
								</template>
							</el-table-column>
							<el-table-column prop="TestAmount" label="题量">
							</el-table-column>
							<el-table-column prop="address" label="顺序">
								<template slot-scope="scope">
									<el-button size="mini" type="text" icon="el-icon-top" @click="moveUp(scope.$index)"
										>上移</el-button>
									<el-button size="mini" type="text" icon="el-icon-bottom" @click="moveDown(scope.$index)"
										>下移</el-button>
								</template>
							</el-table-column>
						</el-table>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
		<el-dialog title="提示" :visible.sync="clShow" width="50vw">
			<div>
				<el-form ref="clForm" :model="clForm" :rules="clRules" label-width="80px">
					<el-row :gutter="10">
						<el-col :span="24">
							<div style="font-weight: bold;text-align: center;margin-bottom: 20px;">
								添加随机策略
							</div>
						</el-col>
						<el-col :span="8">
							<el-form-item label="培训类别" prop="SubjectID">
								<el-select v-model="clForm.SubjectID" disabled >
									<el-option v-for="dict in dict.type.jxjy_zhuanye" :key="dict.value" :label="dict.label"
										:value="parseInt(dict.value)"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item label="专业" prop="LoreID">
								<el-select v-model="clForm.LoreID"  @change="searchNum">
									<el-option v-for="dict in dict.type.jxjy_ks_pxzy" :key="dict.value" :label="dict.label"
										:value="parseInt(dict.value)"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item label="题型名称" prop="TestTypeID">
								<el-select v-model="clForm.TestTypeID"   @change="searchNum">
									<el-option v-for="dict in dict.type.jxjy_ks_tx" :key="dict.value" :label="dict.label"
										:value="parseInt(dict.value)"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="4">
							<el-form-item label="试题总数" prop="total">
								<el-input v-model.number="clForm.total"  />
							</el-form-item>
						</el-col>
						<el-col :span="4">
							<el-form-item label="易" label-width="40px" prop="TestDiff1">
								<el-input v-model.number="clForm.TestDiff1" style="width: 60%;" /> /{{stNumList.TestDiff1}}
							</el-form-item>
						</el-col>
						<el-col :span="4">
							<el-form-item label="较易" label-width="50px" prop="TestDiff2">
								<el-input v-model.number="clForm.TestDiff2" style="width: 60%;" /> /{{stNumList.TestDiff2}}
							</el-form-item>
						</el-col>
						<el-col :span="4">
							<el-form-item label="中等" label-width="50px" prop="TestDiff3">
								<el-input v-model.number="clForm.TestDiff3" style="width: 60%;" /> /{{stNumList.TestDiff3}}
							</el-form-item>
						</el-col>
						<el-col :span="4">
							<el-form-item label="较难" label-width="50px" prop="TestDiff4">
								<el-input v-model.number="clForm.TestDiff4" style="width: 60%;" /> /{{stNumList.TestDiff4}}
							</el-form-item>
						</el-col>
						<el-col :span="4"> 
							<el-form-item label="难" label-width="40px" prop="TestDiff5">
								<el-input v-model.number="clForm.TestDiff5" style="width: 60%;" /> /{{stNumList.TestDiff5}}
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="clConfiem">确 定</el-button>
				<el-button @click="dialogVisible = false">取 消</el-button>
			</span>
		</el-dialog>
		<el-dialog title="试卷预览" :visible.sync="yvlanShow" fullscreen>
		  <yvlanSj :content="sjInfo" :title="sjTitle"></yvlanSj>
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="yvlanShow = false">关闭</el-button>
		  </span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listPaperInfo,
		getPaperInfo,
		delPaperInfo,
		addPaperInfo,
		updatePaperInfo,
		delCl,
		searchClNum,
		previewSj
	} from "@/api/xiehui/jxjy/PaperInfo";
	import yvlanSj from "../../../components/shijuan/yvlanSj.vue"
	
	export default {
		name: "PaperInfo",
		dicts: ['jxjy_ks_ctfs', 'jxjy_ks_sjlx', 'jxjy_sf', 'jxjy_ks_dxgfgz', 'jxjy_ks_xsms','jxjy_ks_tx','jxjy_ks_pxzy','jxjy_zhuanye'],
		components:{
			yvlanSj
		},
		data() {
			var validateNum = (rule, value, callback) => {
				if(value == 0){
					callback();
				}else if(value / this.stNumList[rule.field] > 1){
					return callback(new Error('不能超过题库数量'));
				}else{
					callback();
				}
				// if (!value) {
				// 	return callback(new Error('年龄不能为空'));
				// }
			};
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 试卷表格数据
				PaperInfoList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					PaperName: null,
					PaperType: null,
					ProduceWay: null,
					ShowModal: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					PaperName:{
						required: true,
						message: '请输入试卷名称',
						trigger: ['blur', 'change']
					},
					ProduceWay:{
						required: true,
						message: '请选择出题方式',
						trigger: ['blur', 'change']
					},
					ShowModal:{
						required: true,
						message: '请选择显示模式',
						trigger: ['blur', 'change']
					},
					ExamTime:{
						required: true,
						message: '请输入答题时间',
						trigger: ['blur', 'change']
					},
					PaperMark:{
						required: true,
						message: '请输入试卷总分',
						trigger: ['blur', 'change']
					},
					PassMark:{
						required: true,
						message: '请输入通过分数',
						trigger: ['blur', 'change']
					},
					MarkDefine:{
						required: true,
						message: '请选择分数定义',
						trigger: ['blur', 'change']
					},
					RepeatExam:{
						required: true,
						message: '请选择是否多次考试',
						trigger: ['blur', 'change']
					},
					RepeatExamNum:{
						required: true,
						message: '请输入最多考试次数',
						trigger: ['blur', 'change']
					},
					SeeResult:{
						required: true,
						message: '请选择是否查看考试结果',
						trigger: ['blur', 'change']
					},
					AutoSave:{
						required: true,
						message: '请输入自动保存时间',
						trigger: ['blur', 'change']
					},
					MultipleRule:{
						required: true,
						message: '请选择多选给分规则',
						trigger: ['blur', 'change']
					}
					
				},
				//试题策略表单
				clForm:{},
				clShow:false,
				clRules:{
					LoreID:{
						required: true,
						message: '请选择专业',
						trigger: ['blur', 'change']
					},
					TestTypeID:{
						required: true,
						message: '请选择题型名称',
						trigger: ['blur', 'change']
					},
					TestDiff1:[
						{
							required: true,
							message: '请输入题数',
							trigger: ['blur', 'change']
						},
						{
							validator: validateNum, trigger: ['blur', 'change']
						}
					],
					TestDiff2:[
						{
							required: true,
							message: '请输入题数',
							trigger: ['blur', 'change']
						},
						{
							validator: validateNum, trigger: ['blur', 'change']
						}
					],
					TestDiff3:[
						{
							required: true,
							message: '请输入题数',
							trigger: ['blur', 'change']
						},
						{
							validator: validateNum, trigger: ['blur', 'change']
						}
					],
					TestDiff4:[
						{
							required: true,
							message: '请输入题数',
							trigger: ['blur', 'change']
						},
						{
							validator: validateNum, trigger: ['blur', 'change']
						}
					],
					TestDiff5:[
						{
							required: true,
							message: '请输入题数',
							trigger: ['blur', 'change']
						},
						{
							validator: validateNum, trigger: ['blur', 'change']
						}
					],
				},
				stNumList:{
					TestDiff1:0,
					TestDiff2:0,
					TestDiff3:0,
					TestDiff4:0,
					TestDiff5:0,
				},//试题难易程度数量列表
				lxList:[
					{  PaperTestTypeID:null,PaperID:null,TestTypeID:29,TestTypeTitle:'判断题',TestTypeMark:null,TestAmount:0,TestTotalMark:null,TestTypeOrder:null},
					{  PaperTestTypeID:null,PaperID:null,TestTypeID:27,TestTypeTitle:'单选题',TestTypeMark:null,TestAmount:0,TestTotalMark:null,TestTypeOrder:null},
					{  PaperTestTypeID:null,PaperID:null,TestTypeID:28,TestTypeTitle:'多选题',TestTypeMark:null,TestAmount:0,TestTotalMark:null,TestTypeOrder:null},
				],
				clIndex:null,//所选策略索引
				yvlanShow:false,
				sjInfo:null,
				sjTitle:null,
			};
		},
		created() {
			this.getList();
		},
		watch: { 
		    // 使用对象形式  
		    'form.paperPolicy': {  
				handler(newVal, oldVal) {
					if(newVal != null && newVal.length>0){
						// this.form.
						this.lxList.forEach(typeObj => {  
							let sum = 0
							let index = -1
							this.form.paperPolicy.forEach(numberOrType => {
							// 检查当前的元素是否是字符串，并且与当前类型的type匹配  
								if (numberOrType.TestTypeID === typeObj.TestTypeID) {  
								// 注意：这里的逻辑假设numbersArray中不会直接包含类型的字符串作为和的一部分  
								// 实际上，你可能需要调整逻辑来正确处理这种情况（例如，跳过非数字值）  
								// 在这个例子中，我们简单地跳过非数字值  
									sum += (numberOrType.TestDiff1+numberOrType.TestDiff2+numberOrType.TestDiff3+numberOrType.TestDiff4+numberOrType.TestDiff5)
								} 
							})
							if(sum > 0){
								typeObj.TestAmount = sum
								this.form.paperTestType.forEach((item,i)=>{
									if(item.TestTypeID == typeObj.TestTypeID ){
										index = i
									}
								}) 
								if(this.form.PaperID != null){
									typeObj.PaperID = this.form.PaperID
								}
								if(index == -1){
									this.form.paperTestType.push(typeObj)
								}else{
									this.form.paperTestType[index].TestAmount = sum
								}
								this.form.paperTestType = [...this.form.paperTestType]
								console.log(this.form.paperTestType)
								
							}
						})
					
					}else{
						this.form.paperTestType = []
					}
				},  
				// 可选的其他选项  
				deep: true // 深度观察，用于对象或数组  
		    }  
		},  
		methods: {
			/** 查询试卷列表 */
			getList() {
				this.loading = true;
				listPaperInfo(this.queryParams).then(response => {
					this.PaperInfoList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					PaperID: null,
					PaperName: null,
					PaperType: 1,
					ProduceWay: null,
					ShowModal: null,
					ExamTime: null,
					StartTime: null,
					EndTime: null,
					PaperMark: null,
					PassMark: null,
					MarkDefine: null,
					RepeatExam: null,
					FillAutoGrade: null,
					SeeResult: null,
					AutoSave: 0,
					ExamAccount: null,
					ManagerAccount: null,
					TestCount: 0,
					AutoJudge: null,
					CreateWay: null,
					CreateUserID: null,
					CreateDate: null,
					RepeatExamNum: null,
					MultipleRule: null,
					paperPolicy:[],//试题列表
					paperTestType:[],//题型标题列表
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.PaperID)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加试卷";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const PaperID = row.PaperID || this.ids
				getPaperInfo(PaperID).then(response => {
					this.form = response.data;
					if(this.form.paperTestType.length > 0){
						this.lxList.forEach(item=>{
							this.form.paperTestType.forEach(obj=>{
								if(obj.TestTypeID == item.TestTypeID){
									item = obj
								}
							})
						})
					}
					this.open = true;
					this.title = "修改试卷";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						this.form.paperTestType.forEach((item,index)=>{
							item.TestTotalMark = Number(item.TestTypeMark)*Number(item.TestAmount)
							if(item.TestTypeOrder == null ){
								item.TestTypeOrder = index+1
							}
							this.form.TestCount += Number(item.TestAmount)
						})
						if (this.form.PaperID != null) {
							updatePaperInfo(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addPaperInfo(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const PaperIDs = row.PaperID || this.ids;
				this.$modal.confirm('是否确认删除试卷编号为"' + PaperIDs + '"的数据项？').then(function() {
					return delPaperInfo(PaperIDs);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('system/PaperInfo/export', {
					...this.queryParams
				}, `PaperInfo_${new Date().getTime()}.xlsx`)
			},
			//添加策略
			addCelue(){
				this.clForm = {
					PaperPolicyID:null,
					PaperID:null,
					SubjectID: 8,
					LoreID:null,
					TestTypeID:null,
					TestDiff1:0,
					TestDiff2:0,
					TestDiff3:0,
					TestDiff4:0,
					TestDiff5:0,
				}
				this.clShow = true
			},
			//查询各难度题数
			searchNum(){
				if(this.clForm.LoreID != null && this.clForm.TestTypeID != null){
					searchClNum({LoreID:this.clForm.LoreID,TestTypeID:this.clForm.TestTypeID}).then(res=>{
						console.log(res)
						this.stNumList = res.data.count
						this.clForm.total = res.data.totalCount
					})
				}
			},
			//添加策略确认
			clConfiem(){
				this.$refs["clForm"].validate(valid => {
					if (valid) {
						if(this.clIndex != null){
							this.form.paperPolicy[this.clIndex] = {...this.clForm}
							this.form.paperPolicy = [...this.form.paperPolicy]
							this.clIndex = null
							this.clShow = false
						}else{
							this.form.paperPolicy.push(this.clForm)
							this.clShow = false
						}
						
					}
				});
			},
			//上移
			moveUp(index) { 
			    if (index > 0) {  
			        // 交换当前元素和它前一个元素的位置  
			        [this.form.paperTestType[index], this.form.paperTestType[index - 1]] = [this.form.paperTestType[index - 1], this.form.paperTestType[index]]
					this.form.paperTestType[index].TestTypeOrder = index+1
					this.form.paperTestType[index-1].TestTypeOrder = index
					this.form.paperTestType = [...this.form.paperTestType]
			    }
			},
			//下移
			moveDown(index) {  
			    if (index < this.form.paperTestType.length - 1) {  
			        // 交换当前元素和它后一个元素的位置  
			        [this.form.paperTestType[index], this.form.paperTestType[index + 1]] = [this.form.paperTestType[index + 1], this.form.paperTestType[index]]
					this.form.paperTestType[index].TestTypeOrder = index+1
					this.form.paperTestType[index+1].TestTypeOrder = index+2
					this.form.paperTestType = [...this.form.paperTestType]
			    }
			},
			//修改试题策略
			xiugai(row,index){
				this.clForm = {...row}
				this.clIndex = index
				this.searchNum()
				this.clShow = true
			},
			//删除试题策略
			shanchu(row,index){
				if(row.PaperID != null){
					this.$modal.confirm('确定要删除选择策略吗？').then(function() {
						return delCl(row.PaperPolicyID);
					}).then(() => {
						this.form.paperPolicy.splice(index,1)
						this.$modal.msgSuccess("删除成功");
					}).catch(() => {});
				}else{
					this.form.paperPolicy.splice(index,1)
				}
			},
			//预览试卷
			yvlan(row){
				this.sjTitle = row.PaperName
				previewSj(row.PaperID).then(res=>{
					this.sjInfo = res.data
					this.yvlanShow = true
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	::v-deep .el-input.is-disabled .el-input__inner {
		background-color: #fff !important;
		color: #303133 !important
	}
	::v-deep .el-upload{
		display: block !important;
	}
</style>