Elnumber.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. o2.xDesktop.requireApp("process.Xform", "$Elinput", null, false);
  2. /** @class Elinput 基于Element UI的数字输入框组件。
  3. * @o2cn 数字输入框
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var input = this.form.get("name"); //获取组件
  8. * //方法2
  9. * var input = this.target; //在组件事件脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Process|CMS|Portal}
  13. * @hideconstructor
  14. * @see {@link https://element.eleme.cn/#/zh-CN/component/input-number|Element UI InputNumber 计数器}
  15. */
  16. MWF.xApplication.process.Xform.Elnumber = MWF.APPElnumber = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Elnumber# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APP$Elinput,
  21. options: {
  22. "moduleEvents": ["load", "queryLoad", "postLoad"],
  23. /**
  24. * 当 input 获得焦点时触发。this.event[0]指向Event
  25. * @event MWF.xApplication.process.Xform.Elnumber#focus
  26. * @see {@link https://element.eleme.cn/#/zh-CN/component/input-number|计数器的Events章节}
  27. */
  28. /**
  29. * 当 input 失去焦点时触发。this.event[0]指向Event
  30. * @event MWF.xApplication.process.Xform.Elnumber#blur
  31. * @see {@link https://element.eleme.cn/#/zh-CN/component/input-number|计数器的Events章节}
  32. */
  33. /**
  34. * 绑定值被改变时触发。this.event[0]为组件的currentValue,this.event[1]为组件的oldValue
  35. * @event MWF.xApplication.process.Xform.Elnumber#change
  36. * @see {@link https://element.eleme.cn/#/zh-CN/component/input-number|计数器的Events章节}
  37. */
  38. "elEvents": ["focus", "blur", "change"]
  39. },
  40. /**
  41. * @summary 组件的配置信息,同时也是Vue组件的data。
  42. * @member MWF.xApplication.process.Xform.Elinput#json {JsonObject}
  43. * @example
  44. * //可以在脚本中获取此对象,下面两行代码是等价的,它们获取的是同一个对象
  45. * var json = this.form.get("elinput").json; //获取组件的json对象
  46. * var json = this.form.get("elinput").vm.$data; //获取Vue组件的data数据,
  47. *
  48. * //通过json对象操作Element组件
  49. * json.size = "mini"; //改变输入框大小
  50. * json.disabled = true; //设置输入框为禁用
  51. */
  52. _loadUserInterface: function(){
  53. if ( this.isSectionMergeRead() ) { //区段合并显示
  54. this.node.empty();
  55. this.node.set({
  56. "nodeId": this.json.id,
  57. "MWFType": this.json.type
  58. });
  59. switch (this.json.mergeTypeRead) {
  60. case "amount":
  61. this._loadMergeAmountReadNode();
  62. break;
  63. case "average":
  64. this._loadMergeAverageReadNode();
  65. break;
  66. default:
  67. this._loadMergeReadNode();
  68. break;
  69. }
  70. }else{
  71. if( this.isSectionMergeEdit() ){
  72. switch (this.json.mergeTypeEdit) {
  73. case "amount":
  74. this._loadMergeAmountEidtNode();
  75. break;
  76. case "average":
  77. this._loadMergeAverageEditNode();
  78. break;
  79. }
  80. }else{
  81. this._loadNode();
  82. }
  83. if (this.json.compute === "show"){
  84. this._setValue(this._computeValue());
  85. }else{
  86. this._loadValue();
  87. }
  88. }
  89. },
  90. _loadMergeAmountReadNode: function(){
  91. var data = this.getBusinessDataById();
  92. var total = new Decimal(0);
  93. for( var key in data ){
  94. total = total.plus(new Decimal(data[key] || 0));
  95. }
  96. this.node.set("text", total.toString());
  97. },
  98. _loadMergeAverageReadNode: function(){
  99. var data = this.getBusinessDataById();
  100. var total = new Decimal(0);
  101. for( var key in data ){
  102. total = total.plus(new Decimal(data[key] || 0));
  103. }
  104. var average = total.div( new Decimal(Object.keys(data).length) );
  105. this.node.set("text", average.toString());
  106. },
  107. _loadMergeAmountEidtNode: function(){
  108. var data = this.getBusinessDataById();
  109. var total = new Decimal(0);
  110. for( var key in data ){
  111. total = total.plus(new Decimal(data[key] || 0));
  112. }
  113. this._setBusinessData( total.toNumber() );
  114. this._loadNode();
  115. },
  116. _loadMergeAverageEditNode: function(){
  117. var data = this.getBusinessDataById();
  118. var total = new Decimal(0);
  119. for( var key in data ){
  120. total = total.plus(new Decimal(data[key] || 0));
  121. }
  122. var average = total.div( new Decimal(Object.keys(data).length) );
  123. this._setBusinessData( average.toNumber() );
  124. this._loadNode();
  125. },
  126. _appendVueData: function(){
  127. this.form.Macro.environment.data.check(this.json.id);
  128. this.json[this.json.id] = this._getBusinessData();
  129. // if (!this.json.max || o2.typeOf(this.json.max)!=="number") this.json.max = "Infinity";
  130. // if (!this.json.min || o2.typeOf(this.json.max)!=="number") this.json.min = "-Infinity";
  131. if (!this.json.step || o2.typeOf(this.json.step)!=="number") this.json.step = 1;
  132. if (!this.json.stepStrictly) this.json.stepStrictly = false;
  133. if (!this.json.disabled) this.json.disabled = false;
  134. if (!this.json.precision) this.json.precision = 0;
  135. if (!this.json.size) this.json.size = "";
  136. if (!this.json.controlsPosition) this.json.controlsPosition = "";
  137. if (!this.json.readonly) this.json.readonly = false;
  138. if (!this.json.description) this.json.description = "";
  139. },
  140. // appendVueExtend: function(app){
  141. // if (!app.methods) app.methods = {};
  142. // app.methods.$loadElEvent = function(ev){
  143. // this.validationMode();
  144. // if (ev==="change") this._setBusinessData(this.getInputData());
  145. // if (this.json.events && this.json.events[ev] && this.json.events[ev].code){
  146. // this.form.Macro.fire(this.json.events[ev].code, this, event);
  147. // }
  148. // }.bind(this);
  149. // },
  150. _createElementHtml: function(){
  151. var html = "<el-input-number";
  152. html += " v-model=\""+this.json.$id+"\"";
  153. if (o2.typeOf(this.json.max)==="number") html += " :max=\"max\"";
  154. if (o2.typeOf(this.json.min)==="number") html += " :min=\"min\"";
  155. html += " :step=\"step\"";
  156. html += " :step-strictly=\"stepStrictly\"";
  157. html += " :disabled=\"disabled\"";
  158. html += " :size=\"size\"";
  159. html += " :precision=\"precision\"";
  160. html += " :controls-position=\"controlsPosition\"";
  161. html += " :readonly=\"readonly\"";
  162. html += " :placeholder=\"description\"";
  163. this.options.elEvents.forEach(function(k){
  164. html += " @"+k+"=\"$loadElEvent_"+k.camelCase()+"\"";
  165. });
  166. // this.options.elEvents.forEach(function(k){
  167. // html += " @"+k+"=\"$loadElEvent('"+k+"')\"";
  168. // });
  169. if (this.json.elProperties){
  170. Object.keys(this.json.elProperties).forEach(function(k){
  171. if (this.json.elProperties[k]) html += " "+k+"=\""+this.json.elProperties[k]+"\"";
  172. }, this);
  173. }
  174. if (this.json.elStyles) html += " :style=\"elStyles\"";
  175. // if (this.json.elStyles){
  176. // var style = "";
  177. // Object.keys(this.json.elStyles).forEach(function(k){
  178. // if (this.json.elStyles[k]) style += k+":"+this.json.elStyles[k]+";";
  179. // }, this);
  180. // html += " style=\""+style+"\"";
  181. // }
  182. html += ">";
  183. // if (this.json.vueSlot) html += this.json.vueSlot;
  184. html += "</el-input-number>";
  185. return html;
  186. }
  187. });