$(function(){
|
cheackForm("from");
|
cheackForm("deptfrom");
|
UpFile();
|
$("title").text("单位管理 - " + systemTitle);
|
});
|
|
function UpFile() {
|
var callBackUrl = "http://" + window.location.host + baseURL + "admin/modules/ajaxuploadproxy.html";
|
new AjaxUpload('#upload', {
|
action: restServerBaseURL + 'sys/attachment/upload?token=' + token,
|
name: 'file',
|
data: {callBackUrl:callBackUrl,category:'unit'},
|
autoSubmit:true,
|
responseType:"json",
|
onSubmit:function(file, extension){
|
if (!(extension && /^(jpg|jpeg|png|gif)$/.test(extension.toLowerCase()))){
|
alert('只支持jpg、png、gif格式的图片!');
|
return false;
|
}
|
layer.load(2);
|
},
|
onComplete : function(file, r){
|
/* layer.closeAll('loading');
|
if(r.code == 0){
|
vm.reload();
|
}else{
|
alert(r.msg);
|
}*/
|
}
|
});
|
}
|
function ShowParent() {
|
$("#rowparent").show();
|
|
}
|
function ajaxUploadComplete(code,path){
|
layer.closeAll('loading');
|
if(code == 0){
|
alert("上传成功");
|
vm.unit.photourl = decodeURIComponent(path.toString());
|
$("#imgUrl").attr("src",uploadFileResource + vm.unit.photourl);
|
}else{
|
alert("上传失败");
|
}
|
}
|
var vm = new Vue({
|
el: '#rapp',
|
data: {
|
showList: true,
|
title: null,
|
unit: {},
|
form2:null,
|
unitid :null,
|
parentid:null,
|
isdept:null,
|
dept:{}
|
},
|
methods: {
|
saveOrUpdate: function() {
|
if ($("#from").valid()) {
|
if (vm.title == "新增") {
|
var url = "org/unit/save";
|
}
|
if (vm.title == "单位信息") {
|
var url = "org/unit/update";
|
}
|
var qhids = $("#qhIds").val();
|
var managerids = $("#unitmanagerIds").val();
|
vm.unit.unittype = $("#UNITTYPE").val();
|
if (vm.parentid != null && vm.parentid != 0) {
|
vm.unit.parentid = vm.parentid;
|
}
|
vm.unit.isdept = 0;
|
$.ajax({
|
type: "POST",
|
url: restServerBaseURL + url,
|
contentType: "application/json",
|
data: JSON.stringify({orgUnit:vm.unit,qhids:qhids,managerids:managerids}),
|
success: function(r) {
|
if(r.code === 0) {
|
alert('操作成功', function() {
|
if (vm.title == "新增") {
|
var href = window.location.href;
|
var pid = "";
|
var newurl = href.substring(0,href.indexOf('?'))+"?Id="+r.unitid;
|
if (vm.parentid != '' && vm.parentid != null) {
|
pid = vm.parentid;
|
}
|
newurl+="&parentid="+pid;
|
window.location.href = newurl;
|
}else{
|
window.location.reload();
|
}
|
if(parent.opener.vm && parent.opener.vm.reload){
|
parent.opener.vm.refresh();
|
}
|
});
|
} else {
|
alert(r.msg);
|
}
|
}
|
});
|
}
|
},
|
getInfo: function(unitid) {
|
$.get(restServerBaseURL + "org/unit/info/" + unitid, function(r) {
|
vm.unit = r.unit;
|
if (vm.unit != null) {
|
$("#unitmanagerIds").val(vm.unit.managerids);
|
$("#unitmanagers").val(vm.unit.managernames);
|
$("#qhIds").val(vm.unit.regionid);
|
$("#qhNames").val(vm.unit.regionname);
|
$("#UNITTYPE").val(vm.unit.unittype);
|
}
|
if(vm.unit.photourl != null && vm.unit.photourl !=""){
|
$("#imgUrl").attr("src",uploadFileResource + vm.unit.photourl);
|
}
|
});
|
},
|
del: function(unitid,type){
|
confirm('确定要删除选中记录?', function(){
|
$.ajax({
|
type: "POST",
|
url: restServerBaseURL + "org/unit/delete",
|
contentType: "application/json",
|
data: "[\"" + unitid + "\"]",
|
success: function(r){
|
if(r.code == 0){
|
alert('操作成功', function(){
|
if(type == 0){
|
vm.reload();
|
}else{
|
reloadDept();
|
}
|
});
|
}else{
|
alert(r.msg);
|
}
|
}
|
});
|
})
|
}
|
},
|
created: function() {
|
unitid = GetQuerString("Id");
|
this.parentid = GetQuerString("parentid");
|
$("#qhNames").attr("readonly",true);
|
$("#unitmanagers").attr("readonly",true);
|
if(unitid == null) {
|
this.title = "新增";
|
this.unit = {};
|
}else{
|
this.title = "单位信息";
|
this.getInfo(unitid);
|
}
|
//绑定“单位类型”
|
$.ajax({
|
type: "GET",
|
url: restServerBaseURL + "sys/fieldvalue/queryListByKey?key=UnitType",
|
contentType: "application/json",
|
success: function(msg) {
|
var sysFieldList = msg.sysFieldList;
|
jQuery.each(sysFieldList, function(i, item) {
|
if(item.vcode == vm.unit.unittype) {
|
jQuery("#UNITTYPE").append("<option value=" + item.vcode + " selected = 'true'>" + item.vtext + "</option>");
|
}
|
else {
|
jQuery("#UNITTYPE").append("<option value=" + item.vcode + ">" + item.vtext + "</option>");
|
}
|
});
|
}
|
});
|
}
|
});
|
|
|
//获取地址栏参数
|
function GetQuerString(name){
|
var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
|
var r = window.location.search.substr(1).match(reg);
|
if (r!=null) {
|
if (r[2]!=''&&r[2]!=null&&r[2]!=undefined) {
|
return parseInt(unescape(r[2]));
|
}else{
|
return null;
|
}
|
}else{
|
return null;
|
}
|
}
|
|
//行政区划
|
function xzqhtionOfUnitXqh(){
|
//window.open("xzqhEdit_edit.html",'true', 'height=600, width=1100, top=150,left=220');
|
$("#jqXzqhGrid").jqGrid({
|
url: restServerBaseURL + 'org/region/list',
|
datatype: "json",
|
colModel: [
|
{ label: '区划名称', name: 'regionname', index: 'REGIONNAME', width: 50, align: 'center' },
|
{ label: '编码', name: 'regionid', index: 'REGIONID', width: 50, key: true, align: 'center' },
|
{ label: '行政区划代码', name: 'regioncode', index: 'REGIONCODE', width: 50 ,align: 'center' },
|
{ label: '审批级别', name: 'approvelevel', index: 'APPROVELEVEL', width: 50, align: 'center',
|
formatter: function(value, grid, rows, state) {
|
var spjb = rows.approvelevel;
|
if(spjb == "A") {
|
return "国家级";
|
} else if(spjb == "B") {
|
return "省级";
|
} else if(spjb == "C"){
|
return "市级";
|
}else if(spjb == "D"){
|
return "区县级";
|
}else{
|
return "";
|
}
|
}
|
},
|
{ label: '海域使用等级', name: 'areausegrade', index: 'AREAUSEGRADE', width: 50, align: 'center' },
|
],
|
viewrecords: true,
|
height: "100%",
|
rowNum: 10,
|
//rowList : [10,30,50],
|
rownumbers: true,
|
rownumWidth: 50,
|
autowidth:true,
|
multiselect: true,
|
pager: "#jqXzqhGridPager",
|
jsonReader : {
|
root: "page.list",
|
page: "page.currPage",
|
total: "page.totalPage",
|
records: "page.totalCount"
|
},
|
prmNames : {
|
page:"page",
|
rows:"limit",
|
order: "order"
|
},
|
gridComplete:function(){
|
//隐藏grid底部滚动条
|
$("#jqXzqhGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
|
}
|
});
|
$("#jqXzqhGrid").jqGrid('setLabel','rn','序号',{'text-align':'center'},'');
|
$("#jqXzqhGrid").setGridWidth($("#jqXzqh").width()-35);
|
}
|
|
//单位管理员
|
function unitManager(){
|
//window.open("unitmanager_edit.html?unitid="+unitid,'true', 'height=600, width=1100, top=150,left=220');
|
$("#jqManagerGrid").jqGrid({
|
url: restServerBaseURL + 'org/unitmanager/userlist',
|
datatype: "json",
|
colModel: [
|
{ label: '用户编号', name: 'userid', index: 'USERID', width: 50, key: true,hidden:true },
|
{ label: '用户中文名', name: 'chinesename', index: 'CHINESENAME', width: 50,hidden:true },
|
{ label: '中文名【用户名】', name: 'loginname', index: 'LOGINNAME', width: 80, align: 'center',
|
formatter: function(value, grid, rows, state) {
|
var loginname = rows.loginname;
|
var chinesename = rows.chinesename;
|
return chinesename + "【" + loginname + "】";
|
}
|
},
|
{ label: '手机号[接收短信]', name: 'mobileno', index: 'MOBILENO', width: 80, align: 'center',
|
formatter: function(value, grid, rows, state) {
|
var mobileno = rows.mobileno==null?'':rows.mobileno;
|
var isreceivemsg = rows.isreceivemsg;
|
if(mobileno != ""){
|
if(isreceivemsg == 1) {
|
return mobileno + "[是]";
|
} else if(isreceivemsg == 0){
|
return mobileno + "[否]";
|
} else {
|
return mobileno;
|
}
|
} else {
|
return "";
|
}
|
}
|
},
|
{ label: '状态', name: 'userstatus', index: 'USERSTATUS', width: 40, align: 'center',
|
formatter: function(value, grid, rows, state) {
|
var userstatus = rows.userstatus;
|
if(userstatus == 0) {
|
return "<span class=\"label label-success\">正常</span>";
|
} else if(userstatus == 1) {
|
return "<span class=\"label label-warning\">禁用</span>";
|
} else if(userstatus == 2) {
|
return "<span class=\"label label-warning\">删除</span>";
|
} else if(userstatus == 3) {
|
return "<span class=\"label label-warning\">申请</span>";
|
} else if(userstatus == 4) {
|
return "<span class=\"label label-warning\">拒批</span>";
|
}
|
}
|
}
|
],
|
postData:{'unitid':unitid},
|
viewrecords: true,
|
height: "80%",
|
rowNum: 10,
|
//rowList : [10,30,50],
|
rownumbers: true,
|
rownumWidth: 50,
|
autowidth:true,
|
multiselect: true,
|
pager: "#jqManagerGridPager",
|
jsonReader : {
|
root: "page.list",
|
page: "page.currPage",
|
total: "page.totalPage",
|
records: "page.totalCount"
|
},
|
prmNames : {
|
page:"page",
|
rows:"limit",
|
order: "order"
|
},
|
gridComplete:function(){
|
//隐藏grid底部滚动条
|
$("#jqManagerGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
|
}
|
});
|
$("#jqManagerGrid").jqGrid('setLabel','rn','序号',{'text-align':'center'},'');
|
$("#jqManagerGrid").setGridWidth($("#jqManager").width()-35);
|
}
|
|
//清除
|
function clearInput(){
|
$(".modal input").each(function(){
|
$(this).val("");
|
})
|
}
|
|
function modalQuery(type){
|
if (type == "xzqh") {
|
var page = $("#jqXzqhGrid").jqGrid('getGridParam','page');
|
$("#jqXzqhGrid").jqGrid('setGridParam',{
|
postData:{'regionname':$("#regionname").val()},page:1
|
}).trigger("reloadGrid");
|
}else{
|
var page = $("#jqManagerGrid").jqGrid('getGridParam','page');
|
$("#jqManagerGrid").jqGrid('setGridParam',{
|
postData:{'chinesename':$("#chinesename").val()},page:1
|
}).trigger("reloadGrid");
|
}
|
}
|
|
//获取选中的行
|
function getSelecteds(type){
|
var ids = $("#jq"+type+"Grid").jqGrid("getGridParam","selarrrow");
|
if(null == ids || ids.length == 0){
|
alert("至少选择一个");
|
}else{
|
var names = "";
|
for (var i = 0; i < ids.length; i++) {
|
var data = $("#jq"+type+"Grid").jqGrid("getRowData",ids[i]);
|
names += (type == "Xzqh"?data.regionname:data.chinesename)+",";
|
}
|
names = names.length>0?names.substring(0,names.length-1):"";
|
if (type=="Xzqh") {
|
$("#qhNames").val(names);
|
$("#qhIds").val(ids);
|
}else{
|
$("#unitmanagers").val(names);
|
$("#unitmanagerIds").val(ids);
|
}
|
$("[name=ModelClose]").click();
|
}
|
}
|
|
//根据单位/部门名称获取首字母值 0单位1部门
|
function changeToPinYin(type){
|
var name = $("#"+(type==0?"":"dept")+"unitname").val();
|
if(name == "" || name == null){
|
return;
|
}
|
$.ajax({
|
type: "GET",
|
url: restServerBaseURL + "org/unit/changeToPinYin?name="+encodeURI(name),
|
contentType: "application/json",
|
success: function(msg) {
|
var pinyin = msg.pinyin;
|
if(pinyin != "") pinyin = decodeURI(pinyin);
|
$("#"+(type==0?"":"dept")+"spellfirst").val("");
|
$("#"+(type==0?"":"dept")+"spellfirst").val(pinyin);
|
if(type == 0){
|
vm.unit.spellfirst = pinyin;
|
}else{
|
vm.dept.spellfirst = pinyin;
|
}
|
}
|
});
|
}
|
|
function findUserByWord(){
|
var username = $("#chinesename").val();
|
$("#chinesename").autocomplete({
|
// source: restServerBaseURL + 'org/user/findUserByWord?keyWord='+encodeURI(encodeURI(username)), //请求的url
|
source: restServerBaseURL + 'org/unitmanager/findUnitManageUserByKeyword?keyWord='+encodeURI(encodeURI(username)) + '&unitid=' + unitid, //请求的url
|
minLength: 1,
|
});
|
}
|
|
$(function () {
|
$("[validate='{required:true}']").on("input propertychange keydown change",function(){
|
if ($(this).val() != '') {
|
$(this).css("borderColor",'');
|
}
|
})
|
})
|
|
function clearSelect(obj){
|
$(obj).parent().find("input").each(function(){
|
$(this).val("");
|
})
|
}
|
|
//切换部门列表
|
function showTab(showid){
|
$("div [name='tab']").each(function(){
|
if ($(this)[0].id != showid) {
|
$(this).hide();
|
}
|
else{
|
$(this).show();
|
}
|
})
|
isdept = 1;
|
initList();
|
}
|
|
//展示部门列表
|
function initList(){
|
$("#jqGrid").jqGrid({
|
url: restServerBaseURL + 'org/unit/list',
|
datatype: "json",
|
colModel: [
|
{ label: '部门名称', name: 'unitname', index: 'UNITNAME', width: 30,align:'center' },
|
// { label: '单位类型', name: 'unittypetext', index: 'unittypetext', width: 20,align:'center' },
|
{ label: '联系电话', name: 'contactnumber', index: 'CONTACTNUMBER', width: 20,align:'center' },
|
{ label: '操作',align:'center', width: 20,formatter:function(value,grid,rows,state){
|
var unitid = rows.unitid, html = "";
|
html += '<input type="button" id="action" class="btn btn-warning" value="编辑" style="margin-right:5px;padding:3px 6px;" data-toggle="modal" data-target="#myModal" onclick="initModal('+
|
unitid+')">';
|
html += '<input type="button" id="del" class="btn btn-danger" value="删除" style="padding:3px 6px;" onclick="vm.del(\'' + unitid + '\',1)">';
|
return html;
|
}
|
}
|
],
|
postData:{isdept:1,parentid:unitid},
|
viewrecords: true,
|
height: "100%",
|
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").setGridWidth($("#div_caozuo").width());
|
}
|
|
//保存部门
|
function saveUnitOrDept(){
|
if ($("#hidunit").val() == 0) {
|
var url = "org/unit/save";
|
}else{
|
var url = "org/unit/update";
|
}
|
vm.dept.parentid = unitid;
|
vm.dept.isdept = 1;
|
vm.dept.unitname = $("#deptunitname").val();
|
vm.dept.spellfirst = $("#deptspellfirst").val();
|
vm.dept.unittype = "A";
|
if ($("#deptfrom").valid()) {
|
$.ajax({
|
type: "POST",
|
url: restServerBaseURL + url,
|
contentType: "application/json",
|
data: JSON.stringify({orgUnit: vm.dept}),
|
success: function (r) {
|
if (r.code === 0) {
|
alert('操作成功', function () {
|
reloadDept();
|
$("[name=ModelClose]").click();
|
});
|
} else {
|
alert(r.msg);
|
}
|
}
|
});
|
}
|
}
|
|
function initModal(id){
|
$("#hidunit").val(id);
|
if (id == 0) {
|
$("#myModal input").each(function(){
|
$(this).val("");
|
})
|
$("#myModal textarea").each(function(){
|
$(this).val("");
|
})
|
vm.dept = {};
|
}
|
else{
|
$.get(restServerBaseURL + "org/unit/info/" + id, function(r) {
|
vm.dept = r.unit;
|
})
|
}
|
}
|
|
function reloadDept(){
|
var page = $("#jqGrid").jqGrid('getGridParam','page');
|
//点击查询时,当前页设置为第一页
|
$("#jqGrid").jqGrid('setGridParam',{
|
page:1
|
}).trigger("reloadGrid");
|
}
|