<template>
  <div>
    <el-dialog
      :title="this.title + '试卷'"
      :visible="visible"
      :before-close="handleClose"
      :close-on-click-modal="false"
      custom-class="bbsl-location-dialog"
      top="5vh"
      width="70%"
    >
      <div>
        <el-steps :active="isActive" finish-status="success" simple>
          <el-step title="试卷信息"> </el-step>
          <el-step title="开始组卷"></el-step>
          <el-step title="考生确认"></el-step>
        </el-steps>

        <el-form
          ref="formInfo"
          label-position="top"
          :model="this.params"
          label-width="150px"
          :rules="rules"
        >
          <div v-if="isActive == 0">
            <!-- 试卷信息 -->
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="试卷名称" prop="name">
                  <el-input
                    v-model="params.name"
                    clearable
                    placeholder="请输入试卷名称"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="考核类型" prop="paperType">
                  <el-select
                    clearable
                    placeholder="请选择考核类型"
                    v-model="params.paperType"
                    disabled
                    @change="selectPaperType"
                    style="width:100%"
                  >
                    <el-option
                      v-for="item in khlxList"
                      :key="item.value"
                      :label="item.name"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                  <!-- <el-popover placement="right" width="250" trigger="manual" v-model="visiblePopover"
										content="请确认是否在课目考核功能中将该科目纳入年度考核中！如果没有请先进行配置。">
									</el-popover> -->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="考试课目" prop="subjectId">
                  <el-select
                    v-model="subject"
                    multiple
                    placeholder="请选择课目"
                    @change="selectSubject"
                    disabled
                    style="width:100%"
                  >
                    <el-option
                      v-for="(item, index) in subjectList"
                      :key="index"
                      :label="item.name"
                      :value="item.pkVal"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="考试时长" prop="timeLength">
                  <el-input
                    v-model="params.paperSetting.timeLength"
                    clearable
                    disabled
                    placeholder="请输入考试时长(分钟)"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="考试场地" prop="roomId">
                  <el-select
                    clearable
                    placeholder="请选择考试场地"
                    v-model="params.paperSetting.roomId"
                    disabled
                    style="width:100%"
                  >
                    <el-option
                      v-for="item in roomList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                  <!-- <el-input v-model="params.paperSetting.roomId" clearable placeholder="请输入考试场地">
									</el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="考试时间" prop="examTime">
                  <el-date-picker
                    v-model="examTime"
                    type="datetimerange"
                    format="yyyy-MM-dd HH:mm:ss"
                    disabled
                    value-format="yyyy-MM-dd HH:mm:ss"
                    start-placeholder="开始日期"
                    :picker-options="{
                      disabledDate(time) {
                        return (
                          time.getTime() < Date.now() - 1 * 24 * 3600 * 1000
                        )
                      },
                      selectableRange: startTimeRange
                    }"
                    :editable="false"
                    end-placeholder="结束日期"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="6">
                <el-form-item label="总分数" prop="totalScore">
                  <el-input
                    v-model="params.totalScore"
                    style="width: 50%;"
                    placeholder="请输入总分数"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="页面切换次数" prop="switchCount">
                  <el-input-number
                    v-model="params.paperSetting.switchCount"
                    controls-position="right"
                    disabled
                    :min="1"
                  ></el-input-number>
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="阅卷方式" prop="switchCount">
                  <el-radio-group
                    v-model="params.paperSetting.trainModel"
                    disabled
                  >
                    <el-radio :label="1">系统</el-radio>
                    <el-radio :label="2">人工</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="6" v-if="params.paperType == 2">
                <el-form-item prop="switchCount">
                  <template slot="label">
                    最终成绩
                    <span style="color: red;" v-if="this.tooltip !== ''"
                      >({{ this.tooltip }})</span
                    >
                  </template>
                  <el-radio-group v-model="params.endStatus" disabled>
                    <el-radio label="1">是</el-radio>
                    <el-radio label="0">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <!-- 开始组卷 -->
          <div v-if="isActive == 1">
            <el-row :gutter="24">
              <el-col>
                <el-form-item label="组卷类型" prop="">
                  <div style="display: flex;">
                    <div
                      class="typeBtn"
                      :class="{btnActive: params.wayType == item.value}"
                      v-for="(item, index) in zjfsList"
                      :key="index"
                    >
                      {{ item.name }}
                    </div>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-button v-if="params.wayType==1||params.wayType==3" size="mini" type="primary"
							style="margin-bottom: 5px;" plain @click="addRandom"><i class="el-icon-plus"></i>添加
						</el-button>
						<el-button v-if="params.wayType==2" size="mini" type="primary" style="margin-bottom: 5px;" plain
							@click="addTopic"><i class="el-icon-plus"></i>添加</el-button> -->
            <!-- 配置出卷弹框 -->
            <!-- <span v-if="this.params.paperSetting.trainModel==1&&this.params.paperQuestionSettings.length>0" style="color: red;"> 提示：当前为系统阅卷，不能存在填空题或简答题</span>
						<span v-if="this.params.paperSetting.trainModel==2&&this.params.paperQuestionSettings.length>0" style="color: red;"> 提示：当前为人工阅卷，必须存在填空题或简答题</span> -->
            <configurationDIalog
              v-if="confVisible"
              :confVisible="confVisible"
              :subjectlist="subjectList"
              :paperQuestionSettings="params.paperQuestionSettings"
              @closeFormDiao="closeFormDiao"
              @questions="testQuestions"
            ></configurationDIalog>
            <div v-if="params.wayType == 1 || params.wayType == 3">
              <el-table
                :data="params.paperQuestionSettings"
                border
                style="width: 100%"
                max-height="450"
              >
                <el-table-column type="index" width="50"></el-table-column>
                <el-table-column
                  label="课目"
                  prop="subjectName"
                ></el-table-column>
                <el-table-column
                  label="题型"
                  prop="questionName"
                ></el-table-column>
                <el-table-column
                  label="题目总数量"
                  prop="totalNumuber"
                ></el-table-column>
                <el-table-column label="题目数量" prop="numuber">
                  <!-- <template #default="scope">
										<el-input-number v-model="scope.row.numuber" controls-position="right" disabled
											@change="handleNumber(scope.row.numuber,scope.row.totalNumuber)" :min="1"
											:max="Number(scope.row.totalNumuber)"></el-input-number>
									</template> -->
                </el-table-column>
                <el-table-column label="分数" prop="score">
                  <!-- 	<template #default="scope">
										<el-input-number v-model="scope.row.score" controls-position="right" :min="1" disabled>
										</el-input-number>
									</template> -->
                </el-table-column>
                <!-- 	<el-table-column label="删除" width="60">
									<template #default="scope">
										<el-button type="danger" @click="delSubject(scope.$index)" icon="el-icon-delete"
											plain circle></el-button>
									</template>
								</el-table-column> -->
              </el-table>
              <div class="combined">
                <span
                  v-if="totalScore > params.totalScore"
                  style="color: red;font-weight: 100;"
                  >(当前选择分数超出配置总分数)</span
                >
                总分数：<span
                  :style="{color: totalScore > params.totalScore ? 'red' : ''}"
                >
                  {{ totalScore }}
                </span>
              </div>
            </div>
            <div
              class="disposition"
              v-if="
                params.wayType == 2 && params.paperQuestionSettings.length > 0
              "
            >
              <div
                class="itemBox"
                :key="x"
                v-for="(x, xi) in this.params.paperQuestionSettings"
              >
                <div class="topic">
                  <div class="topic-left">
                    <div>
                      {{ xi + 1 }}/{{ params.paperQuestionSettings.length }}
                    </div>
                    <div>{{ x.questionTypeName }}</div>
                    <span
                      v-html="x.questionsInfo ? x.questionsInfo.question : ''"
                    ></span>
                  </div>
                  <div class="topic-right">
                    <div>{{ x.score }}分</div>
                    <div @click="anShrinkage(x, xi)">
                      {{ x.isShrink ? '收缩' : '展开' }}
                      <i class="el-icon-arrow-down" v-if="!x.isShrink"></i>
                      <i class="el-icon-arrow-up" v-if="x.isShrink"></i>
                    </div>
                  </div>
                </div>
                <div class="details" v-if="x.isShrink">
                  <div
                    v-if="
                      x.questionType == 1 ||
                        x.questionType == 2 ||
                        x.questionType == 3
                    "
                  >
                    <div
                      v-for="(o, oi) in x.questionsInfo.options"
                      style="display: flex;align-items: center;"
                      :key="oi"
                    >
                      {{ o.optionKey }}、<span v-html="o.optionContent"></span>
                    </div>
                  </div>
                  <div
                    class="correct"
                    v-if="
                      x.questionType == 1 ||
                        x.questionType == 2 ||
                        x.questionType == 3 ||
                        x.questionType == 4
                    "
                  >
                    正确答案：
                    <!-- <span v-if="x.questionType==3">{{x.questionsInfo.rightOption==0?'对':'错'}}</span> -->
                    <span>{{ x.questionsInfo.rightOption }}</span>
                  </div>
                  <div class="parsing">
                    题目解析：<span
                      v-html="
                        x.questionsInfo.parsing
                          ? x.questionsInfo.parsing
                          : '无解析'
                      "
                    ></span>
                  </div>
                </div>
                <div class="tally">
                  标签：<el-button type="info" round plain size="mini">
                    {{ x.questionsInfo ? x.questionsInfo.difficultyName : '' }}
                  </el-button>
                </div>
                <div class="footer">
                  <div>
                    更新时间：{{
                      x.questionsInfo ? x.questionsInfo.createTime : ''
                    }}
                  </div>
                  <!-- <div style="width: 30px;text-align: center;" @click="deleteTopic(xi)"><i
											style="color: red;" class="el-icon-delete"></i></div> -->
                </div>
              </div>
            </div>
            <div
              class="combined"
              v-if="
                params.wayType == 2 && params.paperQuestionSettings.length > 0
              "
            >
              <span
                v-if="configScore > params.totalScore"
                style="color: red;font-weight: 100;"
                >(当前选择分数超出配置总分数)</span
              >
              总分数：
              <span
                :style="{color: configScore > params.totalScore ? 'red' : ''}"
              >
                {{ configScore }}
              </span>
            </div>
          </div>
          <!-- 考生确认 -->
          <div style="max-height: 500px;" v-if="isActive == 2">
            <el-form-item prop="">
              <div style="display: flex; margin-top: 10px;">
                <div
                  class="typeBtn"
                  :class="{
                    btnActive: params.paperSetting.testUserType == item.value
                  }"
                  v-for="(item, index) in testUserList"
                  :key="index"
                >
                  {{ item.name }}
                </div>
              </div>
            </el-form-item>

            <!-- <div class="examinee">
							<div class="examinee-left">
								<div class="common-tree-title">
									<i class="el-icon-menu"></i> 岗位
								</div>
								<div class="common-tree-content">
									<el-tree :data="jobsList" :props="defaultProps" accordion
										@node-click="handleNodeClick" style="border: none;">
									</el-tree>
								</div>
							</div>
							<div class="examinee-right"> -->
            <el-container v-if="params.paperSetting.testUserType == 2">
              <el-aside width="230px" class="left-aside">
                <el-card class="box-card org-find-card" shadow="never">
                  <div slot="header" class="clearfix">
                    <span>按岗位查找</span>
                  </div>
                  <div class="common-tree-container">
                    <!-- 	<div class="title">
													<el-input placeholder="请输入关键字搜索" v-model="newParam.querys[0].value"
														@keyup.enter.native="searchName">
														<i slot="suffix" class="el-input__icon el-icon-search"
															style="color:#CCCCCC;cursor:pointer;" @click="searchName()"></i>
													</el-input>
												</div> -->
                    <el-tree
                      highlight-current
                      v-if="jobsList.length"
                      :data="jobsList"
                      :props="defaultProps"
                      default-expand-all
                      @node-click="handleNodeClick"
                    >
                    </el-tree>
                  </div>
                </el-card>
              </el-aside>
              <el-container>
                <el-header class="middle-header">
                  <div style="padding: 10px 0">
                    <el-input
                      size="small"
                      style="width:380px"
                      clearable
                      placeholder="请输入名称"
                      prefix-icon="el-icon-search"
                      @keyup.enter.native="searchEnterFun"
                      v-model="querys[0].value"
                    >
                    </el-input>
                    <el-button
                      style="margin-left: 20px"
                      size="small"
                      type="primary"
                      icon="el-icon-search"
                      @click="searchEnterFun()"
                      >查询</el-button
                    >
                    <!-- <el-button size="small" @click="reset()" icon="el-icon-refresh">重置</el-button> -->
                  </div>
                </el-header>
                <el-main style="padding:0">
                  <el-table
                    size="medium"
                    ref="multipleTable"
                    :data="EquipmentList"
                    stripe
                    border
                    height="400"
                    :row-key="binRowKey"
                    @select="manualSelection"
                  >
                    <!-- <el-table-column type="selection" align="center" width="45"></el-table-column> -->
                    <el-table-column
                      prop="userName"
                      label="考生名称"
                    ></el-table-column>
                    <el-table-column
                      prop="account"
                      label="考生账号"
                    ></el-table-column>
                  </el-table>
                </el-main>
                <el-footer>
                  <el-pagination
                    align="right"
                    background
                    ref="paginationPanel"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="newParam.pageBean.page"
                    :page-sizes="[20, 30, 40, 50]"
                    :page-size="newParam.pageBean.pageSize"
                    layout="prev, pager, next,total, sizes, jumper"
                    :total="total"
                  ></el-pagination>
                </el-footer>
              </el-container>
              <el-aside width="200px" class="select-aside">
                <el-header class="select-header">
                  <span>已选择</span>
                </el-header>
                <div class="select-tree-div">
                  <el-tree
                    ref="selectTree"
                    node-key="userName"
                    :props="selectUserProps"
                    :data="params.userInfoVos"
                  ></el-tree>
                </div>
              </el-aside>
            </el-container>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="isActive > 0" @click="lastStep"
          >上一步</el-button
        >
        <el-button type="primary" v-if="isActive < 2" @click="nextStep"
          >下一步</el-button
        >
        <!-- <el-button type="primary" v-else @click="nextStep">确 定</el-button> -->
        <el-button @click="handleClose">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 普通课目 -->
    <subjectDialog ref="subjectDialog" @getUser="getUser"></subjectDialog>
    <!-- 随机 -->
    <randomDialog ref="randomDialog" @getRandom="getRandom"></randomDialog>
    <!-- 年度课目 -->
    <yearSubjectDialog ref="yearSubject" @getUser="getUser"></yearSubjectDialog>
  </div>
