<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    :before-close="handleClose"
  >
    <el-form>
      <el-form-item label="选择时间段:" prop="">
        <el-date-picker
          v-model="dateValue"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button :loading="okLoading" type="primary" @click="ok"
        >确 定
      </el-button>
    </span>
  </el-dialog>
</template>
<script>
import moment from "moment";
import { getInspectorLocations } from "@/api/inspectorLocation/location";

export default {
  props: {
    userId: {
      type: Number,
    },
    title: {
      type: String,
    },
    target: {
      type: Object,
    },
    gaodeMap: {
      type: Object,
    },
  },

  components: {},
  data() {
    return {
      dialogVisible: false,
      dateValue: "",
      okLoading: false,
      formData: {},
    };
  },

  created() {
    this.formData.userId = this.userId;
  },

  methods: {
    ok() {
      this.okLoading = true;

      this.formData.beginTime = moment(this.dateValue[0]).format(
        "YYYY-MM-DD HH:mm:ss"
      );
      this.formData.endTime = moment(this.dateValue[1]).format(
        "YYYY-MM-DD HH:mm:ss"
      );
      getInspectorLocations(this.formData).then((res) => {
        if (res.code == 200) {
          let arr = res.data.map((res) => {
            return [res.longitude, res.latitude];
          });
          arr = arr.sort((a, b) => {
            return -1;
          });
          this.okLoading = false;
          this.$message({
            type: "success",
            // center:true,
            offset: 100,
            message: res.msg,
          });
          this.dialogVisible=false;
          this.gaodeMap.trackBack(this.target, arr);
        }
      });
    },
    async requeset(id, data) {
      id ? console.log("修改") : console.log("新增");
      return id ? updatePipe(data) : addPipe(data);
    },
    show() {
      this.dialogVisible = true;
    },
    handleClose(done) {
      done();
    },
  },
};
</script>

<style lang="scss">
</style>

