<template>
  <div class="bigBox">
    <MOSTY.FromPage :title="props.formData.title" @closeDialog="handleClose">
      <template #content>
        <MOSTY.Assort :title="'基础信息'" />
        <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="135px" :="true"
          class="demo-ruleForm.value" :disabled="!props.formData.saveBtnShow" :inline="true">
          <el-form-item label="培训计划:" prop="planName">
            <el-input v-model="ruleForm.planName" maxlength="100" autosize type="textarea" show-word-limit
              placeholder="不能超过100个字" style="width: 337px;"></el-input>
          </el-form-item>
          <el-form-item label="主办部门：" prop="planHostsDeptName">
            <el-input v-model="ruleForm.planHostsDeptName" readonly clearable :disabled="disableds"
              style="width: 337px;">
              <template #append>
                <el-button class='cursor' @click="ChooesDdld('01')">选择</el-button></template>
            </el-input>
          </el-form-item>
          <el-form-item label="培训类型:" prop="otherType">
            <el-select v-model="ruleForm.otherType" :disabled='ruleForm.id || props.type == "3"' style="width: 337px;"
              clearable>
              <el-option v-for="item in pxlxlist" :disabled="item.disabled" :key="item" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型：" prop="specialityType">
            <el-select v-model="ruleForm.specialityType" multiple style="width: 337px;" clearable
              placeholder="请选择业务类型：">
              <el-option v-for="item in D_TB_YWLX" :key="item" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="培训开始日期：" prop="startDate">
            <el-date-picker v-model="ruleForm.startDate" style="width: 337px;" type="date" placeholder="培训开始日期"
              format="YYYY-MM-DD" value-format="YYYY-MM-DD" :disabled-date="disablednowDates" @change='changetime' />
          </el-form-item>
          <el-form-item label="培训结束日期：" prop="finshDate">
            <el-date-picker v-model="ruleForm.finshDate" style="width: 337px;" type=" date" placeholder="培训结束日期"
              format="YYYY-MM-DD" value-format="YYYY-MM-DD" :disabled-date="disablednowDate" @change='changetime2' />
          </el-form-item>
          <el-form-item label="报道截止时间：" prop="signFinshDate">
            <el-date-picker v-model="ruleForm.signFinshDate" style="width: 337px;" type="date" format="YYYY-MM-DD"
              value-format="YYYY-MM-DD" :disabled-date="disablednowDate2" />
          </el-form-item>

          <el-form-item label="项目负责人：" prop="planChargePersonName">
            <el-input v-model="ruleForm.planChargePersonName" style="width: 337px;" clearable readonly
              :disabled="disableds">
              <template #append>
                <el-button class='cursor' @click="ChooesDdld('02')">选择</el-button></template>
            </el-input>
          </el-form-item>
          <el-form-item label="联系人：" prop="contactorName">
            <el-input v-model="ruleForm.contactorName" style="width: 337px;" clearable></el-input>
          </el-form-item>
          <el-form-item label="联系人电话：" prop="contactorPhone">
            <el-input v-model="ruleForm.contactorPhone" style="width: 337px;" type="Number"></el-input>
          </el-form-item>
          <el-form-item label="培训预算（元）：" prop="realBudget">
            <el-input v-model="ruleForm.realBudget" type="Number" maxlength="7" style="width: 337px;" @input="check">
              <template #append>元</template></el-input>
          </el-form-item>
          <el-form-item label="考核方式:" prop="examinationType">
            <el-select v-model="ruleForm.examinationType" :disabled='ruleForm.xtCjsj' style="width: 337px;" clearable>
              <el-option v-for="item in D_TB_PXKHFS" :key="item" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="培训课时：" prop="realClassHour">
            <el-input v-model="ruleForm.realClassHour" type="Number" maxlength="3" style="width: 337px;"
              @input="check1"></el-input>
          </el-form-item>
          <el-form-item label="培训教师：" prop="teachers">
            <el-input v-model="ruleForm.teachers" maxlength="200" autosize style="width: 337px;" type="textarea"
              show-word-limit placeholder="不能超过200个字"></el-input>
          </el-form-item>
          <el-form-item label="培训地点:" prop="place">
            <el-input v-model="ruleForm.place" maxlength="100" style="width: 337px;" autosize type="textarea"
              show-word-limit placeholder="不能超过100个字"></el-input>
          </el-form-item>

          <el-form-item label="培训内容:" style='width:100%;'>
            <el-input v-model="ruleForm.realContent" maxlength="500" type="textarea" show-word-limit
              placeholder="不能超过500个字" style="width:100%;" />
          </el-form-item>
          <el-form-item label="备注:" style='width:100%;'>
            <el-input v-model="ruleForm.bz" maxlength="500" type="textarea" show-word-limit placeholder="不能超过500个字"
              style="width: 100%;" />
          </el-form-item>
        </el-form>
        <div v-if='ruleForm.id'>
          <MOSTY.Assort :title="'二维表'" />
          <div style="display: flex">
            <MOSTY.ErwmImg :url="qrcodepxImg(ruleForm.id, 'train_in')" :filename='val.planName' :id='"htmlsmewmqd"' />
            <MOSTY.ErwmImg :url="qrcodepxImg(ruleForm.id, 'train_out')" :filename='val.planName' :id='"htmlsmewmql"' />
            <!-- <div class="erweim">
              <img :src="qrcodepxImg(ruleForm.id, 'train_in')" alt="" id="htmlsmewmqd" />
              <el-button @click="onloadewm1(ruleForm)">点击下载签到二维码</el-button>
            </div>
            <div class="erweim">
              <img :src="qrcodepxImg(ruleForm.id, 'train_out')" alt="" id="htmlsmewmql" />
              <el-button @click="onloadewm2(ruleForm)">点击下载离签二维码</el-button>
            </div> -->
          </div>
        </div>
        <div>
          <MOSTY.Assort :title="'参训学员列表'" />
          <div class="addbtn">
            <el-button type="primary" @click="ChooesDdld('03')">
              <el-icon>
                <CirclePlus />
              </el-icon>
              <span>添加</span>
            </el-button>
          </div>
          <section style="height: 30vh;">
            <MOSTY.Table :table-columns="tableColumns1" :tableData="ruleForm.signList" :tableloading="tableloading"
              :tableHeight="'100%'" :isSelect="false" style="width: 100%;" :isSort="false">
              <template #actions="scope">
                <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon-color="red" title="确定要删除?"
                  @confirm="deldetexy(scope.row)">
                  <template #reference>
                    <span class="operdel" size="small"><el-icon>
                        <Delete />
                      </el-icon>删除</span>
                  </template>
                </el-popconfirm>
              </template>
            </MOSTY.Table>
          </section>
          <div class="fenye" v-if="props.xqId != null">
            <MOSTY.Pages :pageConfiger="pageConfiger" @changeNo="handleCurrentChange" @changeSize="handleSizeChange" />

          </div>
        </div>
        <div v-if='ruleForm.examinationType == "2" || ruleForm.examinationType == "4"'>
          <MOSTY.Assort :title="'配置考题卷'" />
          <div>
            <el-form ref="ruleFormRef2" :model="ruleForm" :rules="ruleForm.examinationType != '2' ? rules2 : rules3"
              :="true" label-width="135px" :inline="true">
              <el-form-item label="试卷：" prop='paperName'>
                <el-input v-model="ruleForm.paperName" style="width: 337px;" clearable readonly>
                  <template #append>
                    <el-button class='cursor' @click="ChooesDdld('04')">选择</el-button></template>
                </el-input>
              </el-form-item>
              <el-form-item label="出题方式：" prop='ctfs'>
                <el-select v-model="ruleForm.ctfs" disabled style="width: 337px;" clearable placeholder='请选择试卷出题方式'>
                  <el-option v-for="item in D_BZ_PXSSCTFS" :key="item" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>

              <el-form-item label="判断题数量：" prop="pdCount">
                <el-input v-model.number="ruleForm.pdCount" style="width: 337px;" disabled type='number'>
                  <template #append>题</template>
                </el-input>
              </el-form-item>
              <el-form-item label="单选题数量：" prop='danxCount'>
                <el-input v-model.number="ruleForm.danxCount" style="width: 337px;" disabled type='number'>
                  <template #append>题</template>
                </el-input>
              </el-form-item>
              <el-form-item label="多选题数量：" prop='duoxCount'>
                <el-input v-model.number="ruleForm.duoxCount" style="width: 337px;" disabled type='number'>
                  <template #append>题</template>
                </el-input>
              </el-form-item>
              <el-form-item label="判断题分值：" prop='pdfz'>
                <el-input v-model.number="ruleForm.pdfz" :min="0" style="width: 337px;" type='number'
                  @change="changeScore()">
                  <template #append>分</template>
                </el-input>
              </el-form-item>
              <el-form-item label="单选题分值：" prop='danxfz'>
                <el-input v-model.number="ruleForm.danxfz" :min="0" style="width: 337px;" type='number'
                  @change="changeScore()">
                  <template #append>分</template></el-input>
              </el-form-item>
              <el-form-item label="多选题分值：" prop='duoxfz'>
                <el-input v-model="ruleForm.duoxfz" :min="0" style="width: 337px;" type='number'
                  @change="changeScore()">
                  <template #append>分</template></el-input>
              </el-form-item>
              <el-form-item label="总分：" prop='zf'>
                <el-input v-model="ruleForm.zf" disabled style="width: 337px;" type='number'>
                  <template #append>分</template></el-input>
              </el-form-item>
              <el-form-item label="合格分数：" prop='hgfs'>
                <el-input v-model.number="ruleForm.hgfs" :min="0" :max="100" style="width: 337px;" type='number'>
                  <template #append>分</template></el-input>
              </el-form-item>
              <el-form-item label="是否查看错题：" prop='sfckct'>
                <el-select v-model="ruleForm.sfckct" clearable>
                  <el-option v-for="item in D_BZ_SF" :key="item" :label="item.label" style="width: 337px;"
                    :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="考题是否随机：" prop='sflx'>
                <el-select v-model="ruleForm.sflx" clearable disabled>
                  <el-option v-for="item in D_BZ_SF" :key="item" :label="item.label" :value="item.value"
                    style="width: 337px;" />
                </el-select>
              </el-form-item>
              <el-form-item label="可考试次数：" prop='kcjcs'>
                <el-input v-model.number="ruleForm.kcjcs" :min="0" type='number' style="width: 337px;">
                  <template #append>次</template></el-input>
              </el-form-item>
              <el-form-item label="是否发证：" prop='sffz'>
                <el-select v-model="ruleForm.sffz" clearable style="width: 337px;">
                  <el-option v-for="item in D_BZ_SF" :key="item" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="最早开考时间:" prop='examStartTime'>
                <el-date-picker v-model="ruleForm.examStartTime" style="width: 337px;" type="datetime"
                  format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" :disabled-date="disablednowDates"
                  @change='ruleForm.examEndTime = ""' />
              </el-form-item>
              <el-form-item label="最晚开考时间:" prop='examEndTime'>
                <el-date-picker v-model="ruleForm.examEndTime" style="width: 337px;" type="datetime"
                  format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" :disabled-date="disabledzwkk" />
              </el-form-item>
              <el-form-item label="考试时间:" prop='examTime'>
                <el-input v-model="ruleForm.examTime" type="number" clearable style="width: 337px;">
                  <template #append>分钟</template></el-input>
              </el-form-item>
              <el-form-item v-if="ruleForm.sffz == '1'" label="证书模板：">
                <el-input v-model="ruleForm.mbName" clearable disabled style="width: 337px;"></el-input>
                <el-button @click="ChooesDdld('06')">选择</el-button>
              </el-form-item>
              <el-form-item v-if="ruleForm.sffz == '1'" label="证书模板：" style='width:100%;'>
                <el-image :src="ruleForm.mbImg" fit="scale-down" :preview-src-list="[ruleForm.mbImg]"></el-image>
              </el-form-item>
            </el-form>
            <div class="addbtn" v-if='exeamobj'>
              <el-button type="primary" @click="chooseexam">
                <el-icon>
                  <View />
                </el-icon>
                <span>预览试卷</span>
              </el-button>
            </div>
          </div>
        </div>
        <div>
          <MOSTY.Assort :title="'培训课件上传'" />
          <div style="margin: 10px">
            <MOSTY.Upload :widthNumber="800" :limit="5" :nopicer="true" :isImg="false" :ShowfileList="true"
              :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" v-model="ruleForm.files"
              :showinput="false" :delrow="delrow"></MOSTY.Upload>
          </div>
        </div>
        <div>
          <MOSTY.Assort :title="'培训方案附件'" />
          <div style="margin: 10px">
            <MOSTY.Upload :widthNumber="800" :limit="5" :nopicer="true" :isImg="false" :ShowfileList="true"
              :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" v-model="ruleForm.pxfa" :showinput="false"
              :delrow="delrow"></MOSTY.Upload>
          </div>
        </div>
        <div>
          <MOSTY.Assort :title="'培训通知文件附件'" />
          <div style="margin: 10px">
            <MOSTY.Upload :widthNumber="800" :limit="5" :nopicer="true" :isImg="false" :ShowfileList="true"
              :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" v-model="ruleForm.pxtzwj"
              :showinput="false" :delrow="delrow"></MOSTY.Upload>
          </div>
        </div>
        <div>
          <MOSTY.Assort :title="'签到表附件'" />
          <div style="margin: 10px">
            <MOSTY.Upload :widthNumber="800" :limit="5" :nopicer="true" :isImg="false" :ShowfileList="true"
              :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" v-model="ruleForm.qdb" :showinput="false"
              :delrow="delrow"></MOSTY.Upload>
          </div>
        </div>
        <div>
          <MOSTY.Assort :title="'培训图片上传'" />
          <div style="margin: 10px">
            <MOSTY.Upload :width="'100%'" :limit="5" :nopicer="false" :isImg="true" :ShowfileList="false"
              v-model="ruleForm.imgs" :nameshow='true' :gsgfList="['jpg', 'png']" :disabled='false'
              @filehandleChange="changeFiles">
            </MOSTY.Upload>
          </div>
        </div>
      </template>

      <template #footer>

        <el-button type="primary" :loading="loading" @click="handleSave(ruleFormRef)">
          <el-icon>
            <DocumentChecked />
          </el-icon>
          <span>保存</span>
        </el-button>
        <el-button @click="handleClose" type="primary">
          <el-icon>
            <DocumentDelete />
          </el-icon>
          <span>关闭</span>
        </el-button>
      </template>
      <template #dwbox>
        <!-- 选择主办部门名称: -->
        <Choosebm :formInfo="fromObj" :showDdld="showDept" @closezzjg="closezzjg" @listdata="getSonValue"
          :zzlx="zzlx" />
        <!-- 选择负责人 :deptId="listQuery.orgCode" -->
        <ChooseUser v-model="chooseUserVisible" :Single="singleShow" :data="memberList" :leaderid="leaderid"
          :deptId="deptId" @choosedUsers="getSonValue"></ChooseUser>
        <!-- 选择参加单位汇总: -->
        <ChooseDept v-if="showCjdw" :formInfo="fromObj" :showDdld="showCjdw" @closezzjg="closedept"
          @listdata="getSonValue" :zzlx="zzlx" />
        <!-- 选择考试试卷 -->
        <AddTest v-model="showJkssbm" :Single="true" :formInfo="fromObj" @closezzjg="closeJhss" @listdata="getSonValue"
          :data="taskList" :zzlx="zzlx" />
        <!-- 选择证书模板 -->
        <ZslbList v-if="showMb" v-model="showMb" @changeClose="closeMbData" @listdata="getSonValue" :data="mbData" />
        <!-- 试卷预览 -->
        <div v-if="examShow" class="dialog-box">
          <Examdaio @close="examShow = false" :Row="exeamobj" />
        </div>
      </template>
    </MOSTY.FromPage>

  </div>
