<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"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission" />
    </div>
    <!-- 表单组件 -->
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="crud.cancelCU"
      :visible.sync="crudCU"
      :title="crud.status.title"
      width="1200px"
    >
      <el-row :gutter="40">
        <el-col :span="8">
          <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
            <el-form-item label="名称" prop="name">
              <el-input v-model="form.name" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="经度" prop="positionX">
              <el-input
                v-model="form.positionX"
                size="small"
                class="filter-item"
                style="width: 280px"
                disabled
              />
            </el-form-item>
            <el-form-item label="纬度" prop="positionY">
              <el-input
                v-model="form.positionY"
                size="small"
                class="filter-item"
                style="width: 280px"
                disabled
              />
            </el-form-item>
            <el-form-item label="高度" prop="positionZ">
              <el-input
                v-model="form.positionZ"
                size="small"
                class="filter-item"
                style="width: 280px"
              />
            </el-form-item>
            <el-form-item label="描述" prop="desc">
              <el-input v-model="form.desc" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="摄像头ID" prop="cameraID">
              <el-select
                v-model="form.cameraID"
                clearable
                size="small"
                placeholder="请选择摄像头"
                class="filter-item"
                style="width: 280px"
              >
                <el-option
                  v-for="item in optionsObj.Camera"
                  :key="item.value"
                  :label="item.label"
                  :value="+item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="浓度报警" prop="ndhh">
              <el-input v-model="form.ndhh" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="浓度预警" prop="ndhi">
              <el-input v-model="form.ndhi" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="浓度值" prop="nd">
              <el-input v-model="form.nd" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="光强" prop="gq">
              <el-input v-model="form.gq" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="水平角度" prop="spjd">
              <el-input v-model="form.spjd" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="垂直角度" prop="czjd">
              <el-input v-model="form.czjd" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="16">
          <JGYT-map v-if="crudCU" ref="JGYTMap" :form="form" />
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">
          取消
        </el-button>
        <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">
          确认
        </el-button>
      </div>
    </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 JGYTTableOptions"
        :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', ' JGYTConfig:edit', ' JGYTConfig:del'])"
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <udOperation :data="scope.row" :permission="permission" />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import permission from '@/directive/permission'
import crudJGYT from '@/api/alarmConfig/JGYT'
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 DateRangePicker from '@/components/DateRangePicker'
import { JGYTTableOptions } from '../tableConfig'
import JGYTMap from './JGYTMap'
import dayjs from 'dayjs'
const defaultForm = {
  // id: null,
  name: '', //名称
  positionX: '', //经度
  positionY: '', //纬度
  positionZ: '', //高度
  desc: '', //描述
  cameraID: '', //摄像头ID
  ndhh: null, //浓度报警
  ndhi: null, //浓度预警
  nd: null, //浓度值
  gq: null, //光强
  spjd: null, //水平角度
  czjd: null //垂直角度
}

export default {
  name: 'JGYTConfig',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker, JGYTMap },
  cruds() {
    return CRUD({
      title: '激光云台',
      url: 'JGYT/tag/getList',
      listOrder: [],
      crudMethod: { ...crudJGYT }
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    }
  },
  data() {
    return {
      JGYTTableOptions,
      permission: {
        add: ['admin', ' JGYTConfig:add'],
        edit: ['admin', ' JGYTConfig:edit'],
        del: ['admin', ' JGYTConfig:del']
      },
      rules: {
        buildId: [{ required: true, message: '请选择建筑名称', trigger: 'blur' }],
        floorNo: [{ required: true, message: '请输入楼层', trigger: 'blur' }],
        railName: [{ required: true, message: '请输入围栏名称', trigger: 'blur' }]
      },
      optionsObj: { Camera: [] }
    }
  },
  created() {
    // this.getOptions()
  },
  methods: {
    [CRUD.HOOK.beforeToAdd]() {},
    // 打开
    [CRUD.HOOK.beforeToEdit]() {},
    // 提交前的验证
    [CRUD.HOOK.afterValidateCU]() {},
    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)
        }
      })
    }
  }
}
</script>

<style></style>
