AddClass.cshtml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. 
  2. @{
  3. ViewBag.Title = "AddClass";
  4. Layout = "~/Views/Shared/_MainLayoutPage.cshtml";
  5. }
  6. <script src="~/Content/Scripts/Common.js"></script>
  7. <div class="easyui-layout" data-options="fit:true">
  8. <table class="layui-table">
  9. <colgroup>
  10. <col width="80">
  11. <col>
  12. </colgroup>
  13. <tr>
  14. <td><label class="layui-form-label">上级分类</label></td>
  15. <td>
  16. <input id="parentid" name="parentid" class="easyui-combotree" data-options="width:300,panelWidth:'300px'" panelheight="200px">
  17. </td>
  18. </tr>
  19. <tr>
  20. <td><label class="layui-form-label">名称</label></td>
  21. <td><input class="easyui-textbox" id="name" name="name" required="required" data-options="prompt:'分类名称',width:300"></td>
  22. </tr>
  23. </table>
  24. <div data-options="region:'south',border:false" style="height:50px;text-align:right; padding:5px">
  25. <button type="button" class="layui-btn layui-btn-normal" id="save">确定</button>
  26. <button type="button" class="layui-btn layui-btn-primary" id="cancel">取消</button>
  27. </div>
  28. <input type="hidden" id="ID" name="ID" value="" />
  29. </div>
  30. <script type="text/javascript">
  31. var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
  32. var ThisUrl = decodeURI(window.location.href);
  33. var id = PublicFun.getQueryValue(ThisUrl, "id");
  34. var type = PublicFun.getQueryValue(ThisUrl, "type");//1新增2修改
  35. var name = PublicFun.getQueryValue(ThisUrl, "name");
  36. $(function () {
  37. if (type == 2) {//修改
  38. $('#ID').val(id);
  39. $("#parentid").combotree("setValue", id);
  40. $("#name").textbox('setValue', name);
  41. }
  42. $("#parentid").combotree({
  43. lines: true,
  44. animate: true,
  45. method: "get",
  46. idField: 'id',
  47. treeField: 'text',
  48. url: '/SmartForm/GetCategory',
  49. loadFilter: function (data, parent) {
  50. //无数据则显示为叶子节点
  51. if (parent && data.length == 0) {
  52. var node = $(this).tree("getSelected");
  53. if (node) {
  54. $(this).tree("update", {
  55. target: node.target,
  56. state: "open",
  57. iconCls: "icon-file"
  58. });
  59. }
  60. }
  61. if (data) {
  62. return eval(data);
  63. }
  64. },
  65. onLoadSuccess: function (node, data) {
  66. var tree = $("#parentid").combotree("tree");
  67. var node = tree.tree('getRoot');
  68. if (node.text != "无") {
  69. $(this).tree("insert", {
  70. before: node.target,
  71. data: [{
  72. id: '0',
  73. text: '无',
  74. state: "open",
  75. iconCls: "icon-file"
  76. }]
  77. });
  78. }
  79. $(this).tree("select", node.id);
  80. },
  81. onSelect: function (node) {
  82. if (node) {
  83. var t = $("#parentid").combotree('tree').tree("getSelected");
  84. $("#parentid").combotree("setValue", t.id);
  85. }
  86. }
  87. });
  88. $('#save').click(function () {
  89. var parentid = $("#parentid").val();
  90. var name = $("#name").val();
  91. var params = { 上级ID: parentid, 名称: name, type: type };
  92. if (type == 2) //修改
  93. {
  94. params = { 上级ID: parentid, 名称: name, type: type, ID: id };
  95. }
  96. //if (params.上级ID == "" || params.上级ID == 0) {
  97. // top.ZLPMS.Msg("请选择分类");
  98. // return
  99. //}
  100. if (params.名称 == "") {
  101. top.ZLPMS.Msg("名称不能为空");
  102. return
  103. }
  104. $.post("/SmartForm/AddCategory", params, function (data) {
  105. if (data.code == 200) {
  106. top.ZLPMS.Msg(data.msg);
  107. top.ZLPMS.CloseWindow(index);
  108. }
  109. else {
  110. top.ZLPMS.Msg("添加失败,请联系管理员");
  111. }
  112. })
  113. });
  114. $('#cancel').click(function () {
  115. top.ZLPMS.CloseWindow(index);
  116. });
  117. })
  118. </script>