<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="filter-wrapper">
      <el-form :inline="true" :model="dataForm" @submit.native.prevent @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="input" placeholder="关键词" class="input-with-select" clearable>
            <el-select slot="prepend" v-model="select" placeholder="请选择">
              <el-option label="工号" value="operateUserJobNumber" />
              <el-option label="用户姓名" value="operateUserName" />
              <el-option label="用户操作" value="operateInfo" />
            </el-select>
            <el-button slot="append" icon="el-icon-search" @click="getDataList()">{{ $t('query') }}</el-button>
          </el-input>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        style="width: 100%;"
        @sort-change="dataListSortChangeHandle"
      >
        <el-table-column prop="operateUserJobNumber" :label="'工号'" header-align="center" align="center" width="120" />
        <el-table-column prop="operateUserName" :label="'用户姓名'" header-align="center" align="center" width="120" />
        <el-table-column prop="operateInfo" :label="'用户操作'" />
        <el-table-column prop="projectName" :label="'课题'" header-align="center" align="center" show-overflow-tooltip />
        <el-table-column prop="operateTime" :label="'操作时间'" header-align="center" sortable="custom" width="180" />
      </el-table>
      <!-- 分页 -->
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      />
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/operate/log/page',
        getDataListIsPage: true
      },
      select: 'operateInfo',
      input: '',
      dataForm: {
        projectId: this.$route.query.projectId,
        operateUserJobNumber: '',
        operateUserName: '',
        operateInfo: '',
      }
    }
  },
  watch: {
    select(val) { this.dataFormHandle() },
    input(val) { this.dataFormHandle() }
  },
  methods: {
    dataFormHandle() {
      const inputValue = !(this.input) ? null : this.input
      switch (this.select) {
        case 'operateUserName':
          this.dataForm.operateUserName = inputValue
          this.dataForm.operateUserJobNumber = ''
          this.dataForm.operateInfo = ''
          break
        case 'operateUserJobNumber':
          this.dataForm.operateUserJobNumber = inputValue
          this.dataForm.operateUserName = ''
          this.dataForm.operateInfo = ''
          break
        case 'operateInfo':
          this.dataForm.operateInfo = inputValue
          this.dataForm.operateUserJobNumber = ''
          this.dataForm.operateUserName = ''
          break
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.input-with-select {
  width: 500px;

  ::v-deep .el-select .el-input {
    width: 120px;
  }

  ::v-deep .el-input-group__prepend {
    background-color: #fff;
  }
}
</style>
