edit.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * Created by Zhong on 2019/12/11.
  3. */
  4. $(document).ready(function () {
  5. const locked = lockUtil.getLocked();
  6. lockUtil.lockTools($(document.body), locked);
  7. try {
  8. let tem = sortJson(JSON.parse($("#originalInfo").val()), compareInfo);
  9. $("#editValue").val(JSON.stringify(tem,null,4));
  10. }catch (err){
  11. console.log(err);
  12. }
  13. $("#format").click( function() {
  14. try {
  15. let jsonText = $("#editValue").val();
  16. $("#editValue").val(JSON.stringify(JSON.parse(jsonText),null,4));
  17. }catch (err){
  18. console.log(err);
  19. alert("输入的JSON格式有误,请重新输入!");
  20. }
  21. });
  22. $("#save").click(async function() {
  23. try {
  24. $.bootstrapLoading.start();
  25. let libID = $("#libID").val();
  26. let jsonText = $("#editValue").val();
  27. if(jsonText.indexOf("'")!=-1){
  28. alert("输入的格式不能包含 ' 位于:"+jsonText.substr(jsonText.indexOf("'")-15,18));
  29. return;
  30. }
  31. await ajaxPost("/overHeight/saveLib",{query:{ID:libID},data:{list:JSON.parse(jsonText)}});
  32. $.bootstrapLoading.end();
  33. }catch (err){
  34. $.bootstrapLoading.end();
  35. console.log(err);
  36. alert("保存失败,请查看输入数据");
  37. }
  38. });
  39. /*[{
  40. "name": "",
  41. "labourName": "定额人工名称",
  42. "machineName": "定额机械名称",
  43. "items": [{
  44. "code": "JZCG-1",
  45. "name": "高度增加30m",
  46. "labourRate": "0.0124",
  47. "machineRate": "0.0313"
  48. },{
  49. "code": "JZCG-2",
  50. "name": "高度增加40m",
  51. "labourRate": "0.023",
  52. "machineRate": "0.0513"
  53. },{
  54. "code": "JZCG-3",
  55. "name": "高度增加50m",
  56. "labourRate": "0.0336",
  57. "machineRate": "0.0665"
  58. },{
  59. "code": "JZCG-4",
  60. "name": "高度增加60m",
  61. "labourRate": "0.023",
  62. "machineRate": "0.0513"
  63. },{
  64. "code": "JZCG-5",
  65. "name": "高度增加70m",
  66. "labourRate": "0.0664",
  67. "machineRate": "0.1104"
  68. },{
  69. "code": "JZCG-6",
  70. "name": "高度增加80m",
  71. "labourRate": "0.0837",
  72. "machineRate": "0.1324"
  73. },{
  74. "code": "JZCG-7",
  75. "name": "高度增加90m",
  76. "labourRate": "0.1012",
  77. "machineRate": "0.1528"
  78. },{
  79. "code": "JZCG-8",
  80. "name": "高度增加100m",
  81. "benchmark": "100",
  82. "labourRate": "0.1309",
  83. "machineRate": "0.1881"
  84. },{
  85. "code": "JZCG-9",
  86. "name": "每增10m以内",
  87. "extra": "10",
  88. "labourRate": "0.0206",
  89. "machineRate": "0.0249"
  90. },{
  91. "code": "JZCG-8 + JZCG-9",
  92. "name": "高度增加110m",
  93. "labourRate": "0.1515",
  94. "machineRate": "0.213"
  95. },{
  96. "code": "JZCG-8 + JZCG-9 * 2",
  97. "name": "高度增加110m",
  98. "limit": "110",
  99. "labourRate": "0.1721",
  100. "machineRate": "0.2379"
  101. }]
  102. }]*/
  103. $("#createNormal").click(async function() {
  104. let normalInfo = [{
  105. "name": "多层建筑物",
  106. "labourMachineName": "定额人工机械名称",
  107. "items": [{
  108. "code": "JZCG-1",
  109. "name": "20-40",
  110. "labourMachineRate": "0.0701"
  111. },{
  112. "code": "JZCG-2",
  113. "name": "40-60",
  114. "labourMachineRate": "0.1148"
  115. },{
  116. "code": "JZCG-3",
  117. "name": "60-80",
  118. "labourMachineRate": "0.1594"
  119. },{
  120. "code": "JZCG-4",
  121. "name": "80-100",
  122. "labourMachineRate": "0.2104"
  123. },{
  124. "code": "JZCG-5",
  125. "name": "100-120",
  126. "benchmark": "120",
  127. "labourMachineRate": "0.2614"
  128. },{
  129. "code": "JZCG-6",
  130. "name": "每增20m",
  131. "extra": "20",
  132. "labourMachineRate": "0.045"
  133. },{
  134. "code": "JZCG-5 + JZCG-6",
  135. "name": "120-140",
  136. "labourMachineRate": "0.3064"
  137. },{
  138. "code": "JZCG-5 + JZCG-6 * 2",
  139. "name": "140-160",
  140. "limit": "160",
  141. "labourMachineRate": "0.3514"
  142. }]
  143. }, {
  144. "name": "单层建筑物",
  145. "labourMachineName": "定额人工机械名称",
  146. "items": [{
  147. "code": "DCCG-1",
  148. "name": "30以内",
  149. "labourMachineRate": "0.025"
  150. },{
  151. "code": "DCCG-2",
  152. "name": "40以内",
  153. "labourMachineRate": "0.0374"
  154. },{
  155. "code": "DCCG-3",
  156. "name": "50以内",
  157. "labourMachineRate": "0.0544"
  158. }]
  159. }];
  160. try {
  161. let jsonText = JSON.stringify(normalInfo);
  162. $("#editValue").val(JSON.stringify(JSON.parse(jsonText),null,4));
  163. }catch (err){
  164. console.log(err);
  165. }
  166. })
  167. });
  168. function compareInfo(a, b) {
  169. let mapping = {
  170. name: 1,
  171. labourName: 2,
  172. machineName: 3,
  173. labourMachineName: 4,
  174. items: 5,
  175. code: 6,
  176. labourRate: 7,
  177. machineRate: 8,
  178. labourMachineRate: 9
  179. };
  180. let aV = mapping[a] ? mapping[a] : 0,
  181. bV = mapping[b] ? mapping[b] : 0;
  182. return aV - bV;
  183. }