explanatory.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Created by Zhong on 2017/12/20.
  3. */
  4. //定额章节节点说明、计算规则
  5. let explanatoryOprObj = {
  6. preTreeNode: null,
  7. currentTreeNode: null,//定额章节树节点
  8. currentExplanation: null,
  9. currentRuleText: null,
  10. setAttribute: function (preNode, currentNode, explanation, ruleText) {
  11. let me = explanatoryOprObj;
  12. me.preTreeNode = preNode;
  13. me.currentTreeNode = currentNode;
  14. me.currentExplanation = explanation;
  15. me.currentRuleText = ruleText;
  16. },
  17. clickUpdate: function (exarea, ruarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  18. let me = explanatoryOprObj;
  19. if(exarea.is(':focus')){
  20. let explanation = exarea.val();
  21. if(explanation !== me.currentExplanation){
  22. me.preTreeNode.data.explanation = explanation;
  23. me.unbindEvents(exarea, ruarea);
  24. exarea.blur();
  25. me.updateExplanation(pageOprObj.rationLibId, me.preTreeNode.getID(), explanation, function () {
  26. me.bindEvents(exarea, ruarea);
  27. });
  28. }
  29. }
  30. if(ruarea.is(':focus')){
  31. let ruleText = ruarea.val();
  32. if(ruleText !== me.currentRuleText){
  33. me.preTreeNode.data.ruleText = ruleText;
  34. me.unbindEvents(exarea, ruarea);
  35. ruarea.blur();
  36. me.updateRuleText(pageOprObj.rationLibId, me.preTreeNode.getID(), ruleText, function () {
  37. me.bindEvents(exarea, ruarea);
  38. });
  39. }
  40. }
  41. },
  42. unbindEvents: function (exarea, ruarea) {
  43. exarea.unbind();
  44. ruarea.unbind();
  45. },
  46. bindEvents: function (exEd, calcEd) {
  47. let me = explanatoryOprObj;
  48. exEd.on('change', function () {
  49. let node = me.currentTreeNode;
  50. let newData = exEd.getValue();
  51. if(node && node.data.explanation !== newData){
  52. me.updateExplanation(pageOprObj.rationLibId, node.getID(), newData, function () {
  53. node.data.explanation = newData;
  54. });
  55. }
  56. });
  57. calcEd.on('change', function () {
  58. let node = me.currentTreeNode;
  59. let newData = calcEd.getValue();
  60. if(node && node.data.ruleText !== newData){
  61. me.updateRuleText(pageOprObj.rationLibId, node.getID(), newData, function () {
  62. node.data.ruleText = newData;
  63. });
  64. }
  65. })
  66. /*exarea.bind('change', function () {
  67. let explanation = exarea.val();
  68. let node = me.currentTreeNode;
  69. exarea.attr('disabled', true);
  70. me.updateExplanation(pageOprObj.rationLibId, node.getID(), explanation, function () {
  71. node.data.explanation = explanation;
  72. exarea.attr('disabled', false);
  73. });
  74. });*/
  75. /*ruarea.bind('change', function () {
  76. let ruleText = ruarea.val();
  77. let node = me.currentTreeNode;
  78. ruarea.attr('disabled', true);
  79. me.updateRuleText(pageOprObj.rationLibId, node.getID(), ruleText, function () {
  80. node.data.ruleText = ruleText;
  81. ruarea.attr('disabled', false);
  82. });
  83. });*/
  84. },
  85. showText: function (exEd, calcEd, explanation, ruleText) {
  86. exEd.setValue(explanation && explanation !== 'undefined' ? explanation : '');
  87. calcEd.setValue(ruleText && ruleText !== 'undefined' ? ruleText : '');
  88. //exarea.val(explanation && explanation !== 'undefined' ? explanation : '');
  89. //ruarea.val(ruleText && ruleText !== 'undefined' ? ruleText : '');
  90. },
  91. //更新说明
  92. updateExplanation: function (repId, nodeId, explanation, callback) {
  93. $.ajax({
  94. type: 'post',
  95. url: 'api/updateExplanation',
  96. data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, nodeId: nodeId, explanation: explanation},
  97. dataType: 'json',
  98. success: function () {
  99. callback();
  100. }
  101. });
  102. },
  103. //更新计算规则
  104. updateRuleText: function (repId, nodeId, explanation, callback) {
  105. $.ajax({
  106. type: 'post',
  107. url: 'api/updateRuleText',
  108. data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, nodeId: nodeId, ruleText: explanation},
  109. dataType: 'json',
  110. success: function () {
  111. callback();
  112. }
  113. });
  114. }
  115. };