<template>
  <div class="app-container">

    <el-tabs v-model="activeName" type="card" >
    <el-tab-pane label="单机故障预警" name="first">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" inline label-position="top">
        <el-row :gutter="20">
          <el-col :span="8"><el-form-item label="故障率较高飞机" prop="highFaultPlanes">
          <el-switch
            style="display: block"
            v-model="form.highFaultPlanes"
            active-color="#13ce66"
            inactive-color="#ff9977"
            active-text="禁用"
            inactive-text="启用"
            active-value="true"
            inactive-value="false"
            @change="submitForm">
          </el-switch>
        </el-form-item></el-col>
          <el-col :span="8"><el-form-item label="单机当月故障" prop="monthPlaneFaults">

          <el-switch
            style="display: block"
            v-model="form.monthPlaneFaults"
            active-color="#13ce66"
            inactive-color="#ff9977"
            active-text="禁用"
            inactive-text="启用"
            active-value="true"
            inactive-value="false"
            @change="submitForm"
            ></el-switch>
        </el-form-item></el-col>
          <el-col :span="8"> <el-form-item label="月份系统故障" prop="monthSysFaults">

          <el-switch
            style="display: block"
            v-model="form.monthSysFaults"
            active-color="#13ce66"
            inactive-color="#ff9977"
            active-text="禁用"
            inactive-text="启用"
            active-value="true"
            inactive-value="false"
            @change="submitForm"
            ></el-switch>
        </el-form-item></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8"> <el-form-item label="月份机件故障" prop="monthPartFaults">

          <el-switch
            style="display: block"
            v-model="form.monthPartFaults"
            active-color="#13ce66"
            inactive-color="#ff9977"
            active-text="禁用"
            inactive-text="启用"
            active-value="true"
            inactive-value="false"
            @change="submitForm"
            ></el-switch>
        </el-form-item></el-col>
          <el-col :span="8"> <el-form-item label="三月未处理故障" prop="threeMonthOpen">

          <el-switch
            style="display: block"
            v-model="form.threeMonthOpen"
            active-color="#13ce66"
            inactive-color="#ff9977"
            active-text="禁用"
            inactive-text="启用"
            active-value="true"
            inactive-value="false"
            @change="submitForm"
            ></el-switch>
        </el-form-item></el-col>
        </el-row>
      </el-form>
    </el-tab-pane>
    <el-tab-pane label="专业故障预警" name="second">

      <el-form ref="form" :model="form" :rules="rules" label-width="120px" inline label-position="top">
        <el-row :gutter="20">
          <el-col :span="8">  <el-form-item label="上月系统异常" prop="lastSysErrors">

          <el-switch
            style="display: block"
            v-model="form.lastSysErrors"
            active-color="#13ce66"
            inactive-color="#ff9977"
            active-value="true"
            inactive-value="false"
            active-text="禁用"
            inactive-text="启用"
            @change="submitForm"
            ></el-switch>
        </el-form-item></el-col>
          <el-col :span="8"> <el-form-item label="上月机件异常" prop="lastPartErrors">
          <el-switch
            style="display: block"
            v-model="form.lastPartErrors"
            active-color="#13ce66"
            inactive-color="#ff9977"
            active-value="true"
            inactive-value="false"
            active-text="禁用"
            inactive-text="启用"
            @change="submitForm"
            ></el-switch>
        </el-form-item></el-col>
        </el-row>
      </el-form>
    </el-tab-pane>
  </el-tabs>
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['fault:faultSetting:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['fault:faultSetting:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['fault:faultSetting:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fault:faultSetting:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <!-- <el-table v-loading="loading" :data="faultSettingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="故障率较高飞机" align="center" prop="highFaultPlanes" />
      <el-table-column label="单机当月故障" align="center" prop="monthPlaneFaults" />
      <el-table-column label="月份系统故障" align="center" prop="monthSysFaults" />
      <el-table-column label="月份机件故障" align="center" prop="monthPartFaults" />
      <el-table-column label="三月未处理故障" align="center" prop="threeMonthOpen" />
      <el-table-column label="上月系统异常" align="center" prop="lastSysErrors" />
      <el-table-column label="上月机件异常" align="center" prop="lastPartErrors" />
      <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)"
            v-hasPermi="['fault:faultSetting:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fault:faultSetting: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"
    />-->

    <!-- 添加或修改预警设置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" inline label-position="top">
        <el-row :gutter="20">
          <el-col :span="8"><el-form-item label="故障率较高飞机" prop="highFaultPlanes">
          <el-input v-model="form.highFaultPlanes" placeholder="请输入故障率较高飞机" />
        </el-form-item></el-col>
          <el-col :span="8"><el-form-item label="单机当月故障" prop="monthPlaneFaults">
          <el-input v-model="form.monthPlaneFaults" placeholder="请输入单机当月故障" />
        </el-form-item></el-col>
          <el-col :span="8"> <el-form-item label="月份系统故障" prop="monthSysFaults">
          <el-input v-model="form.monthSysFaults" placeholder="请输入月份系统故障" />
        </el-form-item></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8"> <el-form-item label="月份机件故障" prop="monthPartFaults">
          <el-input v-model="form.monthPartFaults" placeholder="请输入月份机件故障" />
        </el-form-item></el-col>
          <el-col :span="8"> <el-form-item label="三月未处理故障" prop="threeMonthOpen">
          <el-input v-model="form.threeMonthOpen" placeholder="请输入三月未处理故障" />
        </el-form-item></el-col>
          <el-col :span="8">  <el-form-item label="上月系统异常" prop="lastSysErrors">
          <el-input v-model="form.lastSysErrors" placeholder="请输入上月系统异常" />
        </el-form-item></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8"> <el-form-item label="上月机件异常" prop="lastPartErrors">
          <el-input v-model="form.lastPartErrors" placeholder="请输入上月机件异常" />
        </el-form-item></el-col>
          <el-col :span="8">  <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" style="width: 105%;"/>
        </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>
  </div>
</template>

<script>
import { listFaultSetting, getFaultSetting, delFaultSetting, addFaultSetting, updateFaultSetting } from "@/api/fault/faultSetting";

export default {
  name: "FaultSetting",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预警设置表格数据
      faultSettingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      activeName:'first'
    };
  },
  created() {
    this.form.id=1;
    this.getFaultSetting();
  },
  methods: {
    /** 查询预警设置列表 */
    getFaultSetting() {
      getFaultSetting(this.form.id).then(response => {
        this.form = response.data;

      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: 0,
        highFaultPlanes: null,
        monthPlaneFaults: null,
        monthSysFaults: null,
        monthPartFaults: null,
        threeMonthOpen: null,
        lastSysErrors: null,
        lastPartErrors: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        column9: 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
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预警设置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFaultSetting(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预警设置";
      });
    },
    /** 提交按钮 */
    submitForm() {

      updateFaultSetting(this.form).then(response => {
        this.$modal.msgSuccess("设置成功");
        getFaultSetting(this.form.id).then(response => {
          this.form = response.data;
        });
      });



    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除预警设置编号为"' + ids + '"的数据项？').then(function() {
        return delFaultSetting(ids);
      }).then(() => {
       // this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fault/faultSetting/export', {
        ...this.queryParams
      }, `faultSetting_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
