<template>
  <div class="app-container">
    <div class="filter-container">
      <div v-show="hasPerm('bggl:update') || hasPerm('bggl:regenerate')" class="sub-navbar">
        <sticky>
          <el-button v-if="showResetFlowApply" v-show="hasPerm('bggl:update') && notHasDepartmentId(74)" type="danger" icon="el-icon-refresh" @click="resetFlowApply">
            重启流程发送申请
          </el-button>
          <el-button v-if="hasPerm('bggl:update')" type="danger" icon="el-icon-refresh" @click="resetFlow">
            重启流程
          </el-button>
          <el-button v-if="$store.getters.departmentId === 68 || $store.getters.username === 'admin'" type="success" icon="el-icon-download" @click="batchDownloadWord">
            下载报告
          </el-button>
          <template v-if="hasPerm('bggl:regenerate')">
            <el-button v-if="notHasDepartmentId(74)" type="danger" icon="el-icon-refresh" @click="beforeResetRecord">
              重启申请
            </el-button>
            <el-button type="warning" icon="el-icon-refresh" @click="generatePdf('YSJL')">
              生成记录
            </el-button>
            <el-button type="warning" icon="el-icon-refresh" @click="generatePdf('OTHER')">
              生成附件（压力容器制造）
            </el-button>
            <el-button type="warning" icon="el-icon-refresh" @click="generatePdf('JYBG')">
              生成报告
            </el-button>
            <el-button v-if="notHasDepartmentId(74)" type="warning" icon="el-icon-refresh" @click="generatePdf('HGZ')">
              生成合格证
            </el-button>
            <el-button type="success" icon="el-icon-refresh" @click="createQrcode">
              重新生成一/二维码
            </el-button>
            <el-button v-if="notHasDepartmentId(74)" type="warning" @click="cleanRed">
              <svg-icon icon-class="clear" /> 消红
            </el-button>
          </template>
          <a id="downlink" />
        </sticky>
      </div>
      <el-form style="margin-top: 10px;">
        <el-form-item>
          <el-input
            v-model="listQuery.searchYsjl.baogaobianhao"
            placeholder="报告编号"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleFilter"
          />
          <el-input
            v-model="listQuery.searchYsjl.zhucedaima"
            placeholder="注册代码"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleFilter"
          />
          <el-input
            v-model="listQuery.searchYsjl.shiyongdanwei"
            placeholder="使用单位"
            clearable
            style="width: 350px"
            @keyup.enter.native="handleFilter"
          />
          <br>
          <span class="radio-group-label">查看类型：</span>
          <el-radio-group v-model="listQuery.searchYsjl.createBy" @change="handleFilter">
            <el-radio :label="$store.getters.userId">
              只看创建人
            </el-radio>
            <el-radio :label="undefined">
              全部
            </el-radio>
          </el-radio-group>
          <el-button type="primary" size="small" icon="el-icon-search" @click="handleFilter">
            查询
          </el-button>
          <el-button type="primary" size="small" icon="el-icon-search" @click="highQuery">
            高级查询
          </el-button>
          <el-button type="info" size="small" icon="el-icon-close" @click="clearQuery">
            清空条件
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      ref="list"
      v-adaptive="{bottomOffset: 50}"
      height="0"
      :data="list"
      border
      fit
      highlight-current-row
      stripe
      width="100%"
      size="small"
      @row-click="onRowClick"
      @selection-change="handleSelectionChange"
      @sort-change="sortChange"
    >
      <el-table-column type="selection" width="40" />
      <el-table-column fixed="left" align="center" label="序号" width="50">
        <template slot-scope="scope">
          <span v-text="getIndex(scope.$index)" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="报告编号" prop="baogaobianhao" width="180" sortable="custom" />
      <el-table-column :formatter="formatter.formatterCategory" align="center" label="检验类别" prop="neibuleibie" width="100" />
      <template v-if="$store.getters.departmentId === 69 || $store.getters.departmentId === 86">
        <el-table-column v-if="$store.getters.departmentId === 69" align="center" label="使用单位" prop="shiyongdanwei" width="200" />
        <el-table-column v-if="$store.getters.departmentId === 86" align="center" label="安装单位" prop="shigongdanwei" width="200" />
        <el-table-column align="center" label="产品编号/出厂编号" prop="chanpinbianhao" width="130" />
        <el-table-column align="center" label="制造单位" prop="zhizaodanwei" width="200" />
      </template>
      <template v-else-if="$store.getters.departmentId === 74">
        <el-table-column align="center" label="制造单位" prop="zhizaodanwei" width="200" />
        <el-table-column align="center" label="设备代码" prop="shebeidaima" width="200" />
        <el-table-column align="center" label="锅炉型号" prop="guigexinghao" width="200" />
        <el-table-column align="center" label="产品编号/出厂编号" prop="chanpinbianhao" width="130" />
      </template>
      <template v-else>
        <el-table-column align="center" label="使用登记证号" prop="shiyongdengjibianhao" width="150" sortable="custom" />
        <el-table-column align="center" label="注册代码" prop="zhucedaima" width="170" sortable="custom" />
        <el-table-column align="center" label="使用单位" prop="shiyongdanwei" width="200" />
        <el-table-column align="center" label="产品名称/设备名称" prop="shebeimingcheng" width="130" />
        <el-table-column align="center" label="制造单位" prop="zhizaodanwei" width="200" />
        <el-table-column align="center" label="产品编号/出厂编号" prop="chanpinbianhao" width="130" />
        <el-table-column align="center" label="单位内编号" prop="danweineibubianhao" width="130" sortable="custom" />
      </template>
      <el-table-column :formatter="formatter.getChineseName" align="center" label="检验人员" prop="jianyanrenyuan" width="140" />
      <el-table-column align="center" label="检验日期" prop="jianyanjieshuriqi" width="110" sortable="custom" />
      <el-table-column v-if="$store.getters.departmentId !== 74" align="center" label="下次检验日期" prop="xiacijianyanriqi" width="130" sortable="custom" />
      <el-table-column align="center" label="检验结论" prop="jianyanjielun" width="120" />
      <el-table-column fixed="right" align="center" label="报告类型" prop="inspectionItems" width="95">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.bglx===1">
            主报告
          </el-tag>
          <el-tag v-if="scope.row.bglx===2" type="success">
            {{ scope.row.inspectionItems }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="center" label="重启状态" prop="state" width="160">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.restartstatuslevel===4" type="danger">
            已申请
          </el-tag>
          <el-tag v-else-if="scope.row.restartstatuslevel===5" type="danger">
            待质量师审核
          </el-tag>
          <el-tag v-else-if="scope.row.restartstatuslevel===6" type="danger">
            待业务面技术负责人审核
          </el-tag>
          <el-tag v-else-if="scope.row.restartstatuslevel===7" type="danger">
            待授权签字人审批
          </el-tag>
          <el-tag v-else-if="scope.row.restartstatuslevel===8" type="warning">
            已审批
          </el-tag>
          <el-tag v-else type="success">
            未重启
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="center" label="操作" prop="" width="100">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-view"
            title="预览"
            circle
            @click="common.viewYsjl(scope.row.id, 'JYBG')"
          />
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="totalCount>0"
      :total="totalCount"
      :page-num.sync="listQuery.pageNum"
      :page-row.sync="listQuery.pageRow"
      @pagination="getList"
    />
    <!-- 高级查询窗口 -->
    <el-dialog :visible.sync="dialogQueryVisible" title="高级查询" width="60%">
      <el-container>
        <el-form :inline="true">
          <el-form-item label="检验类别:" style="width: 240px;">
            <el-select
              v-model="listQuery.searchYsjl.neibuleibie"
              placeholder="请选择检验类别"
              style="width: 165px"
              clearable
              default-first-option
            >
              <el-option v-for="item in jylbList" v-show="item.parentId" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备种类:" style="width: 240px;">
            <el-select
              v-model="listQuery.searchYsjl.shebeizhongleidaima"
              placeholder="请选择设备种类"
              style="width: 165px"
              clearable
              default-first-option
            >
              <el-option v-for="item in sbzlList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="检验人员:" style="width: 240px;">
            <el-select
              v-model="listQuery.searchYsjl.jianyanrenyuan"
              placeholder="请选择检验人员"
              style="width: 165px"
              filterable
              clearable
            >
              <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="审核人员:" style="width: 240px;">
            <el-select v-model="listQuery.searchYsjl.shenheren" placeholder="请选择审核人员" style="width: 165px" filterable clearable>
              <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="审批人员:" style="width: 240px;">
            <el-select v-model="listQuery.searchYsjl.shenpiren" placeholder="请选择审批人员" style="width: 165px" filterable clearable>
              <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="检验日期:" style="width: 240px;">
            <el-date-picker
              v-model="listQuery.searchYsjl.jianyanjieshuriqi"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择检验日期"
              style="width: 165px"
            />
          </el-form-item>
          <el-form-item label="审核日期:" style="width: 240px;">
            <el-date-picker
              v-model="listQuery.searchYsjl.shenheriqi"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择审核日期"
              style="width: 165px"
            />
          </el-form-item>
          <el-form-item label="审批日期:" style="width: 240px;">
            <el-date-picker
              v-model="listQuery.searchYsjl.shenpiriqi"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择审批日期"
              style="width: 165px"
            />
          </el-form-item>
          <el-form-item label="下次检验日期:" style="width: 250px;">
            <el-date-picker
              v-model="listQuery.searchYsjl.xiacijianyanriqi"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请输入日期"
              style="width: 145px"
            />
          </el-form-item>
          <el-form-item label="设备/产品名称:" style="width: 290px;">
            <el-input
              v-model="listQuery.searchYsjl.shebeimingcheng"
              placeholder="请输入设备/产品名称"
              clearable
              style="width: 185px"
            />
          </el-form-item>
          <el-form-item label="制造单位:" style="width: 450px;">
            <el-input v-model="listQuery.searchYsjl.zhizaodanwei" placeholder="请输入制造单位" style="width: 370px" />
          </el-form-item>
          <el-form-item label="使用登记证编号:" style="width: 350px;">
            <el-input
              v-model="listQuery.searchYsjl.shiyongdengjibianhao"
              placeholder="请输入使用登记证编号"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="产品/出厂编号:" style="width: 290px;">
            <el-input v-model="listQuery.searchYsjl.chanpinbianhao" placeholder="请输入产品编号" style="width: 185px" />
          </el-form-item>
        </el-form>
      </el-container>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogQueryVisible = false">
          取 消
        </el-button>
        <el-button type="success" @click="handleFilter">
          查 询
        </el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormExportReportVisible" title="导出台账" width="80%">
      <el-container>
        <el-form :inline="true">
          <el-form-item label="监检编号" style="width: 290px;">
            <el-input v-model="listQueryExport.searchYsjl.baogaobianhao" placeholder="监检编号" clearable style="width: 220px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <el-form-item label="产品编号" style="width: 290px;">
            <el-input v-model="listQueryExport.searchYsjl.chanpinbianhao" placeholder="产品编号" clearable style="width: 220px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <el-form-item label="锅炉型号" style="width: 290px;">
            <el-input v-model="listQueryExport.searchYsjl.guigexinghao" placeholder="锅炉型号" clearable style="width: 220px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <br>
          <el-form-item label="出厂开始日期" style="width: 290px;">
            <el-date-picker v-model="listQueryExport.searchYsjl.chuchangkaishiriqi" type="date" placeholder="出厂开始日期" value-format="yyyy-MM-dd" clearable style="width: 190px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <el-form-item label="出厂结束日期" style="width: 290px;">
            <el-date-picker v-model="listQueryExport.searchYsjl.chuchangjieshuriqi" type="date" placeholder="出厂结束日期" value-format="yyyy-MM-dd" clearable style="width: 190px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <el-form-item label="容器名称" style="width: 290px;">
            <el-input v-model="listQueryExport.searchYsjl.shebeimingcheng" placeholder="容器名称" clearable style="width: 220px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <br>
          <el-form-item label="监检开始日期" style="width: 290px;">
            <el-date-picker v-model="listQueryExport.searchYsjl.jianjiankaishiriqi" type="date" placeholder="监检开始日期" value-format="yyyy-MM-dd" clearable style="width: 190px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <el-form-item label="监检结束日期" style="width: 290px;">
            <el-date-picker v-model="listQueryExport.searchYsjl.jianjianjieshuriqi" type="date" placeholder="监检结束日期" value-format="yyyy-MM-dd" clearable style="width: 190px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <el-form-item label="设备类别" style="width: 290px;">
            <el-input v-model="listQueryExport.searchYsjl.shebeileibie" placeholder="设备类别" clearable style="width: 220px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <br>
          <el-form-item label="检验人员" style="width: 290px;">
            <el-select v-model="listQueryExport.searchYsjl.jianyanrenyuan" placeholder="请选择人员" style="width: 220px" clearable @change="handleFilterExportReport">
              <el-option v-for="item in userList" :key="item.key" :label="item.label" :value="item.key" />
            </el-select>
          </el-form-item>
          <el-form-item label="制造单位" style="width: 490px;">
            <el-input v-model="listQueryExport.searchYsjl.zhizaodanwei" placeholder="制造单位" clearable style="width: 350px;" @keyup.enter.native="handleFilterExportReport" />
          </el-form-item>
          <br>
          <el-button type="primary" icon="el-icon-search" @click="handleFilterExportReport">
            查询
          </el-button>
          <el-button type="info" icon="el-icon-close" @click="clearExportReportQuery">
            清空条件
          </el-button>
          <el-button type="success" icon="el-icon-download" @click="ExportShow">
            导出数据
          </el-button>
        </el-form>
      </el-container>
      <el-table
        id="export"
        ref="exportList"
        :data="exportList"
        size="small"
        height="420px"
        width="100%"
        border
        fit
        highlight-current-row
        style="margin-top: 15px;"
      >
        <el-table-column align="center" label="序号" width="50" fixed="left">
          <template slot-scope="scope">
            <span v-text="getIndex(scope.$index)" />
          </template>
        </el-table-column>
        <el-table-column align="center" label="监检编号" prop="baogaobianhao" width="180px;" sortable="custom" />
        <el-table-column align="center" label="制造单位" prop="zhizaodanwei" width="240" />
        <el-table-column align="center" label="容器名称/锅炉型号" prop="guigexinghao" width="220" sortable="custom" />
        <el-table-column align="center" label="产品编号" prop="chanpinbianhao" width="180" />
        <el-table-column align="center" label="类别" prop="shebeileibie" width="150" />
        <el-table-column align="center" label="出厂日期" prop="zhizaoriqi" width="150" />
        <el-table-column align="center" label="监检日期" prop="jianyanjieshuriqi" width="150" />
        <el-table-column align="center" label="监检员" prop="jianyanrenyuan" width="150" />
      </el-table>
      <pagination v-show="totalCount>0" :total="totalCountExport" :page-num.sync="listQueryExport.pageNum" :page-row.sync="listQueryExport.pageRow" @pagination="getExportReportList" />
    </el-dialog>
    <!--重启申请选择方式窗口-->
    <el-dialog :visible.sync="dialogSelectionMethod" title="重启申请方式" width="23%">
      <el-form label-width="120px" inline>
        <el-form-item>
          <el-button type="warning" plain size="small" icon="el-icon-warning-outline" @click="selectionMethodRestart(1)">
            补充检验项目
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="warning" plain size="small" icon="el-icon-warning-outline" @click="selectionMethodRestart(2)">
            结论性错误
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="warning" plain size="small" icon="el-icon-warning-outline" @click="selectionMethodRestart(3)">
            非结论性错误
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--报告重启窗口-->
    <el-dialog :visible.sync="dialogResetFlow" :title="resetData.type === 1 ? '补充检验审批记录' : '检验报告（证书）更改审批表'">
      <div class="sub-navbar">
        <sticky>
          <el-button type="primary" @click="queren">
            保  存
          </el-button>
        </sticky>
      </div>
      <el-form ref="resetData" :model="resetData" label-width="120px" size="small" inline style="height: 600px;overflow: auto;">
        <fieldset style="width: auto">
          <legend>基本信息</legend>
          <el-form-item label="业务科室">
            <el-input v-model="departmentName" size="small" style="width: 250px;" type="text" disabled />
          </el-form-item>
          <el-form-item label="检验员">
            <el-input v-model="jianyanrenyuanmingcheng" size="small" style="width: 250px;" type="text" disabled />
          </el-form-item>
          <el-form-item label="受检单位">
            <el-input v-model="zzdwName" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="设备型号">
            <el-input v-model="resetData.guigexinghao" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="报告编号">
            <el-input v-model="resetData.baogaobianhao" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="检验日期">
            <el-input v-model="resetData.jianyanjieshuriqi" size="small" style="width: 250px;" disabled />
          </el-form-item>
        </fieldset>
        <fieldset style="width: auto">
          <legend>{{ resetData.type === 1 ? '补充检验原因' : '报告、证书更改内容及原因' }}：</legend>
          <el-row>
            <el-input v-model="resetData.reason" type="textarea" :autosize="{ minRows: 4, maxRows: 4}" style="width: 100%" />
          </el-row>
          <div style="margin: 20px 0;" />
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="检验员：">
                <el-input v-model="jianyanrenyuanmingcheng" type="text" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：" prop="jianyanriqi">
                <el-date-picker v-model="resetData.jianyanriqi" type="date" placeholder="选择日期" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="质量师：">
                <el-input v-model="resetData.zhijianrenyuan" type="text" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：" prop="jianyanriqi">
                <el-date-picker v-model="resetData.zhijianriqi" type="date" placeholder="选择日期" disabled />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <div style="margin: 10px 0;" />
          <legend>审核意见：</legend>
          <el-row>
            <el-input v-model="resetData.opinion1" type="textarea" :autosize="{ minRows: 2, maxRows: 2}" disabled />
          </el-row>
          <div style="margin: 20px 0;" />
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label-width="140px" label="业务面技术负责人：">
                <el-input v-model="resetData.jijianrenyuan" type="text" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：">
                <el-date-picker v-model="resetData.jijianriqi" type="date" placeholder="选择日期" disabled />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <legend>批准意见：</legend>
          <div style="margin: 10px 0;" />
          <el-row>
            <el-input v-model="resetData.opinion2" type="textarea" :autosize="{ minRows: 2, maxRows: 2}" disabled />
          </el-row>
          <div style="margin: 20px 0;" />
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="授权签字人：">
                <el-input v-model="resetData.shenpirenyuan" type="text" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：">
                <el-date-picker v-model="resetData.shenpiriqi" type="date" placeholder="选择日期" disabled />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <legend>备注：</legend>
          <div style="margin: 10px 0;" />
          <el-row>
            <el-input v-model="resetData.remarks" type="textarea" :autosize="{ minRows: 2, maxRows: 2}" />
          </el-row>
        </fieldset>
      </el-form>
    </el-dialog>
    <!--填写更改原因或内容-->
    <el-dialog :visible.sync="dialogReason" title="更改原因或内容">
      <div class="sub-navbar">
        <sticky>
          <el-button type="primary" @click="queren(false)">
            保  存
          </el-button>
        </sticky>
      </div>
      <el-form ref="resetData" :model="resetData" label-width="120px" size="small" inline>
        <el-input v-model="resetData.reason" type="textarea" :autosize="{ minRows: 4, maxRows: 4}" style="width: 100%" />
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import Sticky from '@/components/Sticky'
import Pagination from '@/components/Pagination'
import Utils from '../../utils/contact.js'
import qs from 'qs'
export default {
  name: 'HasDoneReport',
  components: { Sticky, Pagination },
  data() {
    return {
      totalCount: 0,
      list: [],
      listQuery: {
        pageNum: 1, // 页码
        pageRow: 20, // 每页条数
        order: 'shenpiriqi desc,id', // 排序字段
        sort: 'desc', // 排序方式
        searchYsjl: {
          createBy: this.$store.getters.departmentId === 70 ? this.$store.getters.userId : undefined
        },
        hasChild: true,
        hasFinish: true
      },
      multipleSelection: [],
      dialogQueryVisible: false,
      dialogResetFlow: false,
      resetData: {
        reason: ''
      },
      sbzlList: [],
      jylbList: [],
      roleName: '容器制造',
      showResetFlowApply: true,
      statusList: [
        {
          value: 1,
          label: '起草报告'
        }, {
          value: 2,
          label: '审核报告'
        }, {
          value: 3,
          label: '审批报告'
        }
      ],
      userList: [],
      exportList: [],
      dialogFormExportReportVisible: false,
      listQueryExport: {
        pageNum: 1, // 页码
        pageRow: 20, // 每页条数
        order: 'shenpiriqi desc,id', // 排序字段
        sort: 'desc', // 排序方式
        searchYsjl: {
          createBy: this.$store.getters.userId
        },
        hasChild: false,
        hasFinish: true
      },
      totalCountExport: 0,
      outFile: '', // 导出文件el
      jianyanrenyuanmingcheng: '',
      departmentName: '',
      zzdwName: '',
      resetRecordList: [],
      dialogResetRecords: false,
      dialogSelectionMethod: false,
      dialogReason: false
    }
  },
  created() {
    this.getList()
    this.getSbzlList()
    this.jylbList = this.$store.getters.allCategory
    this.userList = this.$store.getters.allUser
    // this.getResetFlowApply()
  },
  mounted() {
    const that = this
    this.common.$on('bggl-banjie-list', function() {
      that.handleFilter()
    })
    this.outFile = document.getElementById('downlink')
  },
  methods: {
    // 判断当前用户角色是符合条件
    // getResetFlowApply() {
    //   this.api({
    //     url: 'role/getById',
    //     method: 'get',
    //     params: { id: this.$store.getters.role }
    //   }).then(data => {
    //     this.showResetFlowApply = data.roleName.indexOf(this.roleName) !== -1
    //   })
    // },
    // 获得检验科室名称
    getDepartmentNameById(departmentId) {
      this.api({
        url: '/department/getById',
        method: 'get',
        params: { depId: departmentId }
      }).then(data => {
        this.departmentName = data.name
      })
    },
    // 获得单位名称
    getZzdwNameById(zzdwId) {
      this.api({
        url: '/dwxx/getById',
        method: 'get',
        params: { id: zzdwId }
      }).then(data => {
        this.zzdwName = data.zhizaodanwei
      })
    },
    getList() {
      this.api({
        url: '/ysjl/getList',
        method: 'get',
        params: this.listQuery
      }).then(data => {
        this.list = data.list
        this.totalCount = data.totalCount
        this.common.switchInspection(this.list)
      })
    },
    getExportReportList: function() {
      this.listQueryExport.searchYsjl.jianyanleibie = '制造监检'
      this.listQueryExport.searchYsjl.zfState = false
      this.api({
        url: '/ysjl/getList',
        method: 'get',
        params: this.listQueryExport
      }).then(data => {
        this.exportList = data.list
        for (let i = 0; i < this.exportList.length; i++) {
          if (this.exportList[i].jianyanrenyuan !== null && this.exportList[i].jianyanrenyuan !== undefined) {
            this.exportList[i].jianyanrenyuan = this.common.convertCnName(this.exportList[i].jianyanrenyuan)
          }
          if (this.exportList[i].shebeizhongleidaima !== null && this.exportList[i].shebeizhongleidaima !== undefined && this.exportList[i].shebeizhongleidaima !== '1000') {
            this.exportList[i].guigexinghao = this.exportList[i].shebeimingcheng
          }
        }
        this.totalCountExport = data.totalCount
      })
    },
    ExportShow: function() {
      const listExport = JSON.parse(JSON.stringify(this.listQueryExport))
      listExport.searchYsjl.jianyanleibie = '制造监检'
      listExport.searchYsjl.zfState = false
      listExport.pageRow = 1000
      this.api({
        url: '/ysjl/getList',
        method: 'get',
        params: listExport
      }).then(data => {
        for (let i = 0; i < data.list.length; i++) {
          if (data.list[i].jianyanrenyuan !== null && data.list[i].jianyanrenyuan !== undefined) {
            data.list[i].jianyanrenyuan = this.common.convertCnName(data.list[i].jianyanrenyuan)
          }
          if (data.list[i].shebeizhongleidaima !== null && data.list[i].shebeizhongleidaima !== undefined && data.list[i].shebeizhongleidaima !== '1000') {
            data.list[i].guigexinghao = data.list[i].shebeimingcheng
          }
        }
        let exportData = [{}]
        exportData[0]['baogaobianhao'] = 'baogaobianhao'
        exportData[0]['zhizaodanwei'] = 'zhizaodanwei'
        exportData[0]['guigexinghao'] = 'guigexinghao'
        exportData[0]['chanpinbianhao'] = 'chanpinbianhao'
        exportData[0]['shebeileibie'] = 'shebeileibie'
        exportData[0]['zhizaoriqi'] = 'zhizaoriqi'
        exportData[0]['jianyanjieshuriqi'] = 'jianyanjieshuriqi'
        exportData[0]['jianyanrenyuan'] = 'jianyanrenyuan'
        exportData = exportData.concat(data.list)
        const headLine = { A1: '监检编号', B1: '制造单位', C1: '容器名称/锅炉型号', D1: '产品编号', E1: '类别', F1: '出厂日期', G1: '监检日期', H1: '监检员' }
        this.common.downloadExl(exportData, '台账', headLine, this.outFile)
      })
    },
    sortChange(column) {
      this.listQuery.order = column.prop
      this.listQuery.sort = column.order.replace('ending', '')
      this.getList()
    },
    getIndex($index) {
      // 表格序号
      return (this.listQuery.pageNum - 1) * this.listQuery.pageRow + $index + 1
    },
    handleFilter() {
      // 查询事件
      this.listQuery.pageNum = 1
      this.dialogQueryVisible = false
      this.getList()
    },
    handleFilterExportReport() {
      // 查询事件
      this.listQueryExport.pageNum = 1
      this.getExportReportList()
    },
    onRowClick(row) {
      this.$refs.list.toggleRowSelection(row)
    },
    handleSelectionChange: function(val) {
      this.multipleSelection = val
    },
    getSbzlList() {
      this.api({
        url: '/sedirectory/getList',
        method: 'get',
        params: {
          sbzl: undefined,
          level: '1'
        }
      }).then(data => {
        this.sbzlList = data
      })
    },
    highQuery() {
      this.dialogQueryVisible = true
    },
    resetFlowApply() {
      let message = ''
      if (this.multipleSelection.length === 0) {
        message = '请选择一条数据，进行重启流程申请！'
      }
      if (this.multipleSelection.length > 1) {
        message = '只能选择一条数据进行重启流程申请！'
      }
      if (this.multipleSelection[0].restartstatuslevel && this.multipleSelection[0].restartstatuslevel !== 0) {
        message = '该报告已提交重启流程申请！'
      }
      if (this.multipleSelection[0].jianyanrenyuan !== this.$store.getters.userId + '') {
        message = '您不是此报告的检验人员，无法提交申请！'
      }
      if (message !== '') {
        this.$message({ type: 'error', message: message })
        return false
      }
      this.dialogSelectionMethod = true
    },
    queren(ifReason) {
      this.$refs['resetData'].validate(valid => {
        if (valid) {
          if (!this.resetData.reason && this.resetData.reason === '') {
            this.$message({ type: 'error', message: '请填写更改原因、更改内容、是否已缴费的内容！' })
            return false
          }
          this.api({
            url: '/restartProcess/save',
            method: 'post',
            data: this.resetData
          }).then(() => {
            this.$message.success('添加成功！')
            if (ifReason) {
              this.dialogResetFlow = false
            } else {
              this.dialogReason = false
              this.resetData.reason = ''
            }
            this.getList()
          })
        } else {
          return false
        }
      })
    },
    resetFlow() {
      let ids = ''
      let parentIds = ''
      for (let i = 0; i < this.multipleSelection.length; i++) {
        if (this.multipleSelection[i].neibuleibie === 'ZZ' && this.multipleSelection[i].shebeizhongleidaima === '2000' &&
          (!this.showResetFlowApply || this.multipleSelection[i].restartstatuslevel !== 8)) {
          this.$message({
            type: 'error',
            message: '该' + this.multipleSelection[i].baogaobianhao + '报告重启流程未通过审批！'
          })
          return false
        }
        if (i === 0) {
          ids = this.multipleSelection[i].id
          if (this.multipleSelection[i].bglx === 2) {
            parentIds = this.multipleSelection[i].parentId
          }
        } else {
          ids += ',' + this.multipleSelection[i].id
          if (this.multipleSelection[i].bglx === 2) {
            parentIds += ',' + this.multipleSelection[i].parentId
          }
        }
      }
      if (parentIds !== '') {
        // 判断主原始记录是否处于流转中
        this.api({
          url: '/ysjl/judgeInCirculate',
          method: 'get',
          params: {
            ysjlIds: parentIds
          }
        }).then(data => {
          if (data) {
            this.$message({
              type: 'error',
              message: '主报告处于起草状态才可以重启无损报告，请待主报告办结后重启主报告！'
            })
          } else {
            this.restart(ids)
          }
        })
      } else {
        this.restart(ids)
      }
    },
    beforeResetRecord() {
      const selection = this.$refs.list.selection
      if (selection.length !== 1) {
        this.$message.error('请选择一份报告发起重启申请！')
        return
      }
      const ysjl = selection[0]
      if (ysjl.bglx === 1) {
        this.resetRecord(ysjl.id)
      } else {
        // 判断主原始记录是否处于流转中
        this.api({
          url: '/ysjl/judgeInCirculate',
          method: 'get',
          params: {
            ysjlIds: ysjl.parentId
          }
        }).then(data => {
          if (data) {
            this.$message({
              type: 'error',
              message: '主报告处于起草状态才可以重启无损报告，请待主报告办结后重启主报告！'
            })
          } else {
            this.resetRecord(ysjl)
          }
        })
      }
    },
    resetRecord(ysjlId) {
      this.$message.success('弹窗并获取主报告以及所有的无损分项以供用户选择编辑，展示字段为：检验项目、检验人员。' + ysjlId)
      this.ysjlController.getResetRecordsList(ysjlId).then(data => {
        this.resetRecordList = data
      })
      this.dialogResetRecords = true
    },
    toModify(ysjl) {
      // TODO
      console.log(ysjl)
    },
    restart(ids) {
      // 重启流程
      this.$confirm('确定重启当前选中报告?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.api({
          url: '/flow/reset',
          method: 'post',
          params: {
            ids: ids
          }
        }).then(data => {
          this.$message({
            message: '重启成功！',
            type: 'success',
            duration: 1000,
            onClose: () => {
              this.getList()
              // 刷新待办报告页面
              Utils.$emit('bggl-daiban-list')
              Utils.$emit('bggl-yiban-list')
              Utils.$emit('TODOYsjl')
            }
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消重启！'
        })
      })
    },
    clearQuery() {
      this.$set(this.listQuery, 'searchYsjl', {
        createBy: this.$store.getters.userId
      })
      this.getList()
    },
    clearExportReportQuery() {
      this.$set(this.listQueryExport, 'searchYsjl', {
        createBy: this.$store.getters.userId
      })
      this.getExportReportList()
    },
    generatePdf(viewType) {
      let ids = ''
      for (let i = 0; i < this.multipleSelection.length; i++) {
        if (i === 0) {
          ids = this.multipleSelection[i].id
        } else {
          ids += ',' + this.multipleSelection[i].id
        }
        if (this.multipleSelection[i].bglx !== 1) {
          this.$message({
            type: 'info',
            message: '请选择主报告进行重新生成！'
          })
          return false
        }
      }
      this.common.viewYsjlNoOpen(ids, viewType)
    },
    createQrcode() {
      let ids = ''
      for (let i = 0; i < this.multipleSelection.length; i++) {
        if (i === 0) {
          ids = this.multipleSelection[i].id
        } else {
          ids += ',' + this.multipleSelection[i].id
        }
      }
      this.api({
        url: '/ysjl/createQrcode',
        method: 'get',
        params: {
          ysjlIds: ids
        }
      }).then(() => {
        this.$message({
          message: '生成成功！',
          type: 'success'
        })
      })
    },
    ExportLedger: function() {
      this.dialogFormExportReportVisible = true
      this.getExportReportList()
    },
    cleanRed() {
      if (this.multipleSelection != null && this.multipleSelection.length > 0) {
        this.api({
          url: '/template/getById',
          method: 'get',
          params: {
            id: this.multipleSelection[0].modelId
          }
        }).then(data => {
          if (data.cleanState) {
            const cleanData = []
            this.multipleSelection.forEach(ysjl => {
              // 排除使用单位标注了测试的报告
              if (ysjl.shiyongdanwei.indexOf('测试') < 0) {
                const data = {}
                data.shiyongdanwei = ysjl.shiyongdanwei
                data.shebeizhonglei = ysjl.shebeizhongleidaima
                // 获取内部类别对应中文名称
                data.jianyanleibie = this.formatter.formatterCategory(null, null, ysjl.neibuleibie)
                data.zhucedaima = ysjl.zhucedaima
                data.shiyongdengjibianhao = ysjl.shiyongdengjibianhao
                data.jianyanriqi = ysjl.jianyanjieshuriqi
                data.xiacijianyanriqi = ysjl.xiacijianyanriqi
                data.jianyanjielun = ysjl.jianyanjielun
                data.baogaobianhao = ysjl.baogaobianhao
                data.quxian = ysjl.quhuamingcheng
                data.jianyanjigou = '济南市特种设备检验研究院'
                data.shi = '济南市'
                cleanData.push(data)
              }
            })
            if (cleanData.length > 0) {
              this.apisjse({
                url: '/baseInfo/chaoqijiekoupi',
                method: 'post',
                headers: { 'content-type': 'application/x-www-form-urlencoded' },
                data: qs.stringify({
                  loginname: 'jntjysjgx',
                  password: '123',
                  jiekous: JSON.stringify(cleanData)
                })
              })
            }
          }
        })
      }
    },
    getZzdwList() {
      const queryZzdw = {
        creatingState: true,
        inspectorIfEmpty: false
      }
      const username = this.$store.getters.username
      if (username && username !== 'admin') {
        if (this.$store.getters.clientType === 'Enterprise') {
          queryZzdw.userId = this.$store.getters.userId
        } else {
          queryZzdw.zhuchangjianyanrenyuan = this.$store.getters.userId
        }
      }
      this.api({
        url: '/dwxx/getAll',
        method: 'get',
        params: queryZzdw
      }).then(data => {
        this.zzdwList = data
        if (this.formState === 'newBuild' && this.zzdwList !== null && this.zzdwList.length === 1) {
          this.zzdwObject = data[0]
          this.bjd.zhizaodanwei = this.zzdwObject.zhizaodanwei
          this.bjd.zzdwId = this.zzdwObject.id
          this.bjd.zhizaodanweiLianxiren = this.zzdwObject.zhizaodanweiLianxiren
          this.bjd.zhizaodanweiDianhua = this.zzdwObject.zhizaodanweiDianhua
          this.getXinghao()
        }
      })
    },
    //  重启申请方式选择分流：
    selectionMethodRestart(type) {
      if (type) {
        this.dialogSelectionMethod = false
        this.resetData.ysjlId = this.multipleSelection[0].id
        this.resetData.departmentId = this.multipleSelection[0].departmentId
        this.resetData.zzdwId = this.multipleSelection[0].zzdwId
        this.resetData.guigexinghao = this.multipleSelection[0].guigexinghao
        this.resetData.baogaobianhao = this.multipleSelection[0].baogaobianhao
        this.resetData.jianyanjieshuriqi = this.multipleSelection[0].jianyanjieshuriqi
        this.resetData.jianyanrenyuan = this.multipleSelection[0].jianyanrenyuan
        this.resetData.jianyanriqi = this.formatter.dateFormat('YYYY-MM-dd', new Date())
        this.resetData.renlingren = this.resetData.jianyanrenyuan
        this.resetData.type = type
        this.resetData.state = '4'
        this.getDepartmentNameById(this.resetData.departmentId)
        this.getZzdwNameById(this.resetData.zzdwId)
        this.jianyanrenyuanmingcheng = this.formatter.getChineseName(null, null, this.multipleSelection[0].jianyanrenyuan)
        if (type === 3) {
          //  非结论性错误
          if (this.multipleSelection[0].jianyanleibie === 'ZJ' && this.multipleSelection[0].shebeizhongleidaima === '2000') {
            this.dialogReason = true
          } else {
            this.api({
              url: '/template/getById',
              method: 'get',
              params: { id: this.multipleSelection[0].modelId }
            }).then(data => {
              const template = data
              if (template && template.tempPath) {
                const path = template.tempPath
                console.log('path=>:' + path)
                this.$router.push({ path: path + '/' + this.multipleSelection[0].id, query: { restart: true }})
              }
            })
          }
        } else {
          //  补充检验项目 || 结论性错误
          this.dialogResetFlow = true
        }
      }
    },
    /**
     * 压力管道下载word文档
     */
    batchDownloadWord() {
      if (this.$refs.list.selection.length < 1) {
        this.$message.warning('请至少选择一份报告进行下载！')
        return false
      }
      if (this.$refs.list.selection.filter(report => report.jianyanleibie !== 'DJ' || report.shebeizhongleidaima !== '8000').length) {
        this.$message.warning('只允许下载压力管道定检报告！')
        return false
      }
      this.preview({
        url: '/download/word',
        method: 'get',
        params: {
          ids: this.$refs.list.selection.map(report => report.id)
        },
        paramsSerializer: function(params) {
          return qs.stringify(params, { indices: false })
        }
      }).then(data => {
        data.forEach(path => {
          setTimeout(() => {
            window.open(path)
          }, 1000)
        })
      })
    }
  }
}
</script>

<style>
  .app-container {
    padding-top: 5px;
    padding-bottom: 0px;
  }
</style>
