region_tree.js 5.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. $(function()
  2. {
  3. //给图标的加减号添加展开收缩行为
  4. $('img[ds_type="flex"]').click(function(){
  5. var status = $(this).attr("status");
  6. //状态是加号的事件
  7. if(status == 'open')
  8. {
  9. var pr = $(this).parent('td').parent('tr');
  10. var id = $(this).attr("fieldid");
  11. var obj = $(this);
  12. $(this).attr('status','none');
  13. $.get(AJAX_URL_REGION, {id: id}, function(data){
  14. if(data)
  15. {
  16. var str = "";
  17. var res = eval('('+data+')');
  18. for(var i = 0; i < res.length; i++)
  19. {
  20. var tmp_vertline = "<img class='preimg' src='"+ADMINSITEROOT+"/images/treetable/vertline.gif'/>";
  21. str += "<tr id='ds_row_" + res[i].area_id + "' class='"+pr.attr('class')+" row"+id+"'>";
  22. str += "<td><input type='checkbox' name='check_area_id[]' value='"+res[i].area_id+"' class='checkitem'>";
  23. //给每一个异步取出的数据添加伸缩图标后者无状态图标
  24. if(res[i].switchs == 1)
  25. {
  26. str += "<img src='"+ADMINSITEROOT+"/images/treetable/tv-expandable.gif' ds_type='flex' status='open' fieldid='"+res[i].area_id+"'>";
  27. }
  28. else
  29. {
  30. str += "<img src='"+ADMINSITEROOT+"/images/treetable/tv-item.gif' ds_type='flex' status='none' fieldid='"+res[i].area_id+"'>";
  31. }
  32. str += "</td><td class='sort'>";
  33. //排序
  34. str += " <span title='可编辑下级分类排序' ajax_branch='area_sort' datatype='number' fieldid='"+res[i].area_id+"' fieldname='area_sort' ds_type='inline_edit' class='editable tooltip'>"+res[i].area_sort+"</span></td>";
  35. //名称
  36. str += "<td class='name'>";
  37. for (var tmp_i = 1; tmp_i < (res[i].area_deep - 1); tmp_i++) {
  38. str += tmp_vertline;
  39. }
  40. if (i == res.length-1) {
  41. str += " <img fieldid='" + res[i].area_id + "' status='open' ds_type='flex' src='" + ADMINSITEROOT + "/images/treetable/tv-item1.gif' />";
  42. } else {
  43. str += " <img fieldid='" + res[i].area_id + "' status='none' ds_type='flex' src='" + ADMINSITEROOT + "/images/treetable/tv-expandable1.gif' />";
  44. }
  45. str += " <span title='可编辑下级分类名称' required='1' fieldid='"+res[i].area_id+"' ajax_branch='area_name' fieldname='area_name' ds_type='inline_edit' class='editable tooltip'>"+res[i].area_name+"</span>";
  46. str += "</td>";
  47. //大区名称
  48. str += "<td class='name'>";
  49. for (var tmp_i = 1; tmp_i < (res[i].deep - 1); tmp_i++) {
  50. str += tmp_vertline;
  51. }
  52. if(res[i].area_region == null){
  53. res[i].area_region= ' ';
  54. }
  55. str += " <span title='可编辑下级分类名称' required='1' fieldid='" + res[i].area_id + "' ajax_branch='area_region' fieldname='area_region' ds_type='inline_edit' class='editable tooltip'>" + res[i].area_region + "</span>";
  56. str += "</td>";
  57. str += "<td><a href=\"javascript:dsLayerOpen('" + ADMINSITEURL + "/Region/edit/area_id/" + res[i].area_id + "','编辑-"+res[i].area_name+"')\" class='dsui-btn-edit'><i class='iconfont'></i>编辑</a>";
  58. str += "<a href=\"javascript:dsLayerConfirm('" + ADMINSITEURL + "/Region/drop/area_id/" + res[i].area_id + "','您确定要删除吗'," + res[i].area_id + ");\" class='dsui-btn-del'><i class='iconfont'></i>删除</a>";
  59. if(res[i].add_child){
  60. str += "<a href=\"javascript:dsLayerOpen('" + ADMINSITEURL + "/Region/add/area_id/" + res[i].area_id + "','新增下级')\" class='dsui-btn-add'><i class='iconfont'></i>新增下级</a>";
  61. }
  62. str += "</td></tr>"
  63. }
  64. //将组成的字符串添加到点击对象后面
  65. pr.after(str);
  66. obj.attr('status', 'close');
  67. obj.attr('src', obj.attr('src').replace("tv-expandable", "tv-collapsable"));
  68. $('img[ds_type="flex"]').unbind('click');
  69. $('span[ds_type="inline_edit"]').unbind('click');
  70. //重现初始化页面
  71. $.getScript(ADMINSITEROOT + "/js/jquery.edit.js");
  72. $.getScript(ADMINSITEROOT + "/js/region_tree.js");
  73. }
  74. });
  75. }
  76. //状态是减号的事件
  77. if(status == "close")
  78. {
  79. $(".row"+$(this).attr('fieldid')).remove();
  80. $(this).attr('src',$(this).attr('src').replace("tv-collapsable","tv-expandable"));
  81. $(this).attr('status','open');
  82. }
  83. });
  84. });