<template>
  <div>
    <div class="bigBox">
      <MOSTY.FromPage :title="title" @closeDialog="CloseEvent">
        <template #content>
          <MOSTY.Assort :title="'基本信息'" />
          <div class="fromBox">
            <el-form class="mosty-from-wrap" ref="ruleFormRef" label-width="170px" :model="FromData" :inline="true"
              :rules="rules" :disabled="!saveBtnShow">
              <el-form-item label="申办类型：" prop="thebidtype">
                <MOSTY.DictRidioAndSelect :dictData="[{ label: '上岗证 ', value: '1' }]" v-model="FromData.thebidtype"
                  @onChange="getselecttype" style="width:337px" :disabled="FromData.id" />
              </el-form-item>
              <el-form-item label="上岗证类型：" prop="driverpostType">
                <MOSTY.DictRidioAndSelect :dictData="[{ label: '公务车 ', value: '1' }, { label: '物流车', value: '2' }]"
                  v-model="FromData.driverpostType" style="width:337px" :disabled="FromData.id" />
              </el-form-item>
              <el-form-item label="姓名：" prop="drivername">
                <el-input readonly v-model="FromData.drivername" clearable style="width:337px">
                  <template #append>
                    <el-button class='cursor' @click="ChooesSpry(FromData.thebidtype)">选择</el-button>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item label="性别：" prop="sex">
                <MOSTY.DictRidioAndSelect :dictData="D_BZ_XB" v-model="FromData.sex" style="width:337px"
                  selectType="select" />
              </el-form-item>
              <el-form-item label="出生日期：" prop="brithday">
                <el-date-picker v-model="FromData.brithday" type="data" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                  placeholder="请选择出生日期" :default-value="getDefaultDates" :disabled-date="disabledDate"
                  style="width:337px">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="年龄：" prop="age" v-if="ISzjz || FromData.thebidtype == '2'">
                <el-input v-model.number="FromData.age" type='number' clearable style="width:337px" />
              </el-form-item>
              <el-form-item label="工作单位：" prop="jobpart">
                <el-input v-model="FromData.jobpart" readonly clearable style="width:337px"></el-input>
                <!-- <el-button disabled>选择</el-button> -->
              </el-form-item>
              <el-form-item label="文化程度：" prop="education">
                <MOSTY.DictRidioAndSelect :dictData="D_BZ_AQRYWHCD" v-model="FromData.education" selectType="select"
                  style="width:337px" />
              </el-form-item>
              <el-form-item label="驾驶证申领日期：">
                <el-date-picker v-model="FromData.driverGetTime" type="data" format="YYYY-MM-DD"
                  value-format="YYYY-MM-DD" placeholder="请选择驾驶证申领日期" style="width:337px">
                </el-date-picker>
              </el-form-item>
              <!-- <el-form-item label="驾驶工龄：" prop="driverhistory">
                <el-input v-model="FromData.driverhistory" clearable style="width:337px" type="number"> <template
                    #append><span>年</span></template></el-input>
              </el-form-item> -->
              <el-form-item label="驾驶证证号：" prop="drivernumber">
                <el-input v-model="FromData.drivernumber" clearable style="width:337px" />
              </el-form-item>
              <el-form-item label="准驾车型：" prop="carstyle">
                <MOSTY.DictRidioAndSelect :dictData="D_TB_DRIVELEVEL" v-model="FromData.carstyle" selectType="select"
                  style="width:337px" />
              </el-form-item>
              <el-form-item label="从事岗位：" prop="thejob">
                <el-input v-model="FromData.thejob" clearable style="width:337px" readonly />
              </el-form-item>
              <el-form-item label="有效期：" prop="usestate">
                <el-input v-model="FromData.usestate" clearable disabled style="width:337px">
                  <template #append><span>年</span></template>
                </el-input>
              </el-form-item>
              <el-form-item :label="`${certificateCName}初次领证时间：`" prop="fristpoststime">
                <el-date-picker v-model="FromData.fristpoststime" type="data" format="YYYY-MM-DD"
                  value-format="YYYY-MM-DD" :placeholder="`请选择${certificateCName}初次领证时间`" style="width:337px">
                </el-date-picker>
              </el-form-item>
              <el-form-item :label="`${certificateCName}上次领证时间：`" prop="lastpoststime">
                <el-date-picker v-model="FromData.lastpoststime" type="data" format="YYYY-MM-DD"
                  value-format="YYYY-MM-DD" :placeholder="`请选择${certificateCName}上次领证时间`" style="width:337px">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="家庭住址：">
                <el-input v-model="FromData.address" clearable style="width:337px" />
              </el-form-item>
              <el-form-item label="联系电话:" prop="phone">
                <MaskInput v-model="FromData.phone" placeholder="请输入联系电话：" style="width: 337px" />
              </el-form-item>
              <!-- <el-form-item label="联系电话：" prop="phone">
                <el-input v-model="FromData.phone" clearable style="width:337px" />
              </el-form-item> -->
              <el-form-item label="政治面貌：" prop="zzmm">
                <MOSTY.DictRidioAndSelect :dictData="D_BZ_AQRYZZMM" v-model="FromData.zzmm" selectType="select"
                  style="width:337px" />
              </el-form-item>
              <el-form-item label="技术职称：">
                <el-input v-model="FromData.jszc" clearable style="width:337px" />
              </el-form-item>
              <el-form-item label="理论考试成绩：" prop="theory">
                <el-input v-model.number="FromData.theory" type='number'
                  @blur="FromData.theory = JEblurFn(FromData.theory)" clearable style="width:337px" />
              </el-form-item>
              <el-form-item label="	是否专职：" prop="sfzz">
                <MOSTY.DictRidioAndSelect :dictData="D_BZ_SF" v-model="FromData.sfzz" selectType="select"
                  style="width:337px" />
              </el-form-item>
              <el-form-item label="是否符合办理行业驾驶员上岗证要求：" style="width:50%" prop="isqualified" label-width="280px">
                <MOSTY.DictRidioAndSelect :dictData="D_BZ_SF" v-model="FromData.isqualified" selectType="select"
                  style="width:337px" />
              </el-form-item>
              <el-form-item label="驾驶员照片：" style="width:100%;" prop="pic">
                <div>
                  <MOSTY.Upload width="800px" v-model="FromData.pic" :limit="1" :delrow="delrow" :isEdit="fileEdit"
                    :ShowfileList="false" @filehandleChange="changeFile" :isImg="true" :disabled="!saveBtnShow">
                  </MOSTY.Upload>
                </div>
              </el-form-item>
              <el-form-item label="试用期概况：" prop="probationgk" style="width:100%;">
                <el-input v-model="FromData.probationgk" clearable style="width:1307px" />
              </el-form-item>
              <!-- 审批状态(1待部门车队队长审批2待单位安全部门负责人审批3待单位分管领导审批 4待市公司交安员审批 5市公司安全管理科科长审批 6 完成 7失败 8市公司分管审批) -->
              <el-form-item label="备注：" style="width:100%;">
                <el-input v-model="FromData.bz" clearable style="width:1307px" />
              </el-form-item>
            </el-form>
          </div>
          <!-- <div v-if="ISsy || FromData.first == '2'">
            <MOSTY.Assort :title="'车队证明'">
              <template #icon>
                <span @click='tabshow.cdzmshow = !tabshow.cdzmshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.cdzmshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.cdzmshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.cdzmshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.fleetcertificatefile" :showinput="false"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx','wps']" :disabled="!saveBtnShow"
                  :delrow="delrow"></MOSTY.Upload>
              </div>
            </div>
          </div> -->
          <!-- <MOSTY.Assort :title="'驾驶员上岗证办理申请表'" v-if="FromData.thebidtype == '1'">
            <template #icon>
              <span @click='tabshow.jsysqshow = !tabshow.jsysqshow' class='zkbox'>
                <span class='bqfont'> {{ tabshow.jsysqshow ? '收起' : '展开' }}</span>
                <el-icon v-if='tabshow.jsysqshow' class='iconfont'>
                  <CaretTop />
                </el-icon>
                <el-icon v-else class='iconfont'>
                  <CaretBottom />
                </el-icon>
              </span>
            </template>
          </MOSTY.Assort>
          <div v-if='tabshow.jsysqshow'>
            <div style="margin: 10px">
              <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                :ShowfileList="true" v-model="FromData.certificationfile" :showinput="false" :disabled="!saveBtnShow"
                :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx','wps']" :delrow="delrow"></MOSTY.Upload>
            </div>
          </div> -->
          <!-- <MOSTY.Assort :title="'驾驶员准驾证办理申请表'" v-if="FromData.thebidtype == '2'">
            <template #icon>
              <span @click='tabshow.jsyzjzhow = !tabshow.jsyzjzhow' class='zkbox'>
                <span class='bqfont'> {{ tabshow.jsyzjzhow ? '收起' : '展开' }}</span>
                <el-icon v-if='tabshow.jsyzjzhow' class='iconfont'>
                  <CaretTop />
                </el-icon>
                <el-icon v-else class='iconfont'>
                  <CaretBottom />
                </el-icon>
              </span>
            </template>
          </MOSTY.Assort>
          <div v-if='tabshow.jsyzjzhow'>
            <div style="margin: 10px">
              <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                :ShowfileList="true" v-model="FromData.drivingpermitfile" :showinput="false" :disabled="!saveBtnShow"
                :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow"></MOSTY.Upload>
            </div>
          </div> -->
          <div v-if="!ISsy">
            <MOSTY.Assort :title="'主要驾驶简历及车型'">
              <template #icon>
                <span @click='tabshow.zyjscxshow = !tabshow.zyjscxshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.zyjscxshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.zyjscxshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.zyjscxshow'>
              <div class="tabbox">
                <el-button v-if="showxg" type="primary" @click="addInfo">
                  <el-icon>
                    <CirclePlus />
                  </el-icon>
                  <span>添加驾驶经历</span>
                </el-button>
                <el-table :data="FromData.tbDrivingexpreienceList" border stripe style="width: 100%"
                  :height="tableHeight" :key="keyCount" @current-change="handleCurrentChange">

                  <!-- <el-table-column prop="id" label="id"></el-table-column> -->
                  <el-table-column sortable prop="starttime" align="center" label="开始时间">
                  </el-table-column>
                  <el-table-column sortable prop="endtime" label="结束时间"></el-table-column>
                  <el-table-column sortable prop="orgname" align="center" label="单位名称"></el-table-column>
                  <el-table-column sortable prop="carstyle" align="center" label="主要驾驶车型">
                    <template #default="{ row }">
                      <dict-tag :options="props.dict.D_TB_DRIVELEVEL" :value="row.carstyle" :tag="false" />
                    </template>
                  </el-table-column>
                  <el-table-column sortable align="center" label="操作">
                    <template #default="{ row }">
                      <span class="operedit" @click="editInfo(row)"><el-icon>
                          <EditPen />
                        </el-icon> 修改</span>
                      <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon-color="red" title="确定要删除?"
                        @confirm="delInfo(row)">
                        <template #reference>
                          <span class="operdel" size="small"><el-icon>
                              <Delete />
                            </el-icon>删除</span>
                        </template>
                      </el-popconfirm>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
          <div v-if="!ISsy">
            <MOSTY.Assort :title="'考试资料'">
              <template #icon>
                <span @click='tabshow.kszlshow = !tabshow.kszlshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.kszlshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.kszlshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.kszlshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.examinationfile" :showinput="false" :disabled="!saveBtnShow"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow"></MOSTY.Upload>
              </div>
            </div>
          </div>
          <div v-if="!ISsy">
            <MOSTY.Assort :title="'驾驶证'">
              <template #icon>
                <span @click='tabshow.jszshow = !tabshow.jszshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.jszshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.jszshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.jszshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.driverslicensefile" :showinput="false" :disabled="!saveBtnShow"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow"></MOSTY.Upload>
              </div>
            </div>
          </div>
          <div v-if="!ISsy">
            <MOSTY.Assort :title="'身份证'">
              <template #icon>
                <span @click='tabshow.sfzshow = !tabshow.sfzshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.sfzshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.sfzshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.sfzshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.idcardsfile" :showinput="false" :disabled="!saveBtnShow"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow"></MOSTY.Upload>
              </div>
            </div>
          </div>
          <!-- <div v-if="!ISsy">
            <MOSTY.Assort :title="'健康体检证明'">
              <template #icon>
                <span @click='tabshow.jktjshow = !tabshow.jktjshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.jktjshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.jktjshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.jktjshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.healthfile" :showinput="false" :disabled="!saveBtnShow"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow">
                </MOSTY.Upload>
              </div>
            </div>
          </div> -->
          <div v-if="!ISsy">
            <MOSTY.Assort :title="'职业禁忌症体检附件'">
              <template #icon>
                <span @click='tabshow.zyjjzshow = !tabshow.zyjjzshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.zyjjzshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.zyjjzshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.zyjjzshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.zyjjztj" :showinput="false" :disabled="!saveBtnShow"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow">
                </MOSTY.Upload>
              </div>
            </div>
          </div>
          <div v-if="!ISsy">
            <MOSTY.Assort :title="'三年无重大事故证明'">
              <template #icon>
                <span @click='tabshow.snwsgshow = !tabshow.snwsgshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.snwsgshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.snwsgshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.snwsgshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.certificatefile" :showinput="false" :disabled="!saveBtnShow"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow"></MOSTY.Upload>
              </div>
            </div>
          </div>
          <!-- <div v-if="!ISsy">
            <MOSTY.Assort :title="'安全行车5万公里证明'">
              <template #icon>
                <span @click='tabshow.aqxcshow = !tabshow.aqxcshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.aqxcshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.aqxcshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.aqxcshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.drivingkilometersfile" :showinput="false"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :disabled="!saveBtnShow"
                  :delrow="delrow"></MOSTY.Upload>
              </div>
            </div>
          </div> -->
          <div v-if="!ISsy">
            <MOSTY.Assort :title="'其他相关附件'">
              <template #icon>
                <span @click='tabshow.qtfjshow = !tabshow.qtfjshow' class='zkbox'>
                  <span class='bqfont'> {{ tabshow.qtfjshow ? '收起' : '展开' }}</span>
                  <el-icon v-if='tabshow.qtfjshow' class='iconfont'>
                    <CaretTop />
                  </el-icon>
                  <el-icon v-else class='iconfont'>
                    <CaretBottom />
                  </el-icon>
                </span>
              </template>
            </MOSTY.Assort>
            <div v-if='tabshow.qtfjshow'>
              <div style="margin: 10px">
                <MOSTY.Upload width="600px !important" :widthNumber="800" :limit="5" :nopicer="true" :isImg="false"
                  :ShowfileList="true" v-model="FromData.otherfile" :showinput="false" :disabled="!saveBtnShow"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" :delrow="delrow">
                </MOSTY.Upload>
              </div>
            </div>
          </div>
        </template>
        <template #footer>

          <el-button style="margin-left: 10px" type="primary" @click="handleSave(ruleFormRef)" v-if="saveBtnShow">
            <el-icon>
              <DocumentChecked />
            </el-icon>
            <span>新增</span>
          </el-button>
          <el-button type="primary" @click="CloseEvent">
            <el-icon>
              <DocumentDelete />
            </el-icon>
            <span>关闭</span>
          </el-button>
        </template>
      </MOSTY.FromPage>

    </div>

    <MOSTY.Choosejsy v-if="chooseUserVisible" v-model="chooseUserVisible" :Single="singleShow" :leaderid="leaderid"
      @confirm="getSonValue" :empnature='""' :orgid='getItem("deptId").ssdwid + "XN"'>
    </MOSTY.Choosejsy>

    <!-- 添加驾驶经历 -->
    <el-dialog v-model="dialogVisible" :title="FromTitle.title" :before-close="closeDialog" width="50%" :inline="true">
      <div>
        <el-form class="mosty-from-wrap" ref="elform" label-width="130px" :model="fromObj" :inline="true">
          <el-form-item label="开始时间:">
            <el-date-picker v-model="fromObj.starttime" style="width: 250px" type="date" value-format="YYYY-MM-DD" />
          </el-form-item>
          <el-form-item label="结束时间:">
            <el-date-picker v-model="fromObj.endtime" style="width: 250px" type="date" value-format="YYYY-MM-DD" />
          </el-form-item>
          <el-form-item label="单位名称:">
            <el-input v-model="fromObj.orgname" clearable style="width: 250px" />
          </el-form-item>
          <el-form-item label="主要驾驶车型:">
            <el-select v-model="fromObj.carstyle" style="width: 250px" clearable>
              <el-option v-for="item in props.dict.D_TB_DRIVELEVEL" :key="item" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <span class="dialog-footer">

          <el-button type="primary" @click="submitry">
            <el-icon>
              <DocumentChecked />
            </el-icon>
            <span>保存</span>
          </el-button>
          <el-button @click="closeDialog">
            <el-icon>
              <DocumentDelete />
            </el-icon>
            <span>关闭</span>
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
// 引入
import { ref, onMounted, defineProps, defineEmits, reactive, watch, getCurrentInstance, computed } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { getItem } from "@/utils/storage";
import { IdCard } from "@/utils/dict";
import * as rule from "@/utils/rules.js";
import { JEblurFn } from "@/utils/auth.js";
import * as MOSTY from "@/components/MyComponents/index";
import { getApi, postApi } from "@/api/tobAcco_api.js";
import { getDefaultDate, disabledDate, getBirthdayFromIdCard } from '@/utils/tools.js'
import { useRouter, useRoute } from 'vue-router';
import MaskInput from "@/components/MaskInput.vue"

