$(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);
|
// }
|
}
|
});
|
}
|