</template>

<script setup>
// 引入
import { ref, onMounted, defineProps, defineEmits, reactive, watch, getCurrentInstance } from "vue";
import { getItem } from "@/utils/storage";
import { getApi, postApi } from "@/api/tobAcco_api.js";
import { qrcodepxImg, createAndClickLink, disablednowDates, isString } from "@/utils/tools.js";
import { getSysDictByCode } from "@/api/sysDict"; //引入封装数字字典接口
import { ElMessage, ElMessageBox } from "element-plus";
import * as MOSTY from "@/components/MyComponents/index";
import ChooseUser from "@/components/MyComponents/ChooseUser/Leader.vue";
import Choosebm from "@/components/MyComponents/ChooseDept/index.vue";
import ChooseDept from "@/components/MyComponents/ChooseDept/Depart.vue";
import Examdaio from "@/views/safety/pxzyk/examdaio.vue";
import AddTest from "./addTest.vue";
import ZslbList from "./zslbList.vue";
import { filterqx } from "@/utils/auth.js";
import * as rule from "@/utils/rules.js";
const { proxy } = getCurrentInstance();
const { D_TB_YWLX, D_TB_PXKHFS, D_TB_PXQD, GZ_TRAINOT, D_BZ_SF, D_BZ_PXSSCTFS } = proxy.$dict("D_TB_YWLX", "D_TB_PXKHFS",
  "D_TB_PXQD", "GZ_TRAINOT", "D_BZ_SF", "D_BZ_PXSSCTFS");
