<template>
  <div>
    <div class="gva-search-box">
      <el-form ref="searchForm" :inline="true" :model="searchInfo">
        <el-form-item label="姓名">
          <el-input clearable v-model="searchInfo.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="是否异常">
          <el-select clearable v-model="searchInfo.istrue" placeholder="请选择">
            <el-option label="正常" :value=1></el-option>
            <el-option label="异常" :value=2></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="归属公司">
           <el-select v-model="searchInfo.groupId" clearable placeholder="请选择所属公司">
            <el-option
              v-for="item in groupList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
          
        </el-form-item>

        <el-form-item label="选择日期">
          <el-date-picker
            v-model="searchInfo.time"
            type="date"
            placeholder="请选择上传日期"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          >
          </el-date-picker>
          <!-- <el-date-picker
            v-model="searchInfo.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker> -->
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
          <el-button size="mini" icon="el-icon-refresh" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="gva-table-box">
      
      <el-table :data="tableData" @sort-change="sortChange" @selection-change="handleSelectionChange">
        
        <el-table-column label="姓名" prop="name" />
        <el-table-column label="所在公司" prop="ID">
          <template #default="scope">
            {{scope.row.group}}
          </template>
        </el-table-column>
        <el-table-column label="所在部门" prop="ID">
          <template #default="scope">
            {{scope.row.department}}
          </template>
        </el-table-column>
        <el-table-column label="工号" prop="jobnumber" />
        <!-- <el-table-column label="是否上传行程码" prop="ID" /> -->
        <el-table-column label="是否异常" prop="isabnormal">
          <template #default="scope"> 
            <div>
              <el-tag v-if="scope.row.isabnormal==1">正常</el-tag>
              <el-tag v-else-if="scope.row.isabnormal==2" type="danger">异常</el-tag>
              <el-tag v-else type="info">未知</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="异常详情" prop="abnormalcont" />
        <el-table-column label="上传日期" prop="date" />
      </el-table>
      <div class="gva-pagination">
        <el-pagination
          :current-page="page"
          :page-size="pageSize"
          :page-sizes="[10, 30, 50, 100]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        >
        </el-pagination>
      </div>

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

<script>
// 获取列表内容封装在mixins内部  getTableData方法 初始化已封装完成 条件搜索时候 请把条件安好后台定制的结构体字段 放到 this.searchInfo 中即可实现条件搜索

import {
  getseportstatistics,
  
} from '@/api/healthy'
import {
  grouplist,
} from '@/api/group'
import infoList from '@/mixins/infoList'

export default {
  name: 'Api',
  
  mixins: [infoList],
  data() {
    return {
      groupList:"",
      deleteVisible: false,
      listApi: getseportstatistics,
      dialogFormVisible: false,
      dialogTitle: '新增Api',
      apis: [],
      form: {
        path: '',
        apiGroup: '',
        method: '',
        description: ''
      },
      type: '',
      rules: {
        path: [{ required: true, message: '请输入api路径', trigger: 'blur' }],
        apiGroup: [
          { required: true, message: '请输入组名称', trigger: 'blur' }
        ],
        method: [
          { required: true, message: '请选择请求方式', trigger: 'blur' }
        ],
        description: [
          { required: true, message: '请输入api介绍', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getTableData()
    this.getGroupList()
    // this.getseportstatisticsList()
  },
  methods: {
    // 获取公司架构
    async getGroupList(){
      const res=await grouplist()
      if(res.code==0){
        this.groupList=res.data.list
      }
    },
    // getseportstatisticsList(){
    //   const res = await getseportstatistics()
    //   if (res.code==0) {
    //   } else {
        
    //   }
    // },
    //  选中api
    handleSelectionChange(val) {
      this.apis = val
    },
    async onDelete() {
      const ids = this.apis.forEach(item => item.ID)
      const res = await deleteApisByIds({ ids })
      if (res.code === 0) {
        this.$message({
          type: 'success',
          message: res.msg
        })
        if (this.tableData.length === ids.length && this.page > 1) {
          this.page--
        }
        this.deleteVisible = false
        this.getTableData()
      }
    },
   
    onReset() {
      this.searchInfo = {}
    },
    // 条件搜索前端看此方法
    onSubmit() {
      this.page = 1
      this.pageSize = 10
      this.getTableData()
    },
    initForm() {
      this.$refs.apiForm.resetFields()
      this.form = {
        path: '',
        apiGroup: '',
        method: '',
        description: ''
      }
    },
    closeDialog() {
      this.initForm()
      this.dialogFormVisible = false
    },
    
  }
}
</script>

<style scoped lang="scss">
.button-box {
  padding: 10px 20px;
  .el-button {
    float: right;
  }
}
.warning {
  color: #dc143c;
}
</style>
