<template>
  <el-container>
    <el-header>
      <div class="left-panel"></div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input
            v-model="query.id"
            placeholder="logId"
            clearable
          ></el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="handleQuery"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        row-key="id"
        stripe
        highlightCurrentRow
        @row-click="rowClick"
        @resetQuery="resetQuery"
      >
        <el-table-column label="#" type="index" width="50"></el-table-column>
        <el-table-column
          label="日志id"
          prop="id"
          min-width="200"
        ></el-table-column>
        <el-table-column
          label="地址"
          prop="path"
          min-width="220"
        ></el-table-column>
        <el-table-column label="method" prop="method" min-width="80">
        </el-table-column>
        <el-table-column
          label="view"
          prop="view"
          min-width="150"
        ></el-table-column>
        <el-table-column label="状态码" prop="status_code" min-width="50">
          <template #default="scope">
            <el-tag
              class="ml-2"
              type="success"
              v-if="scope.row.status_code >= 200 && scope.row.status_code < 300"
              >{{ scope.row.status_code }}</el-tag
            >
            <el-tag
              class="ml-2"
              type="warning"
              v-if="scope.row.status_code >= 400 && scope.row.status_code < 500"
              >{{ scope.row.status_code }}</el-tag
            >
            <el-tag
              class="ml-2"
              type="danger"
              v-if="scope.row.status_code >= 500"
              >{{ scope.row.status_code }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column
          label="操作时间"
          prop="requested_at"
          min-width="100"
        ></el-table-column>
        <el-table-column label="操作" align="center" width="80">
          <el-button type="text" size="small">查看</el-button>
        </el-table-column>
      </scTable>
    </el-main>
    <el-drawer
      v-model="infoDrawer"
      title="日志详情"
      :size="'50%'"
      destroy-on-close
    >
      <logInfo ref="logInfo"></logInfo>
    </el-drawer>
  </el-container>
</template>
<script>
import logInfo from "./logInfo";
export default {
  name: "logs",
  components: {
    logInfo,
  },
  data() {
    return {
      apiObj: this.$API.ops.logs.list,
      query: {},
      logLists: [],
      infoDrawer: false,
      logDetailVisible: false,
    };
  },
  mounted() {},
  methods: {
    handleQuery() {
      this.$refs.table.queryData(this.query);
    },
    resetQuery() {
      this.query = {};
    },
    rowClick(row) {
      this.infoDrawer = true;
      this.$nextTick(() => {
        this.$refs.logInfo.setData(row);
      });
    },
  },
};
</script>
<style scoped>
.treeMain {
  height: 280px;
  overflow: auto;
  border: 1px solid #dcdfe6;
  margin-bottom: 10px;
}
</style>