const loading = ref(false); //新增保存按钮截流
const ruleFormRef = ref();
const zzlx = ref(null);
const pxlxlist = ref([])
const leaderid = ref("");
const singleShow = ref(true); //单选多选
const chooseUserVisible = ref(false); //选择负责人弹窗
const memberList = ref([]); //成员选择的id回显
const taskList = ref([]);
const fjtableData = ref([]); //新增文件表格数据
const delrow = ref({}); //删除文件列表
const delrows = ref({}); //删除文件列表
const activeNames = ref(1);
const total = ref(0);
const showDept = ref(false); //选择部门
const showJkssbm = ref(false); //选择试卷
const showCjdw = ref(false); //选择参选部门
const showlable = ref(false); //是否显示对应参数
const disableds = ref(false); //是否显示对应参数
const exeamobj = ref(null)
const examShow = ref(false)
const listQuery = ref({
  pageCurrent: 1,
  pageSize: 1000
});
//表单数据
const ruleForm = ref({});
//规则校验
const rules = reactive({
  planName: [{ required: true, message: "培训计划不能为空", trigger: "blur" }],
  planHostsDeptName: [{ required: true, message: "主办部门不能为空", trigger: "blur" }],
  planChargePersonName: [{ trigger: "blur", required: true, message: "项目负责人不能为空" }],
  planChannel: [{ trigger: "blur", required: true, message: "培训渠道不能为空" }],
  place: [{ trigger: "blur", required: true, message: "培训地点不能为空" }],
  startDate: [{ trigger: "blur", required: true, message: "培训开始日期不能为空" }],
  finshDate: [{ trigger: "blur", required: true, message: "培训结束日期不能为空" }],
  signFinshDate: [{ trigger: "blur", required: true, message: "报道截止时间不能为空" }],
  contactorName: [{ trigger: "blur", required: true, message: "联系人不能为空" }],
  ...rule.phoneRule({ require: true, validator: true }, "contactorPhone"),
  ...rule.intRule({ require: true, validator: true }, "realClassHour"),
  implementationTraineeNumber: [{ trigger: "blur", required: true, message: "培训总人数不能为空" }],
  ...rule.intRule({ validator: true, require: true }, "realBudget"),
  examinationType: [{ trigger: "blur", required: true, message: "考核方式不能为空" }],
  teachers: [{ trigger: "blur", required: true, message: "培训教师不能为空", }],
  specialityType: [{ trigger: "blur", required: true, message: "请选择业务类型" }],
  otherType: [{ trigger: "blur", required: true, message: "请选择培训类型" }],


});
const rules2 = reactive({
  sflx: [{ trigger: "blur", required: true, message: "请选择是否乱序出现考题" }],
  sffz: [{ trigger: "blur", required: true, message: "请选择是否发证" }],
  ctfs: [{ trigger: "blur", required: true, message: "请选择出题方式" }],
  examStartTime: [{ trigger: "blur", required: true, message: "请选择最早开考时间" }],
  examEndTime: [{ trigger: "blur", required: true, message: "请选择最晚开考时间" }],
  paperName: [{ trigger: "blur", required: true, message: "请选择试卷" }],
  sfckct: [{ trigger: "blur", required: true, message: "请选择是否查看错题" }],
  ...rule.intRule({ validator: true, require: true }, "pdCount"),
  ...rule.intRule({ validator: true, require: true }, "danxCount"),
  ...rule.intRule({ validator: true, require: true }, "duoxCount"),
  ...rule.intRule({ validator: true, require: true }, "kcjcs"),
  ...rule.intRule({ validator: true, require: true }, "examTime"),
  ...rule.percentageRule({ validator: true, require: true }, "danxfz"),
  ...rule.percentageRule({ validator: true, require: true }, "hgfs"),
  ...rule.percentageRule({ validator: true, require: true }, "pdfz"),
  ...rule.percentageRule({ validator: true, require: true }, "duoxfz"),
  ...rule.percentageRule({ validator: true, require: true }, "zf"),
})
const rules3 = reactive({
  sflx: [{ trigger: "blur", required: false, message: "请选择是否乱序出现考题" }],
  sffz: [{ trigger: "blur", required: false, message: "请选择是否发证" }],
  ctfs: [{ trigger: "blur", required: false, message: "请选择出题方式" }],
  examStartTime: [{ trigger: "blur", required: false, message: "请选择最早开考时间" }],
  examEndTime: [{ trigger: "blur", required: false, message: "请选择最晚开考时间" }],
  paperName: [{ trigger: "blur", required: false, message: "请选择试卷" }],
  sfckct: [{ trigger: "blur", required: false, message: "请选择是否查看错题" }],
  ...rule.intRule({ validator: true, require: false }, "pdCount"),
  ...rule.intRule({ validator: true, require: false }, "danxCount"),
  ...rule.intRule({ validator: true, require: false }, "duoxCount"),
  ...rule.intRule({ validator: true, require: false }, "kcjcs"),
  ...rule.intRule({ validator: true, require: false }, "examTime"),
  ...rule.percentageRule({ validator: true, require: false }, "danxfz"),
  ...rule.percentageRule({ validator: true, require: false }, "hgfs"),
  ...rule.percentageRule({ validator: true, require: false }, "pdfz"),
  ...rule.percentageRule({ validator: true, require: false }, "duoxfz"),
  ...rule.percentageRule({ validator: true, require: false }, "zf"),
})
const showMb = ref(false)
const mbData = ref({})
const emits = defineEmits(["changeAddVi", "changeclose"]);
const ruleFormRef2 = ref()
const props = defineProps({
  formData: {
    type: Object,
    required: {}
  },
  title: String,
  xqId: String,
  type: String
});
const tableColumns1 = reactive([
  {
    title: "学员名称",
    prop: "name"
  },
  {
    title: "所属部门",
    prop: "deptName"
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const pageConfiger = reactive({
  pageSize: 20,
  pageCurrent: 1,
  total: 0
})
onMounted(() => {
  //只有安全部门人员才能选择三级教育培训
  getSysDictByCode({ dictCode: "GZ_TRAINOT" }).then((res) => {
    if (res) {
      res.itemList.forEach((item) => {
        item.label = item.zdmc;
        item.value = item.dm;
        if (filterqx('isaqbm') == '1' && item.dm == '09') {
          item.disabled = true
        } else {
          item.disabled = false
        }
      });
      pxlxlist.value = res.itemList
    }
  });
  if (props.formData.id) {
    getJhwssxq(props.formData.id);
    getsignList();
    listQuery.value.id = props.formData.id;
    showlable.value = true;
  } else {
    ruleForm.value.otherType = props.type == '3' ? '04' : null
  }
  ruleForm.value.type = props.type;

});
//培训结束日期
function disablednowDate(time) {
  return time.getTime() + 24 * 60 * 60 * 1000 < new Date(ruleForm.value.startDate).getTime()
}
function disabledzwkk(time) {
  return time.getTime() + 12 * 60 * 60 * 1000 < new Date(ruleForm.value.examStartTime).getTime()
}
//报道截止日期
function disablednowDate2(time) {
  return time.getTime() > new Date(ruleForm.value.finshDate).getTime()
}
function changetime(params) {
  ruleForm.value.finshDate = ''
  ruleForm.value.signFinshDate = ''
}
function changetime2(params) {
  ruleForm.value.signFinshDate = ''
}
// 获取模板数据
const closeMbData = (val) => {
  showMb.value = val
}
function check() {
  if (ruleForm.value.realBudget.length > 7) {
    ruleForm.value.realBudget = ruleForm.value.realBudget.slice(0, 7);
  }
}
function check1() {
  if (ruleForm.value.realClassHour.length > 3) {
    ruleForm.value.realClassHour = ruleForm.value.realClassHour.slice(0, 3);
  }
}
//预览试卷
function chooseexam() {
  examShow.value = true
}
//计划外实施-详情
function getJhwssxq(id) {
  getApi({ id: id }, "/mosty-jcgl/training/pxssInfoJhw").then((res) => {
    ruleForm.value = res;
  });
}
//获取签到参训人员
function getsignList() {
  getApi(listQuery.value, "/mosty-jcgl/training/signPage").then((res) => {
    if (res.records) {
      ruleForm.value.signList = res.records;
      ruleForm.value.signList.forEach((item) => {
        item.deptName = item.depname;
        item.userPk = item.userPk;
      });
      pageConfiger.total = res.total;
    }
  });
}
const deptId = ref('')
//选择人员或部门
function ChooesDdld(value) {
  zzlx.value = value;
  leaderid.value = "";
  //主办部门
  if (value == "01") {
    showDept.value = true;
  } else if (value == "02") {
    //项目负责人
    deptId.value = getItem("deptId").ssbmid
    singleShow.value = true;
    chooseUserVisible.value = true;
    leaderid.value = ruleForm.value.planChargePersonId;
  } else if (value == "03") {
    // 人员多选
    singleShow.value = false;
    chooseUserVisible.value = true;
    if (ruleForm.value.signList) {
      memberList.value = ruleForm.value.signList.map((item) => {
        return item.userPk;
      });
    }
  } else if (value == "04") {
    //考试题多选
    showJkssbm.value = true;
    taskList.value = ruleForm.value.paperId
  } else if (value == "05") {
    //选择参选部门
    showCjdw.value = true;
  } else if (value == '06') {
    //选择证书模板
    showMb.value = true
  }
}
//获取部门、人员
const getSonValue = (value) => {
  exeamobj.value = null
  if (zzlx.value == "01") {
    ruleForm.value.planHostsDeptName = value.orgName;
    ruleForm.value.planHostsDeptId = value.id;
  } else if (zzlx.value == "02") {
    ruleForm.value.planChargePersonName = value[0].userName;
    ruleForm.value.planChargePersonId = value[0].id;
  } else if (zzlx.value == "03") {
    ruleForm.value.signList = value;
    ruleForm.value.signList.forEach((item) => {
      item.name = item.userName;
      item.phone = item.telePhone;
      item.userPk = item.id;
    });
    memberList.value = value.map((item) => {
      return item.id;
    });
  } else if (zzlx.value == "04") {
    if (value[0].ctfs == '3') {
      ruleForm.value.danxCount = value[0].danxtl
      ruleForm.value.duoxCount = value[0].duoxtl
      ruleForm.value.pdCount = value[0].pdtl
    } else {
      ruleForm.value.pdCount = value[0].pdCount
      ruleForm.value.danxCount = value[0].danxCount
      ruleForm.value.duoxCount = value[0].duoxCount
    }
    exeamobj.value = value[0]
    ruleForm.value.paperId = value[0].id;
    ruleForm.value.paperName = value[0].name
    ruleForm.value.ctfs = value[0].ctfs
    ruleForm.value.sfckct = ruleForm.value.sfckct || '1'
    if (value[0].ctfs == '1' || value[0].ctfs == '3') {
      ruleForm.value.sflx = '1'
    } else {
      ruleForm.value.sflx = '2'
    }
    ruleForm.value.kcjcs = ruleForm.value.kcjcs || 3
    ruleForm.value.hgfs = ruleForm.value.hgfs || 80
    ruleForm.value.sffz = ruleForm.value.sffz || '2'
    ruleForm.value.zf = null
    ruleForm.value.pdfz = null
    ruleForm.value.danxfz = null
    ruleForm.value.duoxfz = null
  } else if (zzlx.value == '06') {
    mbData.value = value
    ruleForm.value.bbid = value.id
    ruleForm.value.mbImg = value.url
    ruleForm.value.mbName = value.name
  }
};
// 切换分值配置
function changeScore() {
  let pd = ruleForm.value.pdCount * (ruleForm.value.pdfz ? ruleForm.value.pdfz : 0);
  let danx = ruleForm.value.danxCount * (ruleForm.value.danxfz ? ruleForm.value.danxfz : 0);
  let duox = ruleForm.value.duoxCount * (ruleForm.value.duoxfz ? ruleForm.value.duoxfz : 0);
  ruleForm.value.zf = pd + danx + duox
}
//删除人员列表选择
function deldetexy(val) {
  for (let i = 0; i < ruleForm.value.signList.length; i++) {
    const el = ruleForm.value.signList[i];
    if (el.id == val.id) {
      ruleForm.value.signList.splice(i, 1);
      total.value--;
    }
  }
}
//关闭弹窗
const closezzjg = (val) => {
  showDept.value = val;
};
const closedept = (val) => {
  showCjdw.value = val;
};

// 新的文件上传返回
const changeFile = (data) => {
  fjtableData.value = data;

};
//删除文件
const handlefjdelete = (row) => {
  delrow.value = row;
  fjtableData.value = fjtableData.value.filter((item) => {
    return item != row;
  });
};
//点击下载文件
function handledlon(val) {
  createAndClickLink(val.url, val.name)
}

const closeJhss = (val) => {
  showJkssbm.value = val;
};
//清空数据
function reset() {
  fjtableData.value = [];
  ruleForm.value = {};
}
function postgetdata(data, url, text) {
  postApi(data, url)
    .then((res) => {
      ElMessage.success(text);
      reset();
      emits("changeAddVi", false);
      loading.value = false;
    })
    .finally(() => {
      loading.value = false;
      ruleForm.value.specialityType = ruleForm.value.specialityType && isString(ruleForm.value.specialityType) ? ruleForm.value.specialityType.split(',') : ruleForm.value.specialityType;
    });
}
// 保存

const handleSave = async (formEl) => {
  if (!formEl) return
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      if (ruleForm.value.examinationType == "4") {
        // if (!ruleFormRef2.value) return
        ruleFormRef2.value.validate((valid) => {
          if (valid) {
            savefrom()
          } else {
            ElMessage.warning('请输入必填项！！！')
          }
        })
      } else {
        savefrom()
      }
    } else {
      ElMessage.warning('请输入必填项！！！')
    }
  });
};
function savefrom() {
  if (!ruleForm.value.signList || ruleForm.value.signList.length < 1) {
    ElMessage.warning("请选择参训学员");
  }
  if (!ruleForm.value.paperId && (ruleForm.value.examinationType == "2" || ruleForm.value.examinationType == "4")) {
    ElMessage.warning("请选择考试题目");
  }
  loading.value = true;
  ruleForm.value.files = ruleForm.value.files ? ruleForm.value.files.toString() : null;
  ruleForm.value.pxfa = ruleForm.value.pxfa ? ruleForm.value.pxfa.toString() : null;
  ruleForm.value.pxtzwj = ruleForm.value.pxtzwj ? ruleForm.value.pxtzwj.toString() : null;
  ruleForm.value.qdb = ruleForm.value.qdb ? ruleForm.value.qdb.toString() : null;
  ruleForm.value.imgs = ruleForm.value.imgs ? ruleForm.value.imgs.toString() : null;
  ruleForm.value.realClassHour = parseInt(ruleForm.value.realClassHour);
  ruleForm.value.realBudget = parseFloat(ruleForm.value.realBudget);
  ruleForm.value.implementationTraineeNumber = parseInt(
    ruleForm.value.implementationTraineeNumber
  );
  let flag = true
  if (ruleForm.value.zf != 100 && (ruleForm.examinationType == "2" || ruleForm.examinationType == "4")) {
    ElMessageBox.confirm("当前分值不是满分，确认提交?", "警告", {
      confirmButtonText: "确认提交",
      type: "warning"
    }).then(() => {
      flag = true
    }).catch(() => {
      flag = false
    });
  } else {
    flag = true
  }
  if (flag) {
    let library = {}
    library.id = ruleForm.value.paperId
    library.sfckct = ruleForm.value.sfckct
    library.hgfs = ruleForm.value.hgfs
    library.sflx = ruleForm.value.sflx
    library.examStartTime = ruleForm.value.examStartTime
    library.examEndTime = ruleForm.value.examEndTime
    library.examTime = ruleForm.value.examTime
    library.ctfs = ruleForm.value.ctfs
    library.kcjcs = ruleForm.value.kcjcs
    library.sffz = ruleForm.value.sffz
    library.duoxfz = ruleForm.value.duoxfz
    library.danxfz = ruleForm.value.danxfz
    library.pdfz = ruleForm.value.pdfz
    ruleForm.value.library = library
    library.bbid = ruleForm.value.bbid
    ruleForm.value.specialityType = ruleForm.value.specialityType ? ruleForm.value.specialityType.toString() : null;
    ruleForm.value.type = props.type;
    if (ruleForm.value.id && props.formData.id) {
      postgetdata(
        ruleForm.value,
        "/mosty-jcgl/training/pxssEditJhw",
        "修改成功"
      );


    } else {
      postgetdata(
        ruleForm.value,
        "/mosty-jcgl/training/pxssAddJhw",
        "新增成功"
      );

    }
  }
}



