var local = window.location.href;
|
var userid = local.substring(local.lastIndexOf('=')+1,local.length);
|
|
$(function () {
|
$("#jqGrid").jqGrid({
|
url: restServerBaseURL + 'org/userunit/list?userid='+userid,
|
datatype: "json",
|
colModel: [
|
{ label: '用户名', name: 'username', index: 'USERNAME', width: 50,align:'center',
|
formatter:function(value,grid,rows,state){
|
var unitid = rows.unitid,userid = rows.userid;
|
var html = "<a style='cursor:pointer;color:black;' data-toggle='modal' onclick='vm.getInfo(1,"+
|
unitid+","+userid+")' data-target='#myModal'>"+rows.username+"</a>";
|
return html;
|
}
|
},
|
{ label: '单位名称', name: 'unitname', index: 'UNITNAME', width: 80,align:'center' },
|
{ label: '职务名称', name: 'posname', index: 'POSNAME', width: 80,align:'center' },
|
{ label: '从事本职工作时间', name: 'workseasdate', index: 'WORKSEASDATE', width: 80,align:'center',
|
formatter:function(value,grid,rows,state){
|
var dateStr = rows.workseasdate;
|
if (dateStr != null && dateStr !='') {
|
return dateStr.substring(0,10);
|
}
|
else
|
{
|
return "";
|
}
|
}
|
},
|
{ label: '在职情况', name: 'worktype', index: 'WORKTYPE', width: 80,align:'center',
|
formatter:function(value,grid,rows,state){
|
//在职情况1 表示在职、3 表示借调、5 表示离职
|
var type = parseInt(rows.worktype);
|
var typeName = "";
|
switch(type){
|
case 1:
|
typeName="在职";
|
break;
|
case 3:
|
typeName="借调";
|
break;
|
case 5:
|
typeName="离职";
|
break;
|
default:
|
typeName="";
|
break;
|
}
|
return typeName;
|
}
|
},
|
{ label: '到职日期', name: 'workstartdate', index: 'WORKSTARTDATE', width: 80,align:'center',
|
formatter:function(value,grid,rows,state){
|
var dateStr = rows.workstartdate;
|
if (dateStr != null && dateStr !='') {
|
return dateStr.substring(0,10);
|
}
|
else
|
{
|
return "";
|
}
|
}
|
},
|
{ label: '离职日期', name: 'workenddate', index: 'WORKENDDATE', width: 80 ,align:'center',
|
formatter:function(value,grid,rows,state){
|
var dateStr = rows.workenddate;
|
if (dateStr != null && dateStr !='') {
|
return dateStr.substring(0,10);
|
}
|
else
|
{
|
return "";
|
}
|
}
|
} ,
|
{ label: 'rn', name: 'unitid',index:'rn', width: 50, key: true,hidden:true }
|
],
|
viewrecords: true,
|
height: "auto",
|
rowNum: 10,
|
//rowList : [10,30,50],
|
rownumbers: true,
|
rownumWidth: 25,
|
autowidth:true,
|
multiselect: true,
|
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" });
|
}
|
});
|
});
|
|
|
var vm = new Vue({
|
el:'#rapp',
|
data:{
|
showList: true,
|
title: null,
|
userunit: {userid:userid},
|
isupdate:null,
|
oldunitid:null
|
},
|
methods: {
|
query: function () {
|
vm.reload();
|
},
|
add: function(){
|
|
},
|
del: function () {
|
var userunitids = getSelectedRows();
|
if(userunitids == null){
|
return ;
|
}
|
userunitids.push(vm.userunit.userid);//规则:除了最后一个存放userid外,其余的都是unitid
|
confirm('确定要删除选中的记录?', function(){
|
$.ajax({
|
method:"POST",
|
type: "POST",
|
url: restServerBaseURL + "org/userunit/delete",
|
contentType: "application/json",
|
data: JSON.stringify(userunitids),
|
success: function(r){
|
if(r.code == 0){
|
alert('操作成功', function(){
|
vm.reload();
|
});
|
}else{
|
alert(r.msg);
|
}
|
}
|
});
|
});
|
},
|
getInfo: function(type,unitid){
|
var userid = local.substring(local.lastIndexOf('=')+1,local.length);
|
var posname = "";
|
if (type == 0) {
|
this.isupdate = 0;
|
initModal(0,posname);
|
}else{
|
this.isupdate = 1;
|
if (unitid != '' && userid != '') {
|
var id = userid+"|"+unitid;
|
$.get(restServerBaseURL + "org/userunit/queryObjectByUnitid/"+id, function(r){
|
vm.userunit = r.userunit;
|
posname = vm.userunit.posname;
|
vm.oldunitid = vm.userunit.unitid;
|
$("#worktype").val(vm.userunit.worktype);
|
if (vm.userunit.workseasdate!=null&&vm.userunit.workseasdate.length >= 10) {
|
$("#workseasdate").val(vm.userunit.workseasdate.substring(0,10));
|
}
|
if (vm.userunit.workstartdate!=null&&vm.userunit.workstartdate.length >= 10) {
|
$("#workstartdate").val(vm.userunit.workstartdate.substring(0,10));
|
}
|
if (vm.userunit.workenddate!=null&&vm.userunit.workenddate.length >= 10) {
|
$("#workenddate").val(vm.userunit.workenddate = vm.userunit.workenddate.substring(0,10));
|
}
|
initModal(1,posname);
|
});
|
}
|
}
|
},
|
reload: function () {
|
vm.showList = true;
|
var page = $("#jqGrid").jqGrid('getGridParam','page');
|
//点击查询时,当前页设置为第一页
|
$("#jqGrid").jqGrid('setGridParam',{
|
postData:{'userid':vm.userunit.userid},
|
page:1
|
}).trigger("reloadGrid");
|
},
|
save: function () {
|
var url = vm.isupdate == 0 ? "org/userunit/save" : "org/userunit/update";
|
//校验必填
|
var isVaild = true;
|
$(":input").each(function () {
|
if ($(this).attr('validate')) {
|
var text = $(this).val().trim();
|
if (text == '' || text == null || text == 'None') {
|
$(this).css("borderColor","red");
|
isVaild = false;
|
}
|
}
|
})
|
if (!isVaild) {
|
return false;
|
}
|
vm.userunit.workseasdate = null;
|
vm.userunit.workstartdate = null;
|
vm.userunit.workenddate = null;
|
vm.userunit.workseasdatestr = $("#workseasdate").val();
|
vm.userunit.workstartdatestr = $("#workstartdate").val();
|
vm.userunit.workenddatestr = $("#workenddate").val();
|
vm.userunit.posname = $("#posname option:selected").attr("name");
|
vm.userunit.worktype = $("#worktype").val();
|
var name =$("#pinyin").val();
|
$.get(restServerBaseURL + "org/unit/queryObjectByFullName/"+name, function(r){
|
if (r != null && r.code == 0 && r.unit != null) {//存在
|
var ounit = vm.oldunitid != null ?vm.oldunitid :0;
|
vm.userunit.unitid = r.unit.unitid;
|
vm.userunit.oldUnitid = ounit;
|
$.ajax({
|
type: "POST",
|
url: restServerBaseURL + url,
|
contentType: "application/json",
|
data: JSON.stringify(vm.userunit),
|
success: function(result){
|
if (result.code==0) {
|
alert('操作成功', function(){
|
$("#ModelClose").click();
|
window.location.reload();
|
});
|
}
|
else{
|
if (result.msg=="数据库中已存在该记录") {
|
alert("已存在对应的关系,请检查!");
|
}
|
else{
|
alert(result.msg);
|
}
|
}
|
}
|
});
|
}
|
else{
|
alert("不存在此单位,请检查!");
|
}
|
});
|
}
|
}
|
});
|
|
function findPinyinByKeyWord(){
|
var pinyin = $("#pinyin").val();
|
$("#pinyin").autocomplete({
|
source: restServerBaseURL + 'org/user/findPinyinByKeyWord?keyWord='+encodeURI(encodeURI(pinyin)), //请求的url
|
value:restServerBaseURL + 'org/user/findPinyinByKeyWord?keyWord='+encodeURI(encodeURI(pinyin)),
|
minLength: 1,
|
});
|
$("#ui-id-1").css("z-index","9999");
|
}
|
|
function initModal(type,posname){
|
if (type == 0) {
|
$("#myModal input").each(function(){
|
$(this).val("");
|
});
|
$("#worktype").val("");
|
$("#posname").val("");
|
}
|
$.ajax({
|
type: "GET",
|
url: restServerBaseURL + "sys/fieldvalue/queryListByKey?key=JOBLEVEL",
|
contentType: "application/json",
|
success: function(msg) {
|
var sysFieldList = msg.sysFieldList;
|
jQuery("#posname").empty().append("<option name='' value=''>--请选择--</option>")
|
jQuery.each(sysFieldList, function(i, item) {
|
jQuery("#posname").append("<option name='"+ item.vtext +"' value=" + item.vcode + ">" + item.vtext + "</option>");
|
});
|
if (posname != "") {
|
$("#posname option[name="+posname+"]").attr("selected",true);
|
}
|
}
|
});
|
}
|
|
$(function () {
|
$("[validate='true']").on("input propertychange keydown change",function(){
|
if ($(this).val() != '') {
|
$(this).css("borderColor",'');
|
}
|
})
|
})
|