main.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. dispNames.push(result.data[i].dispName);
  87. $("#showArea").append(
  88. "<tr id='tempId'>" +
  89. "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
  90. "<td>"+compilationName+" </td>" +
  91. "<td>"+'xx定额库(xx)'+" </td>" +
  92. "<td>"+createDate+" </td>" +
  93. "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
  94. "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
  95. "<i class='fa fa-remove'></i></a></td></tr>");
  96. var newHref = "/stdGljRepository/glj?gljLibId="+id;
  97. $("#tempId td:first a").attr("href", newHref);
  98. $("#tempId").attr("id", id);
  99. }
  100. }
  101. callback(dispNames);
  102. }
  103. });
  104. }
  105. function getCompilationList(){
  106. $.ajax({
  107. type: 'post',
  108. url: 'api/getCompilationList',
  109. dataType: 'json',
  110. success: function (result) {
  111. //addoptions
  112. for(let i = 0; i < result.data.length; i++){
  113. let $option = $("<option >"+ result.data[i].name +"</option>");
  114. $option.val( result.data[i]._id);
  115. $('#compilationSels').append($option);
  116. }
  117. $('#compilationSels').on("change", function () {
  118. });
  119. }
  120. });
  121. }
  122. function createGljLib(gljLibObj, dispNamesArr){
  123. $.ajax({
  124. type: 'post',
  125. url: 'api/createGljLib',
  126. data: {gljLibObj: JSON.stringify(gljLibObj)},
  127. dataType: 'json',
  128. success: function (result) {
  129. console.log(result);
  130. if(result.data){
  131. let id = result.data.ID;
  132. let libName = result.data.dispName;
  133. let createDate = result.data.createDate.split(' ')[0];
  134. let compilationName = result.data.compilationName;
  135. dispNamesArr.push(libName);
  136. $("#showArea").append(
  137. "<tr id='tempId'>" +
  138. "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
  139. "<td>"+compilationName+" </td>" +
  140. "<td>"+'xx定额库(xx)'+" </td>" +
  141. "<td>"+createDate+" </td>" +
  142. "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
  143. "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
  144. "<i class='fa fa-remove'></i></a></td></tr>");
  145. var newHref = "/stdGljRepository/glj?gljLibId="+id;
  146. $("#tempId td:first a").attr("href", newHref);
  147. $("#tempId").attr("id", id);
  148. }
  149. $('#cancelBtn').click();
  150. }
  151. })
  152. }
  153. function renameGljLib(renameObj, dispNames){
  154. $.ajax({
  155. type: 'post',
  156. url: 'api/renameGljLib',
  157. data: {oprtor: oprtor, renameObj: JSON.stringify(renameObj)},
  158. dataType: 'json',
  159. success: function (result) {
  160. if(!result.error){
  161. let jqSel = "#" + renameObj.ID + " td:first" + " a";
  162. $(jqSel).text(renameObj.newName);
  163. let index = dispNames.indexOf(renameObj.orgName);
  164. dispNames.splice(index, 1);
  165. dispNames.splice(index, 0, renameObj.newName);
  166. }
  167. $('#editCancelBtn').click();
  168. $('#renameText').val('');
  169. }
  170. })
  171. }
  172. function removeGljLib(delObj, dispNames){
  173. $.ajax({
  174. type: 'post',
  175. url: 'api/removeGljLib',
  176. data: {oprtor: oprtor, libId: delObj.libId},
  177. dataType: 'json',
  178. success: function (result) {
  179. if(!result.error){
  180. var jqSel = "#"+ delObj.libId;
  181. $(jqSel).remove();
  182. let index = dispNames.indexOf(delObj.libName);
  183. dispNames.splice(index, 1);
  184. $('#delCancelBtn').click();
  185. }
  186. }
  187. })
  188. }