123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- /**
- *字典管理
- *
- */
- $.namespace("code.main");
- code.main.treeObj=null;
- //初始化树、树对象、列表数据
- code.main.init=function(set){
- $.fn.zTree.init($("#tree"), set);
- code.main.treeObj = $.fn.zTree.getZTreeObj("tree");
- code.main.inittable();
- };
- //单击树节点时,给表单赋值pid,和查询节点下的数据
- code.main.onClick=function(event, treeId, treeNode, clickFlag){
- $('#editpid').val(treeNode.id);
- code.main.inittable(treeNode.id);
- };
- code.main.inittable=function(data){
- $.post($.app + "/code/getDataByPid", {
- pid : data
- }, function(data) {
- if(data){
- var str="";
- for(var i=0;i<data.length;i++){
- var code = data[i];
- var v=code.val||"";
- var gc=code.groupCode||"";
- str+=" <tr class='tr_bg'>";
- str+="<td >"+code.text+"</td>";
- str+="<td >"+code.code+"</td>";
- str+="<td >"+code.id+":"+code.pid+"</td>";
- str+="<td >"+v+"</td>";
- str+="<td >"+gc+"</td>";
- str+="<td >"+code.sortno+"</td>";
- str+="<td class='operatetd'> " +
- "<a class='btn btn-default btn-xs' href='#' title='编辑' onclick=\"code.main.edit('"+code.id+"')\">"+
- "<i class='glyphicon glyphicon-pencil'></i></a> "+
- "<a class='btn btn-default btn-xs' href='#' title='删除' onclick=\"code.main.del('"+code.id+"','"+code.pid+"')\">"+
- "<i class='glyphicon glyphicon-trash'></i></a> "+
- "</td>";
- str+=" </tr >";
- }
- $("#liebiao").empty();
- $("#liebiao").append(str);
- }
- }, "json");
- };
- //删除某个节点时,列表刷新同时树节点也刷新
- code.main.del=function(id,pdata){
- $.confirm({
- title: '确认框',
- content: '确认删除吗',
- confirm: function(){
- $.post($.app + "/code/delete", {
- id : id
- }, function(data) {
- if (data.success) {
- $.alert({
- title: '提示',
- content: '操作成功',
- confirm: function(){
- code.main.inittable(pdata);
- var selNode = code.main.treeObj.getNodesByParam("id",id,null);
- if(selNode){
- code.main.treeObj.removeNode(selNode[0]);
- }
- }
- });
- } else {
- $.alert({
- title: '提示',
- content: data.message,
- confirm: function(){
-
- }
- });
- }
- }, "json");
- },
- cancel: function(){
-
- }
- });
- };
- code.main.edit=function(id){
- $.post($.app + "/code/edit", {
- id : id
- }, function(data) {
- if (data) {
- $('#editid').val(data.id);
- $('#editpid').val(data.pid);
- $('#edittext').val(data.text);
- $('#editbz').val(data.bz);
- $('#editcode').val(data.code);
- $('#editval').val(data.val);
- $('#editgroupCode').val(data.groupCode);
- $('#editsortno').val(data.sortno);
- code.main.show();
- }
- }, "json");
- };
- code.main.add=function(){
- code.main.clearForm();
- code.main.show();
- };
- code.main.clearForm=function(){
- $('#editid').val("");
- $('#edittext').val("");
- $('#editcode').val("");
- $('#editval').val("");
- $('#editbz').val("");
- $('#editgroupCode').val("");
- $('#editsortno').val("");
- };
- code.main.close=function(){
- $('.theme-popover-mask').fadeOut(100);
- $('.theme-popover').slideUp(0);
- };
- code.main.show=function(){
- $('.theme-popover-mask').fadeIn(100);
- $('.theme-popover').slideDown(0);
- };
- //保存后刷新数据和树节点,关闭弹出框
- code.main.save=function(){
- $.ajax({
- url:$.app+"/code/save",
- data:$("#addform").serialize(),
- type:"post",
- dataType:"json",
- success:function(data){//ajax返回的数据
- if (data.success) {
- $.alert({
- title: '提示',
- content: '操作成功',
- confirm: function(){
- code.main.inittable($('#editpid').val());
- var selNode = code.main.treeObj.getNodesByParam("id",$('#editpid').val(),null);
- if(selNode){
- code.main.treeObj.reAsyncChildNodes(selNode[0], "refresh",false);
- }
- code.main.close();
- }
- });
- }else {
- $.alert({
- title: '提示',
- content: data.message,
- confirm: function(){
-
- }
- });
- }
- }
- });
- };
|