workerManView.vue 5.63 KB
Newer Older
纪泽龙's avatar
纪泽龙 committed
1 2 3 4 5 6
<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    :before-close="handleClose"
  >
纪泽龙's avatar
纪泽龙 committed
7 8 9
    <el-form :model="formData" ref="formData" :rules="rules">
      <!-- <el-form-item label="选择时间段:" prop=""> -->
      <!-- <el-date-picker
纪泽龙's avatar
纪泽龙 committed
10 11 12 13 14 15
          v-model="dateValue"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
纪泽龙's avatar
纪泽龙 committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
        </el-date-picker> -->
      <!-- </el-form-item> -->
      <el-row>
        <el-col :span="11">
          <el-form-item label="选择值班人员:" prop="userId">
            <el-select
              style="width: 220px"
              v-model="formData.userId"
              filterable
              placeholder="请选择"
              @change="selectChange"
            >
              <el-option
                v-for="item in workerManArr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="11">
          <el-form-item label="选择开始时间:" prop="beginTime">
            <el-date-picker
              v-model="formData.beginTime"
              type="datetime"
              placeholder="选择开始时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="选择结束时间:" prop="endTime">
            <el-date-picker
              v-model="formData.endTime"
              type="datetime"
              placeholder="选择结束时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
纪泽龙's avatar
纪泽龙 committed
62 63
    </el-form>

纪泽龙's avatar
纪泽龙 committed
64 65 66 67
    <span slot="footer" class="dialog-footer">
      <el-button :loading="okLoading" type="primary" @click="ok"
        >确 定
      </el-button>
纪泽龙's avatar
纪泽龙 committed
68
      <el-button @click="dialogVisible = false">取 消</el-button>
纪泽龙's avatar
纪泽龙 committed
69 70 71 72 73
    </span>
  </el-dialog>
</template>
<script>
import moment from "moment";
纪泽龙's avatar
纪泽龙 committed
74 75
import { getInspectorLocations } from "@/api/inspectorLocation/location";

纪泽龙's avatar
纪泽龙 committed
76 77
export default {
  props: {
纪泽龙's avatar
纪泽龙 committed
78 79 80 81
    userId: {
      type: Number,
    },
    title: {
纪泽龙's avatar
纪泽龙 committed
82 83
      type: String,
    },
纪泽龙's avatar
纪泽龙 committed
84 85 86 87 88 89
    target: {
      type: Object,
    },
    gaodeMap: {
      type: Object,
    },
纪泽龙's avatar
纪泽龙 committed
90 91 92 93 94 95
  },

  components: {},
  data() {
    return {
      dialogVisible: false,
纪泽龙's avatar
纪泽龙 committed
96 97
      dateValue: "",
      okLoading: false,
纪泽龙's avatar
纪泽龙 committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
      formData: {
        userId: null,
      },
      workerManArr: [],

      rules: {
        userId: [
          { required: true, message: "请选择值班人员", trigger: "blur" },
        ],
        beginTime: [
          { required: true, message: "请输入开始时间", trigger: "blur" },
        ],
        endTime: [
          { required: true, message: "请输入结束时间", trigger: "blur" },
        ],
      },
纪泽龙's avatar
纪泽龙 committed
114 115
    };
  },
纪泽龙's avatar
纪泽龙 committed
116 117 118

  created() {
    this.formData.userId = this.userId;
纪泽龙's avatar
纪泽龙 committed
119 120 121 122
    this.workerManArr = this.gaodeMap.workerManArr.map((item) => ({
      label: item.userName,
      value: item.userId,
    }));
纪泽龙's avatar
纪泽龙 committed
123 124
  },

纪泽龙's avatar
纪泽龙 committed
125
  methods: {
纪泽龙's avatar
纪泽龙 committed
126 127 128 129 130
    // 下拉框选项
    selectChange(e) {
      console.log(e);
      this.formData.userId = e;
    },
纪泽龙's avatar
纪泽龙 committed
131
    ok() {
纪泽龙's avatar
纪泽龙 committed
132 133
      this.$refs.formData.validate((valid) => {
        if (valid) {
纪泽龙's avatar
纪泽龙 committed
134 135 136 137 138 139 140 141 142 143 144 145
          if (
            moment(this.formData.beginTime).valueOf() >
            moment(this.formData.endTime).valueOf()
          ) {
            this.msgError(
              "开始时间不能大于结束时间"
            );
            this.formData.endTime = "";

            return;
          }

纪泽龙's avatar
纪泽龙 committed
146 147 148 149 150 151 152
          this.okLoading = true;
          this.formData.beginTime = moment(this.formData.beginTime).format(
            "YYYY-MM-DD HH:mm:ss"
          );
          this.formData.endTime = moment(this.formData.endTime).format(
            "YYYY-MM-DD HH:mm:ss"
          );
纪泽龙's avatar
纪泽龙 committed
153

纪泽龙's avatar
纪泽龙 committed
154
          console.log(this.formData);
纪泽龙's avatar
纪泽龙 committed
155

纪泽龙's avatar
纪泽龙 committed
156 157 158 159 160
          // 找到哪个值班人员
          const target = this.gaodeMap.workerManMarkArr.filter((item) => {
            // console.log("userId",item.getExtData().userId)
            return item.getExtData().userId == this.formData.userId;
          })[0];
纪泽龙's avatar
纪泽龙 committed
161
          // console.log("target.moveMarker", target.moveMarker);
纪泽龙's avatar
纪泽龙 committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
          getInspectorLocations(this.formData).then((res) => {
            if (res.code == 200) {
              // 如果这个时间段没有移动轨迹
              if (res.data.length < 1) {
                this.$message({
                  type: "warn",
                  // center:true,
                  offset: 100,
                  message: "该时间段无移动轨迹",
                });
                this.okLoading = false;
                return;
              }
              let arr = res.data.map((res) => {
                return [res.longitude, res.latitude];
              });
              arr = arr.sort((a, b) => {
                return -1;
              });
              let data = res.data.sort((a, b) => {
                return -1;
              });
              this.okLoading = false;
              this.$message({
                type: "success",
                // center:true,
                offset: 100,
                message: res.msg,
              });
              this.dialogVisible = false;
纪泽龙's avatar
纪泽龙 committed
192
              this.gaodeMap.trackBack(target, arr, data);
纪泽龙's avatar
纪泽龙 committed
193
            }
纪泽龙's avatar
纪泽龙 committed
194 195 196 197
          });
        }
      });
    },
纪泽龙's avatar
纪泽龙 committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    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>