<template>
  <div>
    <div class="app-container">
      <el-form ref="form" :rules="rules" :model="pd" label-width="110px" style="padding:0 40px">
        <el-form-item label="学习任务名称" prop="NAME">
          <el-input v-model="form.STUDY_NAME" placeholder="这里输入证书名称..." />
        </el-form-item>
        <!--        <el-form-item label="培训行业类型" prop="VALIDITYTIME">-->
        <!--          <SelectTree ref="pxTree" :options="pxList" :props="defaultProps" v-model="form.TRAINTYPE" placeholder="请选择" />-->
        <!--        </el-form-item>-->
        <el-form-item label="岗位培训类型" prop="NUMBER">
          <SelectTree ref="gwTree" :options="gwList" :props="defaultProps" v-model="form.POSTTYPE" placeholder="请选择" />
        </el-form-item>
        <el-form-item label="培训时间">
          <el-date-picker v-model="form.PEIXUE_TIME" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"/>
        </el-form-item>
        <el-form-item label="是否签到">
          <div style="display:flex">
            <div>
              <el-radio v-model="form.KJ_STATE" label="1">是</el-radio>
              <el-radio v-model="form.KJ_STATE" disabled label="2">否</el-radio>
            </div>
            <div class="red-tip">*开启签到后，学员培训前需要进行电子手签。并会记录到《学员名册及考勤》档案中</div>
          </div>
        </el-form-item>
        <el-form-item
          label="是否开启防挂机验证"
          class="singerH">
          <div style="display:flex">
            <div>
              <el-radio v-model="form.GJ_STATE" label="1">是</el-radio>
              <el-radio v-model="form.GJ_STATE" disabled label="2">否</el-radio>
            </div>
            <div class="red-tip">*开启放挂机验证员工学习过程会进行人脸识别，确保是员工本人在培训</div>
          </div>

        </el-form-item>
        <el-form-item label="添加课程">
          <div style="display:flex">
            <div>
              <el-button type="primary" icon="el-icon-upload" style="margin-left:10px; " plain @click="addKecheng">添加课程</el-button>
            </div>
            <div style="width:600px;margin-left:20px">
              <el-card v-if="curriculumMap.xzList.length>0" class="box-card">
                <div slot="header" class="clearfix">
                  <span>已选择课程</span>
                </div>
                <el-table
                  v-loading="listLoading"
                  ref="multipleCurTable2"
                  :data="curriculumMap.xzList"
                  :summary-method="getSummaries"
                  :header-cell-style="{ 'font-weight': 'bold','color': '#000' }"
                  show-summary
                  max-height="250"
                  tooltip-effect="dark"
                  border
                  highlight-current-row>
                  <el-table-column prop="CURRICULUMNAME" label="课程名称" />
                  <el-table-column prop="COURSEWARECOUNT" label="课件数" width="70" align="center" />
                  <el-table-column prop="CLASSHOUR" label="学时(分钟)" width="150" align="center" />
                </el-table>
              </el-card>
            </div>
          </div>

        </el-form-item>
        <el-form-item label="添加人员">
          <div style="display:flex">
            <div>
              <el-button type="primary" icon="el-icon-upload" style="margin-left:10px; " plain @click="addUser('1')">添加人员</el-button>
            </div>
            <div style="width:600px;margin-left:20px">
              <el-card v-if="userMap.xzList.length>0" class="box-card">
                <div slot="header" class="clearfix">
                  <span>已选择人员</span>
                </div>
                <el-table v-loading="listLoading" ref="multipleUserTable2" :data="userMap.xzList" :header-cell-style="{ 'font-weight': 'bold','color': '#000' }" max-height="250" tooltip-effect="dark" border fit highlight-current-row>
                  <el-table-column prop="USERNAME" label="用户名" />
                  <el-table-column prop="NAME" label="姓名" />
                  <el-table-column prop="DEPARTMENT_NAME" label="部门" />
                </el-table>
              </el-card>
            </div>
          </div>

        </el-form-item>
        <el-form-item label="设置考试">
          <div style="display:flex">
            <div>
              <el-button type="primary" icon="el-icon-upload" style="margin-left:10px; " plain @click="addKaoshi">设置考试</el-button>
            </div>
            <div style="width:600px;margin-left:20px">
              <el-card v-if="shijuanMap.xzfrom.kaoshoName" class="box-card">
                <div slot="header" class="clearfix">
                  <span>已设置考试</span>
                </div>
                <el-table v-loading="listLoading" ref="multipleKaoshiTable2" :data="shijuanMap.xzList" :header-cell-style="{ 'font-weight': 'bold','color': '#000' }" max-height="250" tooltip-effect="dark" border fit highlight-current-row>
                  <el-table-column prop="kaoshoName" label="考试名称" />
                  <el-table-column prop="ANSWERSHEETTIME" label="考试时长" />
                  <el-table-column prop="examType" label="考试类型" />
                  <el-table-column prop="EXAMNAME" label="阶段试卷" />
                </el-table>
              </el-card>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="设置记录人员">
          <el-row>
            <el-col :span="12">
              <el-input v-model="form.RECORDER" :disabled="true" placeholder="记录人员..." />
            </el-col>
            <el-col :span="12">
              <el-button type="primary" icon="el-icon-upload" style="margin-left:10px; " plain @click="addUser('2')">添加记录人员</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="设置安全生产机构负责人">
          <el-row>
            <el-col :span="12">
              <el-input v-model="form.CHARGE" :disabled="true" placeholder="安全生产机构负责人..." />
            </el-col>
            <el-col :span="12">
              <el-button type="primary" icon="el-icon-upload" style="margin-left:10px; " plain @click="addUser('3')">添加安全生产机构负责人</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </div>
    <div class="ui-height" />
    <div class="ui-foot">
      <el-button type="primary" @click="confirmByAddStudytask">确 定</el-button>
      <el-button plain type="info" @click="goBack" >返 回</el-button>
    </div>
    <el-dialog :visible.sync="dialogAddCur" title="选择课程" width="814px">
      <div class="filter-container">
        <div class="filter-group">
          <div class="filter-lable">课程名称：</div>
          <el-input v-model="curriculumMap.KEYWORDS" placeholder="请输入课程名称或课程简介或课程目的" class="filter-item" style="width: 200px;" />
        </div>
        <div class="filter-group">
          <div class="filter-lable">岗位培训类型：</div>
          <SelectTree ref="postType_Select" :options="gwList" :clearable="false" :props="defaultProps" v-model="curriculumMap.postTypeId" placeholder="请选择" />
        </div>
        <el-button v-waves class="ml-10" type="primary" icon="el-icon-search" @click="getListByCurriculum"> 搜索 </el-button>
        <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="getCurriculumReset"> 重置 </el-button>
      </div>
      <el-table v-loading="listLoading" ref="multipleCurTable" :data="curriculumMap.valueList" :row-key="getRowKeyByCurTable" :header-cell-style="{ 'font-weight': 'bold','color': '#000' }" tooltip-effect="dark" border fit highlight-current-row>
        <el-table-column :reserve-selection="true" type="selection" width="55" align="center" />
        <el-table-column type="index" label="序号" width="50" align="center" />
        <el-table-column prop="CURRICULUMNAME" label="课程名称" />
        <el-table-column :show-overflow-tooltip="true" prop="train_type_name" label="培训行业类型" />
        <el-table-column :show-overflow-tooltip="true" prop="post_type_name" label="岗位培训类型" />
        <el-table-column prop="CLASSHOUR" label="学时(分钟)" width="150" align="center" />
        <el-table-column prop="COURSEWARECOUNT" label="课件数" width="70" align="center" />
      </el-table>
      <div class="mt-10">
        <pagination :total="curriculumMap.total" :page.sync="curriculumMap.page" :limit.sync="curriculumMap.limit" @pagination="getListByCurriculum" />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmByCur">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogAddUser" title="选择人员" width="800px" @close="closeDialog">
      <div class="filter-container">
        <div class="filter-group">
          <div class="filter-lable">人员姓名：</div>
          <el-input v-model="userMap.KEYWORDS" placeholder="搜索" class="filter-item" style="width: 150px;" />
        </div>
        <div class="filter-group">
          <div class="filter-lable">部门：</div>
          <SelectTree ref="deptTree_Select" :clearable="false" :options="userMap.treeData" :props="defaultProps" v-model="userMap.DEPARTMENT_ID" style="width: 150px;" placeholder="请选择部门" />
        </div>
        <el-button v-waves class="ml-10" type="primary" icon="el-icon-search" @click="getUserList"> 搜索 </el-button>
        <el-button v-waves type="success" icon="el-icon-refresh" @click="getUserReset"> 重置 </el-button>
      </div>
      <el-table v-loading="listLoading" ref="multipleUserTable" :data="userMap.valueList" :row-key="getRowKeyByUrtTable" :header-cell-style="{ 'font-weight': 'bold','color': '#000' }" tooltip-effect="dark" border fit highlight-current-row>
        <el-table-column :reserve-selection="true" type="selection" width="55" align="center" />
        <el-table-column type="index" label="序号" width="50" align="center" />
        <el-table-column prop="USERNAME" label="用户名" />
        <el-table-column prop="NAME" label="姓名" />
        <el-table-column prop="DEPARTMENT_NAME" label="部门" />
        <el-table-column prop="POST_NAME" label="岗位" width="150" show-overflow-tooltip />
        <el-table-column prop="ROLE_NAME" label="角色" />
      </el-table>
      <div class="mt-10">
        <pagination :total="userMap.total" :page.sync="userMap.page" :limit.sync="userMap.limit" @pagination="getUserList" />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmByUser">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogAddKaoshi" title="考试设置" width="800px" top="60px">
      <el-form ref="shijuanMap" :rules="rules" :model="shijuanMap" label-width="110px" style="padding-right:30px">
        <el-form-item label="考试名称" prop="kaoshoName">
          <el-input id="kaoshoName" ref="kaoshoName" v-model="shijuanMap.xzfrom.kaoshoName" maxlength="255" placeholder="这里输入试卷名称..." title="试卷名称"/>
        </el-form-item>
        <el-form-item label="考试时间" prop="EXAMTIME">
          <el-date-picker
            v-model="form.PEIXUE_TIME"
            :disabled="true"
            type="daterange"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"/>
        </el-form-item>
        <el-form-item label="考试时长" prop="ANSWERSHEETTIME">
          <el-input-number id="ANSWERSHEETTIME" ref="ANSWERSHEETTIME" :min="1" v-model="shijuanMap.xzfrom.ANSWERSHEETTIME" maxlength="255" placeholder="这里输入考试时长..." title="考试时长"/>
          <span class="ml-10">分钟</span>
        </el-form-item>
        <el-form-item label="考试次数" prop="numberOfExaminations">
          <el-select v-model="shijuanMap.xzfrom.NUMBER_OF_EXAMINATIONS" placeholder="请选择考试次数">
            <el-option v-for="item in shijuanMap.numberOfExmList" :key="item.value" :label="item.label" :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="考试类型" prop="23">
          <el-select v-model="shijuanMap.xzfrom.examType" placeholder="请选择考试类型">
            <el-option v-for="item in shijuanMap.examTypeList" :key="item.value" :label="item.label" :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="总分数" prop="EXAMSCORE">
          <el-input id="EXAMSCORE" ref="EXAMSCORE" :disabled="true" v-model="shijuanMap.xzMap.EXAMSCORE" maxlength="255" placeholder="这里输入试卷分数..." title="试卷分数" style="width:215px"/>
        </el-form-item>
        <el-form-item label="合格分数" prop="CURRICULUMUSERS">
          <el-input id="EXAMSCOR22E" ref="EXAMSCOR22E" :disabled="true" v-model="shijuanMap.xzMap.PASSSCORE" maxlength="255" placeholder="这里输入试卷分数..." title="试卷分数" style="width:215px"/>
        </el-form-item>
        <div style="padding-left:110px;">
          <el-table
            v-loading="listLoading"
            ref="multipleKaoshiTable"
            :row-key="getRowKeyByKaoshi"
            :data="shijuanMap.valueList"
            :header-cell-style="{ 'font-weight': 'bold', 'color': '#000' }"
            tooltip-effect="dark"
            border
            fit
            highlight-current-row
            @current-change="handleSelectionChange"
          >
            <el-table-column type="index" label="序号" width="50" align="center" />
            <el-table-column prop="EXAMNAME" label="阶段试卷" />
            <el-table-column prop="post_type_name" label="培训行业类型" />
            <el-table-column prop="train_type_name" label="岗位培训类型" align="center" />
            <el-table-column prop="ANSWERSHEETTIME" label="试题数" align="center" width="80">
              <template slot-scope="{row}">
                <template>
                  <div>{{ (Number(row.DUOXUANTICOUNT)) + (Number(row.DANYUANTICOUNT))+ (Number(row.PANDUITICOUNT)) }}</div>
                </template>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="page-btn-group">
          <div/>
          <pagination :total="shijuanMap.total" :page.sync="shijuanMap.page" :limit.sync="shijuanMap.limit" @pagination="getKaoshiList" />
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmByKaoshi">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import SelectTree from '@/components/SelectTree'
import waves from '@/directive/waves' // waves directive
export default {
  components: { Pagination, SelectTree },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      defaultProps: {
        value: 'id',
        children: 'nodes',
        label: 'name'
      },
      pxList: [],
      gwList: [],
      form: {
        STUDY_NAME: '', // 学习任务名称
        TRAINTYPE: '', // 培训行业类型
        POSTTYPE: '', // 岗位培训类型
        PEIXUE_TIME: [], // 培训时间
        PEIXUE_START_TIME: '', //  培训开始时间
        PEIXUE_END_TIME: '', // 培训结束时间
        KJ_STATE: '1', // 是否签到
        GJ_STATE: '1', // 是否开启防挂机验证
        STAGEEXAMPAPER_ID: '', // 考试
        STUDY_USER_ID: '', // 人员id
        STUDY_CURRICULUM_ID: '', // 添加课程IDS
        CREATOR: '', // 添加人
        CREATTIME: '', // 添加时间
        OPERATOR: '', // 修改人
        OPERATTIME: '', // 修改时间
        ISDELETE: '', // 是否删除(0:有效 1：删除)
        RECORDER: '', // 记录人员
        CHARGE: '', // 安全生产机构负责人
        RECORDERUSERIDS: '', // 记录人员
        CHARGEUSERIDS: '', // 安全生产机构负责人
        CORPINFO_ID: ''// 企业ID
      },
      pd: {},
      rules: {},
      dialogAddCur: false,
      curriculumMap: {
        valueList: [],
        total: 0,
        page: 1,
        limit: 10,
        KEYWORDS: '',
        postTypeId: '',
        xzList: []
      },
      dialogAddUser: false,
      addUserType: '0',
      recorderUserList: [], // 选中的记录人员
      chargeUserList: [], // 选中的安全生产机构负责人
      userMap: {
        valueList: [],
        total: 0,
        page: 1,
        limit: 10,
        KEYWORDS: '',
        treeData: [],
        DEPARTMENT_ID: '',
        xzList: []
      },
      dialogAddKaoshi: false,
      shijuanMap: {
        kaoshoName: '',
        valueList: [],
        total: 0,
        page: 1,
        limit: 10,
        xzMap: {},
        xzfrom: {},
        xzList: [],
        examType: '1',
        examTypeList: [{
          value: '1',
          label: '线上考试'
        }],
        numberOfExmList: [ // 考试次数  Number of examinations
          { value: '2', label: '2次' },
          { value: '-1', label: '重复考试' }
        ]
      }
    }
  },
  async created() {
    await this.getTreeDicByParId('pxList', '052369aa22d242118236cde52d0c67ea')
    await this.getTreeDicByParId('gwList', 'f6a7c4f5602f46e291d06b1390a3f820')
  },
  methods: {
    getSummaries(param) { // 合计
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总计'
          return
        }
        const values = data.map(item => Number(item[column.property]))
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          if (index === 1) {
            sums[index] += ' 个'
          } else if (index === 2) {
            sums[index] += ' (分钟)'
          }
        } else {
          sums[index] = 'N/A'
        }
      })
      return sums
    },
    getTreeDicByParId(listName, parentId) {
      requestFN(
        '/dictionaries/listAllDictToParId',
        {
          parentId: parentId
        }
      ).then((data) => {
        this[listName] = JSON.parse(data.zTreeNodes)
      }).catch((e) => {
        this.listLoading = false
      })
    },
    addKecheng() { // 点击添加课程按钮
      this.dialogAddCur = true
      if (this.curriculumMap.valueList.length == 0) {
        this.getListByCurriculum()
      }
    },
    getRowKeyByCurTable(row) { // 多行选择器 事件
      return row.CURRICULUM_ID
    },
    getListByCurriculum() { // 获取课程数据
      this.listLoading = true
      requestFN(
        '/curriculum/list?showCount=' + this.curriculumMap.limit + '&currentPage=' + this.curriculumMap.page,
        {
          KEYWORDS: this.curriculumMap.KEYWORDS,
          POSTTYPE: this.curriculumMap.postTypeId
        }
      ).then((data) => {
        this.listLoading = false
        this.curriculumMap.valueList = data.varList
        this.curriculumMap.total = data.page.totalResult
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getCurriculumReset() { // 添加条件 清除数据
      this.curriculumMap.KEYWORDS = ''
      this.curriculumMap.postTypeId = ''
      this.curriculumMap.total = 1
      this.curriculumMap.page = 0
      this.curriculumMap.limit = 10
      this.$refs.postType_Select.clearHandle()
      this.getListByCurriculum()
    },
    confirmByCur() {
      this.curriculumMap.xzList = []
      this.curriculumMap.xzList = this.$refs.multipleCurTable.selection// 选择的资料课件内容
      this.dialogAddCur = false
    },
    cancelByCur() {
      this.curriculumMap.xzList = []
      this.dialogAddCur = false
    },
    addUser(type) {
      this.addUserType = type
      this.dialogAddUser = true
      this.getUserList(type)
      this.getTreeList()
      if (type == '1') {
        this.userMap.xzList.forEach(row => {
          this.$refs.multipleUserTable.toggleRowSelection(row)
        })
      }
      if (type == '2') {
        this.recorderUserList.forEach(row => {
          this.$refs.multipleUserTable.toggleRowSelection(row)
        })
      }
      if (type == '3') {
        this.chargeUserList.forEach(row => {
          this.$refs.multipleUserTable.toggleRowSelection(row)
        })
      }
    },
    getUserList() {
      this.listLoading = true
      requestFN(
        '/user/list?showCount=' + this.userMap.limit + '&currentPage=' + this.userMap.page,
        {
          KEYWORDS: this.userMap.KEYWORDS,
          DEPARTMENT_ID: this.userMap.DEPARTMENT_ID,
          IS_STUDEANT: 1,
          IS_RECORDER: this.addUserType == '2' ? '1' : 0,
          IS_CHARGE: this.addUserType == '3' ? '1' : 0
        }
      ).then((data) => {
        this.listLoading = false
        this.userMap.valueList = data.userList
        this.userMap.total = data.page.totalResult
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getRowKeyByUrtTable(row) {
      return row.USER_ID
    },
    closeDialog() {
      this.$refs.multipleUserTable.clearSelection()
    },
    confirmByUser() {
      if (this.addUserType == '1') {
        this.userMap.xzList = []
        this.userMap.xzList = this.$refs.multipleUserTable.selection// 选择的资料课件内容
      }
      if (this.addUserType == '2') {
        this.recorderUserList = []
        this.recorderUserList = this.$refs.multipleUserTable.selection// 选择的资料课件内容
        var recUserName = ''
        var recUserIds = ''
        this.recorderUserList.forEach(row => {
          recUserName += row.NAME + ','
          recUserIds += row.USER_ID + ','
        })
        this.form.RECORDERUSERIDS = recUserIds
        this.form.RECORDER = recUserName
      }
      if (this.addUserType == '3') {
        this.chargeUserList = []
        this.chargeUserList = this.$refs.multipleUserTable.selection// 选择的资料课件内容
        var chargeUserName = ''
        var chargeUserIds = ''
        this.chargeUserList.forEach(row => {
          chargeUserName += row.NAME + ','
          chargeUserIds += row.USER_ID + ','
        })
        this.form.CHARGEUSERIDS = chargeUserIds
        this.form.CHARGE = chargeUserName
      }
      this.$refs.multipleUserTable.clearSelection()
      this.dialogAddUser = false
    },
    getTreeList() {
      this.listLoading = true
      requestFN(
        '/department/listTree',
        {}
      ).then((data) => {
        this.listLoading = false
        this.userMap.treeData = JSON.parse(data.zTreeNodes)
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getUserReset() {
      this.userMap.KEYWORDS = ''
      this.userMap.DEPARTMENT_ID = ''
      this.userMap.total = 1
      this.userMap.page = 0
      this.userMap.limit = 10
      this.$refs.deptTree_Select.clearHandle()
      this.getUserList()
    },
    addKaoshi() { // 点击添加课程按钮
      this.dialogAddKaoshi = true
      this.getKaoshiList()
    },
    // 获取列表
    getKaoshiList() {
      this.listLoading = true
      requestFN(
        '/stageexampaperinput/list?showCount=' + this.shijuanMap.limit + '&currentPage=' + this.shijuanMap.page,
        {
          KEYWORDS: this.KEYWORDS,
          STATE: '0'
        }
      ).then((data) => {
        this.listLoading = false
        this.shijuanMap.valueList = data.varList
        this.shijuanMap.total = data.page.totalResult
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getRowKeyByKaoshi(row) {
      return row.STAGEEXAMPAPERINPUT_ID
    },
    confirmByAddStudytask() {
      if (!this.form.STUDY_NAME) {
        this.$message.warning('请输入学习任务名称')
        return false
      }
      // if (!this.form.TRAINTYPE) {
      //   this.$message.warning('请选择培训行业类型')
      //   return false
      // }
      if (!this.form.POSTTYPE) {
        this.$message.warning('请选择岗位培训类型')
        return false
      }
      if (this.form.PEIXUE_TIME.length != 0) {
        this.form.PEIXUE_START_TIME = this.form.PEIXUE_TIME[0]
        this.form.PEIXUE_END_TIME = this.form.PEIXUE_TIME[1]
      } else {
        this.$message.warning('请选择培训时间')
        return false
      }
      if (this.curriculumMap.xzList.length > 0) { // 课程信息
        var curIds = ''
        this.curriculumMap.xzList.forEach(cuMap => {
          curIds += cuMap.CURRICULUM_ID + ','
        })
        this.form.curIds = curIds
      } else {
        this.$message.warning('请选择课程信息')
        return false
      }
      if (this.userMap.xzList.length > 0) { // 人员信息
        var userIds = ''
        this.userMap.xzList.forEach(usermap => {
          userIds += usermap.USER_ID + ','
        })
        this.form.userIds = userIds
      } else {
        this.$message.warning('请选择考试人员信息')
        return false
      }
      if (JSON.stringify(this.shijuanMap.xzMap) == '{}') { // 试卷信息
        this.$message.warning('请选择考试信息')
        return false
      } else {
        this.form.INPUT_ID = this.shijuanMap.xzMap.STAGEEXAMPAPERINPUT_ID
        this.form.kaoshoName = this.shijuanMap.xzMap.kaoshoName
        this.form.examType = this.shijuanMap.xzMap.examType
        this.form.ANSWERSHEETTIME = this.shijuanMap.xzMap.ANSWERSHEETTIME
        this.form.EXAMSCORE = this.shijuanMap.EXAMSCORE
        this.form.QUESTIONNUM = parseInt(this.shijuanMap.xzMap.DANYUANTICOUNT) + parseInt(this.shijuanMap.xzMap.DUOXUANTICOUNT) + parseInt(this.shijuanMap.xzMap.PANDUITICOUNT)
        this.form.NUMBER_OF_EXAMINATIONS = this.shijuanMap.xzMap.NUMBER_OF_EXAMINATIONS
      }

      this.listLoading = true
      requestFN(
        '/studytask/add',
        this.form
      ).then((data) => {
        this.listLoading = false
        this.$parent.activeName = 'Course'
      }).catch((e) => {
        this.listLoading = false
      })
    },
    handleSelectionChange(row) {
      this.shijuanMap.xzMap = row
    },
    confirmByKaoshi() {
      if (!this.shijuanMap.xzfrom.kaoshoName) {
        this.$message.warning('请输入考试名称')
        return false
      }
      if (!this.shijuanMap.xzfrom.ANSWERSHEETTIME) {
        this.$message.warning('请输入考试时长')
        return false
      }
      if (!this.shijuanMap.xzfrom.NUMBER_OF_EXAMINATIONS) {
        this.$message.warning('请选择考试次数')
        return false
      }
      if (!this.shijuanMap.xzfrom.examType) {
        this.$message.warning('请选择考试类型')
        return false
      }
      if (!this.shijuanMap.xzfrom.NUMBER_OF_EXAMINATIONS) {
        this.$message.warning('请选择考试次数')
        return false
      }
      if (JSON.stringify(this.shijuanMap.xzMap) == '{}') { // 试卷信息
        this.$message.warning('请选择考试信息')
        return false
      }
      this.dialogAddKaoshi = false
      this.shijuanMap.xzList = []
      if (this.shijuanMap.xzfrom.ANSWERSHEETTIME) {
        this.shijuanMap.xzMap.ANSWERSHEETTIME = this.shijuanMap.xzfrom.ANSWERSHEETTIME
      }
      if (this.shijuanMap.xzfrom.examType) {
        this.shijuanMap.xzMap.examType = this.shijuanMap.xzfrom.examType
      }
      if (this.shijuanMap.xzfrom.NUMBER_OF_EXAMINATIONS) {
        this.shijuanMap.xzMap.NUMBER_OF_EXAMINATIONS = this.shijuanMap.xzfrom.NUMBER_OF_EXAMINATIONS
      }
      if (this.shijuanMap.xzfrom.kaoshoName) {
        this.shijuanMap.xzMap.kaoshoName = this.shijuanMap.xzfrom.kaoshoName
      }
      this.shijuanMap.xzList.push(this.shijuanMap.xzMap)
    },
    goBack() {
      this.$parent.activeName = 'Course'
    }
  }
}

</script>
