<template>
  <div>
    <!-- 上传 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="dialogVisible"
      :before-close="handleClose"
      width="80%"
    >
      <el-form :model="form" :inline="true" class="demo-form-inline">
        <el-form-item v-if="title != '修改技术监督事务'">
          <Area @click="handleNodeClick"></Area>
        </el-form-item>
        <!-- <el-form-item>
          <Timeinterval :interval="3" ref="interval"></Timeinterval>
        </el-form-item> -->
        <!-- <el-form-item label="筛选数据:">
          <el-input
            v-model="form.value"
            placeholder="请输入需要筛选的数据"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item v-if="title != '修改技术监督事务'" label="反馈类型:">
          <el-select v-model="form.type" clearable placeholder="请选择反馈类型">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="title != '修改技术监督事务'"
            type="primary"
            size="small"
            icon="el-icon-search"
            @click="onSubmit"
            >查询</el-button
          >
          <el-button
            v-if="title != '修改技术监督事务'"
            type="primary"
            size="small"
            icon="el-icon-plus"
            @click="create"
            >生成</el-button
          >
          <el-button
            v-else
            type="primary"
            size="small"
            icon="el-icon-edit"
            @click="update"
            >修改</el-button
          >
          <!-- <el-button type="primary" icon="el-icon-download">导出</el-button> -->
        </el-form-item>
      </el-form>
      <el-table
        stripe
        :data="tableList"
        header-cell-class-name="table_header"
        height="500px"
        style="width: 100%"
        v-loading="loading"
        border
        ref="multipleTable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <template v-for="(item, index) in warningList">
          <el-table-column
            :prop="item.prop"
            :label="item.label"
            :min-width="item.width"
            show-overflow-tooltip
            :key="index"
          >
          </el-table-column>
        </template>
        <!-- <el-table-column label="操作" width="210">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" icon="el-icon-view"
              >趋势图</el-button
            >
            <el-button size="mini" type="primary" icon="el-icon-view"
              >日报</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <!-- <el-pagination
        background
        align="right"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="form.pageNum"
        :page-sizes="[20, 30, 40, 50, 100]"
        :page-size="form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        class="mt10"
      >
      </el-pagination> -->
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleClose">确 定</el-button>
      </span> -->
    </el-dialog>
  </div>
</template>
<script>
import Timeinterval from "@/views/components/Timeinterval.vue";
import Area from "@/views/components/Area/Area.vue";
import {
  initSupervise,
  saveOverRunLog,
  superviseDetail,
  updateSupervice,
} from "@/api/Processsupervision/technology.js";
export default {
  components: { Timeinterval, Area },
  props: {
    title: {
      type: String,
    },
    rowList: {
      type: [Array, Object],
    },
  },
  data() {
    return {
      form: {
        deptId: JSON.parse(window.sessionStorage.getItem("Info")).deptId,
        type: "0",
        initType: 1,
      },
      loading: false,
      dialogVisible: true,
      multipleSelection: [],
      pageNum: 1,
      pageSize: 20,
      total: 1,
      thsSupervise: {},
      tableList: [],
      options: [
        {
          name: "预警单",
          id: "0",
        },
        {
          name: "告警单",
          id: "1",
        },
      ],
      warningList: [
        { prop: "companyName", label: "变电站", width: 100 },
        { prop: "lineIndexName", label: "监测点", width: 100 },
        { prop: "overTime", label: "越限次数", width: 100 },
        { prop: "description", label: "描述", width: 200 },
      ],
    };
  },
  created() {},
  mounted() {
    if (this.title == "修改技术监督事务") {
      this.updateList();
    } else {
      this.onSubmit();
    }
  },
  methods: {
    // 查询
    async onSubmit() {
      this.loading = true;
      await initSupervise(this.form).then((res) => {
        this.tableList = res.data.overRunLog;
        this.thsSupervise = res.data.thsSupervise;
      });
      this.loading = false;
    },
    updateList() {
      superviseDetail({ supIndex: this.rowList.supIndex }).then((res) => {
        this.tableList = res.data.overRunLog;
        this.thsSupervise = res.data.thsSupervise;
      });
    },
    // 生成
    create() {
      if (this.multipleSelection == 0) {
        this.$message({
          message: "请选择1条数据 进行生成!",
          type: "warning",
        });
      } else {
        let data = {
          overRunLog: this.multipleSelection,
          thsSupervise: this.thsSupervise,
        };
        saveOverRunLog(data).then((res) => {
          if (res.code == "A0000") {
            this.$message({
              message: "生成成功!",
              type: "success",
            });
            this.$emit("success");
          }
        });
      }
    },
    // 修改
    update() {
      if (this.multipleSelection == 0) {
        this.$message({
          message: "请选择1条数据 进行修改!",
          type: "warning",
        });
      } else {
        let data = {
          overRunLog: this.multipleSelection,
          thsSupervise: this.thsSupervise,
        };
        updateSupervice(data).then((res) => {
          if (res.code == "A0000") {
            this.$message({
              message: "修改成功!",
              type: "success",
            });
            this.$emit("success");
          }
        });
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleNodeClick(data) {
      this.form.deptId = data.id;
      // this.id = data.id;
    },
    handleClose() {
      this.$emit("handleClose");
    },
    handleSizeChange(e) {
      this.form.pageSize = e;
    },
    handleCurrentChange(e) {
      this.form.pageNum = e;
    },
  },

  computed: {},

  watch: {},
};
</script>
<style lang="less" scoped>
@import url("../../../../styles/comStyle.less");
.boxDiv {
  display: flex;
  justify-content: space-between;
  line-height: 28px;
}
</style>
