explanatory.js 6.7 KB

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