<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-__mastertopicuserbrowse}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <div>
          <el-form-item>
            <el-button type="primary" @click="backToDeptList(dataForm.id)">返回</el-button>
          </el-form-item>
        </div>
        <el-form-item label="用户名" prop="nickName">
          <el-input v-model="dataForm.nickName" placeholder="用户名" clearable></el-input>
        </el-form-item>
        <el-form-item label="时间" prop="startTime">
          <el-date-picker
              v-model="dataForm.startTime"
              type="date"
              :picker-options="pickerBeginDateBefore"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              placeholder="选择日期时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="至" label-width="25px" prop="endTime">
          <el-date-picker
              v-model="dataForm.endTime"
              type="date"
              :picker-options="pickerBeginDateAfter"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              placeholder="选择日期时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column label="序号" header-align="center" align="center" width="50px">
          <template slot-scope="scope">
            {{scope.$index+1}}
          </template>
        </el-table-column>
        <el-table-column prop="nickName" label="浏览人-用户名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createdTime" label="浏览时间" header-align="center" align="center"></el-table-column>
      </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">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './mastertopicuserbrowse-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/cloudAnalysis/mastertopicuserbrowse/page',
        getDataListIsPage: true,
        deleteURL: '/cloudAnalysis/mastertopicuserbrowse',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      },
      pickerBeginDateBefore: {
        disabledDate: time => {
          let beginDateVal = this.dataForm.startTime
          if (beginDateVal) {
            return time.getTime() > new Date(beginDateVal).getTime()
          }
        }
      },
      pickerBeginDateAfter: {
        disabledDate: time => {
          let EndDateVal = this.dataForm.endTime
          if (EndDateVal) {
            return time.getTime() < new Date(EndDateVal).getTime()
          }
        }
      }
    }
  },
  components: {
    AddOrUpdate
  },
  mounted () {
    this.dataForm.id = this.$route.query.topicId
    this.getDataList()
  },
  methods: {
    backToDeptList (topicId) {
      this.$parent.selectComponent = 'Mastertopicdetail'
      this.$router.push({ path: '/master-mastertopicroute', query: { topicId: topicId } })
    }
  }
}
</script>