</template>

<script>
import dictUtils from '@/components/dict/DictSelectUtils.js'
import paperMenu from '@/api/examination/paperMenu.js'
import configurationDIalog from './configurationDIalog.vue'
import subjectDialog from './subjectDialog.vue'
import randomDialog from './randomDialog.vue'
import yearSubjectDialog from './yearSubjectDialog.vue'
import moment from 'moment'

export default {
  props: {
    subjectlist: {
      type: Array,
      default: () => []
    }
  },
  components: {
    configurationDIalog,
    subjectDialog,
    randomDialog,
    yearSubjectDialog
  },
  name: 'paperMenuDialog',
  data() {
    return {
      querys: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'u.fullname_',
          relation: 'AND',
          value: ''
        }
      ],
      visible: false,
      confVisible: false, //二级弹框
      activeCollapse1: '1',
      ctlTypeList: '',
      isActive: 0,
      parameter: {},
      params: {
        name: '',
        subjectId: '',
        wayType: 1,
        paperQuestionSettings: [],
        paperSetting: {
          testUserType: 1,
          planStartTime: '',
          planEndTime: '',
          paperType: '',
          totalScore: 100,
          trainModel: 1
        },
        totalScore: 100,
        endStatus: ''
      },
      examTime: [],
      subject: [],
      subjectList: [],
      btnBisabled: true,
      visiblePopover: false,
      rules: {
        name: [
          {
            required: true,
            message: '请输入试卷名称',
            trigger: 'blur'
          }
        ],

        subjectId: [
          {
            required: true,
            message: '请选择考试课目',
            trigger: 'blur'
          }
        ],
        paperType: [
          {
            required: true,
            message: '请选择考试方式',
            trigger: 'blur'
          }
        ],

        // timeLength: [{
        // 	required: true,
        // 	message: '请输入考试时长',
        // 	trigger: 'blur',
        // }, ],
        // roomId: [{
        // 	required: true,
        // 	message: '请选择考试场地',
        // 	trigger: 'blur',
        // }, ],

        totalScore: [
          {
            required: true,
            message: '请输入及格分数',
            trigger: 'blur'
          }
        ],
        // switchCount: [{
        // 	required: true,
        // 	message: '请输入页面切换次数',
        // 	trigger: 'blur',
        // }, ],

        planStartTime: [
          {
            required: true,
            message: '请选择考试结开始时间',
            trigger: 'blur'
          }
        ],
        planEndTime: [
          {
            required: true,
            message: '请选择考试结束时间',
            trigger: 'blur'
          }
        ]
      },
      testUserList: [
        {
          name: '所有人',
          value: '1'
        },
        {
          name: '用户',
          value: '2'
        }
      ],
      //随机组卷
      data: [],
      newParam: {
        pageBean: {
          page: 1,
          pageSize: 10
        }
      },
      ruleForm: {
        startTime: '', // 开始时间
        endTime: '' // 结束时间
      },
      // 禁用今天之前的时间
      pickerOptionsOne: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
      // 禁用今天之前的时间 + 禁用第一个时间选择框选择的小时之前的时间
      pickerOptionsTwo: {
        selectableRange: [],
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },

      title: '',
      search: '',
      search1: '',
      EquipmentList: [],
      multipleSelection: [],
      multipleSelection1: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      selectUserProps: {
        label: 'userName'
      },
      nameArr: [],
      // examsearch: '',
      // examsearch1: '',
      // examEquipmentList: [],
      // examparams.userInfoVos: [],
      // exammultipleSelection: [],
      // exammultipleSelection1: [],
      // examdefaultProps: {
      // 	children: 'children',
      // 	label: 'label'
      // },
      typeList: [
        {
          name: '正在考试',
          value: 0
        },
        {
          name: '模拟考试',
          value: 1
        }
      ],
      pickerOptions: {
        disabledDate: time => {
          console.log(this.params.paperSetting.planStartTime)
          if (this.value2 != '') {
            return time.getTime() > new Date(this.value2).getTime()
          }
        }
      },
      pickerOptions1: {
        disabledDate: time => {
          console.log(time.getTime(), '选中')
          console.log(
            Date.parse(new Date(this.params.paperSetting.planStartTime)),
            '开始'
          )
          return (
            time.getTime() <
            Date.parse(new Date(this.params.paperSetting.planStartTime)) -
              8.64e7
          )
          1000 //减去一天的时间代表可以选择同一天;
        }
      },

      subjectsList: [],
      topicList: [], //题目类型
      stndList: [], //试题难度
      khlxList: [], //考试方式
      isShrink: false, //展开
      //考生确认
      total: 0,
      jobsList: [], //岗位树
      subjectUser: {
        majorIds: [],
        subjectIds: []
      },
      roomList: [], //考场列表
      userInfoVos: [],
      userlength: 0,
      startTimeRange: '',
      endType: false, //是否显示最终成绩
      tooltip: '' //提示语
    }
  },
  computed: {
    totalScore() {
      let totalScore = 0
      this.params.paperQuestionSettings.forEach(p => {
        totalScore += p.numuber * p.score
      })
      return totalScore
    },
    configScore() {
      let configScore = 0
      this.params.paperQuestionSettings.forEach(s => {
        configScore += Number(s.score)
      })
      return configScore
    }
  },
  watch: {
    // 监听计算属性里面的endTime
    endTime: {
      handler: function(val, oldVal) {
        this.pickerOptionsTwo.selectableRange = val
      },
      deep: true
    },
    examTime: {
      handler(newValue, oldValue) {
        if (newValue) {
          let nowDate = moment().format('YYYY-MM-DD HH:mm:ss')
          let dt = nowDate.split(' ')
          let st = ''
          if (typeof newValue === 'string' && newValue.split(' ')[0] == dt[0]) {
            // 如果是当天,选择的时间开始为此刻的时分秒
            st = dt[1]
            // 如果是当天（只有当日期改变时）,默认选中时间为当前时间
            if (newValue.split(' ')[0] != oldValue.split(' ')[0]) {
              this.examTime = nowDate
            }
          } else {
            // 明天以及后面的时间从0时开始
            st = '00:00:00'
          }

          this.startTimeRange = st + ' - 23:59:59'
          //例如：如果今天此刻时间为15:27:00 则选择时间范围为： 15:27:00 - 23:59:59
          //否则为：00:00:00 - 23:59:59
        }
      }
    }
  },

  created() {
    this.zjfsList = dictUtils.getDictItemsFromCache('zjfs')
    this.topicList = dictUtils.getDictItemsFromCache('sttx')
    this.stndList = dictUtils.getDictItemsFromCache('stnd')
    this.khlxList = dictUtils.getDictItemsFromCache('khlx')
  },
  mounted() {},
  methods: {
    // add(val) {
    // 	this.visible = true
    // 	this.parameter = val
    // 	this.title = '新增'
    // 	this.getOrgPostPage()
    // 	this.pagingQuery()
    // },
    add(val) {
      this.getOrgPostPage()
      this.pagingQuery()
      this.visible = true
      this.title = '配置信息'
      this.$nextTick(() => {
        paperMenu.detailIdPaper(val.id, res => {
          if (res) {
            this.params = res
            this.params.paperType = res.paperType.toString()
            this.subjectList = this.params.subjectInfos
            this.subjectList.forEach(s => {
              this.subject.push(s.id)
            })
            console.log(`--------1----------`, this.subjectList)
            this.userInfoVos = JSON.parse(
              JSON.stringify(this.params.userInfoVos)
            )
            this.userlength = this.params.userInfoVos.length
            this.examTime = [
              this.params.paperSetting.planStartTime,
              this.params.paperSetting.planEndTime
            ]
            if (this.params.wayType == 1 || this.params.wayType == 3) {
              this.params.paperQuestionSettings.forEach(p => {
                this.subjectList.forEach(s => {
                  if (s.id == p.subjectId) {
                    p.subjectName = s.name
                  }
                })
                this.topicList.forEach(t => {
                  if (t.value == p.questionType) {
                    p.questionName = t.name
                  }
                })
              })
            }
            if (this.params.wayType == 2) {
              this.params.paperQuestionSettings.forEach(e => {
                e.isShrink = false
                this.topicList.forEach(t => {
                  if (e.questionType == t.value) {
                    e.questionTypeName = t.name
                  }
                })
                this.stndList.forEach(s => {
                  if (e.questionsInfo.difficulty == s.value) {
                    e.questionsInfo.difficultyName = s.name
                  }
                })
              })
            }
          }
        })
      })
    },
    //复制试卷
    copy(val) {
      this.getOrgPostPage()
      this.pagingQuery()
      this.visible = true
      this.title = '复制'
      this.$nextTick(() => {
        paperMenu.detailIdPaper(val.id, res => {
          if (res) {
            this.params = res
            delete this.params.id
            this.subjectList = this.params.subjectInfos
            this.subjectList.forEach(s => {
              this.subject.push(s.id)
            })
            delete this.params.paperSetting.id
            delete this.params.paperSetting.paperId
            delete this.params.pkVal
            this.examTime = [
              this.params.paperSetting.planStartTime,
              this.params.paperSetting.planEndTime
            ]
            this.userInfoVos = JSON.parse(
              JSON.stringify(this.params.userInfoVos)
            )
            this.userlength = this.params.userInfoVos.length
            if (this.params.wayType == 1 || this.params.wayType == 3) {
              this.params.paperQuestionSettings.forEach(p => {
                delete p.paperBaseId
                delete p.id
                this.subjectList.forEach(s => {
                  if (s.id == p.subjectId) {
                    p.subjectName = s.name
                  }
                })
                this.topicList.forEach(t => {
                  if (t.value == p.questionType) {
                    p.questionName = t.name
                  }
                })
              })
            }
            if (this.params.wayType == 2) {
              this.params.paperQuestionSettings.forEach(e => {
                delete e.paperBaseId
                delete e.id
                e.isShrink = false
                this.topicList.forEach(t => {
                  if (e.questionType == t.value) {
                    e.questionTypeName = t.name
                  }
                })
                this.stndList.forEach(s => {
                  if (e.questionsInfo.difficulty == s.value) {
                    e.questionsInfo.difficultyName = s.name
                  }
                })
              })
            }
            this.params.paperType = this.params.paperType.toString()
            if (this.params.paperType == 2) {
              this.subject = []
              this.subjectList = []
            }
          }
        })
      })
    },
    pagingQuery() {
      paperMenu.pagingQuery(
        {
          pageBean: {
            page: -1,
            pageSize: 10,
            showTotal: true
          }
        },
        res => {
          if (res) {
            this.roomList = res.rows
            // console.log(this.roomList);
          }
        }
      )
    },
    // 关闭新增人员窗口
    handleClose() {
      this.params = {
        name: '',
        subjectId: '',
        wayType: 1,
        paperQuestionSettings: [],
        paperSetting: {
          testUserType: 1,
          planStartTime: '',
          planEndTime: '',
          paperType: '',
          totalScore: 100,
          trainModel: 1
        },
        totalScore: 100,
        endStatus: ''
      }
      this.newParam = {
        pageBean: {
          page: 1,
          pageSize: 10
        },
        querys: []
      }
      this.endType = false
      this.isActive = 0
      this.subject = []
      this.subjectList = []
      this.visible = false
    },
    // 确认后不关闭弹框
    addClose() {
      this.params = {
        name: '',
        wayType: 1,
        subjectId: '',
        paperQuestionSettings: [{}]
      }
    },
    changeValue() {
      this.params.paperQuestionSettings[index].questionType = JSON.parse(
        JSON.stringify(this.params.paperQuestionSettings[index].questionType)
      )
    },
    getUser(val) {
      console.log(val)
      this.subject = []
      this.subjectList = val.map(i => ({...i, subjectId: i.subjectId || i.id}))
      this.subjectList.forEach(e => {
        this.subject.push(e.subjectId)
      })

      if (this.params.paperType == 2 && this.subject.length > 0) {
        paperMenu.getEndStatus(this.subject[0], res => {
          if (res.message) {
            this.tooltip = res.message
          }
        })
        this.endType = true
      } else {
        this.endType = false
      }
    },
    //打开课目弹框
    subjectDUsers() {
      console.log(this.params.id)
      // 1为普通考核  2为年度考核
      if (this.params.paperType) {
        if (this.params.paperType == 1) {
          this.$refs.subjectDialog.add(this.subjectList)
        } else if (this.params.paperType == 2) {
          this.$refs.yearSubject.add(this.subjectList, this.params.id)
        }
      } else {
        this.$message({
          message: '请先选择考核类型',
          type: 'warning'
        })
      }
    },

    //上一步
    lastStep() {
      this.isActive -= 1
    },
    //下一步
    nextStep() {
      // if(this.subject.length==0){
      // 	return
      // }
      if (this.isActive == 0) {
        this.params.paperSetting.planStartTime = this.examTime[0]
        this.params.paperSetting.planEndTime = this.examTime[1]
        let arrA = []
        if (this.params.wayType == 1 || this.params.wayType == 1) {
          this.params.paperQuestionSettings.forEach(item => {
            this.subject.forEach(s => {
              if (item.subjectId == s) {
                arrA.push(item)
              }
            })
          })
        } else if (this.params.wayType == 2) {
          this.params.paperQuestionSettings.forEach(item => {
            this.subject.forEach(s => {
              if (item.subId == s) {
                arrA.push(item)
              }
            })
          })
        }
        this.params.paperQuestionSettings = arrA
        if (this.subject.length > 0) {
          this.subject.forEach((s, si) => {
            if (si == 0) {
              this.params.subjectId = s
            } else {
              this.params.subjectId += ',' + s
            }
          })
        } else {
          this.params.subjectId = ''
        }
        if (
          this.params.subjectId == '' ||
          this.params.name == '' ||
          this.params.paperType == '' ||
          this.params.totalScore == '' ||
          this.params.paperSetting.planStartTime == '' ||
          this.params.paperSetting.planEndTime == ''
        ) {
          this.$notify({
            type: 'warning',
            message: '请填写完整试卷信息',
            duration: 2000
          })
          return
        } else {
          this.isActive += 1
        }
      } else if (this.isActive == 1) {
        console.log(this.params.paperQuestionSettings)
        if (this.params.paperQuestionSettings.length == 0) {
          this.$notify({
            type: 'warning',
            message: '题目不能为空',
            duration: 2000
          })
          return
        }
        this.isActive += 1
        this.subjectExaminee()
        // if(this.title=='新增'){
        // }else if(this.title=='修改'){

        // }
      } else if (this.isActive == 2) {
        console.log(this.params)
        // this.$refs.formInfo.validate(valid => {
        // 	if (valid) {
        // 		if (this.title === '新增' || this.title === '复制') {
        // 			paperMenu.addPaper(this.params, response => {
        // 				if (response.state) {
        // 					this.$notify({
        // 						type: 'success',
        // 						message: this.title + '成功',
        // 						duration: 2000
        // 					})
        // 					this.handleClose()
        // 					this.$emit('loadData')
        // 				} else {
        // 					this.$message.warning(response.message)
        // 				}
        // 			})
        // 		} else if (this.title === '修改') {
        // 			paperMenu.editPaper(this.params, response => {
        // 				if (response.state) {
        // 					this.$notify({
        // 						type: 'success',
        // 						message: this.title + '成功',
        // 						duration: 2000
        // 					})
        // 					this.handleClose()
        // 					this.$emit('loadData')
        // 				} else {
        // 					this.$message.warning(response.message)
        // 				}
        // 			})
        // 		}

        // 	}
        // })
      }
    },
    addTable() {
      this.params.paperQuestionSettings.push({})
    },
    testUserType(val) {
      this.params.paperSetting.testUserType = val.value
    },
    changeType(val) {
      console.log(this.params.wayType)
      //判断当前选中的组卷类型
      //如果为1和3时
      //判断是否填写题目
      // 如果存在题目，则弹出提示框确认
      if (this.params.paperQuestionSettings.length > 0) {
        this.$confirm(
          '您确定要修改组卷类型吗？切换后原有的试题将会无效',
          '温馨提示',
          {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning'
          }
        )
          .then(() => {
            this.params.wayType = val.value
            this.params.paperQuestionSettings = []
          })
          .catch(() => {})
      } else {
        // 不存在题目，直接跳转
        this.params.wayType = val.value
        this.params.paperQuestionSettings = []
      }
      // } else {
      // 	if (this.params.paperQuestionSettings.length > 0) {
      // 		this.$confirm('您确定要修改组卷类型吗？切换后原有的试题将会无效', '温馨提示', {
      // 			confirmButtonText: '是',
      // 			cancelButtonText: '否',
      // 			type: 'warning'
      // 		}).then(() => {
      // 			this.params.wayType = val.value
      // 			if (this.params.wayType == 2) {
      // 				this.params.paperQuestionSettings = []
      // 			} else {
      // 				this.params.paperQuestionSettings = [{
      // 					questionType: null,
      // 					score: null,
      // 					numuber: null
      // 				}]
      // 			}
      // 		}).catch(() => {

      // 		});
      // 	} else {
      // 		this.params.wayType = val.value
      // 		if (this.params.wayType == 2) {
      // 			this.params.paperQuestionSettings = []
      // 			// this.confVisible = true
      // 		} else {
      // 			this.params.paperQuestionSettings = [{
      // 				questionType: null,
      // 				score: null,
      // 				numuber: null
      // 			}]
      // 		}
      // 	}
      // }
      //

      return
      this.params.userInfoVos = []
      this.multipleSelection1 = []
      if (this.params.wayType == 2) {
        this.params.paperQuestionSettings = []
        // this.confVisible = true
      } else {
        this.params.paperQuestionSettings = [
          {
            questionType: null,
            score: null,
            numuber: null
          }
        ]
      }
    },
    removeTable(index) {
      if (this.params.paperQuestionSettings.length == 1) {
        this.params.json = ''
        this.params.paperQuestionSettings = [{}]
      } else {
        this.params.paperQuestionSettings.splice(index, 1)
      }
    },
    // 课目树选中ID
    handleChange(val) {
      let ArrIds = []
      ArrIds = val
      if (ArrIds.length == 0) {
        this.params.subjectId = ArrIds[0]
      } else {
        this.params.subjectId = ArrIds[val.length - 1]
      }
    },
    //岗位树点击
    handleNodeClick(val) {
      this.EquipmentList = []
      this.newParam.querys = [
        {
          group: 'defaultQueryGroup',
          operation: 'EQUAL',
          property: 'POS_ID_',
          relation: 'AND',
          value: val.id
        }
      ]
      this.getOrgUserPage(1)
    },
    getOrgUserPage(val) {
      if (val) {
        this.newParam.pageBean.page = val
      }
      if (this.querys[0].value) {
        this.newParam.querys.push(this.querys[0])
      }
      this.EquipmentList = []
      paperMenu.getOrgUserPage(this.newParam, res => {
        if (res.rows) {
          res.rows.forEach(r => {
            this.EquipmentList.push({
              positionId: r.relId,
              account: r.account,
              userName: r.fullName,
              userId: r.userId
            })
          })
          this.$nextTick(() => {
            this.params.userInfoVos.forEach(s => {
              this.EquipmentList.forEach(u => {
                console.log(
                  s.positionId,
                  u.positionId,
                  s.positionId == u.positionId
                )
                if (s.userId == u.userId) {
                  this.$refs.multipleTable.toggleRowSelection(u, true)
                }
              })
            })
          })
          this.total = res.total
        }
      })
    },
    //根据课目id查询考生人员
    subjectExaminee() {
      // if(this.params.)
      if (this.title == '新增') {
        this.subjectUser.subjectIds = []
        this.subjectList.forEach(s => {
          this.subjectUser.subjectIds.push(s.id)
        })
        paperMenu.getSubjectUserList(this.subjectUser, res => {
          this.userInfoVos = JSON.parse(JSON.stringify(res))
          this.userlength = res.length
          this.params.userInfoVos = res
        })
      }
    },

    //添加题目
    addTopic() {
      this.confVisible = true
    },
    //随机添加
    addRandom() {
      this.$refs.randomDialog.add(
        this.subjectList,
        this.params.paperQuestionSettings
      )
    },
    //展开 收缩
    anShrinkage(val, index) {
      if (!val.questionsInfo.options || val.questionsInfo.options.length > 0) {
        val.isShrink = !val.isShrink
        this.$set(this.params.paperQuestionSettings, index, val)
      } else if (val.questionsInfo.options.length == 0 && !val.isShrink) {
        paperMenu.detailIdTopic(val.questionId, res => {
          val.questionsInfo.options = res.options
          val.isShrink = !val.isShrink
          this.$set(this.params.paperQuestionSettings, index, val)
        })
      } else {
        val.isShrink = !val.isShrink
        this.$set(this.params.paperQuestionSettings, index, val)
      }
    },
    closeFormDiao() {
      this.confVisible = false
    },
    deleteTopic(index) {
      this.params.paperQuestionSettings.splice(index, 1)
    },
    //随机弹框返回值
    getRandom(val) {
      this.params.paperQuestionSettings = []
      val.forEach(v => {
        this.subjectList.forEach(s => {
          if (s.id == v.subjectId) {
            v.subjectName = s.name
          }
        })
        this.topicList.forEach(t => {
          if (t.value == v.questionType) {
            v.questionName = t.name
          }
        })
        this.params.paperQuestionSettings.push(v)
      })
    },
    //接收考试题目
    async testQuestions(val) {
      console.log(val)
      this.confVisible = false
      val.forEach(e => {
        this.params.paperQuestionSettings.push({
          questionId: e.id,
          questionType: e.type,
          score: e.score,
          numuber: 1,
          questionsInfo: {
            difficulty: e.difficulty,
            question: e.question,
            rightOption: e.rightOption,
            parsing: e.parsing,
            createTime: e.createTime,
            options: []
          }
        })
      })
      this.params.paperQuestionSettings.forEach(e => {
        e.isShrink = false
        this.topicList.forEach(t => {
          if (e.questionType == t.value) {
            e.questionTypeName = t.name
          }
        })
        this.stndList.forEach(s => {
          if (e.questionsInfo.difficulty == s.value) {
            e.questionsInfo.difficultyName = s.name
          }
        })
      })
      this.params.paperQuestionSettings = this.params.paperQuestionSettings.sort(
        function(a, b) {
          return a.questionType - b.questionType
        }
      )
    },
    //题目数量
    handleNumber(num, totalNumuber) {
      console.log(num, totalNumuber)
    },
    // 考生确认
    //获取岗位树
    getOrgPostPage() {
      paperMenu.getOrgPostPage(this.newParam, res => {
        if (res.rows) {
          this.jobsList = res.rows
          this.total = res.total
        }
      })
    },
    handleSizeChange(val) {
      this.newParam.pageBean.pageSize = val
      this.getOrgUserPage()
    },
    handleCurrentChange(val) {
      this.newParam.pageBean.page = val
      this.getOrgUserPage()
    },
    // 中间列表
    searchEnterFun() {
      this.getOrgUserPage(1)
    },
    // 重置
    reset() {
      this.querys[0].value = ''
      this.getOrgUserPage(1)
    },
    handleSelectionChange(val) {
      if (val.length > 0) {
        val.forEach(v => {
          this.params.userInfoVos.push(v)
        })
      }
    },
    //删除
    delSubject(index) {
      this.params.paperQuestionSettings.splice(index, 1)
    },
    binRowKey(row) {
      return row.userId
    },
    selectable(row) {
      let type = true
      console.log(this.userInfoVos)
      this.userInfoVos.forEach((u, ui) => {
        if (ui <= this.userlength) {
          console.log(row.userId, u.userId)
          if (row.userId == u.userId) {
            type = false
          }
        }
      })
      console.log(type)
      return type
      // return true
    },
    manualSelection(selection, row) {
      //先判断当前操作flag
      //true勾选还是false取消
      let flag = selection.some(item => {
        if (row.userId == item.userId) return true
      })
      if (flag) {
        this.params.userInfoVos.push(row)
      } else {
        this.params.userInfoVos.forEach((s, si) => {
          if (s.userId == row.userId) {
            this.params.userInfoVos.splice(si, 1)
          }
        })
      }
    },
    selectPaperType(val) {
      if (val == 2) {
        this.visiblePopover = true
        this.subjectList = []
        this.subject = []
      } else {
        this.visiblePopover = false
      }
    },
    selectSubject(val) {
      console.log(val)

      let arr = JSON.parse(JSON.stringify(this.subjectList))
      this.subjectList = []
      arr.forEach((p, pi) => {
        val.forEach(v => {
          // console.log(p,v);
          if (p.id == v) {
            this.subjectList.push(p)
          }
        })
      })
      if (this.params.paperType == 2) {
        this.endType = false
      }
    },
    renderContent(h, {node, data, store}) {
      return (
        <span
          class="custom-tree-node"
          on-mouseover={() => {
            this.show = true
          }}
          on-mouseout={() => {
            this.show = false
          }}
        >
          <span>{data.userName}</span>
          <span>
            <el-button
              style="width:100%;border:0;margin:0;"
              size="mini"
              // icon="el-icon-delete"
              type="text"
              on-click={() => this.remove(data)}
            >
              删除
            </el-button>
          </span>
        </span>
      )
    },
    remove(val) {
      this.params.userInfoVos.forEach((u, ui) => {
        if (u.userId == val.userId) {
          this.params.userInfoVos.splice(ui, 1)
        }
      })
      this.userInfoVos = JSON.parse(JSON.stringify(this.params.userInfoVos))
      this.userlength = this.params.userInfoVos.length
      this.getOrgUserPage(1)
    }
  }
}
</script>
<style>
.el-message-box {
  position: absolute;
  top: 25%;
  left: 40%;
}

