<template>
  <!-- 安全信息 -->
  <div class="outElectricity">
    <div class="box">
      <div class="box-top">
        <el-form
          style="overflow: hidden"
          :style="filterForm.show ? null : { height: '0px' }"
          size="mini"
          label-width="75px"
        >
          <el-row>
            <el-col :span="6">
              <el-form-item label="日期">
                <zj-timegran-date
                  v-model="filterForm.data.yearmonth"
                  style="width: 100%"
                  :type="'daterange'"
                  :timegranId="filterForm.data.timegranid"
                  :defaultOffset="-1"
                  :custom="1"
                ></zj-timegran-date>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="被查单位">
                <el-select
                  filterable
                  clearable
                  v-model="filterForm.data.process"
                  placeholder="被查单位"
                  multiple
                  collapse-tags
                  style="width: 100%"
                >
                  <el-option
                    v-for="item of nameObj.process.arr"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="隐患分级">
                <el-select
                  filterable
                  clearable
                  v-model="filterForm.data.hazard"
                  multiple
                  collapse-tags
                  placeholder="隐患分级"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item of nameObj.itemtype.arr"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5"> </el-col>
            <el-col :span="5"> </el-col>
          </el-row>
        </el-form>
        <div class="box-top-gjl">
          <el-form size="mini" label-width="75px">
            <el-row>
              <el-col :span="16">
                <el-button
                  class="button"
                  type="primary"
                  size="mini"
                  icon="el-icon-plus"
                  @click="but_add"
                  :loading="loading"
                  >新增</el-button
                >
                <el-button
                  class="button"
                  type="danger"
                  size="mini"
                  icon="el-icon-delete"
                  v-if="butPrivilege.PUT"
                  @click="but_del_plural()"
                  :loading="loading"
                  >删除</el-button
                >
                <el-upload
                  ref="upload"
                  style="display: inline-block; margin-left: 5px"
                  action="#"
                  :before-upload="beforeUpload"
                  type="primary"
                  :http-request="beforeUpload"
                  :on-change="uploadExcel"
                  :show-file-list="false"
                  :file-list="fileList"
                  :limit="limitUpload"
                  accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
                  :auto-upload="false"
                >
                  <el-button
                    type="primary"
                    size="mini"
                    icon="el-icon-bottom-right"
                    >Excel导入</el-button
                  >
                </el-upload>
                <el-button
                  class="button"
                  type="primary"
                  size="mini"
                  icon="el-icon-download"
                  v-if="butPrivilege.PUT"
                  @click="downloadFile()"
                  :loading="loading"
                  >下载模板</el-button
                >
              </el-col>

              <el-col :span="8">
                <div style="float: right; text-align: right">
                  <el-button
                    class="button"
                    type="primary"
                    size="mini"
                    icon="el-icon-search"
                    v-if="butPrivilege.QUERY"
                    @click="getTableData(1)"
                    >查询</el-button
                  >
                  <el-button
                    class="button"
                    type="success"
                    size="mini"
                    icon="el-icon-download"
                    @click="dowloadFile()"
                    :loading="loading"
                    >导出数据</el-button
                  >
                  <el-button
                    size="mini"
                    :icon="
                      filterForm.show
                        ? 'el-icon-caret-top'
                        : 'el-icon-caret-bottom'
                    "
                    :title="filterForm.show ? '收起搜索区' : '展开搜索区'"
                    @click="
                      filterForm.show = !filterForm.show;
                      $nextTick(() => {
                        singleTableHeight =
                          getRoleHeight($refs['singleTable'].$el) - 45;
                      });
                    "
                    >{{ filterForm.show ? "收起" : "展开" }}</el-button
                  >
                </div>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <div class="box-bottom">
        <el-form
          size="mini"
          ref="dialog_form_arr"
          label-width="0px"
          :model="tableFormDataObj"
        >
          <el-table
            stripe
            id="singleTable"
            ref="singleTable"
            :data="tableData"
            v-loading="tableLoading"
            style="width: 100%"
            :height="singleTableHeight"
            border
            size="mini"
            highlight-current-row
            @selection-change="handleSelectionChange"
            :row-class-name="tableRowClassName"
            @cell-click="cellClick"
          >
            <el-table-column
              type="selection"
              width="40"
              align="center"
              fixed="left"
              class-name="cnspicuous"
            ></el-table-column>
            <el-table-column
              sortable
              type="index"
              prop="index"
              label="序号"
              fixed="left"
              width="50px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="createtime"
              label="检查日期"
              fixed="left"
              width="90px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="process"
              label="被查单位"
              fixed="left"
              width="120px"
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">
                <span>{{
                  nameObj.process.obj[scope.row.process]
                    ? nameObj.process.obj[scope.row.process]
                    : scope.row.process
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="id"
              label="ID"
              fixed="left"
              sortable
              :show-overflow-tooltip="true"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="content"
              label="隐患内容"
              fixed="left"
              width="170px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="createman"
              label="检查人"
              fixed="left"
              width="70px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="measure"
              label="整改措施"
              fixed="left"
              width="120px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="updatetime"
              label="整改期限"
              fixed="left"
              width="60px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="updateman"
              label="整改责任人"
              fixed="left"
              width="70px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="filename"
              label="整改结果"
              fixed="left"
              width="80px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="rectificationdate"
              label="整改日期"
              fixed="left"
              width="80px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="verify"
              label="验证人"
              fixed="left"
              width="70px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="money"
              label="资金"
              fixed="left"
              width="80px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="plan"
              label="预案"
              fixed="left"
              width="80px"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="hazard"
              label="隐患分级"
              fixed="left"
              width="80px"
            >
              <template slot-scope="scope">
                <span>{{
                  nameObj.itemtype.obj[scope.row.hazard]
                    ? nameObj.itemtype.obj[scope.row.hazard]
                    : scope.row.hazard
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="memo"
              label="备注"
              fixed="left"
              width="100px"
              :show-overflow-tooltip="true"
            ></el-table-column>

            <el-table-column
              class-name="gn-TableDownloadExcel-none"
              label="操作"
              align="center"
              width="150px"
              fixed="right"
            >
              <template slot-scope="scope">
                <div>
                  <el-button
                    type="primary"
                    size="mini"
                    v-privilege="activeMenu + 'PUT'"
                    @click="but_edita(scope.row)"
                    >查看</el-button
                  >
                  <el-button
                    size="mini"
                    type="primary"
                    @click="but_editaa(scope.row)"
                    :loading="loading"
                    >编辑
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :page-sizes="[10, 20, 50, 100, 500, 1000]"
          :page-size="pageSize"
          :current-page.sync="pageNum"
          @size-change="tableSizeChange"
          @current-change="getTableData()"
          style="text-align: right; margin-top: 10px"
        ></el-pagination>
      </div>
    </div>
    <el-dialog
      title="安全信息新增"
      :visible.sync="dialog.editorBox1.show"
      width="600px"
      :close-on-click-modal="false"
      :show-close="!loading"
    >
      <div>
        <el-form
          :model="dialog.editorBox.form.data"
          ref="dialog_form"
          size="mini"
          label-width="95px"
          :rules="dialog.editorBox.form.rules"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="被查单位" prop="process">
                <el-select
                  placeholder=""
                  prop="process"
                  v-model="dialog.editorBox.form.data.process"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.process"
                >
                  <el-option
                    v-for="item of nameObj.process.arr"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检查日期" prop="createtime">
                <zj-timegran-date
                  v-model="dialog.editorBox.form.data.createtime"
                  style="width: 100%"
                  :timegranId="'DAY'"
                  :rules="dialog.editorBox.form.createtime"
                ></zj-timegran-date>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="隐患分级" prop="hazard">
                <el-select
                  filterable
                  clearable
                  v-model="dialog.editorBox.form.data.hazard"
                  collapse-tags
                  placeholder="隐患分级"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.hazard"
                >
                  <el-option
                    v-for="item of nameObj.itemtype.arr"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注" prop="meno">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.memo"
                  style="width: 100%"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row> </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="检查人" prop="createman">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.createman"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.content"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="整改措施" prop="measure">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.measure"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.measure"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="整改期限" prop="updatetime">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.updatetime"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.updatetime"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="整改责任人" prop="updateman">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.updateman"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.updateman"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="整改结果" prop="filename">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.filename"
                  style="width: 100%"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="整改日期" prop="rectificationdate">
                <zj-timegran-date
                  v-model="dialog.editorBox.form.data.rectificationdate"
                  style="width: 100%"
                  :timegranId="'DAY'"
                  :rules="dialog.editorBox.form.rectificationdate"
                ></zj-timegran-date>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="验证人" prop="verify">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.verify"
                  style="width: 100%"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="资金" prop="money">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.money"
                  style="width: 100%"
                  type="number"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="预案" prop="plan">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.plan"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.plan"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="隐患内容" prop="content">
                <el-input
                  type="textarea"
                  clearable
                  v-model="dialog.editorBox.form.data.content"
                  style="width: 100%"
                  :rules="dialog.editorBox.form.content"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="loading" @click="dialog.editorBox1.show = false"
          >取 消</el-button
        >
        <el-button type="primary" @click="dataSave" :loading="loading"
          >保 存</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :title="
        '安全信息清单 - ' + (dialog.editorBox.type === 'add' ? '查看' : '编辑')
      "
      :visible.sync="dialog.editorBox.show"
      width="940px"
      :close-on-click-modal="false"
      :show-close="!loading"
    >
      <div>
        <el-form
          ref="dialog_form"
          :model="dialog.editorBox.form.data"
          :rules="dialog.editorBox.form.rules"
          size="mini"
          label-width="120px"
        >
          <el-row>
            <el-col :span="8">
              <el-form-item label="ID" prop="id">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.id"
                  placeholder=""
                  style="width: 100%"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检查日期" prop="createtime">
                <el-date-picker
                  v-model="dialog.editorBox.form.data.createtime"
                  type="date"
                  :disabled="none"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  :formatter="createtime"
                  style="width: 100%"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检查人" prop="createman">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.createman"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label="被查单位" prop="process">
                <el-select
                  filterable
                  clearable
                  v-model="dialog.editorBox.form.data.process"
                  collapse-tags
                  placeholder="类型"
                  :disabled="none"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item of nameObj.process.arr"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="隐患分级" prop="hazard">
                <el-select
                  filterable
                  clearable
                  v-model="dialog.editorBox.form.data.hazard"
                  collapse-tags
                  placeholder="隐患分级"
                  :disabled="none"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item of nameObj.itemtype.arr"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="整改责任人" prop="updateman">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.updateman"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label="整改措施" prop="measure">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.measure"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="整改期限" prop="updatetime">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.updatetime"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="整改结果" prop="filename">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.filename"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label="资金" prop="money">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.money"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                  type="number"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="预案" prop="plan">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.plan"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="整改日期" prop="rectificationdate">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.rectificationdate"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="验证人" prop="verify">
                <el-input
                  clearable
                  v-model="dialog.editorBox.form.data.verify"
                  placeholder=""
                  style="width: 100%"
                  :disabled="none"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-container>
            <el-main style="padding: 0">
              <el-form-item label="隐患内容" prop="content">
                <el-input
                  clearable
                  :disabled="none"
                  class="nr-textarea"
                  type="textarea"
                  v-model="dialog.editorBox.form.data.content"
                  placeholder=""
                  style="width: 100%"
                ></el-input>
              </el-form-item>
            </el-main>
          </el-container>
          <el-form-item label="备注" prop="memo">
            <el-input
              clearable
              type="textarea"
              :disabled="none"
              v-model="dialog.editorBox.form.data.memo"
              placeholder=""
              style="width: 100%"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="but_edita2()">{{
          buttontype ? "确认" : "提交"
        }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { zCheckNumber1 } from "~/utils/validator.js";
import timegranDate from "~/components/zg/timegranDate.vue";
import { formatDate, XtcommonSummaries, getCookie } from "@/utils/util.js";
export default {
  name: "outElectricity",
  components: {
    "zj-timegran-date": timegranDate,
  },
  data() {
    let setDate = new Date();
    setDate.setDate(15);
    setDate.setMonth(setDate.getMonth() - 1);
    return {
      fileList: [], //上传的文件列表, 例如: [{name: 'food.jpg', url: 'https://xxx.cdn.com/xxx.jpg'}]
      limitUpload: 100, //允许上传次数（不刷新页面情况下）
      userInfo: {
        data: null,
      },
      buttontype: true,
      none: true,
      rowIndex: "",
      columnId: "",
      focusTarget: null,
      seqArr: [],
      editSetFlag: "",
      filterForm: {
        show: true,
        data: {
          yearmonth: "", //日期
          type: "",
          hazard: "", //隐患分级
          process: "", //工序
          clock: "",
          clockc: "",
          workprocid: [],
          location: [],
          networkid: [],
          state: "",
          itemname: "",
          searchtype: "0",
          measureid: "",
          rectificationdate: "", //整改日期
          verify: "", //验证人
          money: 0, //资金
          plan: "", //预案
          hazard: "", //隐患分级
          measure: "", //整改措施
          line: "",
          unit: "",
          weight: "",
          cjr: "",
          xgr: "",
          xgsj: "",
          memo: "",
          cp: "",
          sysl: "",
          wxsy: "",
          cjsj: "",
          jzsj: "",
          zt: "",
          show: false,
        },
        rules: {},
        disabled: {
          networkid: false,
        },
      },
      pageNum: 1,
      pageSize: 100,
      total: 0,
      singleTableHeight: 100,
      tableData: [],
      originalData: [],
      loading: false,
      tableLoading: false,
      multipleSelection: [],
      tableFormDataObj: {},
      tableFormRules: {
        mintvalue: [
          // { required: true, message: '该项不能为空', trigger: 'change' },
          { validator: zCheckNumber1, trigger: "change" },
        ],
        mendvalue: [
          // { required: true, message: '该项不能为空', trigger: 'change' },
          { validator: zCheckNumber1, trigger: "change" },
        ],
        weight: [
          { required: true, message: "该项不能为空", trigger: "change" },
        ],
        wastage: [{ validator: zCheckNumber1, trigger: "change" }],
        secondVal: [{ validator: zCheckNumber1, trigger: "change" }],
        type: [{ required: true, message: "该项不能为空", trigger: "change" }],
      },
      nameObj: {
        itemtype: {
          obj: {
            1: "一级",
            2: "二级",
            3: "三级",
          },
          arr: [
            {
              id: "1",
              name: "一级",
            },
            {
              id: "2",
              name: "二级",
            },
            {
              id: "3",
              name: "三级",
            },
          ],
        },
        unitid: {
          obj: {},
          arr: [],
        },
        process: {
          obj: {},
          arr: [],
        },
        location: {
          obj: {},
          arr: [],
          showDataArr: [],
        },
        locateid: {
          obj: {},
          arr: [],
        },
        networkid: {
          obj: {},
          arr: [],
        },
        userId: {
          obj: {},
          arr: [],
        },
      },
      dialog: {
        fRow: null,
        editorBox1: {
          show: false,
        },
        editorBox: {
          show: false,
          type: "",
          form: {
            default: {
              workprocid: "",
            },
            data: {
              process: "", //地点
              yearmonth: "", //日期
              dates: "",
              memo: "", //备注
              type: "", //类型
              hazard: "", //隐患分级
              content: "", //内容
              createman: "", //检查人
              createtime: "", //检查时间
              filename: "", //整改结果
              id: "",
              updateman: "", //整改责任人
              updatetime: "", //整改期限
              rectificationdate: "", //整改日期
              verify: "", //验证人
              money: 0, //资金
              plan: "", //预案
              hazard: "", //隐患分级
              measure: "", //整改措施
            },
            rules: {
              content: [
                { required: true, message: "该项不能为空", trigger: "change" },
              ],
              createtime: [
                { required: true, message: "该项不能为空", trigger: "change" },
              ],
              rectificationdaterectificationdate: [
                { required: true, message: "该项不能为空", trigger: "change" },
              ],
              process: [
                { required: true, message: "该项不能为空", trigger: "change" },
              ],
              type: [
                { required: true, message: "该项不能为空", trigger: "change" },
              ],
            },
          },
        },
        editorBox2: {
          show: false,
          type: "",
          form: {
            data: {
              yearmonth: "",
            },
            rules: {
              yearmonth: [
                { required: true, message: "该项不能为空", trigger: "change" },
              ],
            },
          },
        },
      },
      butPrivilege: {
        QUERY: false,
        PUT: false,
        CHECK: false,
        UNDOCHECK: false,
        IMPORT: false,
      },
      loginName: getCookie("loginName"),
    };
  },
  created() {
    // 获取按钮权限
    this.activeMenu = window.localStorage.getItem("activeMenu");
    for (let key in this.butPrivilege) {
      this.butPrivilege[key] = this.checkPrivilege(this.activeMenu + key);
    }
  },
  mounted() {
    let that = this;
    window.PEDataObj = {
      // 将数据绑定到window上，供main页面使用
      vm: that,
      // tableArr：用于导出成Excel的表格的信息
      tableArr: [
        {
          name: "",
          id: "singleTable",
        },
      ],
    };
    that.$nextTick(() => {
      // 立即获取的height有一定偏差，通过setTimeout延迟来解决
      setTimeout(() => {
        that.singleTableHeight =
          that.getRoleHeight(that.$refs["singleTable"].$el) - 45;
      }, 1);
    });
    // 接收路由参数
    if (that.$route.query.networkid) {
      that.filterForm.disabled.networkid = true;
      that.filterForm.data.networkid = that.$route.query.networkid.split(",");
    }
    that.getworkprocidData();
    that.getTableData(1);
  },
  methods: {
    //上传前校验
    uploadOk(file) {
      // 文件类型
      console.log(`上传前校验---`, file);
      const isType = file.type === "application/vnd.ms-excel";
      const isTypeComputer =
        file.type ===
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      const fileType = isType || isTypeComputer;
      if (!fileType) {
        this.$message.error("上传文件只能是xls/xlsx格式！");
      }
      // 文件大小限制为20M
      const fileLimit = file.size / 1024 / 1024 < 20;
      if (!fileLimit) {
        this.$message.error("上传文件大小不超过20M！");
      }
      return fileType && fileLimit;
    },
    // excel表上传
    uploadExcel(file, fileList) {
      const fileTemp = file.raw;
      const fileName = file.raw.name;
      const fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
      // 判断上传文件格式
      if (fileTemp) {
        if (fileType === "xlsx" || fileType === "xls") {
          const formData = new FormData(); //这一步不能变
          formData.append("fileName", fileName);
          formData.append("file", file.raw);
          this.axios
            .post("pass/ems/v1/emssafeinfos/insertExcel/", formData, {
              headers: { "Content-Type": "multipart/form-data" },
            })
            .then((res) => {
              if (res.code === "0") {
                this.$message({
                  message: "数据导入成功",
                  type: "success",
                });
                this.getTableData(1);
              
              } else {
                this.$message({
                  message: "数据导入失败",
                  type: "warning",
                });
              }
            });
        } else {
          this.$message({
            type: "warning",
            message: "附件格式错误，请重新上传！",
          });
        }
      } else {
        this.$message({
          type: "warning",
          message: "请上传附件！",
        });
      }
    },

    funcShowAllCameras() {
      let that = this;
      that.buttontype = false;
    },

    but_edita(row) {
      let that = this;
      that.dialog.editorBox.type = "add";
      that.none = true;
      that.buttontype = true;

      for (let key in that.dialog.editorBox.form.data) {
        if (typeof row[key] !== "undefined") {
          that.dialog.editorBox.form.data[key] = row[key];
        } else {
          console.log("key:" + key);
        }
      }

      that.dialog.editorBox.show = true;
    },
    but_editaa(row) {
      let that = this;
      that.dialog.editorBox.type = "PUT";
      that.none = false;
      that.buttontype = false;
      for (let key in that.dialog.editorBox.form.data) {
        if (typeof row[key] !== "undefined") {
          that.dialog.editorBox.form.data[key] = row[key];
        } else {
          console.log("key:" + key);
        }
      }
      //   if (row.filename) {
      //     let fn = (row.filename + "").trim().split(";");
      //     if (fn && fn.length > 0) {
      //       let declareid = row.declareid;
      //       for (let i = 0; i < fn.length; i++) {
      //         if (fn[i]) {
      //           let fname = {
      //             name: fn[i],
      //             url:
      //               "/icore.icp.web/pass/ems/static/" + declareid + "/" + fn[i],
      //             file: null,
      //             operation: "",
      //           };
      //           that.dialog.editorBox.files.push(fname);
      //         }
      //       }
      //     }
      //   }
      that.dialog.editorBox.show = true;
    },
    // 修改
    but_edita2() {
      let that = this;
      if (that.buttontype) {
        that.dialog.editorBox.show = false;
      } else {
        let id = that.dialog.editorBox.form.data.id;
        let parmas = {
        dates: that.dialog.editorBox.form.data.yearmonth,
        type: that.dialog.editorBox.form.data.type,
        process: that.dialog.editorBox.form.data.process,
        memo: that.dialog.editorBox.form.data.memo,
        content: that.dialog.editorBox.form.data.content,
        id: that.dialog.editorBox.form.data.id,
        createman: that.dialog.editorBox.form.data.createman,
        createtime: that.dialog.editorBox.form.data.createtime,
        updateman: that.dialog.editorBox.form.data.updateman,
        updatetime: that.dialog.editorBox.form.data.updatetime,
        filename: that.dialog.editorBox.form.data.filename,
        rectificationdate: that.dialog.editorBox.form.data.rectificationdate,
        verify: that.dialog.editorBox.form.data.verify,
        money: that.dialog.editorBox.form.data.money,
        plan: that.dialog.editorBox.form.data.plan,
        hazard: that.dialog.editorBox.form.data.hazard,
        measure: that.dialog.editorBox.form.data.measure,
        };

        that.loading = true;
        that.axios
          .put(`pass/ems/v1/emssafeinfos/${id}`, parmas)
          .then(function (res) {
            if (res.code === "0") {
              let msg = res.message;
              if (!msg || msg === "操作成功") {
                that.$message({
                  message: "操作成功",
                  type: "success",
                });
              } else {
                that.$message.warning("修改成功，注意：" + msg);
              }
              that.dialog.editorBox.show = false;
              that.getTableData(1);
            } else {
              that.$message.error(res.message);
            }
            that.loading = false;
          })
          .catch(function () {
            that.loading = false;
          });
      }
    },
    getworkprocidData() {
      let that = this;
      let url = "pass/ems/v1/trmworkprocs/getIdAndName";
      that.axios.get(url).then(function (res) {
        if (res.code === "0") {
          let arr = [];
          let obj = {};
          for (let item of res.data) {
            arr.push({
              id: item.id,
              name: item.name,
            });
            obj[item.id] = item.name;
          }
          that.nameObj.process.arr = arr;
          that.nameObj.process.obj = obj;
        } else {
          that.$message.error(res.message);
        }
      });
    },
    //  计算树区域高度
    getRoleHeight(dom) {
      return window.innerHeight - dom.offsetTop;
    },
    // 获取工序列表
    // getNodeData () {
    //     let that = this
    //     let url = 'pass/ems/v1/trmworkprocs/getIdAndName?issettle=1';
    //     that.axios.get(url)
    //         .then(function (res) {
    //             if (res.code === '0') {
    //                 let arr = [];
    //                 let obj = {};
    //                 for (let item of res.data) {
    //                     arr.push({
    //                         id: item.id,
    //                         name: item.name
    //                     })
    //                     obj[item.id] = item.name;
    //                 }
    //                 that.nameObj.workprocid.arr = arr;
    //                 that.nameObj.workprocid.obj = obj;
    //                 that.connn();
    //             } else {
    //                 that.$message.error(res.message);
    //             }
    //         });
    // },
    getUnitIdData() {
      let that = this;
      let url = "pass/ems/v1/trmunits/getIdAndName";
      that.axios.get(url).then(function (res) {
        if (res.code === "0") {
          let arr = [];
          let obj = {};
          for (let item of res.data) {
            arr.push({
              id: item.id,
              name: item.name,
            });
            obj[item.id] = item.name;
            if (item.name === "吨") {
              that.nameObj.unitid.defaults = that.nameObj.unitid.defaults
                ? that.nameObj.unitid.defaults
                : item.id;
            }
          }
          that.nameObj.unitid.arr = arr;
          that.nameObj.unitid.obj = obj;
        } else {
          that.$message.error(res.message);
        }
      });
    },
    // 获取位置
    getLocateIdData() {
      let that = this;
      let url = "pass/ems/v1/trmlocations/getidandname/";
      that.axios.get(url).then(function (res) {
        if (res.code === "0") {
          let arr = [];
          let obj = {};
          for (let item of res.data) {
            arr.push({
              id: item.id,
              name: item.name,
            });
            obj[item.id] = item.name;
          }
          that.nameObj.locateid.arr = arr;
          that.nameObj.locateid.obj = obj;
        } else {
          that.$message.error(res.message);
        }
      });
    },
    // 获取表格中的数据
    getTableData(pageNum) {
      let that = this,
        params = {},
        pData = {
          dates: that.filterForm.data.yearmonth[0],
          dates2: that.filterForm.data.yearmonth[1],
          hazard: that.filterForm.data.hazard.toString(),
          process: that.filterForm.data.process.toString(),
        };
      for (let key in pData) {
        if (pData[key]) {
          params[key] = pData[key];
        }
      }
      that.pageNum = pageNum || that.pageNum;
      that.tableLoading = true;
      let url =
        "pass/ems/v1/emssafeinfos/?pageNum=" +
        that.pageNum +
        "&pageSize=" +
        that.pageSize;
      that.axios
        .get(url, {
          params: params,
        })
        .then(function (res) {
          if (res.code === "0") {
            let arr = [];
            for (let e of res.data.list) {
              arr.push({
                content: e.content,
                createman: e.createman,
                createtime: e.createtime,
                dates: e.dates,
                filename: e.filename,
                memo: e.memo,
                process: e.process,
                type: e.type,
                updateman: e.updateman,
                updatetime: e.updatetime,
                id: e.id,
                rectificationdate: e.rectificationdate,
                verify: e.verify,
                money: e.money,
                plan: e.plan,
                hazard: e.hazard,
                measure: e.measure,
              });
            }
            that.total = res.data.total;
            that.tableData = arr;
            that.originalData = arr;
          } else {
            that.$message.error(res.message);
          }
          that.$nextTick(() => {
            setTimeout(() => {
              that.singleTableHeight =
                that.getRoleHeight(that.$refs["singleTable"].$el) - 46;
            }, 1);
          });
          that.tableLoading = false;
        })
        .catch(function () {
          that.tableLoading = false;
        });
    },
    // 改变表格显示条数
    tableSizeChange(val) {
      let that = this;
      that.pageSize = val;
      that.getTableData(1);
    },
    // 重置搜索
    tableDataCancel() {
      let that = this;
      for (let key in that.filterForm.data) {
        if (!that.filterForm.disabled || !that.filterForm.disabled[key]) {
          if (that.filterForm.data[key] instanceof Array) {
            that.filterForm.data[key] = [];
          } else {
            that.filterForm.data[key] = "";
          }
        }
      }
      that.getTableData(1);
    },
    keyDown(event1, disabledFlag) {
      let tdTarget = event1.target;
      let _this = this;
      while (tdTarget.tagName !== "TD") {
        tdTarget = tdTarget.parentElement;
      }
      // 如果按下键盘下键或者回车键
      if (event.keyCode === 40 || event.keyCode === 13) {
        let index = parseInt(this.rowIndex);
        // index++;
        if (index !== this.seqArr[this.seqArr.length - 1]) {
          for (let i = 0; i < this.seqArr.length; i++) {
            if (index === this.seqArr[i]) {
              index = this.seqArr[i + 1];
              break;
            }
          }
        }
        this.editSetFlag = index + this.columnId;
        let id = "#" + this.editSetFlag;
        this.$nextTick(() => {
          $(id).click();
        });
      } else if (event.keyCode === 38) {
        // 键盘上键
        let index = parseInt(this.rowIndex);
        if (index !== this.seqArr[0]) {
          for (let i = 0; i < this.seqArr.length; i++) {
            if (index === this.seqArr[i]) {
              index = this.seqArr[i - 1];
              break;
            }
          }
        }
        this.editSetFlag = index + this.columnId;
        let id = "#" + this.editSetFlag;
        this.$nextTick(() => {
          $(id).click();
        });
      } else if (event.keyCode === 37) {
        // 键盘左键
        $(tdTarget).prevAll().find("input:text").last().click();
      } else if (event.keyCode === 39) {
        // 键盘右键
        $(tdTarget).nextAll().find("input").eq(0).click();
      }
    },
    handleSelectionChange(val) {
      let that = this;
      let tableFormDataObj = {};
      for (let item of that.tableData) {
        item.isSelection = false;
      }
      for (let item of val) {
        let obj = {};
        let xId = item.itemid + "-" + item.clock + "-" + item.timegranid;
        if (that.tableFormDataObj[xId]) {
          tableFormDataObj[xId] = that.tableFormDataObj[xId];
        } else {
          for (let key in item) {
            obj[key] = item[key];
          }
          tableFormDataObj[xId] = obj;
        }
        item.isSelection = true;
      }
      that.tableFormDataObj = tableFormDataObj;
      that.multipleSelection = val;
    },
    //新增
    dataSave() {
      let that = this;
      let SubmitData = {
        dates: that.dialog.editorBox.form.data.yearmonth,
        type: that.dialog.editorBox.form.data.type,
        process: that.dialog.editorBox.form.data.process,
        memo: that.dialog.editorBox.form.data.memo,
        content: that.dialog.editorBox.form.data.content,
        id: that.dialog.editorBox.form.data.id,
        createman: that.dialog.editorBox.form.data.createman,
        createtime: that.dialog.editorBox.form.data.createtime,
        updateman: that.dialog.editorBox.form.data.updateman,
        updatetime: that.dialog.editorBox.form.data.updatetime,
        filename: that.dialog.editorBox.form.data.filename,
        rectificationdate: that.dialog.editorBox.form.data.rectificationdate,
        verify: that.dialog.editorBox.form.data.verify,
        money: that.dialog.editorBox.form.data.money,
        plan: that.dialog.editorBox.form.data.plan,
        hazard: that.dialog.editorBox.form.data.hazard,
        measure: that.dialog.editorBox.form.data.measure,
      };
      console.log("SubmitData", SubmitData);
      that.$refs["dialog_form"].validate((valid) => {
        if (valid) {
          that.loading = true;
          that.axios
            .post("pass/ems/v1/emssafeinfos/", SubmitData)
            .then(function (res) {
              if (res.code === "0") {
                that.$message({
                  message: "新增成功",
                  type: "success",
                });
                that.getTableData();
                that.dialog.editorBox1.show = false;
              } else {
                that.$message.error(res.message);
              }
              that.loading = false;
            })
            .catch(function () {
              that.loading = false;
            });
        }
      });
    },
    // 批量删除
    but_del_plural() {
      let that = this;
      if (this.multipleSelection.length > 0) {
        let id = "";
        for (let item of this.multipleSelection) {
          id += item.id + ",";
        }
        that
          .$confirm("是否删除已选数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            state: "warning",
          })
          .then(() => {
            that.axios
              .delete(`pass/ems/v1/emssafeinfos/${id}`)
              .then(function (res) {
                if (res.code === "0") {
                  that.$message({
                    message: "删除成功",
                    type: "success",
                  });
                  that.getTableData();
                } else {
                  that.$message.error(res.message);
                }
              })
              .catch(function () {});
          })
          .catch(() => {});
      } else {
        this.$message.error("至少要选择一条数据");
      }
    },
    upState(state = "2") {
      let that = this;
      let dataArr = [];
      for (let item of that.multipleSelection) {
        if (item.state !== state) {
          dataArr.push(item);
        }
      }
      if (dataArr.length > 0) {
        that
          .$confirm(
            "本次将要" +
              (state === "2" ? "审核" : "撤销审核") +
              dataArr.length +
              "条数据，是否确定?",
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              state: "warning",
            }
          )
          .then(() => {
            let SubmitData = [];
            for (let item of dataArr) {
              SubmitData.push({
                state: state,
                id: item.id,
              });
            }
            that.loading = true;
            that.axios
              .put("pass/ems/v1/trmtransfereactvalues/batchcheck2", SubmitData)
              .then(function (res) {
                if (res.code === "0") {
                  that.$message({
                    message: (state === "2" ? "审核" : "撤销") + "成功",
                    type: "success",
                  });
                  that.getTableData();
                } else {
                  that.$message.error(res.message);
                }
                that.loading = false;
              })
              .catch(function () {
                that.loading = false;
              });
          })
          .catch(() => {});
      } else {
        if (that.multipleSelection.length > 0) {
          this.$message.error(
            "没有需要" + (state === "2" ? "审核" : "撤销") + "的数据"
          );
        } else {
          this.$message.error("至少要选择一条数据");
        }
      }
    },
    but_add() {
      let that = this;
      that.dialog.editorBox1.show = true;
      (that.dialog.editorBox.form.data.process = ""),
        (that.dialog.editorBox.form.data.content = ""),
        (that.dialog.editorBox.form.data.type = "");
      that.dialog.editorBox.form.data.memo = "";

      that.dialog.editorBox.form.data.id = "";
      that.dialog.editorBox.form.data.createman = "";
      that.dialog.editorBox.form.data.createtime = "";
      that.dialog.editorBox.form.data.updateman = "";
      that.dialog.editorBox.form.data.updatetime = "";
      that.dialog.editorBox.form.data.filename = "";
      that.dialog.editorBox.form.data.rectificationdate = "";
      that.dialog.editorBox.form.data.verify = "";
      that.dialog.editorBox.form.data.money = "";
      that.dialog.editorBox.form.data.plan = "";
      that.dialog.editorBox.form.data.hazard = "";
      that.dialog.editorBox.form.data.measure = "";
      setTimeout(() => {
        that.$refs["dialog_form"].clearValidate();
      }, 100);
    },
    tableRowClassName({ row, rowIndex }) {
      // 把每一行的索引放进row
      row.index = rowIndex;
    },
    cellClick(row, column, cell, event) {
      let _this = this;
      this.rowIndex = row.index;
      this.columnId = column.id;
      _this.editSetFlag = row.index + column.id;
      _this.focusTarget = event.target;
      while (_this.focusTarget.tagName !== "TD") {
        _this.focusTarget = _this.focusTarget.parentElement;
      }
      _this.$nextTick(() => {
        let target = this.focusTarget;
        $(target).find("input").focus();
      });
    },
    // 获取一行的总和
    rowSum: function (item, event) {
      let result = 0;
      let that = this;
      for (let weiIndex in item.weight) {
        for (let weiKey in item.weight[weiIndex]) {
          result += Number(item.weight[weiIndex][weiKey]);
        }
      }
      return result;
    },
    // 导入方法
    beforeUpload(event, file, fileList) {
      let _this = this;
      let formData = new FormData();
      formData.append("file", file.raw);
      _this.loading = true;
      this.axios
        .post("pass/ems/v1/emsprodplanyears/excelimport/", formData, {
          headers: { "Content-Type": "multipart/form-data" },
        })
        .then((res) => {
          if (res.code === "0") {
            this.$message.success("操作成功");
            _this.getTableData(1);
          } else {
            this.$message.error(res.message);
          }
          _this.loading = false;
        })
        .catch(() => {
          _this.loading = false;
        });
    },
    // 导出数据到excel
    dowloadFile() {
      let that = this,
        params = {},
        pData = {
          dates: that.filterForm.data.yearmonth[0],
          dates2: that.filterForm.data.yearmonth[1],
          type: that.filterForm.data.type.toString(),
          process: that.filterForm.data.process,

        memo: that.filterForm.data.memo,
        content: that.filterForm.data.content,
        id: that.filterForm.data.id,
        createman: that.filterForm.data.createman,
        createtime: that.filterForm.data.createtime,
        updateman: that.filterForm.data.updateman,
        updatetime: that.filterForm.data.updatetime,
        filename: that.filterForm.data.filename,
        rectificationdate: that.filterForm.data.rectificationdate,
        verify: that.filterForm.data.verify,
        money: that.filterForm.data.money,
        plan: that.filterForm.data.plan,
        hazard: that.filterForm.data.hazard,
        measure: that.filterForm.data.measure,
        };
      for (let key in pData) {
        if (pData[key]) {
          params[key] = pData[key];
        }
      }
      that.tableLoading = true;
      let url = "pass/ems/v1/emssafeinfos/downloadExcel/?";
      that.axios
        .get(url, {
          responseType: "blob",
          params: params,
        })
        .then(function (res) {
          const blob = new Blob([res]);
          that.saveAs(blob, "安全信息.xlsx");
          that.$message({
            message: "导出成功",
            type: "success",
          });
          that.getTableData(1);
        })
        .catch(function () {
          that.$message.error("导出失败");
        });
    },
    saveAs(text, name, opts) {
      saveAs(text, name, opts);
    },
    //下载文件
    downloadFile(data) {
      let that = this;
      let fileName = "隐患排查登记.xlsx";
      let fileUrl = "/安泰控股集团/测试/2023/05/16/1684234254400060.xlsx";
      let SubmitData = {
        fileName: fileName,
        fileUrl: fileUrl,
      };
      //that.loading = true;
      let urla = "pass/ems/v1/uploadfiles/downloadFile/";
      that.axios
        .get(urla, {
          params: SubmitData,
          responseType: "blob",
        })
        .then(function (res) {
          that.saveAs(res, fileName);
          that.$message({
            message: "下载成功",
            type: "success",
          });
          that.loading = false;
        })
        .catch(function () {
          that.$message.error("下载失败");
          that.loading = false;
        });
    },
    // js实现文件下载而不直接打开
    saveAs(data, fileName) {
      this.loading = true;
      let urlObject = window.URL || window.webkitURL || window;
      // 将二进制流转为blob
      let exportBlob = new Blob([data]);
      if (typeof window.navigator.msSaveBlob !== "undefined") {
        // 兼容IE，window.navigator.msSaveBlob：以本地方式保存文件
        window.navigator.msSaveBlob(exportBlob, decodeURI(fileName));
        this.loading = false;
      } else {
        // 创建新的URL并指向File对象或者Blob对象的地址
        let blobURL = urlObject.createObjectURL(exportBlob);
        let saveLink = document.createElement("a");
        // 兼容：某些浏览器不支持HTML5的download属性
        if (typeof saveLink.download === "undefined") {
          saveLink.setAttribute("target", "_blank");
        } else {
          saveLink.download = fileName;
        }
        // 创建新的URL并指向File对象或者Blob对象的地址
        saveLink.href = blobURL;
        saveLink.click();
        // 释放blob URL地址
        urlObject.revokeObjectURL(exportBlob);
        this.loading = false;
        // let blob = new Blob([data])
        // let fileURL = urlObject.createObjectURL(blob);
        // 下载代码
        // let downEle = document.createElement('a')
        // let fname = `download` //下载文件的名字
        // downEle.href = fileURL
        // downEle.setAttribute('download', fname)
        // document.body.appendChild(downEle)
        // downEle.click()
        // window.open(fileURL);
      }
    },
  },
};
function sortNumber(a, b) {
  return a - b;
}
</script>

<style lang="less">
.outElectricity {
  min-width: 700px;
  height: 100%;

  .box {
    height: 100%;
    padding: 15px 15px 0 15px;

    .box-top {
      .el-form-item {
        margin-bottom: 7px;
      }

      .box-top-gjl {
        overflow: hidden;
        padding: 7px 0;
        border-top: 1px solid #ccc;
      }
    }

    .rowDisable td {
      color: #6bb025 !important;
    }

    .el-table .el-table__row {
      height: 35px;
    }

    .el-table__body .el-form-item--mini.el-form-item {
      margin: 0px;

      .error {
        overflow: hidden;
        color: #f56c6c;
        font-size: 12px;
        line-height: 1;
      }
    }
  }

  .color_no {
    color: #7a7a7a;
  }

  .color_yes {
    color: #1a9f17;
  }

  .cnspicuous .el-checkbox__input.is-disabled .el-checkbox__inner {
    background-color: #dcdfe6;
    border-color: #babbbf;
  }
}
</style>
