explanatory.js 5.5 KB

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