1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
$(function () {
    $("#jqGrid").jqGrid({
        url: restServerBaseURL + 'org/unit/list',
        datatype: "json",
        colModel: [
            { label: '单位ID', name: 'unitid', index: 'UNITID', width: 0, key: true,hidden:true },
            { label: '单位名称', name: 'unitname', index: 'UNITNAME', width: 120,align:'center',sortable: true },
            { label: '单位类型', name: 'unittypetext', index: 'unittypetext', width: 80,align:'center' },
            { label: '联系电话', name: 'contactnumber', index: 'CONTACTNUMBER', width: 60,align:'center' },
            { label: '区划ID', name: 'qhid', index: '', width: 80,hidden:true,align:'center' },
            { label: '操作', width: 80,align:'center',sortable:false,formatter:function(value,grid,rows,state){
                var unitid = rows.unitid, html = "", pid = rows.parentid;
                if(hasPermission('org:unit:edit')){
                    html += '<input type="button" id="action"  class="btn btn-warning" value="编辑" style="margin-right:5px;padding:3px 6px;" onclick=vm.update("' + unitid + '",'+pid+')>';
                    html += '<input type="button" id="addchild"  class="btn btn-success" value="新增" style="margin-right:5px;padding:3px 6px;" onclick=vm.addchild("' + unitid + '")>';
                    html += '<input type="button" id="del"  class="btn btn-danger" value="删除" style="padding:3px 6px;" onclick="vm.del(\'' + unitid + '\')">';
                }
                return html;
              }
            }
        ],
        viewrecords: true,
        height: "auto",
        rowNum: 10,
        //rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 50,
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
            // $("#jqGrid").jqGrid('setGridWidth', $("#rapp").width()-0.1);
        },
        onSortCol:function(index,colindex,sortorder){
            jQuery("#jqGrid").jqGrid('setGridParam',{
                page:$(".ui-pg-input").val()
            });
        }
    });
    $("#jqGrid").jqGrid('setLabel','rn','序号',{'text-align':'center'},'');
    initUnitType();
    initTree();
 
    //初始化高度
    $(".left_div").css('min-height',($(window).height() *0.99)+'px');
    //当文档窗口发生改变时 触发
    $(window).resize(function () {
        $(".left_div").css('min-height',($(window).height() *0.99)+'px');
    });
});
 
var ztree;
var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "unitid",
            pIdKey: "parentid",
            rootPId: -1,
        },
        key: {
            url:"nourl",
            name:"unitname"
        },
    },
    callback: {
        onClick:zTreeOnClick
    }
};
 
