<template>
  <el-dialog  :close-on-click-modal="false"
    :title="!this.taskForm.taskId == '' ? $t('SAI开项管理申请单处理') : $t('SAI开项管理申请单详情')"

    :visible.sync="visible"
    :append-to-body="true"
    width="60%">
    <!-- SAI开项管理详细 -->
    <el-form ref="form" :model="dataForm" :rules="rules" label-width="0px">
      <div id="apply-div">
        <h4>申请详情</h4>
        <el-descriptions title="" :column="3" border>
          <el-descriptions-item label="登记人部门">
            <el-form-item prop="applicantDept">
              <el-select
                disabled
                v-model="dataForm.applicantDept"
                placeholder="请选择部门">
                <el-option
                  v-for="dict in applicantDeptOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="登记人班组">
            <el-form-item prop="applicantTeam">
              <el-select
                disabled
                v-model="dataForm.applicantTeam"
                placeholder="请选择班组">
                <el-option
                  v-for="dict in applicantTeamOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="登记人">
            <el-form-item prop="applicant">
              <el-select
                disabled
                v-model="dataForm.applicant"
                placeholder="请选择登记人">
                <el-option
                  v-for="dict in applicantOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="问题描述" :span="3">
            <el-form-item prop="description">
              <el-input :disabled="applyDisabled" v-model="dataForm.description" placeholder="请输入问题描述" type="textarea" :rows="3"/>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="SAI级别" :span="1">
          <el-form-item prop="saiLevel">
              <el-select v-model="dataForm.saiLevel" placeholder="请选择SAI级别" :disabled="applyDisabled">
                <el-option key="1" label="1" value="1"></el-option>
                <el-option key="2" label="2" value="2"></el-option>
                <el-option key="3" label="3" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="SAI类别" :span="1">
            <el-form-item prop="category">
              <el-select
                filterable
                clearable
                v-model="dataForm.category"
                placeholder="请选择SAI类别"
                :disabled="applyDisabled">
                <el-option
                  v-for="dict in saiCategoryOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="片区" :span="1">
            <el-form-item prop="workArea">
              <el-select
                filterable
                clearable
                v-model="dataForm.workArea"
                placeholder="请选择片区"
                :disabled="applyDisabled">
                <el-option
                  v-for="dict in workAreaList"
                  :key="dict"
                  :label="dict"
                  :value="dict"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="附件" :span="3">
            <el-table :data="doc.commonfileListApply" border>
              <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <a  class="link-type"  @click="handleDownload(scope.row)">
                    <span>{{ scope.row.fileName }}</span>
                  </a>
                </template>
              </el-table-column>
              <!--<el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />-->
              <!--<el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/>-->
              <!--<el-table-column :label="$t('上传时间')" align="center" prop="createdate" :show-overflow-tooltip="true" width="120"/>-->
              <el-table-column :label="$t('操作')" align="center" width="120" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    v-if="scope.row.fileName.endsWith('pdf')||scope.row.fileName.endsWith('xlsx')||scope.row.fileName.endsWith('md')
                 ||scope.row.fileName.endsWith('docx')||scope.row.fileName.endsWith('doc')||scope.row.fileName.endsWith('txt')
                 ||scope.row.fileName.endsWith('jpg')||scope.row.fileName.endsWith('png')||scope.row.fileName.endsWith('csv')
                 ||scope.row.fileName.endsWith('mp4')||scope.row.fileName.endsWith('svg')||scope.row.fileName.endsWith('dwg')
                 ||scope.row.fileName.endsWith('flv')||scope.row.fileName.endsWith('swf')||scope.row.fileName.endsWith('gif')
                 ||scope.row.fileName.endsWith('3gp')||scope.row.fileName.endsWith('mkv')||scope.row.fileName.endsWith('tif')"
                    size="mini"
                    type="text"
                    icon="el-icon-view"
                    @click="handleSee(scope.row)"
                  > {{ $t('预览') }}</el-button>
                  <el-button
                    v-if="scope.row.fileName.endsWith('ppt')||scope.row.fileName.endsWith('pptx') "
                    size="mini"
                    type="text"
                    icon="el-icon-view"
                    @click="handleSeePPT(scope.row)"
                  > {{ $t('ppt预览') }}</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-download"
                    @click="handleDownload(scope.row)"
                  >{{ $t('下载') }}</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-descriptions-item>
          <el-descriptions-item label="隐患" :span="3">
            <el-radio v-model="unsafeChoice" label="1" style="margin-right: 10px;" :disabled="applyDisabled" @change="handleUnsafeChoiceChange">不安全状态</el-radio>
            <el-form-item prop="unsafeStatus" style="display: inline-block;">
              <el-select :disabled="applyDisabled" v-model="dataForm.unsafeStatus" placeholder="请选择不安全状态" style="margin-right: 20px;" clearable>
                <el-option
                  v-for="dict in unsafeStatusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-radio v-model="unsafeChoice" label="2" style="margin-right: 10px;" :disabled="applyDisabled" @change="handleUnsafeChoiceChange">不安全行为</el-radio>
            <el-form-item prop="unsafeAction" style="display: inline-block;">
              <el-select :disabled="applyDisabled" v-model="dataForm.unsafeAction" placeholder="请选择不安全行为" clearable>
                <el-option
                  v-for="dict in unsafeActionOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="登记时间">
            <el-form-item prop="applyDate">
              <el-date-picker
                disabled
                clearable
                size="small"
                style="width: 200px"
                v-model="dataForm.applyDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择登记时间">
              </el-date-picker>
            </el-form-item>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div id="assess-div" v-if="showAssess">
        <h4>评估详情</h4>
        <el-descriptions title="" :column="2" border>
          <el-descriptions-item label="预计完成时间" :span="2">
            <el-form-item prop="estimateFinishDate">
              <el-date-picker
                :disabled="assessDisabled"
                clearable
                size="small"
                style="width: 200px"
                v-model="dataForm.estimateFinishDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择预计完成时间">
              </el-date-picker>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="是否录入开项系统">
            <el-form-item prop="isRecorded">
              <el-radio :disabled="assessDisabled" v-model="dataForm.isRecorded" label="1" @change="handleIsRecordedChange">是</el-radio>
              <el-radio :disabled="assessDisabled" v-model="dataForm.isRecorded" label="0" @change="handleIsRecordedChange">否</el-radio>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="开项编号">
            <el-form-item prop="recordNo">
              <el-input v-model="dataForm.recordNo" placeholder="请输入开项编号" :disabled="recordNoDisabled" style="width: 200px;"/>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="采取的措施" :span="2">
            <el-form-item prop="reaction">
              <el-input :disabled="assessDisabled" v-model="dataForm.reaction" placeholder="请输入采取的措施" type="textarea" :rows="3"/>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="整改负责人">
            <el-form-item prop="executor">
              <el-select
                filterable
                :disabled="assessDisabled"
                clearable
                v-model="dataForm.executor"
                placeholder="请选择整改负责人">
                <el-option
                  v-for="dict in executorOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="验证人">
            <el-form-item prop="inspector1" style="display: inline-block;">
              <el-input v-model="inspector1Name" placeholder="" disabled style="width: 180px; margin-right: 10px;"/>
              <!--<el-select-->
                <!--filterable-->
                <!--:disabled="assessDisabled"-->
                <!--clearable-->
                <!--v-model="inspector1"-->
                <!--placeholder="请选择验证人"-->
                <!--style="margin-right: 10px;">-->
                <!--<el-option-->
                  <!--v-for="dict in applicantOptions"-->
                  <!--:key="dict.dictValue"-->
                  <!--:label="dict.dictLabel"-->
                  <!--:value="dict.dictValue"-->
                <!--&gt;</el-option>-->
              <!--</el-select>-->
            </el-form-item>
            <el-form-item prop="inspector2" style="display: inline-block;">
              <el-select
                filterable
                :disabled="assessDisabled"
                clearable
                v-model="inspector2"
                placeholder="请选择验证人">
                <el-option
                  v-for="dict in inspectorOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="是否需要VE验证" :span="2">
            <el-form-item prop="needVe">
              <el-radio :disabled="assessDisabled" v-model="dataForm.needVe" label="1" @change="handleNeedVeChange">是</el-radio>
              <el-radio :disabled="assessDisabled" v-model="dataForm.needVe" label="0" @change="handleNeedVeChange">否</el-radio>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="VE验证条款" :span="2">
            <el-form-item prop="veItemsList">
              <el-checkbox-group v-model="veItemsList" :disabled="veItemsDisabled">
                <el-checkbox label="Level3、Level4的时间纠正措施"></el-checkbox>
                <el-checkbox label="HIRA的补充措施"></el-checkbox>
                <el-checkbox label="整改措施为程序的制定、更新"></el-checkbox>
                <el-checkbox label="整改措施有关培训"></el-checkbox>
                <el-checkbox label="整改措施为增加新设备、设施、部件，或对设备、设施进行改造"></el-checkbox><br/>
                <el-checkbox label="其它" @change="handleVeItemOtherVeChange"></el-checkbox>
                <el-form-item prop="veItemOther" style="display: inline-block;">
                  <el-input v-model="dataForm.veItemOther" placeholder="请输入" :disabled="veItemOtherDisabled" style="display: inline-block; width: 200px; margin-left: 10px;"/>
                </el-form-item>
              </el-checkbox-group>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="备注" :span="3">
            <el-form-item prop="remarksAssess">
              <el-input :disabled="assessDisabled" v-model="dataForm.remarksAssess" placeholder="请输入备注" type="textarea" :rows="3"/>
            </el-form-item>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div id="execute-div" v-if="showExecute">
        <h4>执行详情</h4>
        <el-descriptions title="" border :column="1">
          <el-descriptions-item label="附件">
            <span v-if="!executeDisabled">
              <el-upload
                ref="doc"
                :limit="50"
                :headers="doc.headers"
                :action="doc.url + '?pType=saiExecute&pId=' + doc.pId"
                :disabled="doc.isUploading"
                :on-progress="handleFileDocProgress"
                :on-success="handleFileDocSuccess"
                :auto-upload="true"
                drag
              >
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">
                {{ $t('将文件拖到此处，或') }}
                <em>{{ $t('点击上传') }}</em>
              </div>
            </el-upload>
            </span>
            <el-table :data="doc.commonfileListExecute" border>
              <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <a  class="link-type"  @click="handleDownload(scope.row)">
                    <span>{{ scope.row.fileName }}</span>
                  </a>
                </template>
              </el-table-column>
              <el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />
              <el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/>
              <el-table-column :label="$t('上传时间')" align="center" prop="createdate" :show-overflow-tooltip="true" width="120"/>
              <el-table-column :label="$t('操作')" align="center" width="120" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    v-if="scope.row.fileName.endsWith('pdf')||scope.row.fileName.endsWith('xlsx')||scope.row.fileName.endsWith('md')
                 ||scope.row.fileName.endsWith('docx')||scope.row.fileName.endsWith('doc')||scope.row.fileName.endsWith('txt')
                 ||scope.row.fileName.endsWith('jpg')||scope.row.fileName.endsWith('png')||scope.row.fileName.endsWith('csv')
                 ||scope.row.fileName.endsWith('mp4')||scope.row.fileName.endsWith('svg')||scope.row.fileName.endsWith('dwg')
                 ||scope.row.fileName.endsWith('flv')||scope.row.fileName.endsWith('swf')||scope.row.fileName.endsWith('gif')
                 ||scope.row.fileName.endsWith('3gp')||scope.row.fileName.endsWith('mkv')||scope.row.fileName.endsWith('tif')"
                    size="mini"
                    type="text"
                    icon="el-icon-view"
                    @click="handleSee(scope.row)"
                  > {{ $t('预览') }}</el-button>
                  <el-button
                    v-if="scope.row.fileName.endsWith('ppt')||scope.row.fileName.endsWith('pptx') "
                    size="mini"
                    type="text"
                    icon="el-icon-view"
                    @click="handleSeePPT(scope.row)"
                  > {{ $t('ppt预览') }}</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-download"
                    @click="handleDownload(scope.row)"
                  >{{ $t('下载') }}</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                    @click="handleDeleteDoc(scope.row)"
                    v-if="!executeDisabled"
                  >{{ $t('删除') }}</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-descriptions-item>
          <el-descriptions-item label="备注" :span="3">
            <el-form-item prop="remarksExecute">
              <el-input :disabled="executeDisabled" v-model="dataForm.remarksExecute" placeholder="请输入备注" type="textarea" :rows="3"/>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="驳回历史">
            <el-table :data="rejectList" border v-loading="historyLoading" style="width: 100%;">
              <el-table-column prop="result" header-align="center" align="center"
                               :label="$t('验证结果')"></el-table-column>
              <el-table-column prop="comment" header-align="center" align="center"
                               :label="$t('备注')"></el-table-column>
              <el-table-column prop="userName" header-align="center" align="center" :label="$t('验证人')"></el-table-column>
              <el-table-column prop="taskEndTime" header-align="center" align="center"
                               :label="$t('提交日期')"></el-table-column>
            </el-table>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div id="inspect-div" v-if="showInspect">
        <h4>验收详情</h4>
        <el-descriptions title="" :column="3" border>
          <el-descriptions-item label="VC/VE验证成果" :span="3">
            <el-form-item prop="veResult">
              <el-radio :disabled="inspectDisabled" v-model="dataForm.veResult" label="1">合格</el-radio>
              <el-radio :disabled="inspectDisabled" v-model="dataForm.veResult" label="0">不合格</el-radio>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="备注" :span="3">
            <el-form-item prop="remarks">
              <el-input :disabled="inspectDisabled" v-model="dataForm.remarks" placeholder="请输入备注" type="textarea" :rows="3"/>
            </el-form-item>
          </el-descriptions-item>
          <el-descriptions-item label="附件" :span="3">
            <span v-if="!inspectDisabled">
              <el-upload
                ref="doc"
                :limit="50"
                :headers="doc.headers"
                :action="doc.url + '?pType=saiInspect&pId=' + doc.pId"
                :disabled="doc.isUploading"
                :on-progress="handleFileDocProgress"
                :on-success="handleFileDocSuccess"
                :auto-upload="true"
                drag
              >
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">
                {{ $t('将文件拖到此处，或') }}
                <em>{{ $t('点击上传') }}</em>
              </div>
            </el-upload>
            </span>
            <el-table :data="doc.commonfileListInspect" border>
              <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <a  class="link-type"  @click="handleDownload(scope.row)">
                    <span>{{ scope.row.fileName }}</span>
                  </a>
                </template>
              </el-table-column>
              <el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />
              <el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/>
              <el-table-column :label="$t('上传时间')" align="center" prop="createdate" :show-overflow-tooltip="true" width="120"/>
              <el-table-column :label="$t('操作')" align="center" width="120" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    v-if="scope.row.fileName.endsWith('pdf')||scope.row.fileName.endsWith('xlsx')||scope.row.fileName.endsWith('md')
                 ||scope.row.fileName.endsWith('docx')||scope.row.fileName.endsWith('doc')||scope.row.fileName.endsWith('txt')
                 ||scope.row.fileName.endsWith('jpg')||scope.row.fileName.endsWith('png')||scope.row.fileName.endsWith('csv')
                 ||scope.row.fileName.endsWith('mp4')||scope.row.fileName.endsWith('svg')||scope.row.fileName.endsWith('dwg')
                 ||scope.row.fileName.endsWith('flv')||scope.row.fileName.endsWith('swf')||scope.row.fileName.endsWith('gif')
                 ||scope.row.fileName.endsWith('3gp')||scope.row.fileName.endsWith('mkv')||scope.row.fileName.endsWith('tif')"
                    size="mini"
                    type="text"
                    icon="el-icon-view"
                    @click="handleSee(scope.row)"
                  > {{ $t('预览') }}</el-button>
                  <el-button
                    v-if="scope.row.fileName.endsWith('ppt')||scope.row.fileName.endsWith('pptx') "
                    size="mini"
                    type="text"
                    icon="el-icon-view"
                    @click="handleSeePPT(scope.row)"
                  > {{ $t('ppt预览') }}</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-download"
                    @click="handleDownload(scope.row)"
                  >{{ $t('下载') }}</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                    @click="handleDeleteDoc(scope.row)"
                    v-if="!inspectDisabled"
                  >{{ $t('删除') }}</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </el-form>
    <!-- 流转详情 -->
    <!--<div>-->
      <!--<h4>流转详情</h4>-->
      <!--<el-table :data="historyList" border v-loading="historyLoading" style="width: 100%;">-->
        <!--<el-table-column prop="taskName" header-align="center" align="center"-->
                         <!--:label="$t('流程进度')"></el-table-column>-->
        <!--<el-table-column prop="comment" header-align="center" align="center"-->
                         <!--:label="$t('审批意见')"></el-table-column>-->
        <!--<el-table-column prop="userName" header-align="center" align="center" :label="$t('姓名')"></el-table-column>-->
        <!--<el-table-column prop="taskCreateTime" header-align="center" align="center"-->
                         <!--:label="$t('开始时间')"></el-table-column>-->
        <!--<el-table-column prop="taskEndTime" header-align="center" align="center"-->
                         <!--:label="$t('结束时间')"></el-table-column>-->
      <!--</el-table>-->
    <!--</div>-->
    <!-- 流程操作 -->
    <div slot="footer" class="dialog-footer">
      <!-- 当前登录用户为处理人（之一）或张力飞 -->
      <span v-if="dataForm.handler.indexOf(loginStaffInfo.userId) != -1 || loginStaffInfo.userId == '20276'" style="margin-right: 10px;">
        <el-button v-if="taskName != null && dataForm.applyStatus != 4 && dataForm.applyStatus != 5" @click="dataFormSave()">{{ $t('保存') }}</el-button>
        <el-button type="success" v-if="taskName != null && dataForm.veResult != '0'" @click="dataFormSubmit(1)">{{ $t('通过') }}</el-button>
        <el-button type="danger" v-if="taskName == '验收' && dataForm.veResult == '0'" @click="dataFormSubmit(2)">{{ $t('驳回') }}</el-button>
        <el-button type="info" v-if="taskName == '评估'" @click="dataFormSubmit(0)">{{ $t('中止') }}</el-button>
      </span>
      <el-button @click="visible = false">{{ $t('返回') }}</el-button>
    </div>
    <!-- 预览对话框 -->
    <el-dialog  :close-on-click-modal="false"  v-loading="loadingFlash"     element-loading-background="rgba(0,0,0,0.2)"                 v-dialogDrag :title="pdf.title" :visible.sync="pdf.open"  width="1300px" :center="true" append-to-body>
      <div style="margin-top: -60px;float: right;margin-right: 40px;">
        <el-button size="mini" type="text" @click="openPdf">{{$t('新页面打开PDF')}}</el-button></div>
      <div style="margin-top: -30px" >
        <iframe id="iFrame" class="iframe-html" :src="pdf.pdfUrl" frameborder="0" width="100%" height="700px" v-if="ppt"></iframe>
      </div>
      <div style="padding: 30px; width: 100%; height: 100%;" >
        <el-carousel class="" ref="carousel"  arrow="always"  v-if="pptView"
                     height="700px"  trigger="click" :autoplay="false" indicator-position="outside">
          <el-carousel-item class="lun_img" v-for="item in imgs" v-bind:key="item" >
            <img :src="item" width="100%" height="100%" object-fit="cover" />
          </el-carousel-item>
        </el-carousel>
      </div>
    </el-dialog>
  </el-dialog>
