edit.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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("/engineerFeature/saveLib",{query:{ID:libID},data:{features: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. { "ID": 1, "ParentID": -1, "name": "建筑特征", "value": ""},
  42. { "ID": 101, "ParentID": 1, "name": "建筑面积", "value": ""},
  43. { "ID": 10101, "ParentID": 101, "name": "总建筑面积*", "value": "","required":true,cellType:'number',index:true,indexUnit:"100M2",coe:100},
  44. { "ID": 10102, "ParentID": 101, "name": "标准层面积", "value": "","cellType":'number'},//cellType:'date'
  45. { "ID": 102, "ParentID": 1, "name": "层数", "value": ""},
  46. { "ID": 10201, "ParentID": 102, "name": "总层数*", "value": "","required":true},
  47. { "ID": 10202, "ParentID": 102, "name": "标准层层数", "value": ""},
  48. { "ID": 2, "ParentID": -1, "name": "结构特征", "value": ""},
  49. { "ID": 201, "ParentID": 2, "name": "结构类型", "value": ""},
  50. { "ID": 202, "ParentID": 2, "name": "基础类型", "value": ""},
  51. { "ID": 203, "ParentID": 2, "name": "混凝土强度等级", "value": ""},
  52. { "ID": 20301, "ParentID": 203, "name": "基础", "value": ""},
  53. { "ID": 20302, "ParentID": 203, "name": "柱", "value": ""},
  54. { "ID": 3, "ParentID": -1, "name": "装饰特征", "value": ""},
  55. { "ID": 301, "ParentID": 3, "name": "楼地面", "value": ""},
  56. { "ID": 30101, "ParentID": 301, "name": "整体面层", "value": ""},
  57. { "ID": 3010101, "ParentID": 30101, "name": "整体面层1", "value": ""},
  58. { "ID": 3010102, "ParentID": 30101, "name": "整体面层2", "value": ""}
  59. ];
  60. try {
  61. let jsonText = JSON.stringify(normalInfo);
  62. $("#editValue").val(JSON.stringify(JSON.parse(jsonText),null,4));
  63. }catch (err){
  64. console.log(err);
  65. }
  66. })
  67. });
  68. function compareInfo(a, b) {
  69. let mapping = {
  70. dispName: 1,
  71. key: 2,
  72. cellType: 3,
  73. readOnly: 4,
  74. required: 5,
  75. value: 6,
  76. options: 7,
  77. items: 8
  78. };
  79. let aV = mapping[a] ? mapping[a] : 0,
  80. bV = mapping[b] ? mapping[b] : 0;
  81. return aV - bV;
  82. }