dict_info.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * 初始化字典详情对话框
  3. */
  4. var DictInfoDlg = {
  5. count: $("#itemSize").val(),
  6. dictName: '', //字典的名称
  7. dictCode: '', //字典类型编码
  8. dictTips: '', //字典备注
  9. mutiString: '', //拼接字符串内容(拼接字典条目)
  10. itemTemplate: $("#itemTemplate").html()
  11. };
  12. Feng.ctxPath = "/admin";
  13. /**
  14. * item获取新的id
  15. */
  16. DictInfoDlg.newId = function () {
  17. if (this.count == undefined) {
  18. this.count = 0;
  19. }
  20. this.count = this.count + 1;
  21. return "dictItem" + this.count;
  22. };
  23. /**
  24. * 关闭此对话框
  25. */
  26. DictInfoDlg.close = function () {
  27. parent.layer.close(window.parent.Dict.layerIndex);
  28. };
  29. /**
  30. * 添加条目
  31. */
  32. DictInfoDlg.addItem = function () {
  33. $("#itemsArea").append(this.itemTemplate);
  34. $("#dictItem").attr("id", this.newId());
  35. };
  36. /**
  37. * 删除item
  38. */
  39. DictInfoDlg.deleteItem = function (event) {
  40. var obj = Feng.eventParseObject(event);
  41. obj = obj.is('button') ? obj : obj.parent();
  42. obj.parent().parent().remove();
  43. };
  44. /**
  45. * 清除为空的item Dom
  46. */
  47. DictInfoDlg.clearNullDom = function () {
  48. $("[name='dictItem']").each(function () {
  49. var num = $(this).find("[name='itemNum']").val();
  50. var name = $(this).find("[name='itemName']").val();
  51. if (num == '' || name == '') {
  52. $(this).remove();
  53. }
  54. });
  55. };
  56. /**
  57. * 收集添加字典的数据
  58. */
  59. DictInfoDlg.collectData = function () {
  60. this.clearNullDom();
  61. var mutiString = "";
  62. $("[name='dictItem']").each(function () {
  63. var code = $(this).find("[name='itemCode']").val();
  64. var name = $(this).find("[name='itemName']").val();
  65. var num = $(this).find("[name='itemNum']").val();
  66. mutiString = mutiString + (code + ":" + name + ":" + num + ";");
  67. });
  68. this.dictName = $("#dictName").val();
  69. this.dictCode = $("#dictCode").val();
  70. this.dictTips = $("#dictTips").val();
  71. this.mutiString = mutiString;
  72. };
  73. /**
  74. * 提交添加字典
  75. */
  76. DictInfoDlg.addSubmit = function () {
  77. this.collectData();
  78. //提交信息
  79. var ajax = new $ax(Feng.ctxPath + "/dict/add", function (data) {
  80. if (data.code == 200) {
  81. Feng.success("添加成功!");
  82. window.parent.Dict.table.refresh();
  83. DictInfoDlg.close();
  84. } else {
  85. Feng.error(data.msg);
  86. }
  87. }, function (data) {
  88. Feng.error("添加失败!" + data.responseJSON.message + "!");
  89. });
  90. ajax.set('dictName', this.dictName);
  91. ajax.set('dictCode', this.dictCode);
  92. ajax.set('dictTips', this.dictTips);
  93. ajax.set('dictValues', this.mutiString);
  94. ajax.start();
  95. };
  96. /**
  97. * 提交修改
  98. */
  99. DictInfoDlg.editSubmit = function () {
  100. this.collectData();
  101. var ajax = new $ax(Feng.ctxPath + "/dict/edit", function (data) {
  102. if (data.code == 200) {
  103. Feng.success("修改成功!");
  104. window.parent.Dict.table.refresh();
  105. DictInfoDlg.close();
  106. } else {
  107. Feng.error(data.msg);
  108. }
  109. }, function (data) {
  110. Feng.error("修改失败!" + data.responseJSON.message + "!");
  111. });
  112. ajax.set('dictId', $("#dictId").val());
  113. ajax.set('dictName', this.dictName);
  114. ajax.set('dictCode', this.dictCode);
  115. ajax.set('dictTips', this.dictTips);
  116. ajax.set('dictValues', this.mutiString);
  117. ajax.start();
  118. };