var token = $.cookie("token");
var code;
var jsname = $('.searJsz').val();
//右边树形结构
tree();
function tree() {
    $.getJSON(huayi.config.callcenter_url + "Department/GetDeptList", {
		"token": $.cookie("token"),
	}, function(result) {
		$(result.data).each(function(i, n) {
			if(n.F_IsSms == 1) {
				n.checked = "true";
			}
		})
		$.fn.zTree.init($("#treeDemo"), setting1, result.data); //实例化树形图
	});
}
var setting1 = {
	check: {
		enable: true,
		//				chkboxType: {"Y":"", "N":""},
	},
	data: {
		key: {
            name: "F_DeptName"
        },
		simpleData: {
			enable: true,
			idKey: "F_DeptId",
			pIdKey: "F_PartentId",
			rootPId: 0
		}
	},
	callback: {
		onCheck: zTreeOnClick
	}
};

function zTreeOnClick(event, treeId, treeNode) {
	var name = treeNode.name;
};

//保存
function pro(app) {
    $.post(huayi.config.callcenter_url + "Department/UpdateSMSList", {
        token: token,
        state: 1, 
        ids: app.toString()
    }, function (data) {
        data = JSON.parse(data);
        if (data.state.toLowerCase() == 'success') {
            layer.confirm('保存成功！', {
                btn: ['确定']
            });
            return;
        }
    });
}

$('.protect').click(function() {
	var app = [];
	var ztree = $.fn.zTree.getZTreeObj("treeDemo").getCheckedNodes(true);
	if (ztree.length > 0) {
	    $.each(ztree, function (i, n) {
	        app.push(n.F_DeptId);
	    });
	    pro(app);
	}
	else {
	    layer.confirm('请选择部门！', {
	        btn: ['确定']
	    });
	}
})




