edit.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $("#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("/mainQuantity/saveLib",{query:{ID:libID},data:{index:JSON.parse(jsonText)}});
  32. $.bootstrapLoading.end();
  33. }catch (err){
  34. $.bootstrapLoading.end();
  35. console.log(err);
  36. alert("保存失败,请查看输入数据");
  37. }
  38. });
  39. $("#createNormal").click(async function() {
  40. let normalInfo = [
  41. { "name": "挖土方量", "unit": "m2", "coe": 2.3},
  42. { "name": "填方量", "unit": "m2", "coe": 1.2},
  43. { "name": "连槽石基层", "unit": "t", "coe": 0.2},
  44. { "name": "砂砾石基层", "unit": "t", "coe": 0.6},
  45. { "name": "块片石", "unit":"m3", "coe": 0.8},
  46. { "name": "多渣","unit": "m3", "coe": ""},
  47. { "name": "砂", "unit":"t", "coe": ""}
  48. ];
  49. try {
  50. let jsonText = JSON.stringify(normalInfo);
  51. $("#editValue").val(JSON.stringify(JSON.parse(jsonText),null,4));
  52. }catch (err){
  53. console.log(err);
  54. }
  55. })
  56. });
  57. function compareInfo(a, b) {
  58. let mapping = {
  59. dispName: 1,
  60. key: 2,
  61. cellType: 3,
  62. readOnly: 4,
  63. required: 5,
  64. value: 6,
  65. options: 7,
  66. items: 8
  67. };
  68. let aV = mapping[a] ? mapping[a] : 0,
  69. bV = mapping[b] ? mapping[b] : 0;
  70. return aV - bV;
  71. }