<template>
  <div class="app-container-list">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item :label="$t('泄露位置')" prop="leakLocation">
        <el-select v-model="queryParams.leakLocation" :placeholder="$t('请选择') + $t('泄露位置')" filterable clearable>
          <el-option
            v-for="leakLocation in leakLocationList"
            :label="leakLocation"
            :value="leakLocation"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('标题')" prop="title">
        <el-input
          v-model="queryParams.title"
          :placeholder="$t('请输入') + $t('标题')"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('备注')" prop="remarks">
        <el-select v-model="queryParams.remarks" :placeholder="$t('请选择') + $t('备注')" filterable clearable>
          <el-option
            v-for="remarks in remarksList"
            :label="remarks"
            :value="remarks"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['process:moc:add']"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['process:moc:edit']"
        >{{ $t('修改') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['process:moc:remove']"
        >{{ $t('删除') }}</el-button>
      </el-col>
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="info"-->
      <!--icon="el-icon-upload2"-->
      <!--size="mini"-->
      <!--@click="handleImport"-->
      <!--v-hasPermi="['process:moc:edit']"-->
      <!--&gt;{{ $t('导入') }}</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="warning"-->
      <!--icon="el-icon-download"-->
      <!--size="mini"-->
      <!--@click="handleExport"-->
      <!--v-hasPermi="['process:moc:export']"-->
      <!--&gt;{{ $t('导出') }}</el-button>-->
      <!--</el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-row class="colorMark">
      <svg-icon icon-class="rectangleLightgreen" class="rectangleLightgreen" style="fill:#000000;"></svg-icon>{{ $t('已移除') }}
      <svg-icon icon-class="rectangleFlesh" class="rectangleFlesh"></svg-icon>{{ $t('7天内到期') }}
      <svg-icon icon-class="rectangleYellow" class="rectangleYellow"></svg-icon>{{ $t('7-14天内到期') }}
    </el-row>

    <el-table
        v-loading="loading"
        :data="mocList"
        @selection-change="handleSelectionChange"
        :cell-style="tableCellStyle"
        :cell-class-name="tableCellClassName"
        :height="clientHeight"
        border
        :default-sort = "{prop: 'mocNo', order: 'descending'}">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :label="$t('MOC编号')" align="center" width="120" prop="mocNo" :show-overflow-tooltip="true" sortable/>
      <el-table-column :label="$t('公司MOC编号')" align="center" width="120" prop="companyMocNo" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('工艺单元')" align="center" width="120" prop="processUnit" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('部门')" align="center" prop="department">
        <template slot="header">
          <span
            @click="departmentChart.open = true"
            id="department">
            部门
            <i class="el-icon-s-data"></i>
          </span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('泄露位置')" align="center" prop="leakLocation">
        <template slot="header">
          <span
            @click="leakLocationChart.open = true"
            id="leakLocation">
            泄露位置
            <i class="el-icon-s-data"></i>
          </span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('标题')" align="center" width="320" prop="title" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('操作压力 (MPaG)')" align="center" width="150" prop="pressure" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('操作温度 (℃)')" align="center" width="120" prop="temperature" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('泄露介质')" align="center" width="100" prop="leakFluid" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('介质类型')" align="center" prop="materialType">
        <template slot="header">
          <span
            @click="materialTypeChart.open = true"
            id="materialType">
            介质类型
            <i class="el-icon-s-data"></i>
          </span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('方案日期')" align="center" prop="planDate" width="100">
        <template slot-scope="scope">
        <span>{{ parseTime(scope.row.planDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('堵漏日期')" align="center" prop="sealDate">
        <template slot="header">
          <span
            @click="sealDateChart.open = true"
            id="sealDate">
            堵漏日期
            <i class="el-icon-s-data"></i>
          </span>
        </template>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sealDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第一次延期')" align="center" prop="extention1" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention1 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention1, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第二次延期')" align="center" prop="extention2" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention2 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention2, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第三次延期')" align="center" prop="extention3" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention3 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention3, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第四次延期')" align="center" prop="extention4" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention4 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention4, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第五次延期')" align="center" prop="extention5" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention5 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention5, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第六次延期')" align="center" prop="extention6" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention6 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention6, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第七次延期')" align="center" prop="extention7" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention7 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention7, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第八次延期')" align="center" prop="extention8" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention8 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention8, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('第九次延期')" align="center" prop="extention9" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.extention9 == null && scope.row.status == 0">N.A.</span>
          <span>{{ parseTime(scope.row.extention9, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('到期时间')" align="center" prop="extention9" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('卡具状态')" align="center" prop="status" :formatter="mocStatusFormat">
        <template slot="header">
          <span
            @click="statusChart.open = true"
            id="status">
            卡具状态
            <i class="el-icon-s-data"></i>
          </span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('移除时间')" align="center" prop="removeTime" :show-overflow-tooltip="true" width="100"/>
      <el-table-column :label="$t('备注')" align="center" prop="remarks" :show-overflow-tooltip="true" width="130" />
      <el-table-column :label="$t('操作')" align="center" fixed="right" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-release"
            @click="handleDelay(scope.row, 1)"
            v-hasPermi="['process:moc:edit']"
            v-if="scope.row.extention9 == null && scope.row.status == 1"
          >{{ $t('自动延期') }}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-release"
            @click="handleDelay(scope.row, 2)"
            v-hasPermi="['process:moc:edit']"
            v-if="scope.row.extention9 == null && scope.row.status == 1"
          >{{ $t('手动延期') }}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-close"
            @click="handleRemove(scope.row)"
            v-hasPermi="['process:moc:edit']"
            v-if="scope.row.status != 0  && scope.row.status != '' && scope.row.status != null"
          >{{ $t('移除') }}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['process:moc:edit']"
          >{{ $t('修改') }}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['process:moc:remove']"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 延期对话框 -->
    <el-dialog v-dialogDrag :title="delayDialog.title" :visible.sync="delayDialog.open" width="500px" append-to-body>
      <el-form ref="form" :model="delayForm" :rules="delayRules" label-width="80px">
        <el-form-item :label="$t('延期时间')" prop="extention">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="delayForm.extention"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('延期时间')">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDelayForm">{{ $t('确 定') }}</el-button>
        <el-button @click="cancelDelay">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改MOC管理对话框 -->
    <el-dialog v-dialogDrag :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item :label="$t('MOC编号')" prop="mocNo">
          <el-input v-model="form.mocNo" :placeholder="$t('请输入') + $t('MOC编号')" />
        </el-form-item>
        <el-form-item :label="$t('公司MOC编号')" prop="companyMocNo">
          <el-input v-model="form.companyMocNo" :placeholder="$t('请输入') + $t('公司MOC编号')" />
        </el-form-item>
        <el-form-item :label="$t('工艺单元')" prop="processUnit">
          <el-input v-model="form.processUnit" :placeholder="$t('请输入') + $t('工艺单元')" />
        </el-form-item>
        <el-form-item :label="$t('部门')" prop="department">
          <el-input v-model="form.department" :placeholder="$t('请输入') + $t('部门')" />
        </el-form-item>
        <el-form-item :label="$t('泄露位置')" prop="leakLocation">
          <el-input v-model="form.leakLocation" :placeholder="$t('请输入') + $t('泄露位置')" />
        </el-form-item>
        <el-form-item :label="$t('标题')" prop="title">
          <el-input v-model="form.title" :placeholder="$t('请输入') + $t('标题')" />
        </el-form-item>
        <el-form-item :label="$t('操作压力 (MPaG)')" prop="pressure">
          <el-input v-model="form.pressure" :placeholder="$t('请输入') + $t('操作压力')" />
        </el-form-item>
        <el-form-item :label="$t('操作温度 (℃)')" prop="temperature">
          <el-input v-model="form.temperature" :placeholder="$t('请输入') + $t('操作温度')" />
        </el-form-item>
        <el-form-item :label="$t('泄露介质')" prop="leakFluid">
          <el-input v-model="form.leakFluid" :placeholder="$t('请输入') + $t('泄露介质')" />
        </el-form-item>
        <el-form-item :label="$t('介质类型')" prop="materialType">
          <el-input v-model="form.materialType" :placeholder="$t('请输入') + $t('介质类型')" />
        </el-form-item>
        <el-form-item :label="$t('方案日期')" prop="planDate">
          <el-date-picker clearable size="small" style="width: 200px"
          v-model="form.planDate"
          type="date"
          value-format="yyyy-MM-dd"
          :placeholder="$t('请选择') + $t('方案日期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('堵漏日期')" prop="sealDate">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.sealDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('堵漏日期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第一次延期')" prop="extention1">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention1"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第一次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第二次延期')" prop="extention2">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention2"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第二次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第三次延期')" prop="extention3">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention3"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第三次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第四次延期')" prop="extention4">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention4"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第四次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第五次延期')" prop="extention5">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention5"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第五次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第六次延期')" prop="extention6">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention6"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第六次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第七次延期')" prop="extention7">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention7"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第七次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第八次延期')" prop="extention8">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention8"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第八次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('第九次延期')" prop="extention9">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.extention9"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('第九次延期')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('卡具状态')" prop="area">
          <el-select v-model="form.status" :placeholder="$t('请选择') + $t('卡具状态')">
            <el-option
              v-for="dict in mocStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('到期时间')" prop="extention9">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.expTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('到期时间')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('备注')" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" :placeholder="$t('请输入') + $t('备注')" />
        </el-form-item>
        <el-form-item :label="$t('归属部门')" prop="deptId">
          <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" :placeholder="$t('请选择') + $t('归属部门')" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{ $t('确 定') }}</el-button>
        <el-button @click="cancel">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog v-dialogDrag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
          <el-link type="info" style="font-size:12px" @click="importTemplate">{{ $t('下载模板') }}</el-link>
        </div>
        <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
          <input name="type" :value="upload.type" hidden />
        </form>
        <div class="el-upload__tip" style="color:red" slot="tip">{{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>
        <el-button @click="upload.open = false">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>

    <!-- 报告附件对话框 -->
    <el-dialog v-dialogDrag :title="doc.title" :visible.sync="doc.open" width="1000px" append-to-body >
      <el-upload v-hasPermi="['training:trainingrecords:file']"
                 ref="doc"
                 :limit="50"
                 :headers="doc.headers"
                 :action="doc.url + '?pType=' + doc.pType + '&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>
      <el-table :data="doc.commonfileList" 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" width="220" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.fileName.endsWith('pdf')"
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleSee(scope.row)"
            >{{ $t('预览') }}</el-button>
            <el-button v-hasPermi="['training:trainingrecords:file']"  type="text" size="small" v-if="scope.row.isEdit" @click="save(scope.row)">{{ $t('保存') }}</el-button>
            <el-button type="text" size="small" v-if="scope.row.isEdit" @click="cancelFile(scope.row, scope.$index)">{{ $t('取消') }}</el-button>
            <!--            <el-button v-hasPermi="['training:trainingrecords:file']" v-if="!scope.row.isEdit" @click="edit(scope.row)" icon="el-icon-edit" type="text" size="mini">编辑</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-hasPermi="['training:trainingrecords:file']"
            >{{ $t('删除') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog v-dialogDrag :title="pdf.title" :visible.sync="pdf.open" width="1300px" 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 :src="pdf.pdfUrl" frameborder="0" width="100%" height="700px"></iframe>
        </div>
      </el-dialog>
      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>-->
        <el-button @click="doc.open = false">{{ $t('返 回') }}</el-button>
      </div>
    </el-dialog>

    <!-- MOC类型说明对话框 -->
    <el-dialog v-dialogDrag :title="mocTypeInfo.title" :visible.sync="mocTypeInfo.open" width="1000px" append-to-body>
      <el-image
        style="width: 947px; height: 394px"
        :src="require('@/assets/image/moc/mocTypeInfo.png')"
        fit="fill"></el-image>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="mocTypeInfo.open = false">{{ $t('确 定') }}</el-button>
      </div>
    </el-dialog>

    <!-- 卡具状态对话框 -->
    <el-dialog v-dialogDrag :title="statusChart.title" :visible.sync="statusChart.open" width="500px" append-to-body>
      <status-chart :timeliness="2" :tempCategory="1"></status-chart>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="statusChart.open = false">{{ $t('确 定') }}</el-button>
      </div>
    </el-dialog>

    <!-- 部门对话框 -->
    <el-dialog v-dialogDrag :title="departmentChart.title" :visible.sync="departmentChart.open" width="500px" append-to-body>
      <department-chart :timeliness="2" :tempCategory="1"></department-chart>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="departmentChart.open = false">{{ $t('确 定') }}</el-button>
      </div>
    </el-dialog>

    <!-- 泄露位置对话框 -->
    <el-dialog v-dialogDrag :title="leakLocationChart.title" :visible.sync="leakLocationChart.open" width="500px" append-to-body>
      <leak-location-chart :timeliness="2" :tempCategory="1"></leak-location-chart>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="leakLocationChart.open = false">{{ $t('确 定') }}</el-button>
      </div>
    </el-dialog>

    <!-- 介质类型对话框 -->
    <el-dialog v-dialogDrag :title="materialTypeChart.title" :visible.sync="materialTypeChart.open" width="500px" append-to-body>
      <material-type-chart :timeliness="2" :tempCategory="1"></material-type-chart>
      <material-type-chart2 :timeliness="2" :tempCategory="1"></material-type-chart2>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="materialTypeChart.open = false">{{ $t('确 定') }}</el-button>
      </div>
    </el-dialog>

    <!-- 堵漏日期对话框 -->
    <el-dialog v-dialogDrag :title="sealDateChart.title" :visible.sync="sealDateChart.open" width="500px" append-to-body>
      <seal-date-chart :timeliness="2" :tempCategory="1"></seal-date-chart>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sealDateChart.open = false">{{ $t('确 定') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { delay, listPermanent, listTemporary, listAquifier, listFacility, listInterlock, getMoc, delMoc, addMoc, updateMoc, exportMoc } from "@/api/process/moc";
  import { treeselect } from "@/api/system/dept";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import {addCommonfile, allFileList, delCommonfile, updateCommonfile} from "@/api/common/commonfile";
  import statusChart from "../chart/statusChart";
  import departmentChart from "../chart/departmentChart";
  import leakLocationChart from "../chart/leakLocationChart";
  import materialTypeChart from "../chart/materialTypeChart";
  import materialTypeChart2 from "../chart/materialTypeChart2";
  import sealDateChart from "../chart/sealDateChart";

  export default {
    name: "Aquifier",
    components: { sealDateChart, materialTypeChart, materialTypeChart2, leakLocationChart, departmentChart, statusChart, Treeselect },
    data() {
      var validateDocUpdate = (rule, value, callback) => {
        if (value == 1) {
          if (this.form.pidMaster == 0 && this.form.sopUpdate == 0) {
            return callback(new Error('PID/SOP未更新'));
          } else {
            return callback();
          }
        } else {
          return callback();
        }
      };
      return {
        leakLocationList: [],
        remarksList: [],
        sealDateChart: {
          open: false,
          title: '堵漏日期数据统计'
        },
        materialTypeChart: {
          open: false,
            title: '介质类型数据统计'
        },
        leakLocationChart: {
          open: false,
            title: '泄露位置数据统计'
        },
        departmentChart: {
          open: false,
            title: '部门数据统计'
        },
        statusChart: {
          open: false,
          title: '卡具状态数据统计'
        },
        delayForm: {
          id: null,
          extention: null,
        },
        delayDialog: {
          open: false,
          title: null,
        },
        mocTypeInfo: {
          open: false,
          title: 'MOC类型说明'
        },
        drawer: false,
        direction: 'rtl',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,
        // MOC管理表格数据
        mocList: [],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        clientHeight:300,
        // 是否显示弹出层
        open: false,
        // 卡具状态字典
        mocStatusOptions: [],
        // 装置字典
        plantCodeOptions: [],
        // 类别字典
        categoryOptions: [],
        // 区域字典
        areaOptions: [],
        // PID MASTER更新字典
        pidMasterOptions: [],
        // 临时MOC状态字典
        temporaryStateOptions: [],
        // SOP更新字典
        sopUpdateOptions: [],
        // 文件更新字典
        docUpdateOptions:[],
        // 实施情况字典
        trueStateOptions: [],
        // 变更性质字典
        changeNatureOptions: [],
        // 风险等级字典
        riskLevelOptions: [],
        // MOC类型字典
        mocTypeOptions: [],
        // MC情况字典
        mcDetailOptions: [],
        //时间选择限制
        ehsCheckDate: '',
        trainingDatePicker: this.pickerOptionsTraining(),
        pssrDatePicker: this.pickerOptionsPssr(),
        // 用户导入参数
        upload: {
          //下载模板请求地址
          downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
          //下载模板类型
          type: 'moc',
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/process/moc/importData"
        },
        // 报告附件参数
        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,
          queryParams: {
            pId: null,
            pType: 'moc'
          },
          pType: 'moc',
          pId: null,
          form: {}
        },
        pdf : {
          title: '',
          pdfUrl: '',
          numPages: null,
          open: false,
          pageNum: 1,
          pageTotalNum: 1,
          loadedRatio: 0,
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          plantCode: null,
          mocNo: null,
          plantNumber: null,
          noticeLetter: null,
          workLetter: null,
          cteNo: null,
          investCost: null,
          category: null,
          significance: null,
          classification: null,
          area: null,
          dashControl: null,
          title: null,
          owner: null,
          approveTime: null,
          estimateEndtime: null,
          endtime: null,
          trueState: null,
          changeNature: null,
          overTime: null,
          riskLevel: null,
          training: null,
          pssr: null,
          ehsCheck: null,
          ehsDb: null,
          pidMaster: null,
          pssrDb: null,
          capex: null,
          remarks: null,
          companyMocNo: null,
          projectNo: null,
          mocType: null,
          mcTime: null,
          mcDetail: null,
          docUpdate: null,
          pssrNo: null,
          timeliness: null,
          tempCategory: null,
          expTime: null,
          tempState: null,
          location: null,
          finishDate: null,
          processUnit: null,
          department: null,
          leakLocation: null,
          pressure: null,
          temperature: null,
          leakFluid: null,
          materialType: null,
          planDate: null,
          sealDate: null,
          extention1: null,
          extention2: null,
          extention3: null,
          extention4: null,
          extention5: null,
          extention6: null,
          extention7: null,
          extention8: null,
          extention9: null,
          status: null,
        },
        chartParams: {
          year : 2021
        },
        yearOption: [2020,2021],
        // 表单参数
        form: {},
        // 表单校验
        delayRules: {
          extention: [
            {required: true, message: this.$t('延期日期') + this.$t('不能为空'), trigger: "change"}
          ],
        },
        rules: {
          mocNo: [
            { required: true, message: this.$t('MOC编号') + this.$t('不能为空'), trigger: "change" }
          ],
          docUpdate: [
            // { required: true, message: this.$t('文档更新') + this.$t('不能为空'), trigger: "change" },
            { validator: validateDocUpdate, trigger: 'change' }
          ],
          deptId: [
            { required: true, message: this.$t('归属部门') + this.$t('不能为空'), trigger: "change" }
          ],
        },
      };
    },
    watch: {
      // 根据名称筛选部门树
      deptName(val) {
        this.$refs.tree.filter(val);
      }
    },
    created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
        this.clientHeight = (document.body.clientHeight - 80) * 0.8
      })
      this.getList();
      this.getTreeselect();
      this.getDicts("MOC_STATUS").then(response => {
        this.mocStatusOptions = response.data;
      });
      this.getDicts("MC_DETAIL").then(response => {
        this.mcDetailOptions = response.data;
      });
      this.getDicts("MOC_TYPE").then(response => {
        this.mocTypeOptions = response.data;
      });
      this.getDicts("PLANT_DIVIDE").then(response => {
        this.plantCodeOptions = response.data;
      });
      this.getDicts("MOC_CATEGORY").then(response => {
        this.categoryOptions = response.data;
      });
      this.getDicts("MOC_AREA").then(response => {
        this.areaOptions = response.data;
      });
      this.getDicts("YES_NO_EN").then(response => {
        this.pidMasterOptions = response.data;
        this.sopUpdateOptions = response.data;
        this.docUpdateOptions = response.data;
      });
      this.getDicts("MOC_TEMPORARYSTATE").then(response => {
        this.temporaryStateOptions = response.data;
      });
      this.getDicts("MOC_STATE").then(response => {
        this.trueStateOptions = response.data;
      });
      this.getDicts("MOC_CHANGE").then(response => {
        this.changeNatureOptions = response.data;
      });
      this.getDicts("MOC_RISKLEVEL").then(response => {
        this.riskLevelOptions = response.data;
      });
    },
    methods: {
      /** 移除按钮操作 */
      handleRemove(row) {
        this.$confirm(this.$t('是否确认移除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          updateMoc({id: row.id, status: 0});
        }).then(() => {
          this.getList();
          this.msgSuccess(this.$t('移除成功'));
        })
      },
      /** 查询MOC管理列表 */
      getList() {
        this.loading = true;
        let _this = this
        listAquifier(this.queryParams).then(response => {
          this.mocList = response.rows;
          this.mocList.forEach(function (value,key,arr) {
            if (value.overTime == null) {
              _this.mocList[key].overTime = "N.A."
            }
            if (value.remarks != null && value.remarks != '') {
              _this.remarksList.push(value.remarks);
            }
            if (value.leakLocation != null && value.leakLocation != '') {
              _this.leakLocationList.push(value.leakLocation);
            }
          });
          // 下拉数据去重
          _this.remarksList = this.unique(_this.remarksList);
          _this.leakLocationList = this.unique(_this.leakLocationList);
          this.total = response.total;
          this.loading = false;
        });
      },
      // 数组去重
      unique(arr) {
        if (!Array.isArray(arr)) {
          console.log('type error!')
          return;
        }
        arr = arr.sort()
        var arrry= [arr[0]];
        for (var i = 1; i < arr.length; i++) {
          if (arr[i] !== arr[i-1]) {
            arrry.push(arr[i]);
          }
        }
        return arrry;
      },
      // 单元格样式
      tableCellStyle( {row, column, rowIndex, columnIndex} ) {
        let today = new Date(); // 当前时间
        let expTime = new Date(row.expTime);
        if (row.status == 0) { // 移除的数据
          return "background-color: rgba(146, 208, 80, 1);";
        }
        if (today.getTime() < expTime.getTime()) {
          let difference = expTime.getTime() - today.getTime(); // 时间差
          if (row.expTime != null && row.expTime != '') {
            if (difference <= 7 * 24 * 60 * 60 * 1000) {  // 到期时间 - 当前时间 <= 7
              return "background-color: rgba(250, 191, 143, 1);";
            } else if (difference >= 7 * 24 * 60 * 60 * 1000
              && difference <= 14 * 24 * 60 * 60 * 1000) {  // 7 <= 到期时间 - 当前时间 <= 14
              return "background-color: rgba(255, 255, 0, 1);";
            }
          }
        }
      },
      //根据分数显示颜色提示
      // tableCellStyle({ row, column, rowIndex, columnIndex }) {
      //   if (columnIndex == 3 && row.trueState == 10){
      //     return "color: rgba(45, 58, 79, 0.98) "
      //   }else if (columnIndex == 3 && row.trueState == 12){
      //     return "color: rgba(255, 26, 26, 0.98) "
      //   }else if (columnIndex == 3 && row.trueState == 14){
      //     return "color: rgba(95, 153, 248, 0.98) "
      //   }
      // },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      // 卡具状态字典翻译
      mocStatusFormat(row, column) {
        return this.selectDictLabel(this.mocStatusOptions, row.status);
      },
      // 装置字典翻译
      plantCodeFormat(row, column) {
        return this.selectDictLabel(this.plantCodeOptions, row.plantCode);
      },
      // 类别字典翻译
      categoryFormat(row, column) {
        return this.selectDictLabel(this.categoryOptions, row.category);
      },
      // 实施情况字典翻译
      trueStateFormat(row, column) {
        return this.selectDictLabel(this.trueStateOptions, row.trueState);
      },
      // 变更性质字典翻译
      changeNatureFormat(row, column) {
        return this.selectDictLabel(this.changeNatureOptions, row.changeNature);
      },
      // 风险等级字典翻译
      riskLevelFormat(row, column) {
        return this.selectDictLabel(this.riskLevelOptions, row.riskLevel);
      },
      // 区域字典翻译
      areaFormat(row, column) {
        return this.selectDictLabel(this.areaOptions, row.area);
      },
      // PID MASTER更新字典翻译
      pidMasterFormat(row, column) {
        return this.selectDictLabel(this.pidMasterOptions, row.pidMaster);
      },
      // 临时MOC状态字典翻译
      temporaryStateFormat(row, column) {
        return this.selectDictLabel(this.temporaryStateOptions, row.temporaryState);
      },
      // SOP更新字典翻译
      sopUpdateFormat(row, column) {
        return this.selectDictLabel(this.sopUpdateOptions, row.sopUpdate);
      },
      // MC情况字典翻译
      mcDetailFormat(row, column) {
        return this.selectDictLabel(this.mcDetailOptions, row.mcDetail);
      },
      // MOC类型字典翻译
      mocTypeFormat(row, column) {
        return this.selectDictLabel(this.mocTypeOptions, row.mocType);
      },
      // 文件更新字典翻译
      docUpdateFormat(row, column) {
        return this.selectDictLabel(this.docUpdateOptions, row.docUpdate);
      },
      // 取消按钮
      cancelDelay() {
        this.delayDialog.open = false;
      },
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          plantCode: null,
          mocNo: null,
          plantNumber: null,
          noticeLetter: null,
          workLetter: null,
          cteNo: null,
          investCost: null,
          category: null,
          significance: null,
          classification: null,
          area: null,
          dashControl: null,
          title: null,
          owner: null,
          approveTime: null,
          estimateEndtime: null,
          endtime: null,
          trueState: null,
          changeNature: null,
          overTime: null,
          riskLevel: null,
          training: null,
          pssr: null,
          ehsCheck: null,
          ehsDb: null,
          pidMaster: null,
          pssrDb: null,
          capex: null,
          delFlag: null,
          createrCode: null,
          createdate: null,
          updaterCode: null,
          updatedate: null,
          deptId: null,
          remarks: null,
          temporaryState: null,
          sopUpdate: null
        };
        this.resetForm("form");
      },
      // 限制时间范围
      pickerOptionsTraining() {
        const self = this
        return {
          disabledDate(time){
            return time.getTime() < new Date(self.form.ehsCheck).getTime()
          }
        }
      },
      pickerOptionsPssr() {
        const self = this
        return {
          disabledDate(time){
            if (self.form.training != null) {
              return time.getTime() < new Date(self.form.training).getTime()
            }else {
              return time.getTime() < new Date(self.form.ehsCheck).getTime()
            }
          }
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = this.$t('新增') + " " + this.$t('MOC管理');
      },
      //实施情况Finished变更
      changeTrueState(val) {
        if (val == 10) {
        }else {
          this.$refs['form'].clearValidate();
        }
      },
      changeChangeNature(val) {
        if (val == 10) {
        }else if (val = 12) {
          this.$refs['form'].clearValidate();
          this.form.temporaryState = "14";
          this.form.overTime = "";
        }
      },
      //根据分数显示颜色提示
      tableCellClassName({ row, column, rowIndex, columnIndex }) {
        if (columnIndex == 13){
          return this.changeColor(row.isEhsCheck, row.ehsCheck)
        }
        if (columnIndex == 14){
          return this.changeColor(row.isTraining, row.training)
        }
        if (columnIndex == 15){
          return this.changeColor(row.isPssr, row.pssr)
        }
      },
      changeColor (value, dateValue) {
        if (value !== "1" && dateValue !== null){
          return 'cellMoc'
        }
      },
      /** 延期按钮操作 */
      handleDelay(row, type) {
        if (type == 1) {  // 自动延期
          if (row.sealDate == null) {
            this.msgError(this.$t('未填写堵漏日期，不可执行延期操作。'));
          } else {
            this.$confirm(this.$t('是否确认延期?'), this.$t('警告'), {
              confirmButtonText: this.$t('确定'),
              cancelButtonText: this.$t('取消'),
              type: "warning"
            }).then(function() {
              return delay({id: row.id, extention: null});
            }).then(() => {
              this.getList();
              this.msgSuccess(this.$t('延期成功'));
            })
          }
        } else if (type == 2) {  // 手动延期
          this.delayForm.id = row.id;
          this.delayDialog.open = true;
          this.delayDialog.title = row.mocNo.toString() + '延期操作';
        }
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getMoc(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = this.$t('修改') + this.$t('MOC管理');
        });
      },
      /** 提交按钮 */
      submitDelayForm() {
        delay(this.delayForm).then(response => {
          this.msgSuccess(this.$t('延期成功'));
          this.delayDialog.open = false;
          this.getList();
        });
      },
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.trueState == "10") {
              if (this.form.mocNo != null && this.form.plantNumber != null && this.form.category != null && this.form.significance != null && this.form.classification != null
                && this.form.area != null && this.form.title != null && this.form.owner != null && this.form.approveTime != null && this.form.estimateEndtime != null
                && this.form.endtime != null && this.form.changeNature != null && this.form.riskLevel != null && this.form.training != null && this.form.pssr != null) {
                if (this.form.id != null) {
                  updateMoc(this.form).then(response => {
                    this.msgSuccess(this.$t('修改成功'));
                    this.open = false;
                    this.getList();
                  });
                } else {
                  this.form.timeliness = 2;
                  this.form.tempCategory = 1;
                  addMoc(this.form).then(response => {
                    this.msgSuccess(this.$t('新增成功'));
                    this.open = false;
                    this.getList();
                  });
                }
              } else {
                this.msgError(this.$t('存在必填项未填，实施情况修改Finished失败'));
              }
            }else {
              if (this.form.id != null) {
                updateMoc(this.form).then(response => {
                  this.msgSuccess(this.$t('修改成功'));
                  this.open = false;
                  this.getList();
                });
              } else {
                this.form.timeliness = 2;
                this.form.tempCategory = 1;
                addMoc(this.form).then(response => {
                  this.msgSuccess(this.$t('新增成功'));
                  this.open = false;
                  this.getList();
                });
              }
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return delMoc(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess(this.$t('删除成功'));
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm(this.$t('是否确认导出所有MOC管理数据项?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return exportMoc(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = this.$t('用户导入');
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        this.$refs['downloadFileForm'].submit()
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        if (response.data[0] != null) {
          this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据') + "，" + this.$t('第') + response.data + this.$t('行数据出现错误导入失败')+"。", this.$t('导入结果'), { dangerouslyUseHTMLString: true });
        }else {
          this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据'), this.$t('导入结果'), { dangerouslyUseHTMLString: true });
        }
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      },
      //数据分析
      handleData(){
        var now = new Date();
        var year = now.getFullYear(); //得到年份
        this.yearOption = [year-2 , year-1 ,year]
        this.drawer = true
      },
      /** 报告附件按钮操作 */
      handleDoc(row , fileType) {
        this.doc.pType = fileType
        this.doc.queryParams.pType = fileType
        this.doc.id = row.id;
        this.doc.title = row.title;
        this.doc.open = true;
        this.doc.queryParams.pId = row.id
        this.doc.pId = row.id
        this.getFileList()
        this.$nextTick(() => {
          this.$refs.doc.clearFiles()
        })
      },
      getFileList (){
        allFileList(this.doc.queryParams).then(response => {
          response.forEach(element => {
            element["isEdit"] = false
          });
          response.forEach(element => {
            element["isAdd"] = false
          });
          this.doc.commonfileList = 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()
      },
      // 文件下载处理
      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()
      },
      //pdf预览
      openPdf(){
        window.open(this.pdf.pdfUrl);//path是文件的全路径地址
      },
      handleSee (row){
        this.pdf.open =true
        this.pdf.title = row.fileName
        this.pdf.pdfUrl = process.env.VUE_APP_BASE_API +'/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + row.fileUrl
      },
      // 取消
      cancelFile(row, index) {
        // 如果是新增的数据
        if (row.isAdd) {
          this.doc.commonfileList.splice(index, 1)
        } else {
          // 不是新增的数据  还原数据
          for (const i in row.oldRow) {
            row[i] = row.oldRow[i]
          }
          row.isEdit = false
        }
      },
      edit(row) {
        // 备份原始数据
        row['oldRow'] = JSON.parse(JSON.stringify(row));
        this.$nextTick(() => {
          row.isEdit = true;
        })
      },
      save(row) {
        row.isEdit = false;
        var that = this;
        that.loading = true;
        this.form = row;
        if (row.isAdd == true) {
          addCommonfile(this.form).then(response => {
            this.msgSuccess(this.$t('新增成功'));
            this.open = false;
            this.getList();
          });
        }else {
          updateCommonfile(this.form).then(response => {
            this.msgSuccess(this.$t('修改成功'));
            this.open = false;
            this.getList();
          });
        }
      },
      /** 删除按钮操作 */
      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('删除成功'));
        })
      },
    }
  };
</script>
<style>
  .colorMark {
    color: #6f6f6f;
    text-align: right;
    font-weight:bold;
    font-size: 13px;
    padding-bottom: 5px;
  }
  .rectangleLightgreen {
    width: 40px !important;
    height: 20px !important;
  }
  .rectangleFlesh {
    width: 40px !important;
    height: 20px !important;
  }
  .rectangleYellow {
    width: 40px !important;
    height: 20px !important;
  }
  #sealDate:hover{
    cursor: pointer;
  }
  #materialType:hover{
    cursor: pointer;
  }
  #leakLocation:hover{
    cursor: pointer;
  }
  #department:hover{
    cursor: pointer;
  }
  #status:hover{
    cursor: pointer;
  }
  #moc-type:hover{
    cursor: pointer;
  }
  .text {
    font-size: 14px;
  }
  .item {
    margin-bottom: 18px;
  }
  .clearfix {
    color: #1e1e1e;
  }
  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }
  .box-card {
    width: 100%;
  }
  .el-drawer__body {
    overflow: auto;
  }
  .el-drawer__container ::-webkit-scrollbar {
    display: none;
  }
</style>