var vm = new Vue({
    el:'#rapp',
    data:{
        showList: true,
        title: null,
        unit: {}
    },
    methods: {
        query: function () {
            vm.unit.unitname = $("#unitname").val();
            vm.unit.unittype = $("#unittype").val();
            vm.reload();
        },
        add: function(){
            window.open(baseURL + "admin/modules/org/unit_edit.html?Id=&parentid=", "_blank");
        },
        addchild:function(unitid){
            window.open(baseURL + "admin/modules/org/unit_edit.html?Id=&parentid="+unitid, "_blank");
        },
        update: function (unitid,pid) {
            window.open(baseURL + "admin/modules/org/unit_edit.html?Id="+unitid+"&parentid="+pid, "_blank");
        },
        saveOrUpdate: function () {
            var url = vm.title == "新增" ? "org/unit/save" : "org/unit/update";
            $.ajax({
                type: "POST",
                url: restServerBaseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.unit),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        del: function (unitid) {
            confirm('确定要删除选中的记录?', function(){
                $.ajax({
                    type: "POST",
                    url: restServerBaseURL + "org/unit/delete",
                    contentType: "application/json",
                    data: "[\"" + unitid + "\"]",
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.refresh();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getInfo: function(unitid){
            $.get(restServerBaseURL + "org/unit/info/"+unitid, function(r){
                vm.unit = r.unit;
            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            //点击查询时,当前页设置为第一页
            $("#jqGrid").jqGrid('setGridParam',{
                url: restServerBaseURL + 'org/unit/list',
                postData:{'unitname':vm.unit.unitname,
                          'unittype':vm.unit.unittype
                },page:1
 
            }).trigger("reloadGrid");
        },
        refresh: function () {
            vm.showList = true;
            window.location.reload();
        }
    }
});
 
function findPinyinByKeyWord(){
    var unitname = $("#unitname").val();
    
    $("#unitname").autocomplete({
 
        source: restServerBaseURL + 'org/unit/findPinyinByKeyWord?keyWord='+encodeURI(encodeURI(unitname)),  //请求的url
 
        minLength: 1,
 
    });
 
}
 
//初始化单位类型
function initUnitType(){
    $.ajax({
        type: "GET",
        url: restServerBaseURL + "sys/fieldvalue/queryListByKey?key=UnitType",
        contentType: "application/json",
        success: function(msg) {
            var sysFieldList = msg.sysFieldList;
            jQuery("#unittype").append("<option value=''>全部</option>")
            jQuery.each(sysFieldList, function(i, item) {
                jQuery("#unittype").append("<option value=" + item.vcode + ">" + item.vtext + "</option>");
            });
        }
    });
}
 
//初始化树
function initTree(){
    //加载菜单树
    $.get(restServerBaseURL + "org/unit/queryUnitTreeList", function(r){
        ztree = $.fn.zTree.init($("#menuTree"), setting, r.unitList);
        var node = ztree.getNodeByParam("unitid", 0);
        ztree.selectNode(node);
       // ztree.expandAll(true);展开全部
    })
}
 
var selecttreeid="0";  //用于排序时要列的parentid值
//树点击事件
function zTreeOnClick(event,treeId,treeNode){
    if (treeNode.parentid == -1) {//全国
        selecttreeid="0";
        vm.reload();
    }else{
        selecttreeid=treeNode.unitid;
        showTreeChildList(treeNode.unitid);
    }
}
 
//根据树节点加载右侧列表
function showTreeChildList(id){
    var page = $("#jqGrid").jqGrid('getGridParam','page');
    $("#jqGrid").jqGrid('setGridParam',{
        url:restServerBaseURL+"org/unit/queryTreeChildList",
        postData:{unitid:id},
        page:1
    }).trigger("reloadGrid");
}
 
//排序列表
function ShowOrderList()
{
    $.ajax({
        type: "GET",
        url: restServerBaseURL + "org/unit/queryListByParentid?unitid="+selecttreeid,
        contentType: "application/json",
        success: function(msg) {
            jQuery("#orgunit_order").empty();
            var orgUnitList = msg.orgUnitList;
            jQuery.each(orgUnitList, function(i, item) {
                jQuery("#orgunit_order").append("<option rorder="+item.rorder+" value=" + item.unitid + ">" + item.unitname + "</option>");
            });
            $("#orgunit_order").attr("size", 15);
        }
    });
}
 
 
// var sorts = "";
function UpdateOrder(type){
    // debugger;
    if ($("#orgunit_order option:selected").length == 0) {
        alert("请选择节点!");
        return false;
    }
    if ($("#orgunit_order option:selected").length >1) {
        alert("请选择一个节点!");
        return false;
    }
    valueids = $("#orgunit_order option:selected").attr("value") +",";
    if (type == 'up') {//升序
        if ($("#orgunit_order option:selected").prev().length == 0) {
            alert("已经是最上了!");
            return false;
        }else{
            // valueids += $("#orgunit_order option:selected").prev().attr("value");
            // sorts = $("#orgunit_order option:selected").prev().attr("rorder")+",";
            $('#orgunit_order option:selected').insertBefore($('#orgunit_order option:selected').prev());
        }
    }else if(type == 'down'){//降序
        if ($("#orgunit_order option:selected").next().length == 0) {
            alert("已经是最下了!");
            return false;
        }else{
            // valueids += $("#orgunit_order option:selected").next().attr("value");
            // sorts = $("#orgunit_order option:selected").next().attr("rorder")+",";
            $('#orgunit_order option:selected').insertAfter($('#orgunit_order option:selected').next());
        }
    }
    else if(type == 'allup') {
        if ($("#orgunit_order option:selected").prev().length == 0) {
            alert("已经是最上了!");
            return false;
        }else {
            // valueids += $("#orgunit_order option:selected").first().attr("value");
            // sorts = $("#orgunit_order option:selected").first().attr("rorder")+",";
            $('#orgunit_order option:selected').insertBefore($('#orgunit_order option').first());
        }
    }
    else if(type == 'alldown') {
        if ($("#orgunit_order option:selected").next().length == 0) {
            alert("已经是最下了!");
            return false;
        }else {
            // valueids += $("#orgunit_order option:selected").last().attr("value");
            // sorts = $("#orgunit_order option:selected").last().attr("rorder")+",";
            $('#orgunit_order option:selected').insertAfter($('#orgunit_order option').last());
        }
    }
    // sorts+=$("#orgunit_order option:selected").attr("rorder");
 
}
 
function submitOrder() {
    var valueids="";
    $("#orgunit_order option").each(function () {
        if(valueids != "") valueids+=",";
        valueids += $(this).attr("value");
    });
    $.ajax({
        type: "POST",
        url: restServerBaseURL + "org/unit/updateRorder",
        contentType: "application/json",
        data: JSON.stringify({valueids:valueids}),
        success: function (r) {
            if(r.code === 0) {
                alert('保存成功!');
                ShowOrderList();
                vm.reload();
            }
            else {
                alert(r.msg);
            }
            // if (r.code === 0) {
            //     //ShowOrderList();
            //     var thisOption = $("#orgunit_order option:selected");
            //     var upOption = $("#orgunit_order option:selected").prev();
            //     var nextOption = $("#orgunit_order option:selected").next();
            //     $("#orgunit_order option").each(function(){
            //         if ($(this).attr("value") == $(thisOption).attr("value")) {
            //             $(this).remove();
            //         }
            //         if(type == 'up'){
            //             if($(this).attr("value") == $(upOption).attr("value")){
            //                 $(this).before("<option selected='selected' rorder='"+
            //                     $(this).attr("rorder")+"' value='"+
            //                     $(thisOption).attr("value")+"'>"+
            //                     $(thisOption).text()+"</option>");
            //                 $(this).attr("rorder",$(thisOption).attr("rorder"));
            //             }
            //         }else{
            //             if($(this).attr("value") == $(nextOption).attr("value")){
            //                 $(this).after("<option selected='selected' rorder='"+
            //                     $(this).attr("rorder")+"' value='"+
            //                     $(thisOption).attr("value")+"'>"+
            //                     $(thisOption).text()+"</option>");
            //                 $(this).attr("rorder",$(thisOption).attr("rorder"));
            //             }
            //         }
            //     })
            // } else {
            //     alert(r.msg);
            // }
        }
    });
}