<template>
  <div>
    <template>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="全部" name="all">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="VIN码" prop="vin">
              <el-input
                v-model="queryParams.vin"
                placeholder="请输入VIN码"
                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="status">
              <el-select v-model="queryParams.status" clearable placeholder="状态">
                <el-option
                  v-for="dict in dict.type.sys_car_fault_log_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">
            <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handelExport">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="messageList" stripe @selection-chang="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="故障码" align="center" prop="faultCode" />
            <el-table-column label="VIN码" align="center" prop="vin" />
            <el-table-column label="开始时间" align="center" prop="createTime" />
            <el-table-column label="结束时间" align="center" prop="updateTime" />
            <el-table-column align="center" label="状态" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_car_fault_log_status" :value="scope.row.status" />
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />

        </el-tab-pane>
        <el-tab-pane label="解决" name="resolve">

          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="VIN码" prop="vin">
              <el-input
                v-model="queryParams.vin"
                placeholder="请输入VIN码"
                clearable
                @ceyup.enter.native="handleQuery"
            />
            </el-form-item>
            <el-form-item label="故障码" prop="faultCode">
              <el-input
                v-model="queryParams.faultCode"
                placeholder="请输入故障码"
                clearable
                @ceyup.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 icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <rl-row>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getListSolve"></right-toolbar>
          </rl-row>
          <el-table v-loading="loading" :data="StatusSolveList" stripe>
            <el-table-column label="故障码" align="center" prop="faultCode" />
            <el-table-column label="VIN码" align="center" prop="vin" />
            <el-table-column label="开始时间" align="center" prop="createTime" />
            <el-table-column label="结束时间" align="center" prop="updateTime" />

          </el-table>
          <pagination
            v-show="totalSolve > 0"
            :total="totalSolve"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getListSolve"
          />
        </el-tab-pane>
        <el-tab-pane label="处理中" name="processing">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="VIN码" prop="vin">
              <el-input
                v-model="queryParams.vin"
                placeholder="请输入VIN码"
                clearable
                @ceyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="故障码" prop="faultCode">
              <el-input
                v-model="queryParams.faultCode"
                placeholder="请输入故障码"
                clearable
                @ceyup.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 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="warning"
                plain
                icon="el-icon-edit"
                size="mini"
                @click="handleUpdateStatusIgnore">忽略</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
          <el-table v-loading="loading" :data="StatusProcessList" stripe @selection-chang="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="故障码" align="center" prop="faultCode" />
            <el-table-column label="VIN码" align="center" prop="vin" />
            <el-table-column label="开始时间" align="center" prop="createTime" />
            <el-table-column label="结束时间" align="center" prop="updateTime" />
            <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="handleUpdateStatusIgnore(scope.row)">
                  忽略
                </el-button>
              </template>
            </el-table-column>

          </el-table>
          <pagination
            v-show="totalProcess > 0"
            :total="totalProcess"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getListProcess"
          />
        </el-tab-pane>
        <el-tab-pane label="忽略" name="ignore">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="VIN码" prop="vin">
              <el-input
                v-model="queryParams.vin"
                placeholder="请输入VIN码"
                clearable
                @ceyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="故障码" prop="faultCode">
              <el-input
                v-model="queryParams.faultCode"
                placeholder="请输入故障码"
                clearable
                @ceyup.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 icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <rl-row>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </rl-row>
          <el-table v-loading="loading" :data="StatusIgnoreList" stripe>
            <el-table-column label="故障码" align="center" prop="faultCode" />
            <el-table-column label="VIN码" align="center" prop="vin" />
            <el-table-column label="开始时间" align="center" prop="createTime" />
            <el-table-column label="结束时间" align="center" prop="updateTime" />
          </el-table>
          <pagination
            v-show="totalIgnore > 0"
            :total="totalIgnore"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getListIgnore"
          />
        </el-tab-pane>
      </el-tabs>


    </template>
  </div>
</template>

<script>
import {
  listLog,
  listStatusIgnore,
  listStatusProcess,
  listStatusSolve,
  updateStatusById
} from '/src/api/breakdown/Log'

export default {
  dicts:['sys_car_fault_log_status'],
  name:"log",
  components:{},
  props:{},
  data() {
    return {
      //选中数组
      ids:[],
      //非单个禁用
      single:true,
      //非多个禁用
      multiple:true,
      activeName:'all',
      loading:true,
      messageList:[],
      StatusSolveList:[],
      StatusProcessList:[],
      StatusIgnoreList:[],
      //总条数
      total:0,
      totalIgnore:0,
      totalProcess:0,
      totalSolve:0,
      // 显示搜索条件
      showSearch: true,
      queryParams:{
        pageNum:1,
        pageSize:10,
        vin:null,
        status:null,
        faultCode:null
      }
    };
  },
  computed:{},
  watch:{},
  methods:{
    handleClick(tab,event) {
      console.log(tab,event);
      this.getList();
    },
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        this.messageList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });

    },
    getListIgnore(){
      listStatusIgnore(this.queryParams).then(response => {
        this.StatusIgnoreList = response.data.rows;
        this.totalIgnore = response.data.total;
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },
    getListProcess(){
      listStatusProcess(this.queryParams).then(response=>{
        this.StatusProcessList=response.data.rows;
        this.totalProcess=response.data.total;
        this.loading=false;
      }).catch(()=>{
        this.loading=false
      })
    },
    getListSolve(){
      listStatusSolve(this.queryParams).then(response=>{
        this.StatusSolveList=response.data.rows;
        this.totalSolve=response.data.total;
        this.loading=false;
      }).catch(()=>{
        this.loading=false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handelExport(){
      this.download('breakdown/log/export',{
        ...this.queryParams
      },`log_${new Date().getTime()}.xlsx`)
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleUpdateStatusIgnore(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认忽略编号为"' + ids + '"的数据项？').then(function() {
        return updateStatusById(ids);
      }).then(() => {
        this.getListIgnore();
        this.$modal.msgSuccess("忽略成功");
      }).catch(() => {});
    },
  },
  created() {
    this.getList();
    this.getListIgnore()
    this.getListProcess()
    this.getListSolve()
  },

};
</script>

<style scoped>
.el-table {
  width:100%;
}
.el-pagination {
  margin:20px 0;
  text-align:right;
}
</style>