const { proxy } = getCurrentInstance();
// 数据
const {
  D_BZ_AQRYWHCD,
  D_BZ_XB,
  D_BZ_AQRYZZMM,
  D_TB_DRIVELEVEL, D_BZ_SF
} = proxy.$dict(
  "D_BZ_AQRYWHCD",
  "D_BZ_XB",
  "D_BZ_AQRYZZMM",
  "D_TB_DRIVELEVEL",
  "D_BZ_SF"
);
const router = useRouter()
const route = useRoute();
/** 证书中文名 */
const certificateCName = computed(() => {
  return { 1: '上岗证', 2: '准驾证' }[FromData.value.thebidtype] || ''
})

const getDefaultDates = ref(getDefaultDate())
const fromref = ref()
const title = ref('');//弹窗标题
const saveBtnShow = ref(false);//是否展示送审按钮
const examineshow = ref(false);//是否展示审批意见按钮
const ISzjz = ref(false)
const ISsy = ref(false)
const orgLevel = ref(null);
const empnature = ref('')
const state = ref(null)
const FromTitle = ref('')
const cgylabel = ref('')
const aqbmlabel = ref('')
const fgldmlabel = ref('')
const FromData = ref({});
const props = defineProps({
  title: {
    type: String,
    default: ""
  },
  type: {
    type: String,
    default: null
  },
  rwid: String,
  examineshow: {
    default: false,
    type: Boolean
  },
  saveBtnShow: {
    type: Boolean,
    default: true
  },
  editObj: {
    type: Object,
    default: () => { }
  },
  showklc: {
    default: false,
    type: Boolean
  },
});
const showxg = ref(false);
//规则校验
const rules = reactive({
  thebidtype: [{ required: true, message: "请选择申办类型", trigger: "change" }],
  driverpostType: [{ required: true, message: "请选择上岗证类型", trigger: "change" }],
  drivername: [{ required: true, message: "姓名不能为空", trigger: ["change", "blur"] }],
  sex: [{ required: true, message: "性别不能为空", trigger: "blur" }],
  brithday: [{ trigger: "blur", required: true, message: "出生年月不能为空" }],
  fristpoststime: [{ trigger: "blur", required: true, message: "初次领证时间不能为空" }],
  lastpoststime: [{ trigger: "blur", required: true, message: "上次领证时间不能为空" }],
  isqualified: [{ trigger: "blur", required: true, message: "是否符合办理行业驾驶员上岗证要求不能为空" }],
  jobpart: [{ required: true, message: "工作单位不能为空", trigger: "blur" }],
  education: [{ required: true, message: "文化程度不能为空", trigger: "blur" }],
  ...rule.numberzzsRule({ validator: true, require: true, num: 90 }, "driverhistory"),
  ...rule.identityCardRule({ validator: true, require: true, text: '驾驶证证号' }, "drivernumber"),
  // ...rule.phoneRule({ validator: true, require: true }, "phone"),
  ...rule.numberzzsRule({ validator: true, require: true, num: 90 }, "age"),
  ...rule.numberzzsRule({ validator: true, require: false, num: 90 }, "fullTimeYearly"),
  ...rule.percentageRule({ validator: true, require: false }, "theory"),//百分制
  driverGetTime: [{ required: true, message: "驾驶证申领日期不能为空", trigger: "blur" }],
  carstyle: [{ required: true, message: "准驾车型不能为空", trigger: "blur" }],
  thejob: [{ required: true, message: "从事岗位不能为空", trigger: "blur" }],
  usestate: [{ required: true, message: "有效期不能为空", trigger: "blur" }],
  pic: [{ required: true, message: "驾驶员照片不能为空", trigger: "blur" }],
  // zzmm: [{ required: true, message: "政治面貌不能为空", trigger: "blur" }],
  probationgk: [{ required: true, message: "试用期概况不能为空", trigger: "blur" }],
  sfzz: [{ required: true, message: "	是否专职不能为空", trigger: "blur" }],
});

