main.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**
  2. * Created by Zhong on 2017/8/14.
  3. */
  4. $(function () {
  5. let dispNameArr;
  6. getAllGljLib(function (dispNames) {
  7. dispNameArr = dispNames;
  8. //添加
  9. $('#addBtn').click(function () {
  10. let compilationName = $('#compilationSels option:selected').text();
  11. let compilationId = $('#compilationSels option:selected').val();
  12. let libName = $('#libNameTxt').val();
  13. if(libName.trim().length === 0){
  14. alert('名称不可为空!');
  15. $('#libNameTxt').val('')
  16. }
  17. else if(dispNames.indexOf(libName) !== -1){
  18. alert('此工料机库已存在!');
  19. $('#libNameTxt').val('')
  20. }
  21. else if(compilationName.trim().length === 0){
  22. alert('编办不可为空!');
  23. }
  24. else{
  25. let newGljLib = {};
  26. newGljLib.dispName = libName;
  27. newGljLib.compilationId = compilationId;
  28. newGljLib.compilationName = compilationName;
  29. newGljLib.creator = oprtor;
  30. newGljLib.appType = "建筑";
  31. $('#libNameTxt').val('');
  32. createGljLib(newGljLib, dispNameArr);
  33. }
  34. });
  35. //重命名
  36. $("#showArea").on("click", "[data-target = '#edit']", function(){
  37. let renameId = $(this).parent().parent().attr("id");
  38. let compilationName = $(this).parent().parent().children()[1].textContent;
  39. $('#compilationEdit option').text(compilationName);
  40. $("#renameA").attr("renameId", renameId);
  41. });
  42. $("#renameA").click(function(){
  43. let newName = $("#renameText").val();
  44. let libId = $(this).attr("renameId");
  45. let jqSel = "#" + libId + " td:first" + " a";
  46. let orgName = $(jqSel).text();
  47. if(newName.trim().length === 0){
  48. alert("名称不可为空!");
  49. $("#renameText").val('');
  50. }
  51. else if(dispNameArr.indexOf(newName) !== -1){
  52. alert("该工料机库已存在!");
  53. $("#renameText").val('');
  54. }
  55. else{
  56. renameGljLib({ID: libId, newName: newName, orgName: orgName}, dispNameArr);
  57. }
  58. });
  59. //删除
  60. $("#showArea").on("click", "[data-target = '#del']", function(){
  61. let deleteId = $(this).parent().parent().attr("id");
  62. $("#deleteA").attr("deleteId", deleteId);
  63. });
  64. $("#deleteA").click(function(){
  65. let deleteId = $(this).attr("deleteId");
  66. let jqSel = "#" + deleteId + " td:first" + " a";
  67. let libName = $(jqSel).text();
  68. removeGljLib({libId: deleteId, libName: libName}, dispNameArr);
  69. });
  70. });
  71. getCompilationList();
  72. });
  73. function getAllGljLib(callback){
  74. $.ajax({
  75. type: 'post',
  76. url: 'api/getAllGljLib',
  77. dataType: 'json',
  78. success: function (result) {
  79. let dispNames = [];
  80. if(result.data.length > 0){
  81. for(let i = 0; i < result.data.length; i++){
  82. let id = result.data[i].ID;
  83. let libName = result.data[i].dispName;
  84. let createDate = result.data[i].createDate.split(' ')[0];
  85. let compilationName = result.data[i].compilationName;
  86. let rationLibs = result.data[i].rationLibs;
  87. let rationLibsName = '';
  88. for(let j = 0; j < rationLibs.length; j++){
  89. rationLibsName += rationLibs[j].dispName + "</br>";
  90. }
  91. dispNames.push(result.data[i].dispName);
  92. $("#showArea").append(
  93. "<tr id='tempId'>" +
  94. "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
  95. "<td>"+compilationName+" </td>" +
  96. "<td>"+rationLibsName+" </td>" +
  97. "<td>"+createDate+" </td>" +
  98. "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
  99. "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
  100. "<i class='fa fa-remove'></i></a></td></tr>");
  101. var newHref = "/stdGljRepository/glj?gljLibId="+id;
  102. $("#tempId td:first a").attr("href", newHref);
  103. $("#tempId").attr("id", id);
  104. }
  105. }
  106. callback(dispNames);
  107. }
  108. });
  109. }
  110. function getCompilationList(){
  111. $.ajax({
  112. type: 'post',
  113. url: 'api/getCompilationList',
  114. dataType: 'json',
  115. success: function (result) {
  116. //addoptions
  117. for(let i = 0; i < result.data.length; i++){
  118. let $option = $("<option >"+ result.data[i].name +"</option>");
  119. $option.val( result.data[i]._id);
  120. $('#compilationSels').append($option);
  121. }
  122. $('#compilationSels').on("change", function () {
  123. });
  124. }
  125. });
  126. }
  127. function createGljLib(gljLibObj, dispNamesArr){
  128. $.ajax({
  129. type: 'post',
  130. url: 'api/createGljLib',
  131. data: {gljLibObj: JSON.stringify(gljLibObj)},
  132. dataType: 'json',
  133. success: function (result) {
  134. console.log(result);
  135. if(result.data){
  136. let id = result.data.ID;
  137. let libName = result.data.dispName;
  138. let createDate = result.data.createDate.split(' ')[0];
  139. let compilationName = result.data.compilationName;
  140. dispNamesArr.push(libName);
  141. $("#showArea").append(
  142. "<tr id='tempId'>" +
  143. "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
  144. "<td>"+compilationName+" </td>" +
  145. "<td>"+''+" </td>" +
  146. "<td>"+createDate+" </td>" +
  147. "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
  148. "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
  149. "<i class='fa fa-remove'></i></a></td></tr>");
  150. var newHref = "/stdGljRepository/glj?gljLibId="+id;
  151. $("#tempId td:first a").attr("href", newHref);
  152. $("#tempId").attr("id", id);
  153. }
  154. $('#cancelBtn').click();
  155. }
  156. })
  157. }
  158. function renameGljLib(renameObj, dispNames){
  159. $.ajax({
  160. type: 'post',
  161. url: 'api/renameGljLib',
  162. data: {oprtor: oprtor, renameObj: JSON.stringify(renameObj)},
  163. dataType: 'json',
  164. success: function (result) {
  165. if(!result.error){
  166. let jqSel = "#" + renameObj.ID + " td:first" + " a";
  167. $(jqSel).text(renameObj.newName);
  168. let index = dispNames.indexOf(renameObj.orgName);
  169. dispNames.splice(index, 1);
  170. dispNames.splice(index, 0, renameObj.newName);
  171. }
  172. $('#editCancelBtn').click();
  173. $('#renameText').val('');
  174. }
  175. })
  176. }
  177. function removeGljLib(delObj, dispNames){
  178. $.ajax({
  179. type: 'post',
  180. url: 'api/removeGljLib',
  181. data: {oprtor: oprtor, libId: delObj.libId},
  182. dataType: 'json',
  183. success: function (result) {
  184. if(!result.error){
  185. if(result.message === '此工料机库已被引用!'){
  186. $('#delCancelBtn').click();
  187. alert("此工料机库已被引用,不可删除!");
  188. }
  189. else if(result.message === '删除成功'){
  190. var jqSel = "#"+ delObj.libId;
  191. $(jqSel).remove();
  192. let index = dispNames.indexOf(delObj.libName);
  193. dispNames.splice(index, 1);
  194. $('#delCancelBtn').click();
  195. }
  196. }
  197. }
  198. })
  199. }