honorinfo.js 5.63 KB
var type = T.p("type");
$(function () {
    if(type=="user"){
        vm.showList = false;
        vm.showCancelButton=false;
    }
    else{
    $("#jqGrid").jqGrid({
        url: '../cloud/honorinfo/list',
        datatype: "json",
        colModel: [			
			{ label: 'ID', name: 'id', index: "id", width: 45, key: true },
            { label: '所属工会名', name: 'unionName', index: "union_name", width: 45 },

        ],
		viewrecords: true,
        height: 385,
        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 setting = {
	data: {
		simpleData: {
			enable: true,
			idKey: "id",
			rootPId: -1
		},
		key: {
			url:"nourl"
		}
	},
	check:{
		enable:true,
		nocheckInherit:true
	}
};
var ztree;
	
var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			askContext: null
		},
		showList: true,
		title:null,
        showCancelButton:true,
		honorinfo:{},
	},
    mounted:function(){
        if(type=="user"){

            $.get("../cloud/honorinfo/list?limit=10&page=1&type="+type, function(r){
                if(r.page.list[0]!=null&&r.page.list[0]!=undefined){
                    vm.honorinfo=r.page.list[0];
                    vm.title="上次更新时间:"+vm.honorinfo.updateTime+",操作者:"+vm.honorinfo.makerName;
                }else{
                    vm.honorinfo={
                        isHome:0,
                        isSmallHome:0,
                        isStar:0,
                        isPioneer:0,
                        isHarmony:0,
                        isMail:0,
                        isBook:0

                    };
                }
            });
        }
    },
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
           vm.showList=false;
           vm.title="新增";
           vm.honorinfo={
               isHome:0,
               isSmallHome:0,
               isStar:0,
               isPioneer:0,
               isHarmony:0,
               isMail:0,
               isBook:0

		   };
		},
		update: function () {
			var roleId = getSelectedRow();
			if(roleId == null){
				return ;
			}
			
			vm.showList = false;
            vm.title = "修改";
            $.get("../cloud/honorinfo/info/"+roleId, function(r){
                vm.showList = false;
                vm.title = "修改";
                vm.honorinfo = r.honorinfo;
            });
		},
		del: function (event) {
			var roleIds = getSelectedRows();
			if(roleIds == null){
				return ;
			}
			confirm('确定要删除选中的记录?', function(){
				$.ajax({
					type: "POST",
				    url: "../cloud/honorinfo/delete",
				    data: JSON.stringify(roleIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								vm.reload();
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		saveOrUpdate: function (event) {
            var url;
            if(type !="user"){
                url = vm.honorinfo.id == null ? "../cloud/honorinfo/save" : "../cloud/honorinfo/update";
            }else{
                url = vm.honorinfo.id == null ? "../cloud/honorinfo/user/save" : "../cloud/honorinfo/user/update";
            }

		    //var url = vm.honorinfo.id == null ? "../cloud/honorinfo/save" : "../cloud/honorinfo/update";
            vm.honorinfo.pioneerTime = $("#pioneerTime").val();
            vm.honorinfo.harmonyTime = $("#harmonyTime").val();
            vm.honorinfo.mailTime = $("#mailTime").val();
            vm.honorinfo.bookTime = $("#bookTime").val();
            vm.honorinfo.starTime = $("#starTime").val();
			$.ajax({
				type: "POST",
			    url: url,
			    data:JSON.stringify(vm.honorinfo),

			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
        reset:function(event){
            vm.showList = false;
            vm.showCancelButton=false;
            if(vm.honorinfo.id != null){
                $.get("../cloud/honorinfo/list?limit=10&page=1&type="+type, function(r){
                    vm.honorinfo=r.page.list[0]
                });
            }else{
                vm.honorinfo={
                    isHome:0,
                    isSmallHome:0,
                    isStar:0,
                    isPioneer:0,
                    isHarmony:0,
                    isMail:0,
                    isBook:0

                };
            }

        },
	    reload: function (event) {
            if(type=="user"){
                $.get("../cloud/honorinfo/list?limit=10&page=1&type="+type, function(r){

                    vm.honorinfo=r.page.list[0]
                });

            }else {
	    	vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData:{'askContext': vm.q.askContext},
                page:page
            }).trigger("reloadGrid");
		}}
	}
});