$Input.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class $Input 组件类,此类为所有输入组件的父类
  3. * @hideconstructor
  4. * @o2category FormComponents
  5. * @extends MWF.xApplication.process.Xform.$Module
  6. * @abstract
  7. */
  8. MWF.xApplication.process.Xform.$Input = MWF.APP$Input = new Class(
  9. /** @lends MWF.xApplication.process.Xform.$Input# */
  10. {
  11. Implements: [Events],
  12. Extends: MWF.APP$Module,
  13. iconStyle: "personfieldIcon",
  14. options: {
  15. "moduleEvents": ["change", "load", "queryLoad", "postLoad"]
  16. },
  17. initialize: function(node, json, form, options){
  18. this.node = $(node);
  19. this.node.store("module", this);
  20. this.json = json;
  21. this.form = form;
  22. this.field = true;
  23. this.fieldModuleLoaded = false;
  24. this.nodeHtml = this.node.get("html");
  25. },
  26. _loadUserInterface: function(){
  27. if ( this.isSectionMergeRead() ) { //区段合并显示
  28. this._loadMergeReadNode();
  29. }else{
  30. if( this.isSectionMergeEdit() ){
  31. this._loadMergeEditNode();
  32. }else{
  33. this._loadNode();
  34. }
  35. if (this.json.compute === "show"){
  36. this._setValue(this._computeValue());
  37. }else{
  38. this._loadValue();
  39. }
  40. }
  41. },
  42. _loadDomEvents: function(){
  43. Object.each(this.json.events, function(e, key){
  44. if (e.code){
  45. if (this.options.moduleEvents.indexOf(key)===-1){
  46. (this.node.getFirst() || this.node).addEvent(key, function(event){
  47. return this.form.Macro.fire(e.code, this, event);
  48. }.bind(this));
  49. }
  50. }
  51. }.bind(this));
  52. },
  53. _loadEvents: function(){
  54. Object.each(this.json.events, function(e, key){
  55. if (e.code){
  56. if (this.options.moduleEvents.indexOf(key)!==-1){
  57. this.addEvent(key, function(event){
  58. return this.form.Macro.fire(e.code, this, event);
  59. }.bind(this));
  60. }else{
  61. (this.node.getFirst() || this.node).addEvent(key, function(event){
  62. return this.form.Macro.fire(e.code, this, event);
  63. }.bind(this));
  64. }
  65. }
  66. }.bind(this));
  67. },
  68. addModuleEvent: function(key, fun){
  69. if (this.options.moduleEvents.indexOf(key)!==-1){
  70. this.addEvent(key, function(event){
  71. return (fun) ? fun(this, event) : null;
  72. }.bind(this));
  73. }else{
  74. (this.node.getFirst() || this.node).addEvent(key, function(event){
  75. return (fun) ? fun(this, event) : null;
  76. }.bind(this));
  77. }
  78. },
  79. /**
  80. * @summary 重新加载组件。会执行postLoad事件。
  81. * @example
  82. * this.form.get("fieldId").reload(); //重新加载事件
  83. */
  84. reload: function(){
  85. if( this.iconNode ){
  86. this.iconNode.destroy();
  87. this.iconNode = null;
  88. }
  89. if( this.descriptionNode ){
  90. this.descriptionNode.destroy();
  91. this.descriptionNode = null;
  92. }
  93. this.node.empty();
  94. this._beforeReloaded();
  95. this._loadUserInterface();
  96. this._loadStyles();
  97. this._afterLoaded();
  98. this._afterReloaded();
  99. this.fireEvent("postLoad");
  100. },
  101. _loadNode: function(){
  102. if (this.isReadonly()){
  103. this._loadNodeRead();
  104. }else{
  105. this._loadNodeEdit();
  106. }
  107. },
  108. _loadNodeRead: function(){
  109. this.node.empty();
  110. this.node.set({
  111. "nodeId": this.json.id,
  112. "MWFType": this.json.type
  113. });
  114. },
  115. loadDescription: function(){
  116. if (this.isReadonly())return;
  117. var v = this._getBusinessData();
  118. if (!v){
  119. if (this.json.description){
  120. var size, w;
  121. if( this.node.offsetParent === null ){ //隐藏
  122. size = { y: 26 }
  123. }else{
  124. size = this.node.getFirst().getSize();
  125. w = size.x-3;
  126. if( this.hasIcon() ){
  127. if (COMMON.Browser.safari) w = w-20;
  128. }
  129. }
  130. /**
  131. * @summary 描述信息节点,允许用户手工输入的组件才有此节点,只读情况下无此节点.
  132. * @member {Element}
  133. */
  134. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  135. this.descriptionNode.setStyles({
  136. "height": ""+size.y+"px",
  137. "line-height": ""+size.y+"px"
  138. });
  139. if( w )this.descriptionNode.setStyles({
  140. "width": ""+w+"px"
  141. });
  142. this.setDescriptionEvent();
  143. }
  144. }
  145. },
  146. setDescriptionEvent: function(){
  147. if (this.descriptionNode){
  148. this.descriptionNode.addEvents({
  149. "mousedown": function(){
  150. this.descriptionNode.setStyle("display", "none");
  151. this.clickSelect();
  152. }.bind(this)
  153. });
  154. this.node.getFirst().addEvents({
  155. "focus": function(){
  156. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  157. }.bind(this),
  158. "blur": function(){
  159. if (!this.node.getFirst().get("value")) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  160. }.bind(this)
  161. });
  162. }
  163. },
  164. checkDescription: function(){
  165. if (!this.node.getFirst().get("value")){
  166. if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  167. }else{
  168. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  169. }
  170. },
  171. _resetNodeEdit: function(){
  172. var input = new Element("input", {
  173. "styles": {
  174. "background": "transparent",
  175. "width": "100%",
  176. "border": "0px"
  177. },
  178. "readonly": true
  179. });
  180. var node = new Element("div", {"styles": {
  181. "overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
  182. "position": "relative",
  183. "margin-right": this.hasIcon() ? "20px" : "0px",
  184. "padding-right": "4px"
  185. }}).inject(this.node, "after");
  186. input.inject(node);
  187. this.node.destroy();
  188. this.node = node;
  189. },
  190. hasIcon: function(){
  191. return this.json.showIcon!='no' && ( !this.form.json || !this.form.json.hideModuleIcon );
  192. },
  193. _loadNodeEdit: function(){
  194. if (!this.json.preprocessing) this._resetNodeEdit();
  195. var input = this.node.getFirst();
  196. if( !input && this.nodeHtml ){
  197. this.node.set("html", this.nodeHtml);
  198. input = this.node.getFirst();
  199. }
  200. input.set(this.json.properties);
  201. this.node.set({
  202. "id": this.json.id,
  203. "MWFType": this.json.type,
  204. "readonly": true,
  205. "events": {
  206. "click": this.clickSelect.bind(this)
  207. }
  208. });
  209. if ( this.hasIcon() ){
  210. this.iconNode = new Element("div", {
  211. "styles": this.form.css[this.iconStyle],
  212. "events": {
  213. "click": this.clickSelect.bind(this)
  214. }
  215. }).inject(this.node, "before");
  216. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  217. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  218. }
  219. this.node.getFirst().addEvent("change", function(){
  220. this.validationMode();
  221. if (this.validation()) {
  222. this._setBusinessData(this.getInputData("change"));
  223. this.fireEvent("change");
  224. }
  225. }.bind(this));
  226. //
  227. // var inputNode = this.node.getFirst();
  228. // if (inputNode) inputNode.addEvent("input", function(e){
  229. // var v=e.target.get("value");
  230. // this._setEnvironmentData(v);
  231. // }.bind(this));
  232. },
  233. _loadStyles: function(){
  234. if (this.json.styles) this.node.setStyles(this.json.styles);
  235. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  236. if (this.iconNode && this.iconNode.offsetParent !== null){
  237. var size = this.node.getSize();
  238. //if (!size.y){
  239. // var y1 = this.node.getStyle("height");
  240. // var y2 = this.node.getFirst().getStyle("height");
  241. // alert(y1+"," +y2);
  242. // var y = ((y1!="auto" && y1>y2) || y2=="auto") ? y1 : y2;
  243. // size.y = (y=="auto") ? "auto" : y.toInt();
  244. // //alert(size.y)
  245. //}
  246. this.iconNode.setStyle("height", ""+size.y+"px");
  247. //alert(this.iconNode.getStyle("height"))
  248. }
  249. },
  250. _computeValue: function(value){
  251. return (this.json.defaultValue && this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  252. },
  253. getValue: function(){
  254. if (this.moduleValueAG) return this.moduleValueAG;
  255. var value = this._getBusinessData();
  256. if (!value) value = this._computeValue();
  257. return value || "";
  258. },
  259. _setValue: function(value){
  260. // if (value && value.isAG){
  261. // var ag = o2.AG.all(value).then(function(v){
  262. // if (o2.typeOf(v)=="array") v = v[0];
  263. // this.__setValue(v);
  264. // }.bind(this));
  265. // this.moduleValueAG = ag;
  266. // ag.then(function(){
  267. // this.moduleValueAG = null;
  268. // }.bind(this));
  269. // }else {
  270. if (!!value && o2.typeOf(value.then)=="function"){
  271. var p = Promise.resolve(value).then(function(v){
  272. this.__setValue(v);
  273. }.bind(this), function(){});
  274. this.moduleValueAG = p;
  275. }else{
  276. this.moduleValueAG = null;
  277. this.__setValue(value);
  278. }
  279. //this.__setValue(value);
  280. // }
  281. },
  282. __setValue: function(value){
  283. this.moduleValueAG = null;
  284. this._setBusinessData(value);
  285. if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
  286. if (this.isReadonly()) this.node.set("text", value);
  287. this.moduleValueAG = null;
  288. this.fieldModuleLoaded = true;
  289. return value;
  290. },
  291. _loadValue: function(){
  292. this._setValue(this.getValue());
  293. },
  294. clickSelect: function(){
  295. },
  296. _afterLoaded: function(){
  297. // if (this.iconNode){
  298. //// var p = this.node.getPosition();
  299. //// var s = this.node.getSize();
  300. //// var is = this.iconNode.getSize();
  301. ////
  302. //// var y = p.y;
  303. //// var x = p.x+s.x-is.x;
  304. // this.iconNode.setStyles({
  305. // "top": "5px",
  306. // "left": "-18px"
  307. // });
  308. // }
  309. if (!this.isReadonly()){
  310. this.loadDescription();
  311. }
  312. },
  313. _beforeReloaded: function(){},
  314. _afterReloaded: function(){},
  315. /**
  316. * @summary 判断组件是否只读.
  317. * @example
  318. * var readonly = this.form.get('subject').isReadonly();
  319. * @return {Boolean} 是否只读.
  320. */
  321. isReadonly : function(){
  322. return !!(this.readonly || this.json.isReadonly || this.form.json.isReadonly || this.isSectionMergeRead());
  323. },
  324. getTextData: function(){
  325. //var value = this.node.get("value");
  326. //var text = this.node.get("text");
  327. var value = (this.node.getFirst()) ? this.node.getFirst().get("value") : this.node.get("text");
  328. var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
  329. return {"value": [value || ""] , "text": [text || value || ""]};
  330. },
  331. /**
  332. * @summary 判断组件值是否为空.
  333. * @example
  334. * if( this.form.get('subject').isEmpty() ){
  335. * this.form.notice('标题不能为空', 'warn');
  336. * }
  337. * @return {Boolean} 值是否为空.
  338. */
  339. isEmpty : function(){
  340. var data = this.getData();
  341. return !data || !data.trim();
  342. },
  343. /**
  344. * 在脚本中使用 this.data[fieldId] 也可以获取组件值。
  345. * 区别如下:<br/>
  346. * 1、当使用Promise的时候<br/>
  347. * 使用异步函数生成器(Promise)为组件赋值的时候,用getData方法立即获取数据,可能返回修改前的值,当Promise执行完成以后,会返回修改后的值。<br/>
  348. * this.data[fieldId] 立即获取数据,可能获取到异步函数生成器,当Promise执行完成以后,会返回修改后的值。<br/>
  349. * {@link https://www.yuque.com/o2oa/ixsnyt/ws07m0#EggIl|具体差异请查看链接}<br/>
  350. * 2、当表单上没有对应组件的时候,可以使用this.data[fieldId]获取值,但是this.form.get('fieldId')无法获取到组件。
  351. * @summary 获取组件值。
  352. * @example
  353. * var data = this.form.get('fieldId').getData(); //没有使用promise的情况、
  354. * @example
  355. * //如果无法确定表单上是否有组件,需要判断
  356. * var data;
  357. * if( this.form.get('fieldId') ){ //判断表单是否有无对应组件
  358. * data = this.form.get('fieldId').getData();
  359. * }else{
  360. * data = this.data['fieldId']; //直接从数据中获取字段值
  361. * }
  362. * @example
  363. * //使用Promise的情况
  364. * var field = this.form.get("fieldId");
  365. * var dict = new this.Dict("test"); //test为数据字典名称
  366. * var promise = dict.get("tools", true); //异步使用数据字典的get方法时返回Promise,参数true表示异步
  367. * promise.then( function(){
  368. * var data = field.getData(); //此时由于异步请求已经执行完毕,getData方法获取到了数据字典的值
  369. * })
  370. * field.setData( promise );
  371. * @return 组件的数据.
  372. */
  373. getData: function(when){
  374. if (this.json.compute == "save") this._setValue(this._computeValue());
  375. return this.getInputData();
  376. },
  377. getInputData: function(){
  378. if (this.node.getFirst()){
  379. return this.node.getFirst().get("value");
  380. }else{
  381. return this._getBusinessData();
  382. }
  383. },
  384. // /**
  385. // * @summary 重置组件的值为默认值或置空。
  386. // * @example
  387. // * this.form.get('subject').resetData();
  388. // */
  389. resetData: function(){
  390. this.setData(this.getValue());
  391. },
  392. /**当参数为Promise的时候,请参考文档: {@link https://www.yuque.com/o2oa/ixsnyt/ws07m0|使用Promise处理表单异步}<br/>
  393. * 当表单上没有对应组件的时候,可以使用this.data.add(fieldId, data, true) 赋值。
  394. * @summary 为组件赋值。
  395. * @param data{String|Promise} .
  396. * @param fireChange{boolean} 可选,是否触发change事件,默认false.
  397. * @example
  398. * this.form.get("fieldId").setData("test"); //赋文本值
  399. * @example
  400. * //如果无法确定表单上是否有组件,需要判断
  401. * if( this.form.get('fieldId') ){ //判断表单是否有无对应组件
  402. * this.form.get('fieldId').setData( data );
  403. * }else{
  404. * this.data.add(fieldId, data, true);
  405. * }
  406. * @example
  407. * //使用Promise
  408. * var field = this.form.get("fieldId");
  409. * var dict = new this.Dict("test"); //test为数据字典名称
  410. * var promise = dict.get("tools", true); //异步使用数据字典的get方法时返回Promise,参数true表示异步
  411. * field.setData( promise );
  412. */
  413. setData: function(data, fireChange){
  414. // if (data && data.isAG){
  415. // var ag = o2.AG.all(data).then(function(v){
  416. // if (o2.typeOf(v)=="array") v = v[0];
  417. // this.__setData(v);
  418. // }.bind(this));
  419. // this.moduleValueAG = ag;
  420. // ag.then(function(){
  421. // this.moduleValueAG = null;
  422. // }.bind(this));
  423. // }else{
  424. if (!!data && o2.typeOf(data.then)=="function"){
  425. var p = o2.promiseAll(data).then(function(v){
  426. this.__setData(v, fireChange);
  427. // if (this.node.getFirst() && !this.readonly && !this.json.isReadonly) {
  428. // this.checkDescription();
  429. // this.validationMode();
  430. // }
  431. }.bind(this), function(){});
  432. this.moduleValueAG = p;
  433. p.then(function(){
  434. this.moduleValueAG = null;
  435. }.bind(this), function(){
  436. this.moduleValueAG = null;
  437. }.bind(this));
  438. }else{
  439. this.moduleValueAG = null;
  440. this.__setData(data, fireChange);
  441. // if (this.node.getFirst() && !this.readonly && !this.json.isReadonly) {
  442. // this.checkDescription();
  443. // this.validationMode();
  444. // }
  445. }
  446. //this.__setData(data);
  447. //}
  448. },
  449. __setData: function(data, fireChange){
  450. var old = this.getInputData();
  451. this._setBusinessData(data);
  452. if (this.node.getFirst()){
  453. this.node.getFirst().set("value", data);
  454. this.checkDescription();
  455. this.validationMode();
  456. }else{
  457. this.node.set("text", data);
  458. }
  459. if (fireChange && old!==data) this.fireEvent("change");
  460. this.moduleValueAG = null;
  461. },
  462. createErrorNode: function(text){
  463. //var size = this.node.getFirst().getSize();
  464. //var w = size.x-3;
  465. //if (COMMON.Browser.safari) w = w-20;
  466. //node.setStyles({
  467. // "width": ""+w+"px",
  468. // "height": ""+size.y+"px",
  469. // "line-height": ""+size.y+"px",
  470. // "position": "absolute",
  471. // "top": "0px"
  472. //});
  473. var node;
  474. if( this.form.json.errorStyle ){
  475. if( this.form.json.errorStyle.type === "notice" ){
  476. if( !this.form.errorNoticing ){ //如果是弹出
  477. this.form.errorNoticing = true;
  478. this.form.notice(text, "error", this.node, null, null, {
  479. onClose : function () {
  480. this.form.errorNoticing = false;
  481. }.bind(this)
  482. });
  483. }
  484. }else{
  485. node = new Element("div",{
  486. "styles" : this.form.json.errorStyle.node,
  487. "text": text
  488. });
  489. if( this.form.json.errorStyle.close ){
  490. var closeNode = new Element("div",{
  491. "styles" : this.form.json.errorStyle.close ,
  492. "events": {
  493. "click" : function(){
  494. //this.destroy();
  495. this.validationMode();
  496. }.bind(this)
  497. }
  498. }).inject(node);
  499. }
  500. }
  501. }else{
  502. node = new Element("div");
  503. var iconNode = new Element("div", {
  504. "styles": {
  505. "width": "20px",
  506. "height": "20px",
  507. "float": "left",
  508. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  509. }
  510. }).inject(node);
  511. var textNode = new Element("div", {
  512. "styles": {
  513. "height": "20px",
  514. "line-height": "20px",
  515. "margin-left": "20px",
  516. "color": "red",
  517. "word-break": "keep-all"
  518. },
  519. "text": text
  520. }).inject(node);
  521. }
  522. return node;
  523. },
  524. notValidationMode: function(text){
  525. if (!this.isNotValidationMode){
  526. this.isNotValidationMode = true;
  527. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  528. this.node.setStyle("border-color", "red");
  529. this.errNode = this.createErrorNode(text);
  530. //if (this.iconNode){
  531. // this.errNode.inject(this.iconNode, "after");
  532. //}else{
  533. this.errNode.inject(this.node, "after");
  534. //}
  535. this.showNotValidationMode(this.node);
  536. var parentNode = this.errNode;
  537. while( parentNode && parentNode.offsetParent === null ){
  538. parentNode = parentNode.getParent();
  539. }
  540. if ( parentNode && !parentNode.isIntoView()) parentNode.scrollIntoView(false);
  541. }
  542. },
  543. showNotValidationMode: function(node){
  544. var p = node.getParent("div");
  545. if (p){
  546. var mwftype = p.get("MWFtype") || p.get("mwftype");
  547. if (mwftype == "tab$Content"){
  548. if (p.getParent("div").getStyle("display")=="none"){
  549. var contentAreaNode = p.getParent("div").getParent("div");
  550. var tabAreaNode = contentAreaNode.getPrevious("div");
  551. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  552. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  553. tabNode.click();
  554. p = tabAreaNode.getParent("div");
  555. }
  556. }
  557. this.showNotValidationMode(p);
  558. }
  559. },
  560. validationMode: function(){
  561. if (this.isNotValidationMode){
  562. this.isNotValidationMode = false;
  563. this.node.setStyles(this.node.retrieve("borderStyle"));
  564. if (this.errNode){
  565. this.errNode.destroy();
  566. this.errNode = null;
  567. }
  568. }
  569. },
  570. validationConfigItem: function(routeName, data){
  571. var flag = (data.status==="all") ? true: (routeName === data.decision);
  572. if (flag){
  573. var n = this.getInputData();
  574. var v = (data.valueType==="value") ? n : n.length;
  575. switch (data.operateor){
  576. case "isnull":
  577. if (!v){
  578. this.notValidationMode(data.prompt);
  579. return false;
  580. }
  581. break;
  582. case "notnull":
  583. if (v){
  584. this.notValidationMode(data.prompt);
  585. return false;
  586. }
  587. break;
  588. case "gt":
  589. if (v>data.value){
  590. this.notValidationMode(data.prompt);
  591. return false;
  592. }
  593. break;
  594. case "lt":
  595. if (v<data.value){
  596. this.notValidationMode(data.prompt);
  597. return false;
  598. }
  599. break;
  600. case "equal":
  601. if (v==data.value){
  602. this.notValidationMode(data.prompt);
  603. return false;
  604. }
  605. break;
  606. case "neq":
  607. if (v!=data.value){
  608. this.notValidationMode(data.prompt);
  609. return false;
  610. }
  611. break;
  612. case "contain":
  613. if (v.indexOf(data.value)!=-1){
  614. this.notValidationMode(data.prompt);
  615. return false;
  616. }
  617. break;
  618. case "notcontain":
  619. if (v.indexOf(data.value)==-1){
  620. this.notValidationMode(data.prompt);
  621. return false;
  622. }
  623. break;
  624. }
  625. }
  626. return true;
  627. },
  628. validationConfig: function(routeName, opinion){
  629. if (this.json.validationConfig){
  630. if (this.json.validationConfig.length){
  631. for (var i=0; i<this.json.validationConfig.length; i++) {
  632. var data = this.json.validationConfig[i];
  633. if (!this.validationConfigItem(routeName, data)) return false;
  634. }
  635. }
  636. return true;
  637. }
  638. return true;
  639. },
  640. getExcelData: function(){
  641. return this.getData();
  642. },
  643. setExcelData: function(data){
  644. if( typeOf(data) === "string" )data = data.replace(/&#10;/g,""); //excel字段换行是 &#10
  645. this.excelData = data;
  646. this.setData(data, true);
  647. },
  648. stringToArray: function(string){ //excel字段换行是 &#10;,换行和逗号作为数组分隔符
  649. return string.replace(/&#10;/g,",").split(/\s*,\s*/g ).filter(function(s){
  650. return !!s;
  651. });
  652. },
  653. validationExcel: function () {
  654. if (!this.isReadonly()){
  655. var errorList = this.validationConfigExcel();
  656. if (errorList.length) return errorList;
  657. if (!this.json.validation) return [];
  658. if (!this.json.validation.code) return [];
  659. var flag = this.form.Macro.exec(this.json.validation.code, this);
  660. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  661. if (flag.toString() !== "true") {
  662. return [flag];
  663. }
  664. }
  665. return [];
  666. },
  667. validationConfigExcel: function () {
  668. var errorList = [];
  669. if (this.json.validationConfig){
  670. if (this.json.validationConfig.length){
  671. for (var i=0; i<this.json.validationConfig.length; i++) {
  672. var flag = this.validationConfigItemExcel(this.json.validationConfig[i]);
  673. if ( flag !== true ){
  674. errorList.push( flag );
  675. }
  676. }
  677. }
  678. }
  679. return errorList;
  680. },
  681. validationConfigItemExcel: function(data){
  682. if ( data.status==="all"){
  683. var n = this._getBusinessData();
  684. var ed = typeOf( this.excelData ) === "null" ? "" : this.excelData;
  685. var v, ev;
  686. if(data.valueType==="value"){
  687. v = n;
  688. ev = ed;
  689. }else{
  690. v = n.length;
  691. ev = ed.length || 0;
  692. }
  693. switch (data.operateor){
  694. case "isnull":
  695. if (!v){
  696. return !ev ? data.prompt : "不在选项中";
  697. }
  698. break;
  699. case "notnull":
  700. if (v)return data.prompt;
  701. break;
  702. case "gt":
  703. if (v>data.value)return data.prompt;
  704. break;
  705. case "lt":
  706. if (v<data.value)return data.prompt;
  707. break;
  708. case "equal":
  709. if (v===data.value)return data.prompt;
  710. break;
  711. case "neq":
  712. if (v!==data.value)return data.prompt;
  713. break;
  714. case "contain":
  715. if (v.indexOf(data.value)!==-1) return data.prompt;
  716. break;
  717. case "notcontain":
  718. if (v.indexOf(data.value)===-1)return data.prompt;
  719. break;
  720. }
  721. }
  722. return true;
  723. }
  724. });