$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/rdarticle/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '栏目', name: 'siteId', index: 'site_id', width: 80,hidden:true  },
            { label: '栏目名称', name: 'siteName', index: 'site_name', width: 80 },
			{ label: '标题', name: 'title', index: 'title', width: 80 }, 			
			{ label: '状态，0：隐藏，1：显示', name: 'status', index: 'status', width: 80,hidden:true },
			{ label: '排序', name: 'sort', index: 'sort', width: 80 }, 			
			{ label: '是否推荐，0：否，1：是', name: 'isRecommend', index: 'is_recommend', width: 80 ,hidden:true},
			{ label: '是否置顶，0：否，1：是', name: 'isTop', index: 'is_top', width: 80,hidden:true },
			{ label: '简介', name: 'introduction', index: 'introduction', width: 80 }, 			
			{ label: '内容', name: 'content', index: 'content', width: 80 }, 			
			{ label: '点击量', name: 'clicks', index: 'clicks', width: 80 ,hidden:true},
			{ label: '添加时间', name: 'addTime', index: 'add_time', width: 80,hidden:true },
			{ label: '添加IP', name: 'addIp', index: 'add_ip', width: 80,hidden:true },
			{ label: '图片路径', name: 'picPath', index: 'pic_path', width: 80 ,hidden:true},
			{ label: '创建人ID', name: 'userId', index: 'user_id', width: 80,hidden:true },
			{ label: '人员所属部门ID', name: 'deptId', index: 'dept_id', width: 80 ,hidden:true},
			{ label: '部门', name: 'deptName', index: 'dept_name', width: 80 ,hidden:true},
			{ label: '创建人', name: 'creator', index: 'creator', width: 80 }, 			
			{ label: '更新时间', name: 'updateTime', index: 'update_time', width: 80 }, 			
			{ label: '更新人', name: 'editor', index: 'editor', width: 80 }, 			
			{ label: '发布时间', name: 'releaseTime', index: 'release_time', width: 80 }, 			
			{ label: '发布人', name: 'releaser', index: 'releaser', width: 80 }			
        ],
		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 site_ztree;
var site_setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "pid",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    }
};
var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
        // content: `J_ueditorBox_${new Date().getTime()}`,
        // ue: null,
		title: null,
		rdArticle: {}
	},
    // mounted() {
    //     this.ue = ueditor.getEditor(this.content, {
    //         // serverUrl: '', // 服务器统一请求接口路径
    //         zIndex: 3000
    //     })
    // },
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.rdArticle = {siteName:null, siteId:null};
            vm.getRdSite();
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            vm.getInfo(id)
            vm.getRdSite();
		},
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.rdArticle.id == null ? "sys/rdarticle/save" : "sys/rdarticle/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.rdArticle),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "sys/rdarticle/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(id){
			$.get(baseURL + "sys/rdarticle/info/"+id, function(r){
                vm.rdArticle = r.rdArticle;
                // vm.getSite();
            });
		},
        getRdSite: function(){
            //加载栏目
            $.get(baseURL + "sys/rdsite/list", function(r){
                site_ztree = $.fn.zTree.init($("#siteTree"), site_setting, r);
                var node = site_ztree.getNodeByParam("id", vm.rdArticle.siteId);
                if(node != null){
                    site_ztree.selectNode(node);
                    vm.rdArticle.siteName = node.name;
                }
            })
        },
        siteTree: function(){
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择栏目",
                area: ['300px', '450px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#siteLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var node = site_ztree.getSelectedNodes();
                    //选择上级部门
                    vm.rdArticle.siteId = node[0].id;
                    vm.rdArticle.siteName = node[0].name;

                    layer.close(index);
                }
            });
        },
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});
<!-- 实例化编辑器 -->
 // var editor = UE.getEditor('editor');
