<!--
 * @Author: SunTao 328867980@qq.com
 * @Date: 2024-12-17 09:18:08
 * @LastEditors: SunTao 328867980@qq.com
 * @LastEditTime: 2024-12-24 10:52:05
 * @FilePath: \znxjxt-ui\src\views\xj\inspection-warn\warning-line\index.vue
 * @Description: 预警中心-大屏图例设置
-->
<template>
  <div class="content">
    <el-table
      ref="setupTable"
      :data="warningLineList"
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column label="病害名称" align="center" prop="defectName" />
      <el-table-column label="范围一" align="center" prop="s1">
        <template slot-scope="scope"> ≤{{ scope.row.s1 }} </template>
      </el-table-column>
      <el-table-column label="范围二" align="center" prop="s2">
        <template slot-scope="scope"> ≤{{ scope.row.s2 }} </template>
      </el-table-column>
      <el-table-column label="范围三" align="center" prop="s3">
        <template slot-scope="scope"> ≤{{ scope.row.s3 }} </template>
      </el-table-column>
      <el-table-column label="范围四" align="center" prop="s4">
        <template slot-scope="scope"> ≤{{ scope.row.s4 }} </template>
      </el-table-column>
      <el-table-column label="范围五" align="center" prop="s5">
        <template slot-scope="scope"> >{{ scope.row.s4 }} </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="图例设置"
      :visible.sync="editVisible"
      width="30rem"
      append-to-body
      :close-on-click-modal="false"
      destroy-on-close
    >
      <edit-line
        v-if="editVisible"
        @cancel="cancel"
        :dialogItem="dialogItem"
      ></edit-line>
    </el-dialog>
  </div>
</template>

<script>
import { getWarnLineList } from "@/api/xj/warningLine";
import EditLine from "./components/edit-line.vue";

export default {
  components: { EditLine },
  name: "WarningLine",
  data() {
    return {
      // 列表加载状态
      loading: false,
      // 列表数据
      warningLineList: [],
      // 编辑弹窗显隐控制
      editVisible: false,
      // 传弹窗数据
      dialogItem: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * @description: 获取列表数据
     * @param {*}
     * @return {*}
     */
    getList() {
      this.loading = true;
      getWarnLineList().then(({ code, data }) => {
        if(code===200){
          this.warningLineList = data;
        }
      }).finally(() => {
        this.loading = false;
      });
    },

    /**
     * @description: 列表点击编辑事件
     * @param {*} val
     * @return {*}
     */
    handleUpdate(val) {
      this.dialogItem = val;
      this.editVisible = true;
    },

    /**
     * @description: 关闭弹窗事件
     * @param {*} val
     * @return {*}
     */
    cancel() {
      this.editVisible = false;
      this.dialogItem = {};
      this.getList();
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  height: calc(100vh - 5.4rem);
  padding: 1rem;
  overflow-y: auto;
}
</style>
