flowMeter.vue 8.54 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2
<template>
  <el-dialog
3
    :title="title"
耿迪迪's avatar
耿迪迪 committed
4
    :visible.sync="dialogVisible"
纪泽龙's avatar
纪泽龙 committed
5 6 7 8
    :before-close="handleClose"
  >
    <el-row>
      <el-form ref="form" :model="form" :rules="rules" label-width="135px">
纪泽龙's avatar
纪泽龙 committed
9
        <el-row>
10
          <el-col :span="11">
11
            <el-form-item label="所属管道" prop="pipeId">
纪泽龙's avatar
纪泽龙 committed
12
              <el-select
13
                v-model="form.pipeId"
纪泽龙's avatar
纪泽龙 committed
14 15 16
                placeholder="请选择所属管道"
                style="width: 100%"
              >
纪泽龙's avatar
纪泽龙 committed
17 18
                <el-option
                  v-for="item in pipeList"
19
                  :key="item.pipeId"
纪泽龙's avatar
纪泽龙 committed
20
                  :label="item.pipeName"
21
                  :value="item.pipeId"
纪泽龙's avatar
纪泽龙 committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="设备名称" prop="deviceName">
              <el-input
                v-model="form.deviceName"
                placeholder="请输入设备名称"
              />
            </el-form-item>
          </el-col>
纪泽龙's avatar
纪泽龙 committed
37

纪泽龙's avatar
纪泽龙 committed
38 39 40 41 42 43 44 45 46
          <el-col :span="11">
            <el-form-item label="设备型号" prop="deviceModel">
              <el-input
                v-model="form.deviceModel"
                placeholder="请输入设备型号"
              />
            </el-form-item>
          </el-col>
        </el-row>
纪泽龙's avatar
纪泽龙 committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

        <el-col :span="11">
          <el-form-item label="所在地址" prop="deviceAddr">
            <el-input v-model="form.deviceAddr" placeholder="请输入所在地址" />
          </el-form-item>
        </el-col>

        <el-col :span="11">
          <el-form-item label="物联网编号" prop="iotNo">
            <el-input v-model="form.iotNo" placeholder="请输入物联网编号" />
          </el-form-item>
        </el-col>

        <el-col :span="22">
          <el-form-item label="经纬度坐标" prop="">
纪泽龙's avatar
纪泽龙 committed
62
            <el-card shadow="newver" class="box-card">
纪泽龙's avatar
纪泽龙 committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
              <div v-text="`[[${form.longitude},${form.latitude}]]`"></div>
            </el-card>
          </el-form-item>
        </el-col>

        <!-- <el-col>
          <el-form-item label="纬度" prop="latitude">
            <el-input v-model="form.latitude" placeholder="请输入纬度" />
          </el-form-item>
        </el-col> -->

        <el-col :span="11">
          <el-form-item label="联系人" prop="linkman">
            <el-input v-model="form.linkman" placeholder="请输入联系人" />
          </el-form-item>
        </el-col>

        <el-col :span="11">
          <el-form-item label="联系电话" prop="phone">
纪泽龙's avatar
纪泽龙 committed
82 83 84 85 86 87
            <el-input
              type="number"
              maxlength="11"
              v-model="form.phone"
              placeholder="请输入联系电话"
            />
纪泽龙's avatar
纪泽龙 committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
          </el-form-item>
        </el-col>

        <el-col>
          <el-form-item label="设备图片上传" prop="iconUrl">
            <MyFileUpload
              listType="picture-card"
              @resFun="getFileInfo"
              @remove="listRemove"
              :fileArr="fileArr"
            />
            <el-input v-show="false" disabled v-model="form.iconUrl"></el-input>
          </el-form-item>
        </el-col>

        <el-col>
          <el-form-item label="安装时间" prop="installationTime">
            <el-date-picker
              clearable
              size="small"
              v-model="form.installationTime"
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择安装时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="22">
          <el-form-item label="备注" prop="remarks">
            <el-input
              type="textarea"
              v-model="form.remarks"
              placeholder="请输入备注"
            />
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>

耿迪迪's avatar
耿迪迪 committed
129
    <span slot="footer" class="dialog-footer">
耿迪迪's avatar
耿迪迪 committed
130
      <el-button type="primary" @click="submitForm">确 定</el-button>
纪泽龙's avatar
纪泽龙 committed
131
      <el-button @click="dialogVisible = false">取 消</el-button>
耿迪迪's avatar
耿迪迪 committed
132 133 134 135 136
    </span>
  </el-dialog>
</template>

<script>
纪泽龙's avatar
纪泽龙 committed
137 138 139 140 141 142 143 144
import {
  getAllDeviceInfo,
  addDeviceInfo,
  updateDeviceInfo,
} from "@/api/device/deviceInfo";
import { pipeAllInfoList } from "@/api/device/pipe";
import MyFileUpload from "@/components/MyFileUpload";
import { DEVICE_TYPE } from "utils/gaodeMap.js";
耿迪迪's avatar
耿迪迪 committed
145

