<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-select
          v-model="query.perimeterId"
          filterable
          clearable
          size="small"
          placeholder="请选择周界"
          class="filter-item"
          style="width: 160px"
          @change="perimeterChangeHandle"
        >
          <el-option
            v-for="item in optionsObj.Perimeter"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select
          v-model="query.segmentId"
          filterable
          clearable
          size="small"
          placeholder="请选择分段"
          class="filter-item"
          style="width: 160px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.Segment"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <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.AlarmType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <date-range-picker
          type="datetimerange"
          v-model="customs.timeRange"
          class="date-item"
          style="width: 400px !important"
          @change="crud.toQuery"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
    </div>
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :visible.sync="dialogVisible"
      title="报警地图"
      width="800px"
    >
      
    </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 perimeterAlarmTableOptions"
        :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 label="操作" width="130px" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            icon="el-icon-view"
            @click="toView(scope.row)"
            style="margin-right: 5px"
          />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

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

export default {
  name: 'PerimeterAlarm',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker },
  cruds() {
    return CRUD({
      title: '周界报警记录',
      url: 'perimeter/alarm/getListJson',
      listOrder: [],
      //crudMethod: { ...crudRailAreaInOutLog },
      optShow: { add: false, edit: false, del: false },
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    },
    VUE_APP_BASE_API() {
      return process.env.VUE_APP_BASE_API
    },
  },
  created() {
    this.getOptions()
  },
  data() {
    return {
      dialogVisible: false,
      dialogType: '',
      datetimeRange: undefined,
      perimeterAlarmTableOptions,
      viewLoading: false,
      permission: {},
      optionsObj: {
        Perimeter: [],
        Segment: [],
        AlarmType: [],
      },
    }
  },
  methods: {
    toView(data) {
      this.form = data
      ;(this.dialogType = 'view'), (this.dialogVisible = true)
    },
    closeDialog() {
      this.dialogVisible = false
    },
    async perimeterChangeHandle(data) {
      this.query.minorType = ''
      if (data) await this.getSegmentOptions(data)
      else this.optionsObj['Segment'] = []
      this.crud.toQuery()
    },
    async getOptions() {
      Object.keys(this.optionsObj).forEach(async (key) => {
        if (key == 'Segment') return
        try {
          let res = await getOptions(key)
          if (res.code === 20000) this.optionsObj[key] = res.data.content
        } catch (error) {
          console.log(error)
        }
      })
    },
    async getSegmentOptions(data) {
      try {
        this.optionsObj['Segment'] = []
        let res = await getOptions('Segment', { id: data })
        if (res.code === 20000) this.optionsObj['Segment'] = res.data.content
      } catch (error) {
        console.log(error)
      }
    },
  },
}
</script>

<style></style>