adddept.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var dept_selectinput;
  2. var selectednodetemp;
  3. function loadData(nodedata) {
  4. var pnode = nodedata;
  5. if (edittype == "add") {
  6. $("#dept_name").val("")
  7. $('#addModal .modal-title').html('添加部门');
  8. }
  9. if (edittype == "edit") {
  10. selectednodetemp = nodedata[0];
  11. $("#dept_name").val(nodedata[0].name)
  12. $("#dept_add_btn").html("保存")
  13. $('#addModal .modal-title').html('修改部门');
  14. if (pnode != null && pnode[0].pId && pnode.length > 0) {
  15. pnode = [dept_tree.getNodeByParam("id", pnode[0].pId, null)]
  16. }
  17. }
  18. dept_selectinput = new TreeSelect({
  19. element: '#dept_select',
  20. data: zdata,
  21. valueKey: "id",
  22. placeholder: "选择部门",
  23. selectvalue: pnode.length > 0 ? pnode[0].id : null
  24. });
  25. }
  26. function addDept() {
  27. //获取名称
  28. var name = $("#dept_name").val();
  29. var pid = dept_selectinput.value;
  30. var data = {
  31. "organname": name,
  32. "parentid": pid
  33. }
  34. if (edittype == "add") {
  35. DeptAdd(data, function(datare) {
  36. layer.msg('添加成功!', {
  37. time: 2000, //20s后自动关闭
  38. }, function() {
  39. $('#addModal').modal('hide')
  40. getDept();
  41. })
  42. }, function(error) {
  43. })
  44. }
  45. if (edittype == "edit") {
  46. data["id"] = selectednodetemp.id;
  47. if (isSelfOrChild(pid, selectednodetemp)) {
  48. layer.msg('不能添加到自身及自身下的子部门!', {
  49. time: 2000, //20s后自动关闭
  50. })
  51. return;
  52. }
  53. DeptEdit(data, function(datare) {
  54. layer.msg('修改成功!', {
  55. time: 2000, //20s后自动关闭
  56. }, function() {
  57. $('#addModal').modal('hide')
  58. getDept();
  59. })
  60. }, function(error) {
  61. });
  62. }
  63. }
  64. function isSelfOrChild(id, node) {
  65. if (id == node.id) return true;
  66. if (typeof(node.children) == "undefinde" || node.children == null || node.children.length < 1) return false;
  67. for (var i = 0; i < node.children.length; i++) {
  68. if (isSelfOrChild(id, node.children[i])) {
  69. return true;
  70. }
  71. }
  72. return false;
  73. }