// 关闭
const handleClose = () => {
  proxy.$modal.confirm('离开会丢失页面中修改的内容，确认离开吗？')
    .then(() => {
      // 关闭上一次的表单校验
      ruleFormRef.value.clearValidate();
      reset();
      emits("changeAddVi", false);
    })
    .catch(() => {
      // catch error
    })

};


/**
 * pageSize 改变触发
 */
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  pageConfiger.pageSize = currentSize;
  getsignList();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  pageConfiger.pageCurrent = currentPage;
  getsignList();
};
</script>

<style lang="scss" scoped>
.sele-title {
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  padding: 10px 20px;
}

.sele-titles {
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  padding: 10px 20px 0px 50px;

}

.beiz {
  width: 100%;
  padding: 10px;
  background: #0b6047;
}

.addbtn {
  margin: 10px;
  display: flex;
  justify-content: end;
}



::v-deep .el-form-item__content {
  flex-wrap: nowrap !important;
}

.el-form {
  width: 100%;
  padding: 0 20px;
  margin: 10px 0;
  flex-wrap: wrap;
  justify-content: space-between;
}

.el-form-item {
  margin: 10px;
  text-align: center;
}


.titleBox {
  align-items: center;
  margin: 0;
  padding: 0;
  height: 60px;
  border: 1px solid rgb(32, 75, 54);
  padding: 20px;
}

.form>div {
  position: relative;
  margin-top: 30px;
  display: flex;
  justify-content: space-between;

  div {
    display: flex;
    align-items: center;

    .el-select {
      width: 65%;
    }
  }
}


.four {
  display: flex;
  align-items: center;

  span {
    width: 5%;
  }

  .el-textarea__inner {
    width: 95%;
  }
}


.el-table {
  height: 300px !important;
  border: 1px solid var(--el-color-primary);
}

.el-form-item__content {
  flex-wrap: nowrap;
}

.el-collapse {
  border-color: var(--el-color-primary);
  height: 460px;
}

::v-deep .el-collapse-item__header {
  border-bottom-color: var(--el-color-primary);
}

::v-deep .el-collapse-item__header.is-active {
  border-bottom-color: transparent;
}

.erweim {
  text-align: center;
  margin-right: 10px;

  >img {
    width: 148px;
    height: 148px;
    display: block;
    border: 1px solid var(--el-color-primary);
  }
}
</style>
