<template>
  <div class="container-main" ref="main">
    <div class="search-hearder" ref="topSearch">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
        <el-form-item label="系统名称" prop="steamName">
          <el-input
            v-model="queryParams.steamName"
            placeholder="请输入系统名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单位名称" prop="unitName">
          <el-input
            v-model="queryParams.unitName"
            placeholder="请输入单位名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button size="mini" @click="resetQuery" icon="el-icon-refresh"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <div class="layui-table-tool" ref="tableTool">
      <el-button
        type="primary"
        size="mini"
        @click="handleAdd()"
        v-hasPermi="['zongzhi:system:add']"
        >新增</el-button
      >
      <el-button
        type="warning"
        size="mini"
        :loading="exportLoading"
        @click="handleExport"
        v-hasPermi="['zongzhi:system:export']"
        >导出</el-button
      >
    </div>

    <el-table
      v-loading="loading"
      :data="systemList"
      :height="tableHeigth"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="系统名称"
        align="center"
        prop="steamName"
        show-overflow-tooltip
      />
      <el-table-column
        label="备案编号"
        align="center"
        prop="beianNum"
        show-overflow-tooltip
      />

      <el-table-column
        label="单位名称"
        align="center"
        prop="unitName"
        show-overflow-tooltip
      />
      <el-table-column label="业务类型" align="center" prop="yewuType" />
      <el-table-column label="服务范围" align="center" prop="servicesArea" />
      <el-table-column label="服务对象" align="center" prop="servicesObj" />
      <el-table-column label="覆盖范围" align="center" prop="coverageArea" />
      <el-table-column label="网络性质" align="center" prop="networkNature" />
      <el-table-column
        label="投入运行使用日期"
        align="center"
        prop="useTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.useTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="系统是否分级" align="center" prop="isRate">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tc_yes_no" :value="scope.row.isRate" />
        </template>
      </el-table-column>
      <el-table-column
        label="系统定级时间"
        align="center"
        prop="rankTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rankTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="系统状态" align="center" prop="systemState">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.tc_db_steam_state"
            :value="scope.row.systemState"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="300"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleInfo(scope.row)"
            v-hasPermi="['zongzhi:system:list']"
          >
            查看
          </el-button>
          <el-button
            type="success"
            size="mini"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['zongzhi:system:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)"
            v-hasPermi="['zongzhi:system:remove']"
            >删除</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"
    ></pagination>

    <!-- 添加或修改安全检测对话框 -->
    <el-dialog
      :visible.sync="open"
      width="1000px"
      append-to-body
      custom-class="dialog-box"
    >
      <div slot="title" class="dialog-title">{{ title }}</div>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="auto"
        class="dialog-from"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="区域" prop="areaId">
              <el-cascader
                v-model="form.areaId"
                :options="townList"
                :props="treeProps"
                clearable
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="系统名称" prop="steamName">
              <el-input v-model="form.steamName" placeholder="请输入系统名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="备案编号" prop="beianNum">
              <el-input v-model="form.beianNum" placeholder="请输入备案编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="信息系统安全保护等级" prop="safetyLevel">
              <el-select
                v-model="form.safetyLevel"
                placeholder="请选择信息系统安全保护等级"
              >
                <el-option
                  v-for="dict in dict.type.tc_net_safety_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位名称" prop="unitName">
              <el-input v-model="form.unitName" placeholder="请输入单位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务类型" prop="yewuType">
              <el-input v-model="form.yewuType" placeholder="请输入业务类型" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="服务范围" prop="servicesArea">
              <el-input
                v-model="form.servicesArea"
                placeholder="请输入服务范围"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="服务对象" prop="servicesObj">
              <el-input
                v-model="form.servicesObj"
                placeholder="请输入服务对象"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="覆盖范围" prop="coverageArea">
              <el-input
                v-model="form.coverageArea"
                placeholder="请输入覆盖范围"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="网络性质" prop="networkNature">
              <el-input
                v-model="form.networkNature"
                placeholder="请输入网络性质"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="系统互联情况" prop="systemSitutation">
              <el-input
                v-model="form.systemSitutation"
                placeholder="请输入系统互联情况"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投入运行使用日期" prop="useTime">
              <el-date-picker
                clearable
                size="small"
                v-model="form.useTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择投入运行使用日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="系统是否分级" prop="isRate">
              <el-select
                v-model="form.isRate"
                placeholder="请选择是否有主管部门"
              >
                <el-option
                  v-for="dict in dict.type.tc_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="系统定级时间" prop="rankTime">
              <el-date-picker
                clearable
                size="small"
                v-model="form.rankTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择系统定级时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="专家评审情况" prop="reviewCase">
              <el-input
                v-model="form.reviewCase"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否有主管部门" prop="isParent">
              <el-select
                v-model="form.isParent"
                placeholder="请选择是否有主管部门"
              >
                <el-option
                  v-for="dict in dict.type.tc_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="系统定级报告">
              <el-input
                v-model="form.rankReport"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="系统状态" prop="systemState">
              <el-select
                v-model="form.systemState"
                placeholder="请选择系统状态"
              >
                <el-option
                  v-for="dict in dict.type.tc_db_steam_state"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="infoOpen"
      width="1000px"
      append-to-body
      custom-class="dialog-box"
    >
      <div slot="title" class="dialog-title">{{ infoTitle }}</div>
      <el-descriptions
        title="等保系统"
        :column="2"
        border
        labelClassName="desLable"
      >
        <el-descriptions-item label="区域">{{
          form.areaId
        }}</el-descriptions-item>

        <el-descriptions-item label="系统名称">{{
          form.steamName
        }}</el-descriptions-item>

        <el-descriptions-item label="备案编号">{{
          form.recordCode
        }}</el-descriptions-item>

        <el-descriptions-item label="信息系统安全保护等级">
          <dict-tag :options="dict.type.tc_yes_no" :value="form.safetyLevel" />
        </el-descriptions-item>

        <el-descriptions-item label="单位名称">{{
          form.unitName
        }}</el-descriptions-item>

        <el-descriptions-item label="业务类型">{{
          form.yewuType
        }}</el-descriptions-item>

        <el-descriptions-item label="服务范围">{{
          form.servicesArea
        }}</el-descriptions-item>

        <el-descriptions-item label="服务对象">{{
          form.servicesObj
        }}</el-descriptions-item>

        <el-descriptions-item label="覆盖范围">{{
          form.coverageArea
        }}</el-descriptions-item>

        <el-descriptions-item label="网络性质">{{
          form.networkNature
        }}</el-descriptions-item>

        <el-descriptions-item label="系统互联情况">{{
          form.systemSitutation
        }}</el-descriptions-item>

        <el-descriptions-item label="投入运行使用日期">{{
          form.useTime
        }}</el-descriptions-item>

        <el-descriptions-item label="系统是否分级">
          <dict-tag :options="dict.type.tc_yes_no" :value="form.isRate" />
        </el-descriptions-item>

        <el-descriptions-item label="系统定级时间">{{
          form.rankTime
        }}</el-descriptions-item>

        <el-descriptions-item label="专家评审情况">{{
          form.reviewCase
        }}</el-descriptions-item>

        <el-descriptions-item label="是否有主管部门">
          <dict-tag :options="dict.type.tc_yes_no" :value="form.isParent" />
        </el-descriptions-item>

        <el-descriptions-item label="系统定级报告">{{
          form.rankReport
        }}</el-descriptions-item>

        <el-descriptions-item label="系统状态">{{
          form.systemState
        }}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import {
  listSystem,
  getSystem,
  delSystem,
  addSystem,
  updateSystem,
  exportSystem,
} from "@/api/zongzhi/netSecurity/supervise/DbSteam/index.js";

export default {
  name: "Detection",
  //注释字典
  dicts: ["tc_yes_no", "tc_net_safety_level", "tc_db_steam_state"],
  computed: {
    ...mapGetters(["townList", "treeProps"]),
  },
  data() {
    return {
      tableHeigth: 0,
      //查看详情
      infoOpen: false,
      //详情标题
      infoTitle: "",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 等保系统表格数据
      systemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        steamName: null,

        unitName: null,

        systemState: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  mounted() {
    // //给表格一个固定值
    this.$nextTick(() => {
      this.tableHeigth =
        this.$refs.main.offsetHeight -
        (this.$refs.topSearch.offsetHeight +
          this.$refs.tableTool.offsetHeight) -
        46;
      this.getList();
    });
  },
  methods: {
    /** 查询等保系统列表 */
    getList() {
      this.loading = true;
      listSystem(this.queryParams).then((response) => {
        this.systemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,

        areaId: null,

        steamName: null,

        beianNum: null,

        safetyLevel: null,

        unitName: null,

        yewuType: null,

        servicesArea: null,

        servicesObj: null,

        coverageArea: null,

        networkNature: null,

        systemSitutation: null,

        useTime: null,

        isRate: null,

        rankTime: null,

        reviewCase: null,

        isParent: null,

        rankReport: null,

        systemState: null,

        createId: null,

        createBy: null,

        createTime: null,

        updateId: null,

        updateBy: null,

        updateTime: null,

        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    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;
    },
    /**查看按钮操作 */
    handleInfo(row) {
      this.reset();
      const id = row.id || this.ids;
      getSystem(id).then((response) => {
        response.data.areaId = JSON.parse(response.data.areaId);
        if (
          response.data.areaId.length > 0 &&
          Array.isArray(response.data.areaId)
        ) {
          response.data.areaId = response.data.areaId.join("、");
        } else {
          response.data.areaId = "";
        }
        this.form = response.data;
        this.infoOpen = true;
        this.infoTitle = "查看等保系统详情";
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加等保系统";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getSystem(id).then((response) => {
        response.data.areaId = JSON.parse(response.data.areaId);
        this.form = response.data;
        this.open = true;
        this.title = "修改等保系统";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.areaId = JSON.stringify(this.form.areaId);
          if (this.form.id != null) {
            updateSystem(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSystem(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除等保系统编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delSystem(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有等保系统数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.download(
            "/zongzhi/system/export",
            {
              ...this.queryParams,
            },
            "等保系统_" + new Date().getTime() + ".xlsx"
          );
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped></style>