</template>

<script>
import { getToken } from "@/utils/auth";
import { updateApply, getApply, handleApply } from "@/api/production/apply";
import { listFile } from "@/api/production/saiApproveFile";
import { getHistorylist } from "@/api/ehs/approvedanger";
import { listUserPost } from "@/api/system/user";
import { treeselect, listDept } from "@/api/system/dept";
import { listSaiInspectors, listSaiExecutors, listStaffmgrByDeptAndTeam, getLoginStaffInfo } from "@/api/plant/staffmgr";
import { allFileList, delCommonfile } from "@/api/common/commonfile";
import { categoryList } from "@/api/production/category";
import { selectDevice } from "@/api/invoice/device";

export default {
  name: "sai-apply-detail",
  data() {
    var validateInspector1 = (rule, value, callback) => {
      if (this.inspector1 == null) {
        return callback(new Error('验证人不能为空'));
      } else {
        return callback();
      }
    };
    var validateInspector2 = (rule, value, callback) => {
      if (this.inspector2 == null) {
        return callback(new Error('验证人不能为空'));
      } else {
        return callback();
      }
    };
    var validateVeItemsList = (rule, value, callback) => {
      if (this.dataForm.needVe == '1') {
        if (this.veItemsList.length == 0) {
          return callback(new Error('VE验证条款不能为空'));
        } else {
          return callback();
        }
      } else {
        return callback();
      }
    };
    var validateRecordNo = (rule, value, callback) => {
      if (this.dataForm.isRecorded == '1') {
        if (this.dataForm.recordNo == null) {
          return callback(new Error('开项编号不能为空'));
        } else {
          return callback();
        }
      } else {
        return callback();
      }
    };
    return {
      // SAI类别列表
      saiCategoryOptions: [],
      // 当前登录员工
      loginStaffInfo: {},
      //图片集合   打开关闭按钮 等等
      imgs:[],
      jpgList:[],
      ppt:false,
      pptView:false,
      loadingFlash:false,
      doc: {
        file: "",
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 报告附件上传位置编号
        ids: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/commonfile/uploadFile",
        commonfileList: null,
        commonfileListApply: null,
        commonfileListExecute: null,
        commonfileListInspect: null,
        queryParams: {
          pId: null,
          pType: 'saiApply'
        },
        pType: 'saiApply',
        pId: null
      },
      // pdf文件参数
      pdf : {
        title: '',
        pdfUrl: '',
        numPages: null,
        open: false,
        pageNum: 1,
        pageTotalNum: 1,
        loadedRatio: 0,
      },
      visible: false,
      //流转列表
      historyList: [],
      rejectList: [],
      historyLoading: true,
      taskName: '',
      rules: {
        estimateFinishDate: [
          { required: true, message: this.$t('预计完成时间') + this.$t('不能为空'), trigger: "change" }
        ],
        isRecorded: [
          { required: true, message: this.$t('是否录入开项系统') + this.$t('不能为空'), trigger: "change" }
        ],
        reaction: [
          { required: true, message: this.$t('采取的措施') + this.$t('不能为空'), trigger: "change" }
        ],
        executor: [
          { required: true, message: this.$t('整改负责人') + this.$t('不能为空'), trigger: "change" }
        ],
        inspector1: [
          { required: true, message: this.$t('验证人1') + this.$t('不能为空'), trigger: "change" }
        ],
        inspector2: [
          { required: true, message: this.$t('验证人2') + this.$t('不能为空'), trigger: "change" }
        ],
        needVe: [
          { required: true, message: this.$t('是否需要VE验证') + this.$t('不能为空'), trigger: "change" }
        ],
        recordNo: [
          { validator: validateRecordNo, trigger: 'change' }
        ],
        veItemsList: [
          { validator: validateVeItemsList, trigger: 'change' }
        ],
        inspector1: [
          { validator: validateInspector1, trigger: 'change' }
        ],
        inspector2: [
          { validator: validateInspector2, trigger: 'change' }
        ],
        veResult: [
          { required: true, message: this.$t('VC/VE验证成果') + this.$t('不能为空'), trigger: "change" }
        ],
        remarks: [
          { required: true, message: this.$t('备注') + this.$t('不能为空'), trigger: "change" }
        ],
      },
      // SAI开项管理对象
      dataForm: {
        saiApplyId: null,
        deptId: null,
        applyStatus: null,
        apNo: null,
        processId: null,
        applicant: null,
        assessor: null,
        executor: null,
        inspectors: null,
        applicantDept: null,
        applicantTeam: null,
        description: null,
        unsafeStatus: null,
        unsafeAction: null,
        applyDate: null,
        taskId: null,
        handler: null,
        taskName: null,
        estimateFinishDate: null,
        actualFinishDate: null,
        isRecorded: null,
        recordNo: null,
        reaction: null,
        needVe: null,
        veItems: null,
        veResult: null,
        veItemOther: null,
        remarksAssess: null,
        remarksExecute: null,
      },
      taskForm: {
        comment: '',
        taskId: '',
        files: '',
        businessKey: '',
        saiApply: null,
      },
      showAssess: false,
      showExecute: false,
      showInspect: false,
      // 登记人班组字典
      applicantTeamOptions: [],
      // 登记人部门列表
      applicantDeptOptions: [],
      // 登记人列表
      applicantOptions: [],
      inspectorOptions: [],
      executorOptions: [],
      // 不安全状态字典
      unsafeStatusOptions: [],
      // 不安全行为字典
      unsafeActionOptions: [],
      // 不安全状态/行为选项
      unsafeChoice: null,
      // 是否禁用开项编号输入框
      recordNoDisabled: true,
      // 是否禁用VE验证条款
      veItemsDisabled: true,
      // 是否禁用VE验证条款（其它）
      veItemOtherDisabled: true,
      // 是否禁用VE验证条款数组
      veItemsList: [],
      // 验证人1
      inspector1: null,
      inspector1Name: null,
      // 验证人2
      inspector2: null,
      // 是否禁用不安全状态下拉框
      unsafeStatusDisabled: false,
      // 是否禁用不安全行为下拉框
      unsafeActionDisabled: true,
      // 是否禁用申请
      applyDisabled: false,
      // 是否禁用评估
      assessDisabled: false,
      // 是否禁用执行
      executeDisabled: false,
      // 是否禁用验收
      inspectDisabled: false,
      workAreaList: [],
    }
  },
  methods: {
    // 初始化
    init(id, taskId, processId, taskName) {
      this.doc.id = id;
      this.doc.queryParams.pId = id;
      this.doc.pId = id;
      // 表单重置
      this.reset();
      this.inspector1 = null;
      this.inspector2 = null;
      this.veItemsList = [];
      this.dataForm = {};
      this.historyList = [];
      this.dataForm.saiApplyId = id || 0;
      this.form.id = id || 0;
      this.visible = true;
      this.taskName = taskName;
      this.taskForm.taskId = taskId;
      this.taskForm.businessKey = id;
      this.dataForm.processId = processId;
      // 查询SAI开项管理详细
      getApply(id).then(response => {
        this.dataForm = response.data;
        this.getFileList()
        this.inspector1 = this.dataForm.applicant;
        if (this.dataForm.inspectors != null) {
          let inspectors = this.dataForm.inspectors.split(",");
          this.inspector1 = inspectors[0];
          this.inspector2 = inspectors[1];
        }
        // 加载登记人列表
        this.listStaffmgrByDeptAndTeam(null, null);
        if (this.dataForm.veItems != null) {
          let veItems = this.dataForm.veItems.split(",");
          for (let i = 0; i < veItems.length; i++) {
            this.veItemsList.push(veItems[i]);
          }
        }
        if (this.dataForm.isRecorded != null) {
          this.dataForm.isRecorded = this.dataForm.isRecorded.toString();
        }
        if (this.dataForm.needVe != null) {
          this.dataForm.needVe = this.dataForm.needVe.toString();
        }
        this.handleIsRecordedChange();
        this.handleNeedVeChange();
        this.handleVeItemOtherVeChange();
        this.handleUnsafeChoiceChange();
        if (this.dataForm.unsafeStatus != null && this.dataForm.unsafeStatus != "") {
          this.unsafeChoice = '1';
          this.dataForm.unsafeStatus = this.dataForm.unsafeStatus.toString();
        }
        if (this.dataForm.unsafeAction != null && this.dataForm.unsafeAction != "") {
          this.unsafeChoice = '2';
          this.dataForm.unsafeAction = this.dataForm.unsafeAction.toString();
        }
        if (this.dataForm.category != null && this.dataForm.category != "") {
          this.dataForm.category = Number(this.dataForm.category);
        }
        if (this.dataForm.veResult == null) {
          this.dataForm.veResult = '1';
        }
        let applyStatus = this.dataForm.applyStatus;
        console.log(applyStatus);
        switch (applyStatus) {
          case 1:
            this.showAssess = true;
            this.assessDisabled = false;
            this.applyDisabled = false;
            break;
          case 2:
            this.showAssess = true;
            this.showExecute = true;
            this.applyDisabled = true;
            this.assessDisabled = true;
            this.executeDisabled = false;
            this.recordNoDisabled = true;
            this.veItemsDisabled = true;
            this.veItemOtherDisabled = true;
            this.dataForm.veResult = '1';
            break;
          case 3:
            this.showAssess = true;
            this.showExecute = true;
            this.showInspect = true;
            this.applyDisabled = true;
            this.assessDisabled = true;
            this.executeDisabled = true;
            this.veItemsDisabled = true;
            this.veItemOtherDisabled = true;
            break;
          case 4:
            this.showAssess = true;
            this.showExecute = true;
            this.showInspect = true;
            this.applyDisabled = true;
            this.assessDisabled = true;
            this.executeDisabled = true;
            this.inspectDisabled = true;
            break;
          case 5:
            this.showAssess = false;
            this.assessDisabled = true;
            break;
        }
      });
      // 查询流转详情
      getHistorylist({processId: processId}).then(response => {
        this.historyList = response.rows;
        this.rejectList = [];
        for (let i = 0; i < response.rows.length; i++) {
          if(response.rows[i].comment != null) {
            if (response.rows[i].comment.indexOf("驳回") != -1) {
              let reject = {};
              reject.result = response.rows[i].comment.split(",")[0];
              reject.comment = response.rows[i].comment.split(",")[1];
              reject.userName = response.rows[i].userName;
              reject.taskEndTime = response.rows[i].taskEndTime;
              this.rejectList.push(reject);
            }
          }

        }
        this.historyLoading = false
      });
      // 加载登记人班组字典
      this.getDicts("TEAM_DIVIDE").then(response => {
        this.applicantTeamOptions = response.data;
      });
      // 加载登记人部门列表
      this.getApplicantDeptOptions();

      // 加载整改负责人列表
      this.listSaiInspectors();
      // 加载执行人列表
      this.listSaiExecutors();
      // 加载不安全状态字典
      this.getDicts("SAI_UNSAFE_STATUS").then(response => {
        this.unsafeStatusOptions = response.data;
      });
      // 加载不安全行为字典
      this.getDicts("SAI_UNSAFE_ACTION").then(response => {
        this.unsafeActionOptions = response.data;
      });
      // 加载当前登录员工信息
      this.getLoginStaffInfo();
      // 加载SAI类别字典
      this.getCategoryList();
      this.getWorkAreaList();
    },
    getWorkAreaList() {
      selectDevice().then(response => {
        let data = response.data;
        for (let i = 0; i < data.length; i++) {
          this.workAreaList.push(data[i]);
        }
      });
    },
    /** 获取SAI类别列表数据 */
    getCategoryList() {
      this.saiCategoryOptions = [];
      categoryList().then(response => {
        let data = response.data;
        for (let i = 0; i < data.length; i++) {
          if (data[i].saiCategoryName != null && data[i].saiCategoryName != "") {
            this.saiCategoryOptions.push({
              dictLabel: data[i].saiCategoryName,
              dictValue: data[i].saiCategoryId
            });
          }
        }
      });
    },
    /** 加载当前登录员工信息 */
    getLoginStaffInfo() {
      getLoginStaffInfo().then(response => {
        let staff = response.data;
        if (staff != null) {
          this.loginStaffInfo = response.data;
        }
      });
    },
    /** 文件下载处理 */
    handleDownload(row) {
      var name = row.fileName;
      var url = row.fileUrl;
      var suffix = url.substring(url.lastIndexOf("."), url.length);
      const a = document.createElement('a')
      a.setAttribute('download', name)
      a.setAttribute('target', '_blank')
      a.setAttribute('href', process.env.VUE_APP_BASE_API + url)
      a.click()
    },
    /** 报告附件按钮操作 */
    handleDoc(row) {
      this.doc.id = row.saiApplyId;
      this.doc.title = "附件";
      this.doc.open = true;
      this.doc.queryParams.pId = row.saiApplyId
      this.doc.pId = row.saiApplyId
      this.getFileList()
      this.$nextTick(() => {
        this.$refs.doc.clearFiles()
      })
    },
    getFileList() {
      listFile({
        approveId: this.dataForm.saiApplyId
      }).then(response => {
        this.doc.commonfileListApply = response;
      });
      allFileList({
        pId: this.doc.queryParams.pId,
        pType: "saiExecute"
      }).then(response => {
        this.doc.commonfileListExecute = response;
      });
      allFileList({
        pId: this.doc.queryParams.pId,
        pType: "saiInspect"
      }).then(response => {
        this.doc.commonfileListInspect = response;
      });
    },
    /** 附件上传中处理 */
    handleFileDocProgress(event, file, fileList) {
      this.doc.file = file;
      this.doc.isUploading = true;
    },
    /** 附件上传成功处理 */
    handleFileDocSuccess(response, file, fileList) {
      this.doc.isUploading = false;
      this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true });
      this.getFileList()
    },
    /** 删除按钮操作 */
    handleDeleteDoc(row) {
      const ids = row.id || this.ids;
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: "warning"
      }).then(function() {
        return delCommonfile(ids);
      }).then(() => {
        this.getFileList();
        this.msgSuccess(this.$t('删除成功'));
      })
    },
    //文件预览
    openPdf(){
      //ppt就跳路由预览，office就直接打开文件新页面
      const didi={ imgs:this.imgs}
      if( this.pptView==true&&this.ppt==false){
        let routeUrl = this.$router.resolve({
          path: "/cpms/index.html#/pptyulan",
          query:didi
        });
        window.open("/cpms/index.html#/pptyulan?id=" + this.pdf.pdfUrl, '_blank')
      }else {
        window.open(this.pdf.pdfUrl)
      }
    },
    handleSeePPT (row){
      //ppt预览
      this.loadingFlash=true
      this.pdf.open =true
      this.pdf.title = row.fileName
      this.pdf.pdfUrl = row.fileUrl
      this.pptView=true
      this.ppt=false
      const formatDate =new FormData();
      formatDate.append("filepath",row.fileUrl)

      //调用文件预览api
      let res= this.officeConvert.pptConvertCommon(formatDate)

      //查看接受的全局方法的返回结果 console.log(res)
      //利用.then方法接受Promise对象

      res.then((result)=>{
        //关闭加载中
        this.loadingFlash=false

        //成功时直接给地址
        this.videoList = result.data.imagePathList
        //将返回的地址集合遍历添加到绑定的数组中
        this.imgs=[]
        for (var key=0;key<this.videoList.length;key++) {
          this.imgs.push( process.env.VUE_APP_BASE_API+  this.videoList[key]  );
        }
      }).catch(result => {

        //请求失败，关闭loading，pdf地址直接为为空，不显示
        this.pdf.pdfUrl =""
        this.loadingFlash = false;
      })
    },
    handleSee (row){
      //office预览
      this.loadingFlash=true
      this.pdf.open =true
      this.pdf.title = row.fileName
      this.pdf.pdfUrl =""

      this.pptView=false
      this.ppt=true
      //如果是PDF等直接可以打开的就不调接口，否则调用接口
      if(row.fileName.endsWith('pdf')){
        this.pdf.pdfUrl = process.env.VUE_APP_BASE_API + '/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + row.fileUrl
        this.loadingFlash=false
      }
      else{
        const formatDate =new FormData();
        formatDate.append("filepath",row.fileUrl)

        //调用文件预览api
        let res= this.officeConvert.officeConvertCommon(formatDate)


        //查看接受的全局方法的返回结果 console.log(res)
        //利用.then方法接受Promise对象
        res.then((result)=>{
          //关闭加载中
          this.loadingFlash=false

          if(result.msg.includes("csv")){
            this.pdf.pdfUrl =process.env.VUE_APP_BASE_API+ result.data
            this.$alert(result.msg, this.$t('检查乱码'), { dangerouslyUseHTMLString: true });
            //    this.$message({message: result.msg, center: true,type:'warning',  offset:400, });

          }else if(result.msg.includes("不存在")){
            //文件不存在时提示
            this.pdf.pdfUrl =""
            this.$alert(result.msg, this.$t('预览失败'), { dangerouslyUseHTMLString: true });
            //    this.$message({message: result.msg, center: true,type:'warning',  offset:400, });
            this.pdf.open =false
          }else if(result.msg.includes("不支持此格式")){

            this.pdf.pdfUrl =""
            this.$alert(result.msg, this.$t('预览失败'), { dangerouslyUseHTMLString: true });
            //    this.$message({message: result.msg, center: true,type:'warning',  offset:400, });
            this.pdf.open =false
          } else{
            //成功时直接给地址
            this.pdf.pdfUrl =process.env.VUE_APP_BASE_API+ result.data
          }
          // this.$nextTick(() => {
          //   const iframe = window.frames['iFrame']
          //   const handleLoad = () => {
          //     setTimeout(() => {
          //       const Do = (iframe.contentWindow || iframe.contentDocument)
          //       console.log(Do.document.getElementsByTagName('table')[0])
          //       Do.document.getElementsByTagName('table')[0].style.width = "100%"
          //       Do.document.getElementsByTagName('table')[0].setAttribute("class","table")
          //     }, 500)
          //   }
          //   iframe.addEventListener('load', handleLoad, true)
          // })
        }).catch(result => {

          //请求失败，关闭loading，pdf地址直接为为空，不显示
          this.pdf.pdfUrl =""
          this.loadingFlash = false;

        })
      }


    },
    /** 不安全行为/状态单选按钮值改变事件 */
    handleUnsafeChoiceChange() {
      if (this.unsafeChoice == '1') {
        this.dataForm.unsafeAction = null;
        this.unsafeStatusDisabled = false;
        this.unsafeActionDisabled = true;
      } else if (this.unsafeChoice == '2') {
        this.dataForm.unsafeStatus = null;
        this.unsafeStatusDisabled = true;
        this.unsafeActionDisabled = false;
      }
    },
    /** VE验证条款（其它）单选按钮值改变事件 */
    handleVeItemOtherVeChange() {
      let veItemsList = this.veItemsList;
      let flag = false;
      for (let i = 0; i < veItemsList.length; i++) {
        if (veItemsList[i] == '其它') {
          flag = true;
        }
      }
      if (flag) {
        this.veItemOtherDisabled = false;
      } else {
        this.veItemOtherDisabled = true;
        this.dataForm.veItemOther = null;
      }
    },
    /** 是否需要VE验证单选按钮值改变事件 */
    handleNeedVeChange() {
      if (this.dataForm.needVe == '1') {
        this.veItemsDisabled = false;
      } else if (this.dataForm.needVe == '0') {
        this.veItemsDisabled = true;
        this.veItemsList = [];
        this.handleVeItemOtherVeChange();
      }
    },
    /** 是否录入开项系统单选按钮值改变事件 */
    handleIsRecordedChange() {
      if (this.dataForm.isRecorded == '1') {
        this.recordNoDisabled = false;
      } else if (this.dataForm.isRecorded == '0') {
        this.recordNoDisabled = true;
        this.dataForm.recordNo = null;
      }
    },
    /** 加载登记人部门列表 */
    getApplicantDeptOptions() {
      // listDept(null).then(response => {
      //   let deptList = response.data;
      //   this.applicantDeptOptions = [];
      //   for (let i = 0; i < deptList.length; i++) {
      //     if (deptList[i].deptId == 103 || deptList[i].deptId == 10058 || deptList[i].deptId == 10042) {
      //       this.applicantDeptOptions.push({
      //         dictLabel: deptList[i].deptName,
      //         dictValue: deptList[i].deptId
      //       });
      //     }
      //   }
      // });
      this.applicantDeptOptions = [];
      this.applicantDeptOptions.push({ dictLabel: "CBP/C", dictValue: '10' });
      this.applicantDeptOptions.push({ dictLabel: "CTA/B", dictValue: '12' });
      this.applicantDeptOptions.push({ dictLabel: "CTM/B", dictValue: '14' });
    },
    /** 加载登记人列表 */
    listStaffmgrByDeptAndTeam(applicantDept, applicantTeam) {
      console.log('123');
      listStaffmgrByDeptAndTeam({
        deptId: applicantDept,
        team: applicantTeam
      }).then(response => {
        let staffList = response.rows;
        this.applicantOptions = [];
        for (let i = 0; i < staffList.length; i++) {
          if (this.inspector1 != null) {
            if (this.inspector1 == staffList[i].userId) {
              this.inspector1Name = staffList[i].name;
            }
          }
          let staffOption = {
            dictLabel: staffList[i].name,
            dictValue: staffList[i].userId
          }
          this.applicantOptions.push(staffOption);
        }
      });
    },
    /** 加载验证人列表 */
    listSaiInspectors() {
      listSaiInspectors().then(response => {
        let staffList = response.data;
        this.inspectorOptions = [];
        for (let i = 0; i < staffList.length; i++) {
          let staffOption = {
            dictLabel: staffList[i].name,
            dictValue: staffList[i].userId
          }
          this.inspectorOptions.push(staffOption);
        }
      });
    },
    /** 加载整改负责人列表 */
    listSaiExecutors(applicantDept, applicantTeam) {
      listSaiExecutors({
        deptId: applicantDept,
        team: applicantTeam
      }).then(response => {
        let staffList = response.data;
        this.executorOptions = [];
        for (let i = 0; i < staffList.length; i++) {
          let staffOption = {
            dictLabel: staffList[i].name,
            dictValue: staffList[i].userId
          }
          let isRepeated = false;
          for (let j = 0; j < this.executorOptions.length; j++) {
            if (this.executorOptions[j].dictValue == staffList[i].userId) {
              isRepeated = true;
              break;
            }
          }
          if (isRepeated == false) {
            this.executorOptions.push(staffOption);
          }
        }
      });
    },
    // 重置
    reset() {
      this.showAssess = false;
      this.showExecute = false;
      this.showInspect = false;
      this.form = {
        saiApplyId: null,
        deptId: null,
        applyStatus: null,
        apNo: null,
        processId: null
      };
      this.dataForm =  {
        saiApplyId: null,
        deptId: null,
        applyStatus: null,
        apNo: null,
        processId: null,
        applicant: null,
        assessor: null,
        executor: null,
        inspectors: null,
        applicantDept: null,
        applicantTeam: null,
        description: null,
        unsafeStatus: null,
        unsafeAction: null,
        applyDate: null,
        taskId: null,
        handler: null,
        taskName: null,
        estimateFinishDate: null,
        actualFinishDate: null,
        isRecorded: null,
        recordNo: null,
        reaction: null,
        needVe: null,
        veItems: null,
        veResult: null,
        veItemOther: null,
      };
      this.taskForm =  {
        comment: '',
        taskId: '',
        files: '',
        businessKey: '',
        saiApply: null,
      };
    },
    /**
     * 处理流程操作按钮点击事件
     */
    dataFormSubmit(condition) {
      if (condition == 0) {
        // 验证人字符串拼接
        this.dataForm.inspectors = this.inspector1 + "," + this.inspector2;
        // VE验证条款字符串拼接
        if (this.veItemsList.length != 0) {
          this.dataForm.veItems = "";
          for (let i = 0; i < this.veItemsList.length; i++) {
            this.dataForm.veItems += this.veItemsList[i];
            if (i != this.veItemsList.length - 1) {
              this.dataForm.veItems += ",";
            }
          }
        }
        this.taskForm.saiApply = this.dataForm;
        this.taskForm.condition = condition;
        handleApply(this.taskForm).then(response =>{
          this.msgSuccess("提交成功");
          this.visible = false;
          // refreshDataList事件：调用父组件getList方法刷新页面
          this.$emit('refreshDataList');
        });
      } else {
        this.$refs["form"].validate(valid => {
          if (valid) {
            // 验证人字符串拼接
            this.dataForm.inspectors = this.inspector1 + "," + this.inspector2;
            // VE验证条款字符串拼接
            if (this.veItemsList.length != 0) {
              this.dataForm.veItems = "";
              for (let i = 0; i < this.veItemsList.length; i++) {
                this.dataForm.veItems += this.veItemsList[i];
                if (i != this.veItemsList.length - 1) {
                  this.dataForm.veItems += ",";
                }
              }
            }
            this.taskForm.saiApply = this.dataForm;
            this.taskForm.condition = condition;
            handleApply(this.taskForm).then(response =>{
              this.msgSuccess("提交成功");
              this.visible = false;
              // refreshDataList事件：调用父组件getList方法刷新页面
              this.$emit('refreshDataList');
            });
          }
        })
      }
    },
    /**
     * 保存按钮点击事件
     */
    dataFormSave() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 验证人字符串拼接
          this.dataForm.inspectors = this.inspector1 + "," + this.inspector2;
          // VE验证条款字符串拼接
          if (this.veItemsList.length != 0) {
            this.dataForm.veItems = "";
            for (let i = 0; i < this.veItemsList.length; i++) {
              this.dataForm.veItems += this.veItemsList[i];
              if (i != this.veItemsList.length - 1) {
                this.dataForm.veItems += ",";
              }
            }
          }
          updateApply(this.dataForm).then(response =>{
            this.msgSuccess("保存成功");
            // refreshDataList事件：调用父组件getList方法刷新页面
            this.$emit('refreshDataList');
            this.visible = false;
          });
        }
      })
    },
  }
}
</script>

<style scoped lang="scss">
  h4{
    margin: 20px 0px 10px 0px;
  }
  .el-checkbox {
    color: #606266;
    padding: 5px 0px;
  }
  ::v-deep .el-input.is-disabled .el-input__inner {
    color: #606266;
    background-color: transparent;
  }
  ::v-deep .el-textarea.is-disabled .el-textarea__inner {
    color: #606266;
    background-color: transparent;
  }
  ::v-deep .el-radio__input.is-checked + .el-radio__label {
    color: #4a7cf9;
  }
  ::v-deep .el-radio__input.is-disabled.is-checked .el-radio__inner {
    background-color: #4a7cf9;
    border-color: #4a7cf9;
  }
  ::v-deep .el-radio__input.is-disabled.is-checked .el-radio__inner::after {
    background-color: #fff;
  }
  ::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #606266;
    cursor: not-allowed;
  }
  ::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
    background-color: #4a7cf9;
    border-color: #4a7cf9;
  }
  ::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    border-color: #fff;
  }
</style>
