main.js 8.5 KB

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