<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <date-range-picker
          type="datetimerange"
          v-model="query.datatimevalue"
          class="date-item"
          style="width: 400px !important;"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission"> </crudOperation>
    </div>
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :visible.sync="showMap"
      title="查看报警位置"
      width="1000px"
    >
      <my-map />
    </el-dialog>
    <!--表格渲染-->
    <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 perimeterTableOptions"
        :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-column
        v-if="checkPer(['admin', 'perimeter:edit', 'perimeter:del'])"
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button size="mini" icon="el-icon-view" @click="showDetail(scope.row.id)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import permission from '@/directive/permission'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import { crudOperation, rrOperation, udOperation, pagination } from '@crud'
import crudComps from '@crud'
import DateRangePicker from '@/components/DateRangePicker'
import { perimeterTableOptions } from '../tableConfig'
import Dayjs from 'dayjs'
import MyMap from './myMap.vue'
const defaultForm = {
  id: '',
  positionName: '',
  positionSort: 999,
  enabled: true
}

export default {
  name: 'Perimeter',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker, MyMap },
  cruds() {
    return CRUD({
      title: '周界报警',
      url: 'alarm/perimeter/getList',
      listOrder: [],
      //crudMethod: { ...crudBeacon },
      optShow: {},
      query: {
        datatimevalue: [
          Dayjs()
            .subtract(1, 'month')
            .format('YYYY-MM-DD HH:mm:ss'),
          Dayjs().format('YYYY-MM-DD HH:mm:ss')
        ]
      }
    })
  },
  data() {
    return {
      perimeterTableOptions,
      permission: {
        add: ['admin', 'perimeter:add'],
        edit: ['admin', 'perimeter:edit'],
        del: ['admin', 'perimeter:del']
      },
      showMap: false
    }
  },
  methods: {
    showDetail() {
      this.showMap = true
    }
  }
}
</script>
