hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
192
193
194
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<template>
  <div class="grid_watch">
    <div class="map">
      <v-poi :map="map"></v-poi>
      <div id="map-grid"></div>
      <transition name="moveright">
        <div class="f">
          <v-m
            @on-value="onSetPoly"
            :area="area"
            :edit="item"
            v-if="+type !== 2"
          >
            <button
              class="m_btn small bgc_green"
              v-if="+type === 1"
              @click="onResetModel"
            >
              重新绘制网格区域
            </button>
          </v-m>
          <v-m2 v-else :item="item"></v-m2>
        </div>
      </transition>
    </div>
    <p class="desc">
      点击鼠标左键在地图上进行标点绘制,标记3个点自动生成网格面,可拖动网格边缘上的圆点,进行多边绘制,绘制完成后可在弹出的编辑框里进行网格基本信息编辑,为防止误操作,该页面最多可创建1个网格,若还需绘制新的网格,请在点击确定添加后,在跳转后的页面里再次点击添加后重新进入此页面再次绘制即可。
    </p>
    <div class="flex">
      <button class="m_btn" @click="onAdd" v-if="+type === 0">确认添加</button>
      <button class="m_btn" v-else-if="+type === 1" @click="onEdit">
        保存修改
      </button>
      <button
        class="m_btn"
        @click="$router.back()"
        v-if="+type === 1 || +type === 0"
      >
        取消
      </button>
      <button class="m_btn" @click="$router.back()" v-if="+type === 2">
        返回
      </button>
    </div>
  </div>
</template>
 
