edit.js 3.4 KB

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