<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="sn">
              <el-input v-model="form.sn" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="mac地址" prop="mac">
              <el-input v-model="form.mac" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="ip地址" prop="ip">
              <el-input v-model="form.ip" size="small" class="filter-item" style="width: 280px" />
            </el-form-item>
            <el-form-item label="经度" prop="x">
              <el-input
                v-model="form.x"
                size="small"
                class="filter-item"
                style="width: 280px"
                disabled
              />
            </el-form-item>
            <el-form-item label="纬度" prop="y">
              <el-input
                v-model="form.y"
                size="small"
                class="filter-item"
                style="width: 280px"
                disabled
              />
            </el-form-item>
            <el-form-item label="高度" prop="z">
              <el-input
                v-model="form.z"
                size="small"
                class="filter-item"
                style="width: 280px"
                disabled
              />
            </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>
        </el-col>
        <el-col :span="16">
          <visualIntercom-map v-if="crudCU" ref="visualIntercomMap" :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 visualIntercomTableOptions"
        :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', ' visualIntercomConfig:edit', ' visualIntercomConfig: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 crudvisualIntercom from '@/api/alarmConfig/visualIntercom'
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 { visualIntercomTableOptions } from '../tableConfig'
import visualIntercomMap from './visualIntercomMap.vue'
import dayjs from 'dayjs'
const defaultForm = {
  // id: null,
  name: '', //名称
  sn: '', //序列号
  mac: '', //mac地址
  ip: '', //ip地址
  x: '', //经度
  y: '', //纬度
  z: '', //高度
  cameraID: '0' //摄像头
}

export default {
  name: 'visualIntercomConfig',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker, visualIntercomMap },
  cruds() {
    return CRUD({
      title: '可视对讲',
      url: 'visualIntercom/config/getListJson',
      listOrder: [],
      crudMethod: { ...crudvisualIntercom }
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    }
  },
  data() {
    return {
      visualIntercomTableOptions,
      permission: {
        add: ['admin', ' visualIntercomConfig:add'],
        edit: ['admin', ' visualIntercomConfig:edit'],
        del: ['admin', ' visualIntercomConfig:del']
      },
      rules: {
        buildId: [{ required: true, message: '请选择建筑名称', trigger: 'blur' }],
        floorNo: [{ required: true, message: '请输入楼层', trigger: 'blur' }],
        railName: [{ required: true, message: '请输入围栏名称', trigger: 'blur' }]
      },
      optionsObj: { 
        VisualIntercom: [],
        MajorType: [],
        MinorType: [],
        Name: [],
        Build: [],
        FloorNo: [],
        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>
