$Input.js 27 KB

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