<template>
  <div class="layout-no-cols">
    <div class="tar">
      <el-row type="flex" class="row-bg" justify="end">
        <el-col :span="10">
          <el-input v-model="cronLog.search.message" placeholder="原始消息" @keyup.enter.native="searchLogsClickHandler" size="medium">
              <el-select placeholder="" clearable slot="prepend"  v-model="cronLog.search.subType" @change="searchLogsClickHandler">
                <el-option label="所有类型" value=""></el-option>
                <el-option label="任务开始" value="start"></el-option>
                <el-option label="任务结束" value="end"></el-option>
            </el-select>
            </el-input>
            <span class="search-icon"><i class="fa fa-search" @click="searchLogsClickHandler" title="查询"></i></span>
        </el-col>
      </el-row>
    </div>
      <el-list-view ref="dataTable1" :data-read-url="getCronLogsUrl" :pageSize="10">
        <template slot-scope="item">
          <div class="panel-card">
            <div class="card-header">
              <el-row>
                <el-col :span="24">
                  <span class="f12"><i class="fa fa-clock-o"></i>{{item.addTime | fixDateTime}}</span>
                </el-col>
              </el-row>
            </div>
          <div class="card-content">
            <el-row v-if="item.userName !='-' && item.IP !='-'">
              <el-col :span="12">
                <span>用户名：<em>{{item.userName}}</em></span>
              </el-col>
              <el-col :span="12">
                <span>IP地址：<em>{{item.IP}}</em></span>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <span>原始消息：<em>{{item.logMessage}}</em></span>
              </el-col>
            </el-row>
          </div>
          </div>
        </template>
      </el-list-view>
  </div>
</template>

<script>
import util from '@src/common/util.js'
export default {
  filters: {
    fixDateTime: function(val) {
      if (!val) {
        return ''
      }
      return util.formatDate(val, 'yyyy-MM-dd HH:mm')
    }
  },
  data() {
    return {
      cronLog: {
        search: {
          subType: '',
          message: ''
        }
      }
    }
  },
  methods: {
    getCronLogsUrl() {
      const subType = this.cronLog.search.subType
      const message = this.cronLog.search.message
      return [
        '/ui/logs/cronlog',
        {
          params: {
            subType,
            message
          }
        }
      ]
    },
    searchLogsClickHandler() {
      this.$refs.dataTable1.getData(1)
    }
  }
}
</script>

<style scoped>
  .panel-card {
    padding: 0px;
    margin: 10px auto 20px;
  }

  .panel-card .card-header{
    background-color: #fafafa;
    padding: 10px 15px;
  }

  .card-content{
    padding: 10px 15px;
  }
  .search-icon {
    top: 9px;
    right: 8px;
  }
</style>
