Brak opisu

department.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. $(document).ready(function() {
  2. tree();
  3. })
  4. $(".inps").focus(function () {
  5. $(".xlAdd").css("display", "block");
  6. });
  7. $(".xl").click(function () {
  8. if ($(".xlAdd").css("display") == "block") {
  9. $(".xlAdd").css("display", "none");
  10. } else {
  11. $(".xlAdd").css("display", "block");
  12. }
  13. });
  14. $(".addTree").mouseleave(function () {
  15. $(this).css("display", "none");
  16. });
  17. //清除
  18. $(".Cleans ").click(function () {
  19. $(".inps").val("");
  20. $("#PID").val("");
  21. });
  22. function tree() {
  23. $.get(
  24. huayi.config.callcenter_url + "Department/GetDeptList",
  25. {
  26. token: $.cookie("token"),
  27. // "pid": pid
  28. },
  29. function (result) {
  30. result = $.parseJSON(result);
  31. $.fn.zTree.init($("#addTreeDemo"), setting1, result.data); //实例化树形图
  32. }
  33. );
  34. }
  35. var setting1 = {
  36. data: {
  37. key: {
  38. name: "F_DeptName",
  39. },
  40. simpleData: {
  41. enable: true,
  42. idKey: "F_DeptId",
  43. pIdKey: "F_PartentId",
  44. rootPId: 0,
  45. },
  46. },
  47. callback: {
  48. onClick: zTreeOnClick,
  49. },
  50. };
  51. function zTreeOnClick(event, treeId, treeNode) {
  52. if (treeNode.level >= 1) {
  53. $(".inps").val(treeNode.F_DeptName);
  54. $("#PID").val(treeNode.F_DeptId);
  55. $(".Cleans").show();
  56. }
  57. }
  58. function Close() {
  59. $(".lyxz").removeClass("cx");
  60. if ($("audio").length > 0) {
  61. $("audio")[0].pause();
  62. }
  63. }
  64. $("#sponsor").on("click", "li", function () {
  65. $(".selDpart1").css("display", "none");
  66. $(".inps").val($(this).html());
  67. $("#PID").val($(this).attr("index"));
  68. $(".Cleans").show();
  69. });
  70. $(".inps").bind("input propertychange", function() {
  71. $(".xlAdd").css("display", "none");
  72. $(".selDpart1").css("display", "block");
  73. if ($(".inps").val() == "") {
  74. $(".selDpart1").css("display", "none");
  75. return
  76. }
  77. var debounceDepart = debounce(depart, 500);
  78. debounceDepart($(".inps").val());
  79. })
  80. ///部门
  81. function depart(dept) {
  82. $("#sponsor").empty();
  83. $.getJSON(
  84. huayi.config.callcenter_url + "Department/GetDeptListByDept",
  85. {
  86. token: $.cookie("token"),
  87. dept: dept,
  88. },
  89. function (data) {
  90. if (data.state.toLowerCase() == "success") {
  91. var content = data.data;
  92. $(content).each(function (i, n) {
  93. $(
  94. "<li index='" +
  95. n.F_DeptId +
  96. "'>" +
  97. n.F_DeptName +
  98. "</li>"
  99. ).appendTo("#sponsor");
  100. });
  101. }
  102. }
  103. );
  104. }
  105. function debounce (fun, delay) {
  106. return function(args) {
  107. var _args = args;
  108. var that = this;
  109. clearTimeout(fun.id);
  110. fun.id = setTimeout(function() {
  111. fun.call(that, _args);
  112. }, delay)
  113. }
  114. }