const dialogType = ref(null)
const emits = defineEmits(["close"]);
const showtjjsz = ref(false);
const fromObj = ref({});
const leaderid = ref("");
const singleShow = ref(true); //单选多选
const chooseUserVisible = ref(false);
const tabshow = reactive({
  cdzmshow: true,
  jsysqshow: true,
  jsyzjzhow: true,
  zyjscxshow: true,
  kszlshow: true,
  jszshow: true,
  sfzshow: true,
  jktjshow: true,
  zyjjzshow: true,
  snwsgshow: true,
  aqxcshow: true,
})
watch(
  () => props.title,
  (val) => {
    if (props.type && props.type == 'sy') {
      // 是否是审验
      ISsy.value = true
    }
    if (props.type && props.type == 'zjzsq') {
      ISzjz.value = true
    }
    title.value = val;
    saveBtnShow.value = props.saveBtnShow
    examineshow.value = props.examineshow
    dialogType.value = props.type
    if (val == "驾驶员上岗证修改") {
      showxg.value = true;
    } else {
      showxg.value = false;
    }
  },
  {
    immediate: true,
    deep: true
  }
);

const ruleFormRef = ref()

const zllx = ref('1')
const showPeop = ref(false);
const showDept = ref(false);

onMounted(() => {
  if (props.editObj) {
    if (props.editObj.rowId) {
      getmain(props.editObj.rowId)
    } else {
      FromData.value.tbDrivingexpreienceList = [];
      FromData.value.thebidtype = '1'
      FromData.value.thejob = '驾驶员';
      getdeptId();
      if (FromData.value.thebidtype == "2") {
        FromData.value.usestate = '1';
      } else {
        FromData.value.jobpart = '劳务公司';
        FromData.value.usestate = '1'
      }

    }
  } else if (route.query) {
    // 审批状态(1待部门车队队长审批2待单位安全部门负责人审批"+"3待单位分管领导审批 4待市公司车管员审批5市公司安全管理科科长审批 6 完成 7失败
    title.value = route.query.title;
    state.value = route.query.p2
    examineshow.value = true
    saveBtnShow.value = false
    getmain(route.query.id)
  } else {
    FromData.value.tbDrivingexpreienceList = [];
  }
  ChooesDdld()
});
function ChooesDdld(val) {
  //选择检查成员
  if (val == "02") {
    showPeop.value = true;
  } else {
    showDept.value = true;
  }
}
const CloseEvent = () => {
  if (saveBtnShow.value) {
    proxy.$modal.confirm('离开会丢失页面中修改的内容，确认离开吗？')
      .then(() => {
        if (route.query.id) {
          router.go(-1);
        } else {
          emits("close");
        }
      })
      .catch(() => {
        // catch error
      })
  } else {
    if (route.query.id) {
      router.go(-1);
    } else {
      emits("close");
    }
  }

};
function closeDialog() {
  proxy.$modal.confirm('离开会丢失页面中修改的内容，确认离开吗？')
    .then(() => {
      showtjjsz.value = false
    })
    .catch(() => {
      // catch error
    })

}
//详情
function getmain(id) {
  if (id) {
    getApi({ id: id }, "/mosty-jcgl/driverposts/queryDriverpostsById").then(
      (res) => {
        if (res) {
          FromData.value = res;
          if (res.tbdwid) {
            getApi({ id: res.tbdwid }, '/mosty-base/deptFeign/getOrgById').then(res => {
              //1、省  其余为市
              orgLevel.value = res.orgLevel.substring(0, 1)
              if (FromData.value.carcontrollerstate == '1') {
                cgylabel.value = orgLevel.value == '1' ? '省' + '公司安全管理员审批意见【同意】：' : '市' + '公司安全管理员审批意见【同意】：'
              } else if (FromData.value.carcontrollerstate == '2') {
                cgylabel.value = orgLevel.value == '1' ? '省' + '公司安全管理员审批意见【不同意】：' : '市' + '公司安全管理员审批意见【不同意】：'
              } else {
                cgylabel.value = orgLevel.value == '1' ? '省' + '公司安全管理员审批意见：' : '市' + '公司安全管理员审批意见：'
              }
              if (FromData.value.tokzstate == '1') {
                aqbmlabel.value = orgLevel.value == '1' ? '省' + '公司安全管理处处长意见【同意】：' : '市' + '公司安全管理科科长意见【同意】：'
              } else if (FromData.value.tokzstate == '2') {
                aqbmlabel.value = orgLevel.value == '1' ? '省' + '公司安全管理处处长意见【不同意】：' : '市' + '公司安全管理科科长意见【不同意】：'
              } else {
                aqbmlabel.value = orgLevel.value == '1' ? '省' + '公司安全管理处处长意见：' : '市' + '公司安全管理科科长意见：'
              }
              if (FromData.value.fgldstate == '1') {
                fgldmlabel.value = orgLevel.value == '1' ? '省' + '公司公司分管领导意见【同意】：' : '市' + '公司公司分管领导意见【同意】：'
              } else if (FromData.value.fgldstate == '2') {
                fgldmlabel.value = orgLevel.value == '1' ? '省' + '公司公司分管领导意见【不同意】：' : '市' + '公司公司分管领导意见【不同意】：'
              } else {
                fgldmlabel.value = orgLevel.value == '1' ? '省' + '公司公司分管领导意见：' : '市' + '公司公司分管领导意见：'
              }
            })
          }

        }
      }
    );
    // getApi(
    //   { id: id },
    //   "/mosty-jcgl/drivingexpreience/queryDrivingexpreienceById"
    // ).then((res) => {
    //   if (res) {
    //     FromData.value.tbDrivingexpreienceList = res;
    //   }
    // });
  }
};
//限制选人只能为本部门的人
function getdeptId() {
  FromData.value.deptId = getItem("deptId").ssbmid;
  FromData.value.jobpartid = getItem("deptId").ssdwid;
  FromData.value.jobpart = getItem("deptId").ssdwmc;
}

