workerManView.vue 6.89 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 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    <el-form :model="formData" ref="formData" :rules="rules">
      <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>
31 32 33 34 35 36 37 38 39 40 41
        <el-col>
          <el-form-item label="请选择时间段" prop="changeTime">
            <el-radio-group v-model="formData.changeTime" @change="radioChange">
              <el-radio :label="1">最近2小时</el-radio>
              <el-radio :label="2">最近24小时</el-radio>
              <el-radio :label="3">自定义时间段</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>

42
      <el-row>
纪泽龙's avatar
纪泽龙 committed
43 44 45
        <el-col :span="11">
          <el-form-item label="选择开始时间:" prop="beginTime">
            <el-date-picker
46
              :disabled="formData.changeTime != 3"
纪泽龙's avatar
纪泽龙 committed
47 48 49 50 51 52 53 54 55 56
              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
57
              :disabled="formData.changeTime != 3"
纪泽龙's avatar
纪泽龙 committed
58 59 60 61 62 63 64 65
              v-model="formData.endTime"
              type="datetime"
              placeholder="选择结束时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
纪泽龙's avatar
纪泽龙 committed
66 67
    </el-form>

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

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

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

      rules: {
        userId: [
          { required: true, message: "请选择值班人员", trigger: "blur" },
        ],
115 116 117 118 119 120 121
        changeTime: [
          {
            required: true,
            message: "选择查询时间",
            trigger: ["blur", "change"],
          },
        ],
纪泽龙's avatar
纪泽龙 committed
122 123 124 125 126 127 128
        beginTime: [
          { required: true, message: "请输入开始时间", trigger: "blur" },
        ],
        endTime: [
          { required: true, message: "请输入结束时间", trigger: "blur" },
        ],
      },
纪泽龙's avatar
纪泽龙 committed
129 130
    };
  },
纪泽龙's avatar
纪泽龙 committed
131 132 133

  created() {
    this.formData.userId = this.userId;
纪泽龙's avatar
纪泽龙 committed
134
    this.workerManArr = this.gaodeMap.workerManArr.map((item) => ({
135
      label: item.nickName,
纪泽龙's avatar
纪泽龙 committed
136 137
      value: item.userId,
    }));
138 139
    this.formData.beginTime = moment().format("YYYY-MM-DD HH:mm:ss");
    this.formData.endTime = moment().add(2, "h").format("YYYY-MM-DD HH:mm:ss");
纪泽龙's avatar
纪泽龙 committed
140 141
  },

纪泽龙's avatar
纪泽龙 committed
142
  methods: {
纪泽龙's avatar
纪泽龙 committed
143 144 145 146 147
    // 下拉框选项
    selectChange(e) {
      console.log(e);
      this.formData.userId = e;
    },
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    radioChange(e) {
      if (e == 1) {
        this.formData.beginTime = moment().format("YYYY-MM-DD HH:mm:ss");
        this.formData.endTime = moment()
          .add(2, "h")
          .format("YYYY-MM-DD HH:mm:ss");
      } else if (e == 2) {
        this.formData.beginTime = moment().format("YYYY-MM-DD HH:mm:ss");
        this.formData.endTime = moment()
          .add(1, "d")
          .format("YYYY-MM-DD HH:mm:ss");
      } else {
        this.formData.beginTime = "";
        this.formData.endTime = "";
      }
    },
纪泽龙's avatar
纪泽龙 committed
164
    ok() {
纪泽龙's avatar
纪泽龙 committed
165 166
      this.$refs.formData.validate((valid) => {
        if (valid) {
纪泽龙's avatar
纪泽龙 committed
167 168 169 170
          if (
            moment(this.formData.beginTime).valueOf() >
            moment(this.formData.endTime).valueOf()
          ) {
171
            this.msgError("开始时间不能大于结束时间");
纪泽龙's avatar
纪泽龙 committed
172 173 174 175
            this.formData.endTime = "";
            return;
          }

纪泽龙's avatar
纪泽龙 committed
176
          this.okLoading = true;
177 178 179 180 181 182 183 184 185 186
          if (this.formData.changeTime != 3) {
            this.radioChange(this.formData.changeTime);
          } else {
            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
187

188
          // console.log(this.formData);
纪泽龙's avatar
纪泽龙 committed
189 190 191 192 193
          // 找到哪个值班人员
          const target = this.gaodeMap.workerManMarkArr.filter((item) => {
            // console.log("userId",item.getExtData().userId)
            return item.getExtData().userId == this.formData.userId;
          })[0];
纪泽龙's avatar
纪泽龙 committed
194
          // console.log("target.moveMarker", target.moveMarker);
纪泽龙's avatar
纪泽龙 committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
          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
225
              this.gaodeMap.trackBack(target, arr, data);
纪泽龙's avatar
纪泽龙 committed
226
            }
纪泽龙's avatar
纪泽龙 committed
227 228 229 230
          });
        }
      });
    },
纪泽龙's avatar
纪泽龙 committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    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>