.parsing p {
  margin: 0;
  display: inline;
}
</style>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  height: 100% !important;
  max-height: 80%;
}

::v-deep .bbsl-location-dialog .el-dialog__body {
  margin: 0 !important;
}

.column-box {
  display: flex;
  justify-content: space-around;
}

.disposition {
  max-height: 500px;
  overflow-y: auto;

  .itemBox {
    width: 100%;
    padding: 10px 20px;
    box-sizing: border-box;
    border: 1px solid #e6e6e6;
    margin-bottom: 10px;
  }

  .itemBox:hover {
    border: 1px solid #009aff;
  }

  .details {
    .correct {
      margin: 10px 0;
      color: #009aff;
    }

    .parsing {
      margin: 10px 0;
      color: #999;
    }
  }

  .topic {
    padding: 10px 0;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;

    .topic-left {
      display: flex;
      justify-content: space-between;
      align-items: center;

      div:nth-child(1) {
        color: #36aafd;
        padding: 0 4px;
        border: 1px solid #36aafd;
      }

      div:nth-child(2) {
        color: #36aafd;
        padding: 0 4px;
        margin: 0 5px;
        border: 1px solid #36aafd;
      }
    }

    .topic-right {
      display: flex;
      justify-content: space-between;

      div:nth-child(1) {
        margin: 0 20px;
      }
    }
  }

  .tally {
    color: #999;
    padding: 5px 0;
    box-sizing: border-box;
  }

  .footer {
    color: #999;
    padding: 5px 0;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
  }
}

