zengh
2022-05-16 63ad2c3598400370dd7da5534659fd7e768a0a4a
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
/**
 * infoWindow的template
 * @author Wenyb
 * @date 2015/11/4
 */
define([
    "dojo",
    "dojo/_base/declare",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/text!controls/infowindow/template.html",
    "dojo/_base/lang",
    "dojo/query",
    "dojo/dom-construct",
    "dojo/dom-style",
    "dojo/on",
    "dojo/dom-class",
    "dojo/dom-attr",
    "controls/searchbox/SearchBox",
    "base/AppEvent",
    "base/ConfigData",
    "dojo/domReady!"
], function(
    dojo,
    declare,
    _WidgetBase,
    _TemplatedMixin,
    template,
    lang,
    query,
    domConstruct,
    domStyle,
    on,
    domClass,
    domAttr,
    SearchBox,
    AppEvent,
    ConfigData
) {
    var Widget = declare([_WidgetBase, _TemplatedMixin], {
        templateString: template,
        _tabType: "fromHear", //fromHear,toHear,nearBy三种类型
        constructor: function(options) {
            this._tabType = "fromHear";
            this.routeStartSearchboxId = "InfowindowRouteStartSearchBox" + uuid();
            this.routeEndSearchboxId = "InfowindowRouteEndSearchBox" + uuid();
            this.nearbySearchBoxId = "InfowindowNearbySearchBox" + uuid();
            this.nearbySearchWidgetId = "NearbySearchWidget";
        },
        postCreate: function() {
            this.inherited(arguments);
            this.nearbySearchboxControl = new SearchBox({
                id: this.nearbySearchBoxId,
                baseClass: "infowindowNearbySearchbox",
                disableSuggest: true
            }, this.nearbySearchbox);
            this.nearbySearchboxControl.startup();
 
            this.routeStartSearchboxControl = new SearchBox({
                id: this.routeStartSearchboxId,
                baseClass: "infowindowRouteSearchbox",
                placeholder: "请选择到达地点"
            }, this.routeStartSearchbox);
            this.routeStartSearchboxControl.startup();
 
            this.routeEndSearchboxControl = new SearchBox({
                id: this.routeEndSearchboxId,
                hockId: ConfigData.hockId.routeEndSearchbox,
                baseClass: "infowindowRouteSearchbox",
                placeholder: "请选择出发地点"
            }, this.routeEndSearchbox);
            this.routeEndSearchboxControl.startup();
 
        },
        startup: function() {
            this.initEventHandler();
        },
        initEventHandler: function() {                
            query(".custom-infotemplate-nearbysearch-poitype span").on("click", lang.hitch(this, function(evt) {
                var poiType = domAttr.get(evt.currentTarget, "data-poi-type");
                var poiName = evt.currentTarget.innerHTML;
                AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, {
                    hockId: this.nearbySearchWidgetId,
                    type: "updateState",
                    graphic: this.getGraphic()
                });
                AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, {
                    hockId: this.nearbySearchWidgetId,
                    type: "search",
                    poiType: poiType,
                    poiName: poiName,
                    model:"address"
                });
            }));
 
            AppEvent.addAppEventListener(AppEvent.SEARCHBOX_QUERY, lang.hitch(this, this.onSearchboxQueryHandler));
            AppEvent.addAppEventListener(AppEvent.ROUTE_ARGUMENT_CHANGED, lang.hitch(this, this.onRouteArgumentChanged));
        },
 
        onRouteArgumentChanged: function(evt) {
            switch (evt.type) {
                case "start":
                    AppEvent.dispatchAppEvent(AppEvent.CHANGE_SEARCHBOX_STATE, {
                        hockId: this.routeStartSearchboxId,
                        type: "update",
                        data: evt.data
                    });
                    break;
                case "end":
                    AppEvent.dispatchAppEvent(AppEvent.CHANGE_SEARCHBOX_STATE, {
                        hockId: this.routeEndSearchboxId,
                        type: "update",
                        data: evt.data
                    });
                    break;
                default:
                    break;
            }
        },
 
        onSearchboxQueryHandler: function(evt) {
            if (evt.hockId == this.routeStartSearchboxId) {
                this.routeStartSearchboxQueryHandler(evt);
            } else if (evt.hockId == this.routeEndSearchboxId) {
                this.routeEndSearchboxQueryHandler(evt);
            } else if (evt.hockId == this.nearbySearchBoxId) {
                this.nearbySearchboxQueryHandler(evt);
            }
        },
        nearbySearchboxQueryHandler: function(evt) {
            switch (evt.type) {
                case "search":
                    if (evt.args.keyword) {
                        AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, {
                            hockId: this.nearbySearchWidgetId,
                            type: "updateState",
                            graphic: this.getGraphic()
                        });
                        AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, {
                            hockId: this.nearbySearchWidgetId,
                            type: "search",
                            keyword: evt.args.keyword,
                            poiType: null,
                            poiName: "全部"
                        });
                    }
                    break;
                case "clear":
                    AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, {
                        hockId: this.nearbySearchWidgetId,
                        type: "clearState"
                    });
                    break;
                default:
                    break;
            }
        },
        routeStartSearchboxQueryHandler: function(evt) {
            switch (evt.type) {
                case "suggest":
                    AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, {
                        end: this.getGraphic(),
                        start: null
                    });
                    AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, {
                        hockId: this.routeSearchWidgetId,
                        type: "start",
                        searchboxEventType: "suggest",
                        poiId: evt.args.poiId
                    });
 
                    break;
                case "search":
                    AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, {
                        end: this.getGraphic(),
                        start: null
                        /*start: evt.args.keyword*/
                    });
                    AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, {
                        hockId: this.routeSearchWidgetId,
                        type: "start",
                        searchboxEventType: "search",
                        keyword: evt.args.keyword
                    });
                    break;
                case "clear":
                    AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, {
                        hockId: this.routeSearchWidgetId,
                        type: "start",
                        searchboxEventType: "clear",
                    });
                    break;
                default:
                    break;
            }
        },
        routeEndSearchboxQueryHandler: function(evt) {
            switch (evt.type) {
                case "suggest":
                    AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, {
                        start: this.getGraphic(),
                        end: null
                    });
                    AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, {
                        hockId: this.routeSearchWidgetId,
                        type: "end",
                        searchboxEventType: "suggest",
                        poiId: evt.args.poiId
                    });
                    break;
                case "search":
                    AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, {
                        start: this.getGraphic(),
                        end: null
                    });
                    AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, {
                        hockId: this.routeSearchWidgetId,
                        type: "end",
                        searchboxEventType: "search",
                        keyword: evt.args.keyword
                    });
                    break;
                case "clear":
                    AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, {
                        hockId: this.routeSearchWidgetId,
                        type: "end",
                        searchboxEventType: "clear",
                    });
                    break;
                default:
                    break;
            }
        },
 
        _tabButtonClick: function(evt) {
            if (evt.target == this.fromHearButton) {
                this.switchTab("fromHear");
            } else if (evt.target == this.toHearButton) {
                this.switchTab("toHear");
            } else {
                this.switchTab("nearBy");
            }
        },
        switchTab: function(type) {
            switch (this._tabType) {
                case "fromHear":
                    domClass.remove(this.fromHearButton);
                    domClass.add(this.fromHearButton, "custom-infotemplate-tabbutton");
                    break;
                case "toHear":
                    domClass.remove(this.toHearButton);
                    domClass.add(this.toHearButton, "custom-infotemplate-tabbutton");
                    break;
                case "nearBy":
                    domClass.remove(this.nearByButton);
                    domClass.add(this.nearByButton, "custom-infotemplate-tabbutton");
                    break;
            }
            if (type == "fromHear") {
                this._tabType = type;
                domClass.remove(this.fromHearButton);
                domClass.add(this.fromHearButton, "custom-infotemplate-tabbutton-actived");
                domStyle.set(this.nearByPanel, "display", "none");
                domStyle.set(this.routeEnd, "display", "none");
                domStyle.set(this.routeStart, "display", "block");
            } else if (type == "toHear") {
                domClass.remove(this.toHearButton);
                domClass.add(this.toHearButton, "custom-infotemplate-tabbutton-actived");
                domStyle.set(this.nearByPanel, "display", "none");
                domStyle.set(this.routeStart, "display", "none");
                domStyle.set(this.routeEnd, "display", "block");
                this._tabType = type;
            } else if (type == "nearBy") {
                this._tabType = type;
                domClass.remove(this.nearByButton);
                domClass.add(this.nearByButton, "custom-infotemplate-tabbutton-actived");
                domStyle.set(this.nearByPanel, "display", "block");
                domStyle.set(this.routeStart, "display", "none");
                domStyle.set(this.routeEnd, "display", "none");
            }
        },
        reset: function() {
 
            domStyle.set(this.tabcontainer, "display", "block");
            domStyle.set(this.content, "bottom", "");
            this.content.innerHTML = "";
            domConstruct.empty(this.content);
 
            //            this._tabType = "fromHear";
            //            this.routekeywordInput.innerHTML = "";
            //            domStyle.set(this.nearByPanel, "display", "none");
            //            domStyle.set(this.routePanel, "display", "block");
            //            domClass.remove(this.fromHearButton);
            //            domClass.add(this.fromHearButton, "custom-infotemplate-tabbutton-actived");
            //            domClass.remove(this.toHearButton);
            //            domClass.add(this.toHearButton, "custom-infotemplate-tabbutton");
            //            domClass.remove(this.nearByButton);
            //            domClass.add(this.nearByButton, "custom-infotemplate-tabbutton");
            //this.nearbySearchboxControl.clear();
        },
        setGraphic: function(graphic) {
            this.graphic = graphic;
        },
        getGraphic: function(graphic) {
            return this.graphic;
        },
        hideTab: function() {
            domStyle.set(this.tabcontainer, "display", "none");
            domStyle.set(this.content, "bottom", "0px");
        },
        setContent: function(content) {
            if (typeof(content) == "string") {
                this.content.innerHTML = content;
            } else {
                domConstruct.place(content, this.content);
            }
 
        }
    });
    return Widget;
});