edit.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Created by zhang on 2018/9/3.
  3. */
  4. $(document).ready(function () {
  5. try {
  6. let tem = sortJson(JSON.parse($("#originalInfo").val()), compareInfo);
  7. $("#editValue").val(JSON.stringify(tem,null,4));
  8. }catch (err){
  9. console.log(err);
  10. }
  11. $("#format").click( function() {
  12. try {
  13. let jsonText = $("#editValue").val();
  14. $("#editValue").val(JSON.stringify(JSON.parse(jsonText),null,4));
  15. }catch (err){
  16. console.log(err);
  17. alert("输入的JSON格式有误,请重新输入!");
  18. }
  19. });
  20. $("#save").click(async function() {
  21. try {
  22. $.bootstrapLoading.start();
  23. let libID = $("#libID").val();
  24. let jsonText = $("#editValue").val();
  25. if(jsonText.indexOf("'")!=-1){
  26. alert("输入的格式不能包含 ' 位于:"+jsonText.substr(jsonText.indexOf("'")-15,18));
  27. return;
  28. }
  29. await ajaxPost("/mainQuantity/saveLib",{query:{ID:libID},data:{index:JSON.parse(jsonText)}});
  30. $.bootstrapLoading.end();
  31. }catch (err){
  32. $.bootstrapLoading.end();
  33. console.log(err);
  34. alert("保存失败,请查看输入数据");
  35. }
  36. });
  37. $("#createNormal").click(async function() {
  38. let normalInfo = [
  39. { "name": "挖土方量", "unit": "m2", "coe": 2.3},
  40. { "name": "填方量", "unit": "m2", "coe": 1.2},
  41. { "name": "连槽石基层", "unit": "t", "coe": 0.2},
  42. { "name": "砂砾石基层", "unit": "t", "coe": 0.6},
  43. { "name": "块片石", "unit":"m3", "coe": 0.8},
  44. { "name": "多渣","unit": "m3", "coe": ""},
  45. { "name": "砂", "unit":"t", "coe": ""}
  46. ];
  47. try {
  48. let jsonText = JSON.stringify(normalInfo);
  49. $("#editValue").val(JSON.stringify(JSON.parse(jsonText),null,4));
  50. }catch (err){
  51. console.log(err);
  52. }
  53. })
  54. });
  55. function compareInfo(a, b) {
  56. let mapping = {
  57. dispName: 1,
  58. key: 2,
  59. cellType: 3,
  60. readOnly: 4,
  61. required: 5,
  62. value: 6,
  63. options: 7,
  64. items: 8
  65. };
  66. let aV = mapping[a] ? mapping[a] : 0,
  67. bV = mapping[b] ? mapping[b] : 0;
  68. return aV - bV;
  69. }