item_increase_edit.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Created by zhang on 2018/9/3.
  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. $("#template").val(JSON.stringify(tem, null, 4));
  10. } catch (err) {
  11. console.log(err);
  12. }
  13. $("#format").click(function () {
  14. try {
  15. let jsonText = $("#template").val();
  16. $("#template").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 = $("#template").val();
  27. if (jsonText.indexOf("'") != -1) {
  28. alert(
  29. "输入的格式不能包含 ' 位于:" +
  30. jsonText.substr(jsonText.indexOf("'") - 15, 18)
  31. );
  32. return;
  33. }
  34. await ajaxPost("/itemSetting/saveLib", {
  35. query: { ID: libID },
  36. data: { template: JSON.parse(jsonText) },
  37. });
  38. $.bootstrapLoading.end();
  39. } catch (err) {
  40. $.bootstrapLoading.end();
  41. console.log(err);
  42. alert("保存失败,请查看输入数据");
  43. }
  44. });
  45. $("#createNormal").click(async function () {
  46. let basicTemplate = [
  47. {
  48. ID: "1",
  49. name: "在生产车间边生产边施工",
  50. base: "人工费",
  51. coe: 10,
  52. isCalc: false,
  53. reductionRate: 100,
  54. measureRate: 70,
  55. position: "010001",
  56. },
  57. {
  58. ID: "2",
  59. name: "在有害身体健康的场所内施工",
  60. base: "人工费",
  61. coe: 10,
  62. isCalc: false,
  63. reductionRate: 100,
  64. measureRate: 70,
  65. position: "010001",
  66. },
  67. {
  68. ID: "3",
  69. name: "在洞内、地下室内、库内或暗室内进行施工",
  70. base: "人工费",
  71. coe: 40,
  72. isCalc: false,
  73. reductionRate: 100,
  74. measureRate: 70,
  75. position: "010001",
  76. },
  77. {
  78. ID: "4",
  79. name: "在洞内、地下室内、库内或暗室内进行施工(模板拆除)",
  80. base: "人工费",
  81. coe: 10,
  82. isCalc: false,
  83. reductionRate: 100,
  84. measureRate: 70,
  85. position: "010001",
  86. },
  87. ];
  88. try {
  89. let jsonText = JSON.stringify(basicTemplate);
  90. $("#template").val(JSON.stringify(JSON.parse(jsonText), null, 4));
  91. } catch (err) {
  92. console.log(err);
  93. }
  94. });
  95. });
  96. function compareInfo(a, b) {
  97. let mapping = {
  98. ID: 1,
  99. name: 2,
  100. };
  101. let aV = mapping[a] ? mapping[a] : 0,
  102. bV = mapping[b] ? mapping[b] : 0;
  103. return aV - bV;
  104. }