<template>
  <div class="gassVehicle gass-vehiche" >

    <drawer title="事故信息" :inner="true" :width="drawerWidth" :mask="false">
      <div class="scroll">
        <el-row style="margin-bottom: 10px">
          <el-col :span="14" style="margin-right: 30px">
            <el-input
              v-model="queryParams.accidentName"
              placeholder="请输入事故名称"
              clearable
              size="small"
            />
          </el-col>
          <el-col :span="8">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="carInfoSearch()">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-col>
        </el-row>

        <el-table v-loading="loading" :data="infoList">
          <el-table-column label="事故名称" align="center" prop="accidentName" />
          <el-table-column label="事故发生时间" align="center" prop="happenDate">
            <template slot-scope="scope">
              <span>{{ scope.row.happenDate }}</span>
            </template>
          </el-table-column>
          <el-table-column label="事故地点" align="center" prop="accidentLocation">
          </el-table-column>
          <el-table-column label="事故描述" align="center" prop="accidentDescription"/>
          <el-table-column label="事故原因" align="center" prop="accidentReason" />
          <el-table-column label="责任人" align="center" prop="obligationPerson" />
          <el-table-column label="备注" align="center" prop="remark" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-map-location"
                @click="getViewLocation(scope.row)"
              >查看位置</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </drawer>
    <div id="map"></div>

  </div>
</template>

<script>

import { getPipe} from "@/api/bigWindow/getDevice";
import drawer from  "./component/drawer";
import { listAccident } from "@/api/inspectionWork/inspectionAccident";
import { mapBound } from "@/utils/mapClass/boundaryMap";
export default {
  name: "InspectionAccident",
  components: {
    drawer
  },
  data() {
    return {
      tooltipVisible: false,
      pipeTooltipVisible: false,
      //地图
      map: null,
      recordMarkers: [],
      drawerWidth: '800px',
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      infoList: [],
      form: {},
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: "",
      coordinateslist:[],
      //轨迹回放
      backOpen: false,
      backForm:{
        changeTime: 1,
        beginTime: "",
        endTime: "",
        carNum: "",
        vehicleId: ""
      },
      traceabilityAnalysisData:{},
      traceabilityAnalysisShow:false,
      rules: {
        remark: [
          { required: true, message: "请输入备注", trigger: "blur" },
        ],
      }

    };
  },
  computed: {

  },
  created() {
    this.getList();
    this.getCoordinateslist();
  },
  mounted(){
    this.map = new AMap.Map("map", {
      center: [114.85,38.02],
      zoom: 14,
    });
    mapBound('藁城区', this.map, false);
  },
  methods: {
    getCoordinateslist(){
      getPipe().then(response => {
        console.log(response)
        response.data.forEach(item => {
          const text=item.path
          if(text){

            var polyline = new AMap.Polyline({
              path: JSON.parse(text),
              isOutline: true,
              outlineColor: '#ffeeff',
              borderWeight: 3,
              strokeOpacity: 1,
              // 折线样式还支持 'dashed'
              strokeStyle: "solid",
              // strokeStyle是dashed时有效
              strokeDasharray: [10, 5],
              lineJoin: 'round',
              lineCap: 'round',
              zIndex: 50,
              strokeWeight: 4,
              strokeColor: "#09f",
            })
            /*polyline.on('click', () => {
              this.showpipeDetail(item);
            });*/
            this.map.add([polyline]);
          }
        })
        /*console.log("this.coordinateslist",this.coordinateslist)
        if (this.coordinateslist!=null && this.coordinateslist.length > 0) {
          this.coordinateslist.forEach(item => {
            this.map.addPipeLine({ path: item });
          })
        }*/
      });
    },
    /** 查询报警信息 */
    getList(){
      this.loading = true;
      listAccident(this.queryParams).then(response => {
        this.infoList = response.rows;
        console.log(this.infoList)
        this.total = response.total;
        this.loading = false;
      });
    },
    /**获取设备位置*/
    getViewLocation(row){
      this.map.remove(this.recordMarkers);
      if (row.longitude!=="" && row.latitude!="" && row.longitude!==undefined && row.latitude!==undefined){
        let marker = new AMap.Marker({
          icon: require("@/assets/firstimage/device/wxy.png"),
          position: [row.longitude,row.latitude],
          offset: new AMap.Pixel(-13, -30)
        });
        /*marker.on('click', () => {
          this.showDetail(row);
        });*/
        console.log(this.map)
        this.map.add(marker);
        this.map.setCenter([row.longitude,row.latitude]);
        this.recordMarkers.push(marker);
      }else{
        this.$message({
          message: '当前设备未配置位置信息！',
          type: 'warning'
        });
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        vehicleId: null,
        carNum: null,
        brandModel: null,
        vehicleType: null,
        vehicleLoad: null,
        vehicleSize: null,
        vehicleLimt: null,
        vehicleInspect: null,
        beyondEnterpriseId: null,
        personLiable: null,
        phone: null,
        isDel: null,
        remarks: null
      };
      this.resetForm("form");
    },
    handleCurrentChangvale(val){
      this.queryParams.pageNum = val;
      this.getList();
    },
    carInfoSearch(){
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery(){
      this.queryParams.pageNum = 1;
      this.queryParams.accidentName = null;
      this.getList();
    },
  }
};
</script>
<style lang="scss" scoped>
.gassVehicle{
  positoin:relative;
  /*background-color: red;*/
  height:calc(100vh - 50px);
  padding:20px;
  padding-bottom:0px;
}

#map{
  /*position: fixed;*/
  /*width:calc(100vw - 250px);*/
  /*top:70px;*/
  /*bottom:0;*/
  height: 100%;
  float: right;
  width: calc(100vw - 1000px);
}

/*!* 表格最外边框 *!
.el-table --border, .el-table --group{
  border: none;
}*/
.el-table{
  background-color: #00afff !important;
}

</style>