function getselecttype(val) {
  FromData.value = {}
  FromData.value.thebidtype = val
  if (FromData.value.thebidtype == "2") {
    FromData.value.usestate = '1';
    FromData.value.thejob = '驾驶员';
  } else {
    FromData.value.jobpart = '劳务公司';
    FromData.value.usestate = '1'
    FromData.value.thejob = '驾驶员';
  }
}
//选择人员
function ChooesSpry(val) {
  leaderid.value = FromData.value.driverLeaderId;
  singleShow.value = true;
  // if (val == '1') {
  //   empnature.value = '1'
  // } else {
  //   empnature.value = '3'
  // }
  zllx.value = '1'
  getdeptId()
  //上岗证
  chooseUserVisible.value = true;
}
//完成选人
const getSonValue = (value) => {
  const { drivername, driveruserid, driverfileno, initgetlicensedate, drivelevel, driveage, educationlevel, id, idcard, picture, drivenumber, sex, mobile, deptname, deptcode, homeaddr, politicalstatus, technicaltitle, drivertype } = value[0]
  FromData.value = {
    ...FromData.value,
    drivername: drivername,
    idnumber: driverfileno,
    // driverLeaderId: id,
    driverLeaderId: driveruserid,
    // drivernameid: driveruserid,
    drivernameid: id,
    drivernumber: drivenumber,
    // fristpoststime: initgetlicensedate,
    address: homeaddr,
    education: educationlevel,
    sex,
    pic: picture,
    phone: mobile,
    brithday: idcard ? getBirthdayFromIdCard(idcard) : "",
    age: idcard ? IdCard(idcard, 3) : '',
    jobpart: deptname,
    jobpartid: deptcode,
    carstyle: drivelevel,
    driverhistory: driveage,
    zzmm: politicalstatus,
    jszc: technicaltitle,
    // sfzz: drivertype=='1'?'1':'2', // 1: 专职 （是）， 2：兼职 （否）
  }
  getApi({ userId: id }, "/mosty-jcgl/health/selectLastHealthRecord")
    .then((res) => {
      FromData.value.zyjjztj = res.files
    })
    .catch((err) => {
    });
};


