<template>
  <div>
    <!-- 头部导航栏 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>小工具</el-breadcrumb-item>
      <el-breadcrumb-item>构建记录</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <div class="filter">
        <!-- job下拉框 -->
        <el-select v-model="queryInfo.jobName" placeholder="请选择任务">
          <el-option v-for="item in jobList" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <el-input v-model="queryInfo.num" placeholder="请输入个数"></el-input>
        <el-input v-model="queryInfo.project" placeholder="请输入项目名"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="getBuildList">搜索</el-button>
      </div>
      <!-- build信息列表 -->
      <el-table :data="buildList" border style="width: 100%">
        <el-table-column prop="project" label="项目" width="150">
        </el-table-column>
        <el-table-column prop="branch" label="分支" width="280">
        </el-table-column>
        <el-table-column prop="namespace" label="namespace" width="150">
        </el-table-column>
        <el-table-column prop="userName" label="用户" width="180">
        </el-table-column>
        <el-table-column prop="result" label="构建结果" width="150">
        </el-table-column>
        <el-table-column prop="createAt" label="构建时间">
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getBuildList, getJobList } from '@/api/effect'
export default {
  data() {
    return {
      buildList: [],
      jobList: [],
      queryInfo: {
        jobName: 'tke-java',
        num: 10,
        project: null
      }
    }
  },
  methods: {
    // 获取构建列表
    getBuildList() {
      if (isNaN(this.queryInfo.num) === true) {
        return this.$message.error('获取数量请输入数字！')
      }
      getBuildList(this.queryInfo)
        .then((resp) => {
          this.buildList = resp.data.data
        })
        .catch((error) => {
          console.log(error)
        })
    },
    // 获取任务列表
    getJobList() {
      getJobList()
        .then((resp) => {
          this.jobList = resp.data.data
        })
        .catch((error) => {
          console.log(error)
          return this.$message.error('服务器异常！')
        })
    }
  },
  created() {
    this.getBuildList()
    this.getJobList()
  }
}
</script>

<style lang="less" scoped>
.filter {
  margin-bottom: 20px;
}

.el-input {
  width: 200px;
  margin-right: 10px;
}
</style>