<script>
import vM from "./_m";
import vM2 from "./_m2";
import vPoi from "com/map/poi";
export default {
  props: {
    type: { type: [String, Number], default: 0 },
    item: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  components: { vM, vM2, vPoi },
  data() {
    return {
      map: null,
      $map: null,
      modelId: "",
      path: [],
      area: "",
      child: {}
    };
  },
  watch: {
    item: {
      handler() {
        this.setItem();
      },
      deep: true
    }
  },
  inject: ["appObject"],
  methods: {
    init() {
      let ts = this;
      this.$api.post(
        "eventgridmember/event/list",
        { pageNum: 1, pageSize: 60 },
        e => {
          let m = e.records.map(r => {
            let os = {
              path: [],
              poyConfig: {
                color: r.fillColor || "",
                lineWidth: r.lineBroadband || 1,
                line: r.lineColor,
                opacity: r.opacity || 0.5
              },
              ext: r
            };
            try {
              os.path = JSON.parse(r.data);
            } catch (e) {}
            return ts.appObject(os, {});
          });
          m = m
            .filter(r => {
              return r.path.length >= 3;
            })
            .forEach(v => {
              ts.map.polygon(
                v,
                res => {
                  let dv = res.data;
                  dv.edit.close();
                  dv.event.on("click", () => {
                    ts.childData = dv.data.ext;
                  });
                },
                1
              );
            });
        }
      );
    },
    onEdit() {
      if (!this.child.id) return demo.toast("请先绘制网格");
      if (!this.child.title) return demo.toast("请输入网格名称");
      if (!this.child.ids.length) return demo.toast("请选择网格员");
      if (this.path.length === 0) return demo.toast("请绘制网格");
      let v = this.child;
      let os = {
        area: v.area,
        data: JSON.stringify(
          this.path.map(r => {
            return [r.lng, r.lat];
          })
        ),
        gridCommunityId: v.gridCommunityId,
        lcGridId: v.lcGridId,
        fillColor: v.color,
        gridName: v.title,
        lineBroadband: v.px,
        lineColor: v.color2,
        memberIds: v.ids,
        remarks: v.desc,
        gridId: v.id
      };
      let ts = this;
      ts.$model.model("20", "", v => {
        if (v) {
          ts.$api.post("eventgridmember/event/edit", os, () => {
            demo.toast("编辑成功");
            setTimeout(() => {
              ts.$router.back();
            }, 300);
          });
        }
      });
    },
    onResetModel() {
      this.$model.model("21", "", e => {
        if (e) {
          this.map.polygonDel({ id: this.modelId });
          this.path = [];
          this.modelId = "";
          this.onCreated();
        }
      });
    },
    onAdd() {
      if (!this.child.id) return demo.toast("请先绘制网格");
      if (!this.child.title) return demo.toast("请输入网格名称");
      if (!this.child.ids.length) return demo.toast("请选择网格员");
      let v = this.child;
      let os = {
        area: v.area,
        data: JSON.stringify(
          this.path.map(r => {
            return [r.lng, r.lat];
          })
        ),
        gridCommunityId: v.gridCommunityId,
        lcGridId: v.lcGridId,
        lcGridName: v.lcGridName,
        fillColor: v.color,
        gridName: v.title,
        lineBroadband: v.px,
        lineColor: v.color2,
        memberIds: v.ids,
        remarks: v.desc
      };
      let ts = this;
      ts.$model.model("25", "", v => {
        if (v) {
          ts.$api.post("eventgridmember/event/add", os, () => {
            demo.toast("添加成功");
            setTimeout(() => {
              ts.$router.back();
            }, 300);
          });
        }
      });
    },
    onSetPoly(v) {
      console.log(v);
      this.area = v.area;
      this.child = v;
      if (this.modelId) {
        this.map.polygonOption({
          id: this.modelId,
          config: {
            color: v.color,
            bgcOpacity: v.opacity / 100,
            lineWidth: v.px,
            line: v.color2
          }
        });
      }
    },
    setItem() {
      if (!this.item.id) return 0;
      let v = this.item;
      let ts = this;
      console.log(v);
      try {
        ts.path = JSON.parse(v.data);
      } catch (e) {
        ts.path = [];
      }
      // ts.area = v.area;
      ts.map.polygon(
        {
          path: ts.path,
          poyConfig: {
            line: v.lineColor,
            color: v.fillColor,
            lineWidth: +v.lineBroadband,
            bgcOpacity: 0.5
          }
        },
        e => {
          ts.modelId = e.data.id;
          ts.area = e.data.area;
          ts.path = e.data.path;
          ts.map.polygonGets(ts.modelId, r => {
            if (r.code) {
              ts.area = r.data.area;
              ts.path = r.data.path;
            }
          });
        }
      );
    },
    onCreated() {
      let t = this;
      t.map.polygon(
        { poyConfig: { line: "#38f", color: "rgba(0, 0, 0, 0)" } },
        e => {
          t.modelId = e.data.id;
          t.area = e.data.area;
          t.path = e.data.path;
          t.map.polygonGets(t.modelId, r => {
            if (r.code) {
              t.area = r.data.area;
              t.path = r.data.path;
            }
          });
        }
      );
    }
  },
  mounted() {
    let t = this;
    t.init();
    // t.map = new DemoAMap("#map-grid", { zoom: 15, layer: [2] });
    t.map = new DemoAMap("#map-grid", {}, e => {
      if (e.code) {
        this.$map = e.data.map;
      }
    });
    t.map.style("blue");
    t.map.center(101.640511, 26.601773);
    if (+t.type === 0) {
      t.onCreated();
    } else {
      t.setItem();
    }
  }
};
</script>
<style lang="less" scoped>
.grid_watch {
  padding: 10px;
  .map {
    height: 500px;
    background-color: #eee;
    position: relative;
    margin-bottom: 15px;
    .f {
      position: absolute;
      right: 10px;
      top: 10px;
      height: calc(100% - 50px);
      width: 250px;
      background: rgba(34, 34, 34, 0.3);
      color: #fff;
    }
    #map-grid {
      width: 100%;
      height: 100%;
    }
  }
  .desc {
    font-size: 15px;
    line-height: 1.2;
    margin-bottom: 20px;
    letter-spacing: 2px;
  }
  .m_btn {
    margin-right: 15px;
  }
}
</style>