//改变审核状态
const changestate = () => {
  let params = {
    id: route.query.rwid,
    sfyd: "1",
    clzt: "02"
  };
  postApi(params, "/mosty-jcgl/rw/updateRw")
    .then((res) => {
      // ElMessage.success("修改任务状态成功");
      router.go(-1);
    });
};

const addInfoFrom = ref()
// 新增
function addInfo() {
  fromObj.value = {};
  dialogVisible.value = true;
  // getwplist();
  addInfoFrom.value = "驾驶经历新增";
}
const current = ref();
//修改
function editInfo(row) {
  current.value = row.$index;
  fromObj.value = row.row;
  dialogVisible.value = true;
  // getwplist();
  addInfoFrom.value = "驾驶经历修改";
}
//删除
function delInfo(row) {
  FromData.value.tbDrivingexpreienceList.forEach((item, index) => {
    if (row == item) {
      FromData.value.tbDrivingexpreienceList.splice(index, 1);
    }
  });
}
//新增修改完毕
const submitry = () => {
  if (addInfoFrom.value == "驾驶经历新增") {
    if (FromData.value.tbDrivingexpreienceList) {
      FromData.value.tbDrivingexpreienceList.push(fromObj.value);
      dialogVisible.value = false;
      wplist.value = [];
    } else {
      let arr = [];
      arr.push(fromObj.value);
      FromData.value.tbDrivingexpreienceList = arr;
      dialogVisible.value = false;
      wplist.value = [];
    }
  }
  if (addInfoFrom.value == "驾驶经历修改") {
    FromData.value.tbDrivingexpreienceList[current.value] = fromObj.value;
    dialogVisible.value = false;
    wplist.value = [];
  }
};

