<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-input
          v-model="query.name"
          clearable
          size="small"
          placeholder="请输入姓名"
          style="width: 160px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="query.type"
          filterable
          clearable
          size="small"
          placeholder="请选择人员类型"
          class="filter-item"
          style="width: 160px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.PersonType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-cascader
          v-model="query.department"
          filterable
          :options="optionsObj.Department"
          :props="{ checkStrictly: true, emitPath: false }"
          clearable
          size="small"
          placeholder="请选择部门"
          style="width: 160px;"
          class="filter-item"
        />
        <el-select
          v-model="query.position"
          filterable
          clearable
          size="small"
          placeholder="请选择职位"
          class="filter-item"
          style="width: 160px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.Position"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-input
          v-model="query.railAreaName"
          clearable
          size="small"
          placeholder="请输入围栏区域名称"
          style="width: 160px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
          <date-range-picker
          type="datetimerange"
          v-model="datetimeRange"
          class="date-item"
          style="width: 400px !important;"
          @change="handleDatetimeRange"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
    </div>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      style="width: 100%;"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column
        v-for="item in railAreaInOutLogTableOptions"
        :key="item.prop"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        :align="item.align"
        :fixed="item.fixed"
        :sortable="item.sortable"
      ></el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import permission from '@/directive/permission'
import DateRangePicker from '@/components/DateRangePicker'
import crudRailAreaInOutLog from '@/api/positioning/railAreaInOutLog'
import { getOptions } from '@/api/positioning/public'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import { crudOperation, rrOperation, udOperation, pagination } from '@crud'
import crudComps from '@crud'
import { railAreaInOutLogTableOptions } from '../tableConfig'
import Dayjs from 'dayjs'
const defaultForm = {
  id: "",
}

export default {
  name: 'RailAreaInOutLog',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps,DateRangePicker },
  cruds() {
    return CRUD({
      title: '进出记录',
      url: 'positioning/railAreaInOutLog/getPageListJson',
      listOrder: [],
      crudMethod: { ...crudRailAreaInOutLog },
      optShow: { add: false, edit: false, del: false },
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    }
  },
  created() {
    this.getOptions()
  },
  data() {
    return {
      datetimeRange : undefined,
      railAreaInOutLogTableOptions,
      viewLoading: false,
      permission: {
        del: ['admin', 'railAreaInOutLog:del']
      },
      optionsObj: {
        PersonType: [],
        Department: [],
        Position: []
      },
    }
  },
  methods: {
    getOptions() {
      Object.keys(this.optionsObj).forEach(async key => {
        try {
          let res = await getOptions(key, {})
          if (res.code === 20000) this.optionsObj[key] = res.data.content
        } catch (error) {
          console.log(error)
        }
      })
    },
    handleDatetimeRange(range) {
      if (range){
        this.query.startTime = range[0]
        this.query.endTime = range[1]
      }
    }
  }
}
</script>

<style></style>
