<template>
  <div>
    {{fenceGroups.groupsName}}下属围栏
    <el-button type="text" @click="add(fenceGroups.groupsId)">增加围栏</el-button>
    <el-table :data="fenceGroups.fenceList">
      <el-table-column prop="fenceName" label="围栏名称"></el-table-column>
      <el-table-column prop="fenceType" label="围栏类型"></el-table-column>
      <el-table-column prop="eventType" label="驶入驶出">
        <span slot-scope="scope">
          <span v-if="scope.row.eventType === 'Y'">驶入</span>
          <span v-if="scope.row.eventType === 'N'">驶出</span>
        </span>
      </el-table-column>
      <el-table-column prop="staut" label="围栏状态">
        <span slot-scope="scope">
          <span v-if="scope.row.staut === 'Y'">启用</span>
          <span v-if="scope.row.staut === 'N'">禁止</span>
        </span>
      </el-table-column>
      <el-table-column prop="polygonPoints" label="坐标"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <span slot-scope="scope">
          <span v-if="scope.row.staut === 'Y'">
            <el-button type="text" icon="el-icon-edit" @click="query(scope.row.fenceId)">禁止</el-button>
          </span>
          <span v-if="scope.row.staut === 'N'">
            <el-button type="text" icon="el-icon-edit" @click="query(scope.row.fenceId)">启用</el-button>
          </span>
          <br>
          <el-button size="mini" icon="el-icon-delete" type="text" @click="del(scope.row.fenceId)">删除</el-button>
        </span>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {selectFenceGroupsById, deleteFence, updateFence} from "@/api/goods/map";
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
// 例如：import 《组件名称》 from '《组件路径》,
export default {
  // import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    // 这里存放数据"
    return {
      carId: this.$route.query.carId,
      fenceGroups: {}
    }
  },
  // 计算属性 类似于data概念",
  computed: {},
  // 监控data中的数据变化",
  watch: {},
  // 方法集合",
  methods: {
    //初始化
    getInfo() {
      selectFenceGroupsById(this.carId).then(res => {
        this.fenceGroups = res.data
        console.log(res.data)
      })
    },
    //删除
    del(fenceId) {
      deleteFence(fenceId).then(res => {
        this.$message.success(res.data)
        this.getInfo()
      })
    },
    //前往地图增加围栏
    add(groupsId) {
      this.$router.push({path:'/client/sever/map',query:{groupsId:groupsId}})
    },
    //修改围栏状态
    query(fenceId) {
      updateFence(fenceId).then(res => {
        this.$message.success(res.data)
        this.getInfo()
      })
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.getInfo()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, // 生命周期 - 创建之前",
  beforeMount() {
  }, // 生命周期 - 挂载之前",
  beforeUpdate() {
  }, // 生命周期 - 更新之前",
  updated() {
  }, // 生命周期 - 更新之后",
  beforeDestroy() {
  }, // 生命周期 - 销毁之前",
  destroyed() {
  }, // 生命周期 - 销毁完成",
  activated() {
  } // 如果页面有keep-alive缓存功能，这个函数会触发",
}
</script>
<style scoped>

</style>