// 保存
const handleSave = async (formEl) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      // 在非审验情况下，验证必传文件字段
      if (!ISsy.value) {
        const requiredFiles = [
          { field: 'examinationfile', name: '考试资料' },
          { field: 'driverslicensefile', name: '驾驶证' },
          { field: 'idcardsfile', name: '身份证' },
          { field: 'zyjjztj', name: '职业禁忌症体检附件' },
          { field: 'certificatefile', name: '三年无重大事故证明' }
        ];

        const missingFiles = [];

        requiredFiles.forEach(item => {
          const fileValue = FromData.value[item.field];
          if (!fileValue ||
            (Array.isArray(fileValue) && fileValue.length === 0) ||
            (typeof fileValue === 'string' && fileValue.trim() === '')) {
            missingFiles.push(item.name);
          }
        });

        if (missingFiles.length > 0) {
          ElMessage.error(`请上传以下必需文件：${missingFiles.join('、')}`);
          return;
        }
      }
      FromData.value.pic = FromData.value.pic ? FromData.value.pic.toString() : null;
      FromData.value.fleetcertificatefile = FromData.value.fleetcertificatefile
        ? FromData.value.fleetcertificatefile.toString()
        : null;
      FromData.value.certificationfile = FromData.value.certificationfile
        ? FromData.value.certificationfile.toString()
        : null;
      FromData.value.drivingpermitfile = FromData.value.drivingpermitfile
        ? FromData.value.drivingpermitfile.toString()
        : null;

      FromData.value.examinationfile = FromData.value.examinationfile
        ? FromData.value.examinationfile.toString()
        : null;
      FromData.value.driverslicensefile = FromData.value.driverslicensefile
        ? FromData.value.driverslicensefile.toString()
        : null;
      FromData.value.idcardsfile = FromData.value.idcardsfile
        ? FromData.value.idcardsfile.toString()
        : null;
      FromData.value.healthfile = FromData.value.healthfile
        ? FromData.value.healthfile.toString()
        : null;
      FromData.value.certificatefile = FromData.value.certificatefile
        ? FromData.value.certificatefile.toString()
        : null;
      FromData.value.drivingkilometersfile = FromData.value.drivingkilometersfile
        ? FromData.value.drivingkilometersfile.toString()
        : null;
      FromData.value.otherfile = FromData.value.otherfile
        ? FromData.value.otherfile.toString()
        : null;
      FromData.value.zyjjztj = FromData.value.zyjjztj
        ? FromData.value.zyjjztj.toString()
        : null;
      FromData.value.tbDrivingexpreienceList = FromData.value.tbDrivingexpreienceList && FromData.value.tbDrivingexpreienceList.length > 0
        ? FromData.value.tbDrivingexpreienceList
        : null;
      // FromData.value.datedue = FromData.value.usestate
      FromData.value.tbdw = FromData.value.jobpart
      FromData.value.tbdwid = FromData.value.jobpartid
      FromData.value.first = ISsy.value ? '2' : '1'; // 审验'2' 非审验 '1'
      if (ISsy.value == false) {
        // FromData.value.first = "1";

        // 新增不判断年龄，====================
        // /** 是否是申报（新增）阶段 */
        // const isAddOrShenBan = !FromData.value.id
        // /**@type {Boolean} 获取了身份证之后就截取年龄，上岗证超过50岁、准驾证超过45岁，弹窗提示“年龄超标不可办理” */
        // const isOverAge = (FromData.value.thebidtype == '1' && IdCard(FromData.value.drivernumber, 3) > 50) || (FromData.value.thebidtype == '2' && IdCard(FromData.value.drivernumber, 3) > 45)
        // if (isAddOrShenBan && isOverAge) {
        //   ElMessage.warning('年龄超标不可办理');
        // } else {
        // }
        if (FromData.value.id) {
          xgagzData(FromData.value, '修改成功，正在送审')
        } else {
          xzsgzData(FromData.value, '新增成功，请前往审验列表查看')
        }

      } else {
        if (FromData.value.id) {
          xgagzData(FromData.value, '修改成功，正在送审')
        } else {
          xzsgzData(FromData.value, '新增成功，请前往审验列表查看')
        }
        // xzsgzData(FromData.value, '新增成功，请前往审验列表查看')
      }
    } else {
      ElMessage.error("表单验证失败，请检查输入内容");
    }
  });
};
//修改上岗证
function xgagzData(obj, str) {
  postApi(obj, "/mosty-jcgl/driverposts/updateDriverpostsOne").then(() => {
    ElMessage.success(str);
    emits("close");
  })
}
//新增上岗证
function xzsgzData(obj, str) {
  postApi(obj, "/mosty-jcgl/driverposts/addPassDriverposts").then(() => {
    ElMessage.success(str);
    emits("close");
  })
}
</script>

