explanatory.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Created by Zhong on 2017/12/20.
  3. */
  4. //定额章节节点说明、计算规则
  5. let explanatoryOprObj = {
  6. exEditor: null,
  7. calcEditor: null,
  8. preTreeNode: null,
  9. currentTreeNode: null,//定额章节树节点
  10. currentExplanation: null,
  11. currentRuleText: null,
  12. // 初始化说明、计算规则编辑器
  13. initEditor: function () {
  14. const locked = lockUtil.getLocked();
  15. const exEditor = CodeMirror.fromTextArea(document.getElementById("explanationShow"), {
  16. mode: "text/html",
  17. lineNumbers: true,
  18. theme:"material",
  19. readOnly: locked
  20. });
  21. exEditor.setSize('auto','500px');
  22. $('#explanationLink').click(function () {
  23. setTimeout(function () {
  24. exEditor.refresh();
  25. }, 100);
  26. });
  27. this.exEditor = exEditor;
  28. const calcEditor = CodeMirror.fromTextArea(document.getElementById("ruleTextShow"), {
  29. mode: 'text/html',
  30. lineNumbers: true,
  31. theme: 'material',
  32. readOnly: locked
  33. });
  34. calcEditor.setSize('auto', '500px');
  35. $('#ruleTextLink').click(function () {
  36. setTimeout(function () {
  37. calcEditor.refresh();
  38. }, 100);
  39. });
  40. this.calcEditor = calcEditor;
  41. },
  42. setAttribute: function (preNode, currentNode, explanation, ruleText) {
  43. let me = explanatoryOprObj;
  44. me.preTreeNode = preNode;
  45. me.currentTreeNode = currentNode;
  46. me.currentExplanation = explanation;
  47. me.currentRuleText = ruleText;
  48. },
  49. clickUpdate: function (exarea, ruarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  50. let me = explanatoryOprObj;
  51. if(exarea.is(':focus')){
  52. let explanation = exarea.val();
  53. if(explanation !== me.currentExplanation){
  54. me.preTreeNode.data.explanation = explanation;
  55. me.unbindEvents(exarea, ruarea);
  56. exarea.blur();
  57. me.updateExplanation(pageOprObj.rationLibId, me.preTreeNode.getID(), explanation, function () {
  58. me.bindEvents(exarea, ruarea);
  59. });
  60. }
  61. }
  62. if(ruarea.is(':focus')){
  63. let ruleText = ruarea.val();
  64. if(ruleText !== me.currentRuleText){
  65. me.preTreeNode.data.ruleText = ruleText;
  66. me.unbindEvents(exarea, ruarea);
  67. ruarea.blur();
  68. me.updateRuleText(pageOprObj.rationLibId, me.preTreeNode.getID(), ruleText, function () {
  69. me.bindEvents(exarea, ruarea);
  70. });
  71. }
  72. }
  73. },
  74. unbindEvents: function (exarea, ruarea) {
  75. exarea.unbind();
  76. ruarea.unbind();
  77. },
  78. bindEvents: function (exEd, calcEd) {
  79. let me = explanatoryOprObj;
  80. exEd.on('change', function () {
  81. let node = me.currentTreeNode;
  82. let newData = exEd.getValue();
  83. if(node && node.data.explanation !== newData){
  84. me.updateExplanation(pageOprObj.rationLibId, node.getID(), newData, function () {
  85. node.data.explanation = newData;
  86. });
  87. }
  88. });
  89. calcEd.on('change', function () {
  90. let node = me.currentTreeNode;
  91. let newData = calcEd.getValue();
  92. if(node && node.data.ruleText !== newData){
  93. me.updateRuleText(pageOprObj.rationLibId, node.getID(), newData, function () {
  94. node.data.ruleText = newData;
  95. });
  96. }
  97. })
  98. /*exarea.bind('change', function () {
  99. let explanation = exarea.val();
  100. let node = me.currentTreeNode;
  101. exarea.attr('disabled', true);
  102. me.updateExplanation(pageOprObj.rationLibId, node.getID(), explanation, function () {
  103. node.data.explanation = explanation;
  104. exarea.attr('disabled', false);
  105. });
  106. });*/
  107. /*ruarea.bind('change', function () {
  108. let ruleText = ruarea.val();
  109. let node = me.currentTreeNode;
  110. ruarea.attr('disabled', true);
  111. me.updateRuleText(pageOprObj.rationLibId, node.getID(), ruleText, function () {
  112. node.data.ruleText = ruleText;
  113. ruarea.attr('disabled', false);
  114. });
  115. });*/
  116. },
  117. showText: function (exEd, calcEd, explanation, ruleText) {
  118. exEd.setValue(explanation && explanation !== 'undefined' ? explanation : '');
  119. calcEd.setValue(ruleText && ruleText !== 'undefined' ? ruleText : '');
  120. //exarea.val(explanation && explanation !== 'undefined' ? explanation : '');
  121. //ruarea.val(ruleText && ruleText !== 'undefined' ? ruleText : '');
  122. },
  123. //更新说明
  124. updateExplanation: function (repId, nodeId, explanation, callback) {
  125. $.ajax({
  126. type: 'post',
  127. url: 'api/updateExplanation',
  128. data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, nodeId: nodeId, explanation: explanation},
  129. dataType: 'json',
  130. success: function () {
  131. callback();
  132. }
  133. });
  134. },
  135. //更新计算规则
  136. updateRuleText: function (repId, nodeId, explanation, callback) {
  137. $.ajax({
  138. type: 'post',
  139. url: 'api/updateRuleText',
  140. data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, nodeId: nodeId, ruleText: explanation},
  141. dataType: 'json',
  142. success: function () {
  143. callback();
  144. }
  145. });
  146. }
  147. };