JkDictionary.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. var data;
  2. var type;
  3. $(function() {
  4. getdata();
  5. });
  6. function getdata() {
  7. var param = {};
  8. $.post("/JkEdu/Dictionary/getDictionary", param, function(result) {
  9. if (result.Code == 10000) {
  10. data = eval(result.data);
  11. type = eval(result.type);
  12. init();
  13. }
  14. });
  15. }
  16. function init() {
  17. var html = '';
  18. html += '<thead>' + '<tr>' + '<th>业务类型</th>' + '<th>字典ID</th>'
  19. + '<th>字典名称</th>' + '<th>备注</th>' + '<th>操作</th>' + '</tr>'
  20. + '</thead>' + '<tbody>';
  21. $
  22. .each(
  23. type,
  24. function(i, t) {
  25. var cols = 0;
  26. $.each(data, function(i, d) {
  27. if (d.typename == t.typename) {
  28. cols += 1;
  29. }
  30. });
  31. console.log(cols);
  32. $
  33. .each(
  34. data,
  35. function(i, d) {
  36. if (d.typename == t.typename) {
  37. html += '<tr>';
  38. html += '<td>' + d.typename
  39. + '</td>';
  40. html += '<td">' + t.typename
  41. + '</td>';
  42. html += '<td>'
  43. + d.code
  44. + '</td>'
  45. + '<td>'
  46. + d.codename
  47. + '</td>'
  48. + '<td>'
  49. + d.dictionarytext
  50. + '<td>'
  51. + '<a id="Edit" href="javascript:;" class="c-btn c-btn-green" onclick="update(this,'
  52. + d.dictionaryid
  53. + ')">修改</a>'
  54. + '<a id="Delete" href="javascript:;" class="c-btn c-btn-red ml10" onclick="deleteRow(this,'
  55. + d.dictionaryid
  56. + ')">删除</a>' + '</td>'
  57. + '</tr>';
  58. }
  59. });
  60. });
  61. html += '</tbody>';
  62. $("#process-demo-1").append(html);
  63. }
  64. function deleteRow(r, id) {
  65. var i = r.parentNode.parentNode.rowIndex;
  66. var artBox = art.dialog({
  67. lock : true,
  68. artIcon : 'ask',
  69. opacity : 0.4,
  70. width : 250,
  71. title : '删除',
  72. content : '是否确定删除 ?',
  73. ok : function() {
  74. document.getElementById('process-demo-1').deleteRow(i);
  75. var param = {};
  76. param.dictionaryid = id;
  77. $.post("/JkEdu/Dictionary/delDictionary", param, function(result) {
  78. console.log(result.Code);
  79. if (result.Code == 10000) {
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. });
  85. },
  86. cancel : true
  87. });
  88. }
  89. function update(r, id) {
  90. var contents = '';
  91. $
  92. .each(
  93. data,
  94. function(i, d) {
  95. if (d.dictionaryid == id) {
  96. contents += '<table class="tb tb-b c-100 c-t-center">'
  97. + '<tr><td>业务类型:</td><td><input id="typename" type="text" class="cus-input" value="'
  98. + d.typename
  99. + '" placeholder=""/></td></tr>'
  100. + '<tr><td>字典ID:</td><td><input id="code" type="text" class="cus-input" value="'
  101. + d.code
  102. + '" placeholder=""/></td></tr>'
  103. + '<tr><td>字典名称:</td><td><input id="codename" type="text" class="cus-input" value="'
  104. + d.codename
  105. + '" placeholder=""/></td></tr>'
  106. + '<tr><td>备注</td><td><input id="dictionarytext" type="text" class="cus-input" value="'
  107. + d.dictionarytext
  108. + '" placeholder=""/></td></tr>'
  109. + '</table>';
  110. }
  111. });
  112. var artBox = art
  113. .dialog({
  114. lock : true,
  115. artIcon : 'ask',
  116. opacity : 0.4,
  117. width : 'auto',
  118. height : 'auto',
  119. overflow : true,
  120. title : '修改',
  121. content : contents,
  122. button : [
  123. {
  124. name : '保存',
  125. callback : function() {
  126. if ($("#typename").val() == "") {
  127. return false;
  128. }
  129. if ($("#code").val() == "") {
  130. return false;
  131. }
  132. if ($("#codename").val() == "") {
  133. return false;
  134. }
  135. if ($("#dictionarytext").val() == "") {
  136. return false;
  137. }
  138. var tr = r.parentNode.parentNode;
  139. tr.cells[0].innerText = $("#typename").val();
  140. tr.cells[1].innerText = $("#code").val();
  141. tr.cells[2].innerText = $("#codename").val();
  142. tr.cells[3].innerText = $("#dictionarytext")
  143. .val();
  144. var param = {};
  145. param.dictionaryid = id;
  146. param.typename = $("#typename").val();
  147. param.code = $("#code").val();
  148. param.codename = $("#codename").val();
  149. param.dictionarytext = $("#dictionarytext")
  150. .val();
  151. $
  152. .post(
  153. "/JkEdu/Dictionary/updateDictionary",
  154. param,
  155. function(result) {
  156. console.log(result.Code);
  157. if (result.Code == 10000) {
  158. var param = {};
  159. $
  160. .post(
  161. "/JkEdu/Dictionary/getDictionary",
  162. param,
  163. function(
  164. result) {
  165. if (result.Code == 10000) {
  166. data = eval(result.data);
  167. type = eval(result.type);
  168. }
  169. });
  170. return true;
  171. } else {
  172. return false;
  173. }
  174. });
  175. },
  176. focus : true
  177. }, {
  178. name : '取消',
  179. }, ]
  180. });
  181. }
  182. function add() {
  183. var contents = '';
  184. contents += '<table class="tb tb-b c-100 c-t-center">'
  185. + '<tr><td>业务类型:</td><td><input id="typename" type="text" class="cus-input"'
  186. + ' placeholder="请输入内容"/></td></tr>'
  187. + '<tr><td>字典ID:</td><td><input id="code" type="text" class="cus-input"'
  188. + ' placeholder="请输入内容"/></td></tr>'
  189. + '<tr><td>字典名称:</td><td><input id="codename" type="text" class="cus-input"'
  190. + ' placeholder="请输入内容"/></td></tr>'
  191. + '<tr><td>备注</td><td><input id="dictionarytext" type="text" class="cus-input"'
  192. + ' placeholder="请输入内容"/></td></tr>' + '</table>';
  193. var artBox = art.dialog({
  194. lock : true,
  195. artIcon : 'ask',
  196. opacity : 0.4,
  197. width : 'auto',
  198. height : 'auto',
  199. overflow : true,
  200. title : '添加',
  201. content : contents,
  202. button : [
  203. {
  204. name : '保存',
  205. callback : function() {
  206. if ($("#typename").val() == "") {
  207. return false;
  208. }
  209. if ($("#code").val() == "") {
  210. return false;
  211. }
  212. if ($("#codename").val() == "") {
  213. return false;
  214. }
  215. if ($("#dictionarytext").val() == "") {
  216. return false;
  217. }
  218. var param = {};
  219. param.typename = $("#typename").val();
  220. param.code = $("#code").val();
  221. param.codename = $("#codename").val();
  222. param.dictionarytext = $("#dictionarytext").val();
  223. $.post("/JkEdu/Dictionary/addDictionary", param,
  224. function(result) {
  225. console.log(result.Code);
  226. if (result.Code == 10000) {
  227. $("#process-demo-1").empty();
  228. getdata();
  229. return true;
  230. } else {
  231. return false;
  232. }
  233. });
  234. },
  235. focus : true
  236. }, {
  237. name : '取消',
  238. }, ]
  239. });
  240. }