<style lang="scss" scoped>
.el-collapse {
  width: 100%;
}

.box_cont {
  height: 78vh;
  overflow-y: scroll;
}

.searchBox {
  width: 1333px;
  margin: 20px auto;
  padding: 15px 15px 0 15px;
}

.ld_box {
  display: flex;
  margin-right: 30px;
}

.el-form {
  width: 100%;
  align-items: center;
  display: flex;
  // justify-content: space-between;
  flex-wrap: wrap;
}

.el-form-item {
  display: flex;
  margin-right: 20px;
}

.addbtn {
  margin-bottom: 10px;
}

.iconfont {
  font-size: 26px;
  color: var(--el-color-primary)
}

.bqfont {
  color: var(--el-color-primary)
}

.zkbox {
  display: flex;
  align-items: center;
  margin-left: 10px;
}

.bigBox {
  display: block !important;
  box-sizing: border-box;
}

.tabbox {
  max-height: 300px;
  overflow-y: scroll;

  .input {
    width: 100%;
    height: 100%;
  }
}

::v-deep .el-table .cell {
  padding: 0 0 !important;
}

::v-deep .el-table--border .el-table__cell .cell {
  padding-left: 0px !important;

  >input {
    width: 100%;
    height: 33px;
  }
}

::v-deep .el-upload-list {
  width: 50%;
}
</style>
