<template>
  <div class="layout-no-cols">
    <div class="tar">
      <el-row type="flex" class="row-bg" justify="end" v-if="!isComplexSearch">
        <el-col :span="6" >
          <el-input v-model="contentOperateLog.search.content" placeholder="内容名称或ID" @keyup.enter.native="searchLogsClickHandler"></el-input>
        </el-col>
        <el-col :span="4">
          <el-button-group>
            <el-button @click="searchLogsClickHandler">
              <i class="fa fa-search"></i>搜索
            </el-button>
            <el-button @click="isComplexSearch=!isComplexSearch">高级搜索 ...</el-button>
          </el-button-group>
        </el-col>
      </el-row>
      <template v-else>
        <el-row type="flex" class="row-bg" justify="space-around" align="middle">
          <el-col :span="6">
            <el-input v-model="contentOperateLog.search.userName" @keyup.enter.native="searchLogsClickHandler" placeholder="用户名"></el-input>
          </el-col>
          <el-col :span="6">
            <tree-select class="layout-select" :value.sync="contentOperateLog.search.catalogID" :items="catalogTrees" clearable placeholder="栏目名称"></tree-select>
          </el-col>
          <el-col :span="10">
            <el-date-picker id="contentOperateLog-date-picker" class="layout-date-picker" v-model="contentOperateLog.search.dateInterval" type="datetimerange" placeholder="选择日志时间范围" style="width:100%"></el-date-picker>
          </el-col>
        </el-row>
        <div style="padding:3px"></div>
        <el-row type="flex"  class="row-bg" justify="space-around">
          <el-col :span="6">
            <el-input v-model="contentOperateLog.search.content" @keyup.enter.native="searchLogsClickHandler" placeholder=" 内容名称或ID"></el-input>
          </el-col>
          <el-col :span="6">
            <el-select class="layout-select" v-model="contentOperateLog.search.actionResult" clearable placeholder="操作结果" @change="searchLogsClickHandler">
              <el-option label="成功" value="S"></el-option>
              <el-option label="失败" value="F"></el-option>
            </el-select>
          </el-col>
          <el-col :span="10">
            <el-button-group style="float:left">
              <el-button  type="primary" @click="searchLogsClickHandler">
                <i class="fa fa-search"></i>高级搜索
              </el-button>
              <el-button @click="isComplexSearch=!isComplexSearch">搜索 ...</el-button>
            </el-button-group>
          </el-col>
        </el-row>
      </template>
    </div>

      <el-list-view ref="dataTable1" :data-read-url="getOperateLogUrl" :pageSize="10">
        <template slot-scope="item">
          <div class="panel-card">
            <div class="card-header">
              <el-row>
                <el-col :span="12">
                  <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>
              <el-col :span="8">
                <span>用户名：<em>{{item.addUser}}</em></span>
              </el-col>
              <el-col :span="8">
                <span>操作类型：<em>{{item.actionName}}</em></span>
              </el-col>
              <el-col :span="8">
                <span>内容类型：<em>{{item.contentTypeName}}</em></span>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <span>栏目：<em>{{item.catalogName}}({{item.catalogID}})</em></span>
              </el-col>
              <el-col :span="16">
                <span>内容(ID)：<em>{{item.contentTitle}}({{item.dataID}})</em></span>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <span>操作明细：<em>{{item.actionDetail}}</em></span>
              </el-col>
            </el-row>
          </div>
          </div>
        </template>
      </el-list-view>
  </div>
</template>

<script>
import util from '@src/common/util.js'
import TreeSelect from '@src/components/TreeSelect.vue'
export default {
  filters: {
    fixDateTime: function(val) {
      if (!val) {
        return ''
      }
      return util.formatDate(val, 'yyyy-MM-dd HH:mm')
    }
  },
  data() {
    return {
      isComplexSearch: false,
      catalogTrees: [],
      contentOperateLog: {
        search: {
          userName: '',
          catalogID: '',
          dateInterval: [],
          content: '',
          actionResult: ''
        }
      }
    }
  },
  methods: {
    getOperateLogUrl() {
      const userName = this.contentOperateLog.search.userName
      const catalogID = this.contentOperateLog.search.catalogID
      const dateInterval = this.contentOperateLog.search.dateInterval
      const actionResult = this.contentOperateLog.search.actionResult
      const searchname = encodeURI(encodeURI(this.contentOperateLog.search.content))
      return [
        '/ui/contentlogs/operateLogs',
        {
          params: {
            userName,
            catalogID,
            startTime: dateInterval && dateInterval.length ? Date.parse(dateInterval[0]) : null,
            endTime: dateInterval && dateInterval.length > 1 ? Date.parse(dateInterval[1]) : null,
            searchname,
            actionResult
          }
        }
      ]
    },
    searchLogsClickHandler() {
      this.$refs.dataTable1.getData(1)
    },
    async initTreeSelect() {
      let editTree = await axios.get('/ui/catalog/bindeditortree')
      this.catalogTrees = editTree.data.data
    }
  },
  created() {
    this.initTreeSelect()
  },
  components: {
    'tree-select': TreeSelect
  }
}
</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;
  }
</style>