纪泽龙's avatar
纪泽龙 committed
146 147 148 149 150 151 152 153 154
export default {
  props: {
    title: { type: String },
  },
  data() {
    return {
      form: {
        deviceType: "3",
      },
155
      type: DEVICE_TYPE.FLOWMETER,
纪泽龙's avatar
纪泽龙 committed
156 157 158 159 160 161 162 163 164
      dialogVisible: false,
      fileList: [],
      // 表单校验
      rules: {},
      map: null,
      obj: null,
      gaoMap: null,
      fileArr: [],
      pipeList: [],
纪泽龙's avatar
纪泽龙 committed
165

纪泽龙's avatar
纪泽龙 committed
166
      rules: {
167
        pipeId: [
纪泽龙's avatar
纪泽龙 committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
          { required: true, message: "请选择所属管道", trigger: "blur" },
          // { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        deviceName: [
          { required: true, message: "请输入设备名称", trigger: "blur" },
        ],
        deviceModel: [
          { required: true, message: "请输入设备型号", trigger: "blur" },
        ],
        deviceAddr: [
          { required: true, message: "请输入所在地址", trigger: "blur" },
        ],
        iotNo: [
          { required: true, message: "请输入物联网编号", trigger: "blur" },
        ],
纪泽龙's avatar
纪泽龙 committed
183
        linkman: [{ required: true, message: "请输入联系人", trigger: "blur" }],
纪泽龙's avatar
纪泽龙 committed
184 185 186 187
        phone: [
          { required: true, message: "请输入联系电话", trigger: "blur" },
          { min: 11, max: 11, message: "长度11个数字", trigger: "blur" },
        ],
纪泽龙's avatar
纪泽龙 committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
        iconUrl: [{ required: true, message: "请上传图片", trigger: "change" }],
        installationTime: [
          {
            // type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
      },
    };
  },
  components: {
    MyFileUpload,
  },
  methods: {
    show() {
      this.dialogVisible = true;
耿迪迪's avatar
耿迪迪 committed
206
    },
纪泽龙's avatar
纪泽龙 committed
207 208
    hide() {
      this.remove();
耿迪迪's avatar
耿迪迪 committed
209
    },
纪泽龙's avatar
纪泽龙 committed
210 211
    getFileInfo(res) {
      this.form.iconUrl = res.url;
耿迪迪's avatar
耿迪迪 committed
212
    },
纪泽龙's avatar
纪泽龙 committed
213
    submitForm() {
214
      console.log(this.form);
纪泽龙's avatar
纪泽龙 committed
215 216 217 218
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.deviceId != null) {
            updateDeviceInfo(this.form).then((response) => {
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
              if (response.code == 200) {
                this.dialogVisible = false;
                const index = this.gaoMap.markers.indexOf(this.obj);
                if (index >= 0) {
                  this.gaoMap.markers.splice(index, 1);
                  this.gaoMap.changePolineListNum = index;
                }
                this.map.remove(this.obj);
                this.gaoMap.addMarker(
                  // this.form.deviceType,
                  //这个是上图用的type,跟后台的type不一致
                  this.type,
                  this.form,
                  () => {
                    const arr = this.gaoMap.markers.map((item) => {
                      return item.getExtData();
                    });
                    console.log(arr);
                    this.gaoMap.view.deviceClassify(arr);
                    this.gaoMap.view.pipeList();
                  }
                );
                this.msgSuccess("修改成功");
              }
纪泽龙's avatar
纪泽龙 committed
243 244
            });
          } else {
纪泽龙's avatar
纪泽龙 committed
245 246 247 248 249
            addDeviceInfo(this.form).then((response) => {
              if (response.code == 200) {
                this.remove();
                this.map.remove(this.obj);
                this.form.deviceId = response.data;
250 251 252 253 254 255 256
                this.gaoMap.addMarker(this.type, this.form, () => {
                  const arr = this.gaoMap.markers.map((item) => {
                    return item.getExtData();
                  });
                  this.gaoMap.view.deviceClassify(arr);
                  this.gaoMap.view.pipeList();
                });
纪泽龙's avatar
纪泽龙 committed
257 258 259 260
                //this.gaoMap.placeSearch.clear();
                this.gaoMap.closeAddMarker();
                this.msgSuccess("新增成功");
              } else {
261
                // this.msgSuccess("新增失败");
纪泽龙's avatar
纪泽龙 committed
262 263
              }
            });
耿迪迪's avatar
耿迪迪 committed
264
          }
纪泽龙's avatar
纪泽龙 committed
265
        }
纪泽龙's avatar
纪泽龙 committed
266
      });
纪泽龙's avatar
纪泽龙 committed
267 268 269 270 271 272 273
    },
    handleClose(done) {
      done();
    },
    listRemove(e) {
      this.form.url = "";
      this.fileArr = [];
274
    },
纪泽龙's avatar
纪泽龙 committed
275
    getPipeInfos() {
276 277 278
      pipeAllInfoList({}).then((response) => {
        this.pipeList = response.data;
      });
纪泽龙's avatar
纪泽龙 committed
279
    },
纪泽龙's avatar
纪泽龙 committed
280
  },
纪泽龙's avatar
纪泽龙 committed
281 282 283
  watch: {
    dialogVisible(val) {
      if (val) {
284 285
        this.getPipeInfos();
      }
纪泽龙's avatar
纪泽龙 committed
286 287
    },
  },
纪泽龙's avatar
纪泽龙 committed
288
};
耿迪迪's avatar
耿迪迪 committed
289 290 291
</script>