<template>
  <div>
    <h1>车辆管理页面</h1>

    <!--    列表-->
    <el-table :data="vehicleList" style="width: 100%" border>
      <el-table-column label="车辆id" width="90" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.vehicleId }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆类型" width="90" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.vehicleTypeName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电机厂商" width="150" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.motorManufacturer }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电池厂商" width="150" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.batteryManufacturer }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电机编号" width="180" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.motorNumber }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电池编号" width="180" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.batteryNumber }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="vin码" width="180" align="center">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span style="margin-left: 10px">{{ scope.row.vin }}</span>-->0
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="车辆状态" width="120" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px" v-if="1==scope.row.vehicleState">
            <el-tag type="success">在线</el-tag>
          </span>
          <span style="margin-left: 10px" v-if="0==scope.row.vehicleState">
            <el-tag type="danger">离线</el-tag>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="deleteById(scope.row.middleId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--    &lt;!&ndash;    分页&ndash;&gt;-->
<!--    <el-pagination-->
<!--      @size-change="handleSizeChange"-->
<!--      @current-change="handleCurrentChange"-->
<!--      :current-page="vehicleListParams.pageNum"-->
<!--      :page-sizes="[5,7,10,20]"-->
<!--      :page-size="vehicleListParams.pageSize"-->
<!--      layout="total, sizes, prev, pager, next, jumper"-->
<!--      :total="total">-->
<!--    </el-pagination>-->
    <!-- Form -->
    <el-button type="text" @click="dialogFormVisible = true">添加管理车辆</el-button>

    <el-dialog title="添加管理车辆" :visible.sync="dialogFormVisible">
      <el-form :model="Addform">

        <el-checkbox v-model="Addform.vehicleIds" v-for="item in vehicleTypes" :label="item.vehicleId">{{item.motorManufacturer}}</el-checkbox>
      </el-form>
      <el-button size="mini" type="danger" @click="insertVehicle()">添加</el-button>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {deleteMiddleId, insertVehicle, vehicleAll, VehicleManageList} from "@/api/couplet/vehiclemanage";

export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"
    return {
      //车辆列表
      vehicleList: [],
      Addform:{
        vehicleIds:[],
        userId:''
      },
      //总页数
      total: 0,


      //车辆类型
      vehicleTypes: [],

      dialogTableVisible: false,
      delivery: false,
      dialogFormVisible: false,
      formLabelWidth: '120px',
      // 弹出层标题
      title: ""

    };
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    //获取车辆列表
    getVehicleList() {
      VehicleManageList(this.vehicleListParams).then(
        res => {
          this.vehicleList = res.data;
          this.total = res.data.total;
        }
      )
    },

    insertVehicle(){

      insertVehicle(this.Addform).then(

        res => {
          if(res.code==200){
            this.getVehicleList()
            this.$message({
              type: 'success',
              message: '添加成功!'
            });
          }else{
            this.$message({
              type: 'error',
              message: '添加失败!'
            });
          }
        }
      )},

    //获取车辆类型
    getVehicleTypes() {
      vehicleAll().then(
        res => {
          this.vehicleTypes = res.data;
        }
      )
    },

    //根据车辆id进行删除
    deleteById(middleId) {
      this.$confirm('此操作将永久删除该数据，是否继续？', "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteMiddleId(middleId).then(
          res => {
            if (res.code == 200) {
              //刷新列表
              this.getVehicleList();
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            } else {
              this.$message({
                type: 'error',
                message: '删除失败!'
              });
            }
          }
        )
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },


  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    //获取车辆列表
    this.getVehicleList()

    //获取车辆类型
    this.getVehicleTypes()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
<style scoped>

</style>
