<template>
  <div>
    <div>
      <el-form :inline="true" :model="queryParams" class="demo-form-inline">

        <el-form-item label="围栏名称">
          <el-input v-model="queryParams.vehicleVIN" placeholder="模糊查询车辆VIN"></el-input>
        </el-form-item>

        <el-form-item label="围栏名称">
          <el-input v-model="queryParams.vehicleTypeId" placeholder="模糊查询围栏名称"></el-input>
        </el-form-item>

        <el-form-item label="围栏名称">
          <el-input v-model="queryParams.motorBusiness" placeholder="模糊查询围栏名称"></el-input>
        </el-form-item>

        <el-form-item label="围栏名称">
          <el-input v-model="queryParams.batteryBusiness" placeholder="模糊查询围栏名称"></el-input>
        </el-form-item>

        <el-form-item label="围栏名称">
          <el-input v-model="queryParams.MotorID" placeholder="模糊查询围栏名称"></el-input>
        </el-form-item>

        <el-form-item label="围栏名称">
          <el-input v-model="queryParams.BatteryID" placeholder="模糊查询围栏名称"></el-input>
        </el-form-item>


        <el-form-item label="围栏类型">
          <el-select v-model="queryParams.fenceTypeId" placeholder="请选择围栏类型">
            <el-option label="驶出" value="1">驶出</el-option>
            <el-option label="驶入" value="2">驶入</el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="围栏状态">
          <el-select v-model="queryParams.fenceState" placeholder="请选择围栏状态">
            <el-option label="正常" value="1">正常</el-option>
            <el-option label="停用" value="2">停用</el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit" icon="el-icon-search">搜索</el-button>
        </el-form-item>
      </el-form>

      <el-button type="primary" plain icon="el-icon-plus" @click="fencadd">新增</el-button>



      <el-table :data="fenceList" style="width: 100%"  ref="multipleTable">

        <el-table-column label="围栏名称" align="center" prop="fenceName" />

        <el-table-column
          label="围栏类型"
          width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px" v-if="scope.row.fenceTypeId==1">驶出</span>
            <span style="margin-left: 10px" v-if="scope.row.fenceTypeId==2">驶入</span>
          </template>
        </el-table-column>

        <el-table-column
          label="围栏状态"
          width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px" v-if="scope.row.fenceState==1"><el-tag>正常</el-tag></span>
            <span style="margin-left: 10px" v-if="scope.row.fenceState==2"><el-tag>停用</el-tag></span>
          </template>
        </el-table-column>

        <el-table-column label="经纬度信息" width="280">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.fenceMessage }}</span>
          </template>
        </el-table-column>


        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" icon="el-icon-map-location" @click="handleWdit(scope.row)">编辑围栏</el-link>

            <el-link type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-link>

            <el-link type="primary" icon="el-icon-delete"  @click="handleDelete(scope.row.fenceId)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />


      <!--    围栏添加-->
      <el-dialog :title="title" :visible.sync="dialogFormVisible">

        <el-form :model="fences">

          <el-form-item label="围栏名称" :label-width="formLabelWidth">
            <el-input v-model="fences.fenceName" autocomplete="off"></el-input>
          </el-form-item>


          <el-form-item label="围栏类型" :label-width="formLabelWidth">
            <el-select v-model="fences.fenceTypeId" placeholder="请选择活动区域">
              <el-option label="驶出" value="1">驶出</el-option>
              <el-option label="驶入" value="2">驶入</el-option>
            </el-select>
          </el-form-item>

        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addAll">新增</el-button>
        </div>
      </el-dialog>


      <!--    修改电子围栏-->
      <el-dialog :title="title" :visible.sync="dialogFormVisible1">

        <el-form :model="fences">
          <el-form-item label="围栏名称" :label-width="formLabelWidth1">
            <el-input v-model="fences.fenceName" autocomplete="off"></el-input>
          </el-form-item>


          <el-form-item label="围栏类型" :label-width="formLabelWidth1">
            <el-select v-model="fences.fenceTypeId" placeholder="请选择活动区域">
              <el-option label="驶出" value="1">驶出</el-option>
              <el-option label="驶入" value="2">驶入</el-option>
            </el-select>
          </el-form-item>


          <el-form-item label="围栏状态">
            <el-radio-group v-model="fences.fenceState" :label-width="formLabelWidth1">
              <el-radio :label="1">正常</el-radio>
              <el-radio :label="2">停用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>


        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="updateAll">修 改</el-button>
        </div>
      </el-dialog>

    </div>
  </div>

</template>

<script>
import {vehicleInsert, insertMarkersFence, vehicleList, vehicleDelete, vehicleUpdate} from "@/api/system/vehicle";
export default {
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"

    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vehicleVIN: null,
        vehicleTypeId: null,
        motorBusiness: null,
        batteryBusiness: null,
        MotorID: null,
        BatteryID: null,
      },
      total:0,
      dialogFormVisible:false,
      formLabelWidth:'120px',

      fences:{

      },
      title:'',
      dialogFormVisible1:false,
      formLabelWidth1:'120px',

      vehicleList: [],

    };
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    //获取围栏列表
    getList() {
      this.loading = true;
      vehicleList(this.queryParams).then(res => {
        this.vehicleList = res.data.rows;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    // 搜索框
    onSubmit() {
      this.getList()
    },

    //修改电子围栏
    handleEdit(obj) {
      this.dialogFormVisible1 = true
      this.fences = obj
      this.title = '修改电子围栏'

    },


    updateAll() {
      fenceUpdate(this.fences).then(
        res => {
          this.$message.success(res.msg)
          this.list()
        }
      )
      this.dialogFormVisible1=false;
    },
    //新增
    fencadd() {
      this.fences = {}
      this.dialogFormVisible = true
      this.title = '新增页面'
    },


    addAll() {
      fenceAdd(this.fences).then(
        res => {
          this.$message.success(res.msg)
          this.list()
        }
      )
      this.dialogFormVisible = false
    },


    //删除电子围栏
    handleDelete(fenceId){
      fenceDelete(fenceId,'deleted').then(
        res=>{
          this.$message.success(res.msg)
          this.list()
        }
      )
    },


    //编辑围栏
    handleWdit(obj) {
      this.showMap=true
      this.showMapp=false
      this.fences = obj
      this.initAMap()
    },
  },

  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.getList();
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
