<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="故障名称" prop="faultName">
        <el-input
          v-model="queryParams.faultName"
          placeholder="请输入故障名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="故障码" prop="faultCode">
        <el-input
          v-model="queryParams.faultCode"
          placeholder="请输入故障码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否产生报警" prop="alarmFlag" :label-width="100">
        <el-select v-model="queryParams.alarmFlag" placeholder="请选择是否产生报警" clearable size="mini">
          <el-option
            v-for="dict in dict.type.vehicle_alarm_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <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">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="faultCodesList" @selection-change="handleSelectionChange">
      <el-table-column label="故障码" align="center" prop="faultCode" />
      <el-table-column label="故障名称" align="center" prop="faultName" />
      <el-table-column label="故障类型" align="center" prop="faultType">
        <template slot-scope="scope">
<!--          <span v-if="scope.row.faultType==1">通讯丢失故障</span>-->
<!--          <span v-if="scope.row.faultType==2">车身故障</span>-->
<!--          <span v-if="scope.row.faultType==3">底盘故障</span>-->
<!--          <span v-if="scope.row.faultType==4">电子围栏故障</span>-->
<!--          <span v-if="scope.row.faultType==5">其他故障</span>-->
            <dict-tag :options="dict.type.fault_type" :value="scope.row.faultType"/>
        </template>
      </el-table-column>
      <el-table-column label="故障等级" align="center" prop="faultLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fault_level" :value="scope.row.faultLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="是否产生报警" align="center" prop="alarmFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.vehicle_alarm_status" :value="scope.row.alarmFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="故障描述" align="center" prop="faultDesc" />
      <el-table-column label="故障位" align="center" prop="faultLocation" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listFaultCodes } from '@/api/business/fault_code_info'

export default {
  name: "FaultCodes",
  dicts: ['fault_type','fault_level','vehicle_alarm_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 故障码表格数据
      faultCodesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        faultName: null,
        faultCode: null,
        alarmFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询故障码列表 */
    getList() {
      this.loading = true;
      listFaultCodes(this.queryParams).then(res => {
        this.faultCodesList = res.data.rows;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