.examinee {
  margin-top: 10px;
  display: flex;
  min-height: 400px;

  .examinee-left {
    width: 20%;

    ::v-deep .el-tree {
      border: none;
    }
  }

  .examinee-right {
    width: 80%;
  }
}

::v-deep .el-tree-node__content {
  padding: 5px 0;
}

.typeBtn {
  height: 40px;
  padding: 0 20px;
  box-sizing: border-box;
  border: 1px solid #dcdfe6;
  text-align: center;
  border-radius: 3px;
  margin-right: 5px;
}

.btnActive {
  background-color: #1289fe;
  color: #fff;
}

.el-row {
  height: 100%;
}

.el-col {
  height: 100%;
}

.el-table {
  height: calc(100% - 50px);
  margin-bottom: 10px;
}

.buttons {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.combined {
  text-align: right;
  font-weight: bold;
  font-size: 16px;
  margin-right: 20px;
}

.select-header {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebeef5;
}

.el-tree {
  border: none;
}

::v-deep .el-popover {
  position: absolute;
  // background: #ffffff;
  // min-width: 7.8125vw;
  // border-radius: 0.20833vw;
  // border: 1px solid #ebeef5;
  // padding: 0.625vw;
  // z-index: 2000;
  // color: #606266;
  // line-height: 1.4;
  // text-align: justify;
  // font-size: 0.72917vw;
  // // box-shadow: 0 0.10417vw 0.625vw 0 rgb(0 0 0 / 10%);
  // word-break: break-all;
  right: 0;
}
</style>
