fuchengshen
2022-07-04 343ba87e09501be7a63abde000a43e13a5b4f03e
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
"use script"; //开发环境建议开启严格模式
 
//对应widget.js中MyWidget实例化后的对象
var thisWidget;
var $table;
var drawEntity;
var selectType;
var nowData = [];
 
//当前页面业务
function initWidgetView(_thisWidget) {
  thisWidget = _thisWidget;
 
  $("#txtCity").citypicker({
    simple: true,
    level: "district",
    placeholder: "请选择省/市州/区县",
    province: "安徽省",
    city: "合肥市",
    // district: '蜀山区'
  });
  // $(".city-picker-span .placeholder").text("请选择省/市州/区县");
 
  initTable();
 
  $('input:radio[name="queryContent"]').change(function () {
    selectType = $(this).val();
    switch (selectType) {
      default:
        //按城市
        $(".queryByCity").show();
        $(".queryByDraw").hide();
        break;
      case "2": //当前视角范围
        $(".queryByCity").hide();
        $(".queryByDraw").hide();
        break;
      case "3": //按范围
        $(".queryByCity").hide();
        $(".queryByDraw").show();
        break;
    }
  });
 
  $("#query").click(function () {
    $table.bootstrapTable("load", []);
 
    $("#resultView").hide();
    $("#loadMore").hide();
    thisWidget.clearAll(selectType == "3");
 
    nowData = [];
 
    var queryVal = $.trim($("#queryText").val());
 
    switch (selectType) {
      default:
        //按城市
        var dnnm = $("#txtCity").data("citypicker").getCode();
        if (!dnnm) {
          window.toastr.error("请选择具体地区!");
          haoutil.loading.close();
          return;
        }
        if (queryVal.length == 0) {
          window.toastr.error("请输入 名称 关键字筛选数据!");
          return;
        }
        thisWidget.loadData({
          text: queryVal,
          city: dnnm,
          citylimit: true,
          page: 1,
        });
        break;
      case "2": //当前视角范围
        if (queryVal.length == 0) {
          window.toastr.error("请输入 名称 关键字筛选数据!");
          return;
        }
        var extent = thisWidget.getExtent();
        thisWidget.loadData({
          text: queryVal,
          polygon: [
            [extent.xmin, extent.ymin],
            [extent.xmin, extent.ymax],
            [extent.xmax, extent.ymax],
            [extent.xmax, extent.ymin],
          ],
          page: 1,
        });
        break;
      case "3": //按范围
        if (!thisWidget.drawGraphic) {
          haoutil.loading.hide();
          toastr.warning("请绘制限定范围!");
          return;
        }
        if (queryVal.length == 0) {
          window.toastr.error("请输入 名称 关键字筛选数据!");
          return;
        }
        thisWidget.loadData({
          text: queryVal,
          graphic: thisWidget.drawGraphic,
          page: 1,
        });
        break;
    }
  });
  //框选查询 矩形
  $("#drawRectangle").click(function () {
    clearAll();
    thisWidget.draw(1);
  });
  //框选查询   多边
  $("#drawPolygon").click(function () {
    clearAll();
    thisWidget.draw(2);
  });
  //框选查询   圆
  $("#drawCircle").click(function () {
    clearAll();
    thisWidget.draw(3);
  });
 
  $("#clearDraw").click(function () {
    $("#txtCity").citypicker("reset");
    $(".city-picker-span .placeholder").text("请选择省/市州/区县");
    $("#queryText").val("");
    clearAll();
    thisWidget.clearAll();
  });
 
  //加载更多- 下一页
  $("#loadMore").click(function () {
    thisWidget.loadMore();
  });
}
 
function loadSuccess(res) {
  var data = res.list;
  nowData = nowData.concat(data);
 
  $("#resultView").show();
  $table.bootstrapTable("append", data);
 
  $("#count").html(nowData.length);
  $("#allcount").html(res.allcount);
 
  if (data.length == 0 || nowData.length >= res.allcount || res.allcount < 25 || nowData.length < 20) {
    $("#loadMore").hide();
  } else {
    $("#loadMore").show();
  }
}
 
//清除页面
function clearAll() {
  $table.bootstrapTable("load", []);
  $("#resultView").hide();
  $("#loadMore").hide();
  thisWidget.clearAll();
}
 
function getHeight() {
  return $(window).height() - 230;
}
 
function initTable() {
  $table = $("#table");
  $table.bootstrapTable({
    height: getHeight(),
    singleSelect: true, //单选
    pagination: false,
    iconsPrefix: "fa",
    columns: [
      {
        field: "index",
        title: "序号",
        sortable: true,
        editable: false,
        align: "left",
        formatter: function (value, row, index) {
          return index + 1;
        },
      },
      {
        field: "name",
        title: "名称",
        sortable: true,
        editable: false,
        align: "left",
        formatter: function (value, row) {
          if (value.length == 0 || !value) {
            return "";
          }
          return value;
        },
      },
      {
        field: "address",
        title: "地址",
        sortable: true,
        editable: false,
        align: "left",
        formatter: function (value, row) {
          if (value.length == 0 || !value) {
            return "";
          }
          return value;
        },
      },
    ],
    onClickRow: function (item, $element, field) {
      thisWidget.flyTo(item);
    },
  });
 
  $(window).resize(function () {
    $table.bootstrapTable("refreshOptions", {
      height: getHeight(),
    });
  });
}