ligerEx.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. /**
  2. * ligerUI 扩展组件
  3. */
  4. (function ($, win) {
  5. /******************** 条件选取控件 ***********************/
  6. //add by hzp at 20160223
  7. $.fn.ligerCondition = function ()
  8. {
  9. return $.ligerui.run.call(this, "ligerCondition", arguments);
  10. };
  11. $.ligerDefaults.Condition = {
  12. nameField:"code",
  13. textField:"text",
  14. typeField:"type",
  15. dictField:"dict",
  16. disabled: false,
  17. readonly: false,
  18. andOrData:[{code:" AND ",value:"并且"},{code:" OR ",value:"或者"}],
  19. stringTypeData:[{code:" = ",value:"等于"},{code:" LIKE ",value:"模糊匹配"},{code:" IN ",value:"包含"},{code:" NOT IN ",value:"不包含"}],
  20. numberTypeData:[{code:" = ",value:"等于"},{code:" <> ",value:"不等于"},{code:" > ",value:"大于"},{code:" >= ",value:"大于等于"},{code:" < ",value:"小于"},{code:" <= ",value:"小于等于"}],
  21. dateTypeData:[{code:" = ",value:"等于"},{code:" <> ",value:"不等于"},{code:" > ",value:"大于"},{code:" >= ",value:"大于等于"},{code:" < ",value:"小于"},{code:" <= ",value:"小于等于"}],
  22. fields:[], //条件字段
  23. value:'',
  24. stdDictUrl:'', //字典数据
  25. stdDictVersion:'',//字典版本号
  26. isMoveLeft:true,//默认第二条件开始左移
  27. index:0,
  28. andOrControlFlag:"and_or",
  29. fieldControlFlag:"field",
  30. conditionControlFlag:"condition",
  31. valueControlFlag:"value"
  32. };
  33. $.ligerMethos.Condition = {};
  34. $.ligerui.controls.Condition = function (element, options)
  35. {
  36. $.ligerui.controls.Condition.base.constructor.call(this, element, options);
  37. };
  38. $.ligerui.controls.Condition.ligerExtend($.ligerui.controls.Input,
  39. {
  40. _getType: function ()
  41. {
  42. return 'Condition';
  43. },
  44. _extendMethods: function ()
  45. {
  46. return $.ligerMethos.Condition;
  47. },
  48. _init: function () {
  49. $.ligerui.controls.Condition.base._init.call(this);
  50. },
  51. _render: function ()
  52. {
  53. var me = this, p = this.options;
  54. me.inputValue = null;
  55. me.inputControl = null;
  56. me.value = null;
  57. me.textFieldID = "";
  58. if (this.element.tagName.toLowerCase() == "input" && this.element.type)
  59. {
  60. if(this.element.type == "text")
  61. {
  62. $(this.element).attr("type","hidden");
  63. }
  64. me.inputValue = $(this.element);
  65. if (this.element.id)
  66. me.textFieldID = this.element.id;
  67. }
  68. if (me.textFieldID == "" && p.textFieldID)
  69. me.textFieldID = p.textFieldID;
  70. me.addButton = $('<div class="l-button l-button-green" style="clear:both;margin-left:0px;" id="'+me.textFieldID+'_add_btn"><span>添加条件</span></div>');
  71. me.content = $("<div id='"+me.textFieldID+"_content' class='m-form-condition'></div>");
  72. me.inputValue.after(me.addButton).after(me.content);
  73. /*if (p.disabled)
  74. {
  75. me.inputValue.parent().addClass("l-text-disabled");
  76. }*/
  77. //初始化值
  78. me.addButton.click(function () {
  79. me.newItem();
  80. });
  81. if(p.value!=undefined && p.value.length >0)
  82. {
  83. me.setValue(p.value);
  84. }
  85. else{
  86. me.newItem();
  87. }
  88. },
  89. //设置字段
  90. setFields:function(fields){
  91. var me =this;
  92. var option = me.options;
  93. option.fields = fields;
  94. me.setValue("");
  95. },
  96. //设置字典参数
  97. setDictParms:function(parms){
  98. var me =this;
  99. var option = me.options;
  100. option.stdDictParms = parms;
  101. },
  102. //赋值
  103. setValue:function(data){
  104. try{
  105. var me = this;
  106. me.content.find("div.m-form-group").remove();
  107. if(data!=null && data.length>0 && data!="[]")
  108. {
  109. //判断是否字符串
  110. if(typeof(data)=="string")
  111. {
  112. data = eval(data);
  113. }
  114. for(var i=0;i<data.length;i++)
  115. {
  116. me.newItem(data[i].andOr,data[i].field,data[i].condition,data[i].value);
  117. }
  118. }
  119. else{
  120. me.newItem();
  121. }
  122. }
  123. catch(e)
  124. {
  125. }
  126. },
  127. //取值
  128. getValue:function(){
  129. var me = this;
  130. var option = me.options;
  131. var re = '';
  132. $.each(me.content.find("div.m-form-group"),function(index,item){
  133. var o = '{';
  134. var groupId = this.id;
  135. var andOrControlId = groupId+"_"+option.andOrControlFlag;
  136. var fieldControlId = groupId+"_"+option.fieldControlFlag;
  137. var conditionControlId =groupId+"_"+option.conditionControlFlag;
  138. var valueControlId =groupId+"_"+option.valueControlFlag;
  139. var andOr = " AND ";
  140. if(index!=0) {
  141. andOr = $("#"+andOrControlId).ligerComboBox("getValue");
  142. }
  143. var field = $("#"+fieldControlId).ligerComboBox("getValue");
  144. var condition = $("#"+conditionControlId).ligerComboBox("getValue");
  145. debugger
  146. var value = $("#"+valueControlId).val();
  147. var type = $("#"+valueControlId+"_div").attr("controlType");
  148. var selFieldData = $("#"+fieldControlId).ligerComboBox("getSelected");
  149. var fieldType = "";
  150. if(type == "combobox")
  151. {
  152. value = $("#"+valueControlId).ligerComboBox("getValue");
  153. }
  154. else if(type == "mult_combobox" || type =="mult_textbox"){
  155. value = $("#"+valueControlId).ligerMultbox("getValue");
  156. }
  157. if(selFieldData && selFieldData.type){
  158. fieldType = selFieldData.type;
  159. }
  160. if(andOr.length>0 && field.length>0 && condition.length>0 && value.length>0)
  161. {
  162. o+='andOr:"'+andOr+'",';
  163. o+='field:"'+field+'",';
  164. o+='type:"' + fieldType + '",';
  165. o+='condition:"'+condition+'",';
  166. o+='value:"'+value+'"';
  167. o+='}';
  168. if(re.length>0)
  169. {
  170. re += ","+o;
  171. }
  172. else{
  173. re = o;
  174. }
  175. }
  176. });
  177. return '['+re+']';
  178. },
  179. //创建元素
  180. newItem:function(andOr,field,condition,value){
  181. var me = this;
  182. var option = me.options;
  183. var index = option.index;
  184. var groupId = me.textFieldID+"_"+index;
  185. var andOrControlId = groupId+"_"+option.andOrControlFlag;
  186. var fieldControlId = groupId+"_"+option.fieldControlFlag;
  187. var conditionControlId =groupId+"_"+option.conditionControlFlag;
  188. var valueControlId = groupId+"_"+option.valueControlFlag;
  189. var html = '<div class="m-form-group" id="'+groupId+'">';
  190. if(me.content.find("div.m-form-group").length >0)
  191. {
  192. if(option.isMoveLeft)
  193. {
  194. html = '<div class="m-form-group m-form-move-left" id="'+groupId+'">';
  195. }
  196. html += '<div class="m-form-control"><input type="text" id="'+andOrControlId+'" data-type="select"/></div>';
  197. }
  198. html += '<div class="m-form-control"><input type="text" id="'+fieldControlId+'" data-type="select"/></div>';
  199. html += '<div class="m-form-control"><input type="text" id="'+conditionControlId+'" data-type="select"/></div>';
  200. html += '<div class="m-form-control" controlType="textbox" id="'+valueControlId+'_div" style="margin-left:0px;"><input type="text" id="'+valueControlId+'" class="l-textbox"/></div>';
  201. if(index >0)
  202. {
  203. html += '<div class="m-form-control"><a class="m-btn-cancle" href="javascrip:void()" style="display:block;" onclick="$(\'#'+groupId+'\').remove()"></a></div>';
  204. }
  205. html += '</div>';
  206. me.content.append(html);
  207. if(index!=0)
  208. {
  209. $("#"+andOrControlId).ligerComboBox({width:65,data:option.andOrData,value:"and"});
  210. }
  211. $("#"+fieldControlId).ligerComboBox({width:100,data:option.fields,textField:"text",extendField:"type",
  212. onSelected:function(value,text,row){
  213. //改变条件控件
  214. if(row.type=="NUMERIC"||row.type=="FLOAT")
  215. {
  216. $("#"+conditionControlId).ligerComboBox("setData",option.numberTypeData)
  217. }
  218. else if(row.type=="DATE"){
  219. $("#"+conditionControlId).ligerComboBox("setData",option.dateTypeData)
  220. }
  221. else{
  222. $("#"+conditionControlId).ligerComboBox("setData",option.stringTypeData)
  223. }
  224. $("#"+conditionControlId).ligerComboBox("setValue"," = ");
  225. }
  226. });
  227. $("#"+conditionControlId).ligerComboBox({width:80});
  228. if(andOr!=undefined)
  229. {
  230. $("#"+andOrControlId).ligerComboBox("setValue",andOr);
  231. }
  232. if(field!=undefined)
  233. {
  234. $("#"+fieldControlId).ligerComboBox("setValue",field);
  235. }
  236. if(condition!=undefined)
  237. {
  238. $("#"+conditionControlId).ligerComboBox("setValue",condition);
  239. }
  240. if(value!=undefined)
  241. {
  242. me.changeValueType(index,value);
  243. //$("#"+conditionControlId).ligerComboBox("setValue",condition);
  244. }
  245. //绑定事件
  246. $("#"+conditionControlId).ligerComboBox({
  247. onSelected:function(value,text){
  248. //改变值控件
  249. me.changeValueType(index);
  250. }
  251. });
  252. option.index = index+1;
  253. },
  254. //改变值控件类型
  255. changeValueType:function(index,value){
  256. try{
  257. var me = this;
  258. var option = me.options;
  259. var groupId = me.textFieldID+"_"+index;
  260. var fieldControlId = groupId+"_"+option.fieldControlFlag;
  261. var conditionControlId = groupId+"_"+option.conditionControlFlag;
  262. var field = $("#"+fieldControlId).ligerComboBox("getSelected");
  263. var condition = $("#"+conditionControlId).ligerComboBox("getValue");
  264. if(field==null || condition==null)
  265. {
  266. return;
  267. }
  268. var dict =field.dict;
  269. var dataType = field.type;
  270. var type="textbox";
  271. if(dataType == "NUMERIC")//数值
  272. {
  273. type = "numberbox";
  274. }
  275. else if(dataType == "DATE") //时间
  276. {
  277. type = "datebox";
  278. }
  279. else{
  280. if(dict!=null && dict!="0")//字典控件
  281. {
  282. if(condition == " IN " || condition == " NOT IN ")
  283. {
  284. type = "mult_combobox";
  285. }
  286. else{
  287. type = "combobox";
  288. }
  289. }
  290. else{
  291. if(condition == " IN " || condition == " NOT IN ")
  292. {
  293. type = "mult_textbox";
  294. }
  295. }
  296. }
  297. me.createValueControl(index,type,dict,value);
  298. }
  299. catch(e)
  300. {
  301. return;
  302. }
  303. },
  304. //创建值控件
  305. createValueControl:function(index,type,dict,value){
  306. var me = this;
  307. var option = me.options;
  308. var groupId = me.textFieldID+"_"+index;
  309. var valueControlId = groupId+"_"+option.valueControlFlag;
  310. var valueDiv =$("#"+groupId+"_"+option.valueControlFlag+"_div");
  311. var oldType = valueDiv.attr("controlType");
  312. if(oldType != type || value!=undefined)
  313. {
  314. if(value==undefined) value = "";
  315. valueDiv.attr("controlType",type)
  316. if(type=="combobox") //字典
  317. {
  318. valueDiv.html('<input type="text" id="'+valueControlId+'" data-type="select"/>');
  319. var parms = {dictId:dict};
  320. $.extend(parms,option.stdDictParms);
  321. $("#"+valueControlId).ligerComboBox({width:200,url:option.stdDictUrl,urlParms:parms,value:value});
  322. }
  323. else if(type=="datebox") //时间
  324. {
  325. valueDiv.html('<input type="text" id="'+valueControlId+'" />');
  326. $("#"+valueControlId).ligerDateEditor({width:200,value:value});
  327. }
  328. else if(type=="numberbox") //数值
  329. {
  330. valueDiv.html('<input type="text" id="'+valueControlId+'" />');
  331. $("#"+valueControlId).ligerTextBox({width: 200,digits:true,value:value});
  332. }
  333. else if(type=="mult_combobox") //多选字典
  334. {
  335. valueDiv.html('<input type="text" id="'+valueControlId+'" />');
  336. var parms = {dictId:dict};
  337. $.extend(parms,option.stdDictParms);
  338. $("#"+valueControlId).ligerMultbox({width:200,stdDictUrl:option.stdDictUrl,urlParms:parms,value:value});
  339. }
  340. else if(type=="mult_textbox") //多项文本
  341. {
  342. valueDiv.html('<input type="text" id="'+valueControlId+'" />');
  343. $("#"+valueControlId).ligerMultbox({width:200,value:value});
  344. }
  345. else //文本框
  346. {
  347. valueDiv.html('<input type="text" id="'+valueControlId+'" class="l-textbox" value="'+value+'"/>');
  348. }
  349. }
  350. }
  351. });
  352. /******************* 搜索控件 *************************************/
  353. //add by hzp at 20160223
  354. $.fn.ligerSearch = function ()
  355. {
  356. return $.ligerui.run.call(this, "ligerSearch", arguments);
  357. };
  358. $.ligerDefaults.Search = {
  359. onChange: null, //改变值事件
  360. onClick: null, //搜索按钮事件
  361. disabled: false,
  362. readonly: false //是否只读
  363. };
  364. $.ligerMethos.Search = {};
  365. $.ligerui.controls.Search = function (element, options)
  366. {
  367. $.ligerui.controls.Search.base.constructor.call(this, element, options);
  368. };
  369. $.ligerui.controls.Search.ligerExtend($.ligerui.controls.Input, {
  370. __getType: function ()
  371. {
  372. return 'Search';
  373. },
  374. _extendMethods: function ()
  375. {
  376. return $.ligerMethos.Search;
  377. },
  378. _init: function () {
  379. $.ligerui.controls.Search.base._init.call(this);
  380. },
  381. _render: function ()
  382. {
  383. var g = this, p = this.options;
  384. g.inputText = null;
  385. g.value = null;
  386. g.textFieldID = "";
  387. if (this.element.tagName.toLowerCase() == "input" && this.element.type && this.element.type == "text")
  388. {
  389. g.inputText = $(this.element);
  390. if (this.element.id)
  391. g.textFieldID = this.element.id;
  392. }
  393. else
  394. {
  395. g.inputText = $('<input type="text"/>');
  396. g.inputText.appendTo($(this.element));
  397. }
  398. if (g.textFieldID == "" && p.textFieldID)
  399. g.textFieldID = p.textFieldID;
  400. g.searchBtn = $('<div class="l-trigger l-trigger-search"><div class="l-trigger-icon"></div></div>');
  401. g.wrapper = g.inputText.wrap('<div class="l-text"></div>').parent();
  402. g.wrapper.append(g.searchBtn);
  403. g.inputText.addClass("l-text-field");
  404. //设置宽度
  405. if(p.width)
  406. {
  407. g.wrapper.width(p.width);
  408. g.inputText.width(p.width-12);
  409. }
  410. if (p.disabled)
  411. {
  412. g.wrapper.addClass("l-text-disabled");
  413. }
  414. //初始化
  415. if (g.value!=null)
  416. {
  417. g.setValue(g.value);
  418. }
  419. //点击事件
  420. if(!p.disabled && p.onClick!=null && typeof(p.onClick)=="function")
  421. {
  422. g.searchBtn.click(function(){
  423. p.onClick(g.getValue());
  424. });
  425. }
  426. //值改变事件
  427. if(!p.disabled && p.onChange!=null && typeof(p.onChange)=="function")
  428. {
  429. g.inputText.change(function () {
  430. p.onChange(g.getValue());
  431. });
  432. }
  433. g.inputText.blur(function ()
  434. {
  435. if (!p.disabled)
  436. g.wrapper.removeClass("l-text-focus");
  437. }).focus(function ()
  438. {
  439. if (!p.disabled)
  440. g.wrapper.addClass("l-text-focus");
  441. });
  442. g.wrapper.hover(function ()
  443. {
  444. if (!p.disabled)
  445. g.wrapper.addClass("l-text-over");
  446. }, function ()
  447. {
  448. g.wrapper.removeClass("l-text-over");
  449. });
  450. },
  451. setValue: function (value)
  452. {
  453. var g = this, p = this.options;
  454. if (!value || value == "NaN") value = "";
  455. this.inputText.val(value)
  456. },
  457. getValue:function()
  458. {
  459. return this.inputText.val();
  460. }
  461. });
  462. /******************* 多选控件 *************************************/
  463. //add by hzp at 20160223
  464. $.fn.ligerMultbox = function ()
  465. {
  466. return $.ligerui.run.call(this, "ligerMultbox", arguments);
  467. };
  468. $.ligerDefaults.Multbox = {
  469. disabled: false,
  470. readonly: false, //是否只读
  471. boxType:"text",
  472. gridOptions: {
  473. },
  474. valueField: 'CustomerID',
  475. textField: 'CustomerID'
  476. };
  477. $.ligerMethos.Multbox = {};
  478. $.ligerui.controls.Multbox = function (element, options)
  479. {
  480. $.ligerui.controls.Multbox.base.constructor.call(this, element, options);
  481. };
  482. $.ligerui.controls.Multbox.ligerExtend($.ligerui.controls.Input, {
  483. __getType: function ()
  484. {
  485. return 'Multbox';
  486. },
  487. _extendMethods: function ()
  488. {
  489. return $.ligerMethos.Multbox;
  490. },
  491. _init: function () {
  492. $.ligerui.controls.Multbox.base._init.call(this);
  493. },
  494. _render: function ()
  495. {
  496. var g = this, p = this.options;
  497. g.inputValue = null;
  498. g.inputControl = null;
  499. g.value = null;
  500. g.textFieldID = "";
  501. if (this.element.tagName.toLowerCase() == "input" && this.element.type)
  502. {
  503. if(this.element.type == "text")
  504. {
  505. $(this.element).attr("type","hidden");
  506. }
  507. g.inputValue = $(this.element);
  508. if (this.element.id)
  509. g.textFieldID = this.element.id;
  510. }
  511. if (g.textFieldID == "" && p.textFieldID)
  512. g.textFieldID = p.textFieldID;
  513. g.addBtn = $('<div class="m-form-mult-add"></div>');
  514. g.addBtnWrapper = g.addBtn.wrap('<div class="m-form-mult-add-panel"></div>').parent();
  515. g.addBtnWrapper.append('<div class="m-form-mult-control-panel"><input type="text" id="'+g.textFieldID+'_control" class="l-textbox" style="float:left;width:135px;margin-top:5px;margin-left:5px;"/><a href="javascript:void(0);" id="'+g.textFieldID+'_control_cancle" class="m-btn-cancle" style="float: right"></a><a href="javascript:void(0);" id="'+g.textFieldID+'_control_ok" class="m-btn-ok" style="float: right"></a></div>');
  516. g.wrapper = g.inputValue.wrap('<div class="m-form-mult"></div>').parent();
  517. g.wrapper.append('<div class="m-form-mult-blank"></div><div class="m-form-mult-content" id="'+g.textFieldID+'_content"></div>').after(g.addBtnWrapper);
  518. g.inputControl = $("#"+g.textFieldID+"_control");
  519. g.content = $("#"+g.textFieldID+"_content");
  520. g.wrapper.wrap('<div style="position: relative"></div>');
  521. //字典控件
  522. if(p.stdDictUrl!=null)
  523. {
  524. p.boxType = "combo";
  525. /*g.inputControl.ligerComboBox({width:135,url:p.stdDictUrl,urlParms:p.urlParms});
  526. if(g.inputControl[0].type == "text")
  527. {
  528. $(g.inputControl).attr("type","hidden");
  529. }*/
  530. }
  531. g.setWidth();
  532. //初始化
  533. if (p.value!=null)
  534. {
  535. g.setValue(p.value);
  536. }
  537. //禁用
  538. if (p.disabled)
  539. {
  540. g.wrapper.addClass("l-text-disabled");
  541. //按钮失效
  542. return;
  543. }
  544. //添加按钮
  545. g.addBtn.click(function(){
  546. if(p.boxType != "text")
  547. {
  548. //弹窗多选字典数据
  549. var val = g.getValue();
  550. g.selectDialog(val,function(val,text){
  551. g.setValue(val,text);
  552. });
  553. }
  554. else
  555. {
  556. g.inputControl.val('');
  557. $(this).next().show();
  558. }
  559. })
  560. //添加确认按钮
  561. $("#"+g.textFieldID+"_control_ok").click(function(){
  562. var val = g.inputControl.val();
  563. var text = g.inputControl.val();
  564. if(val!=null && val.length>0)
  565. {
  566. if(g.inputControl.prev().hasClass('l-text-combobox')){
  567. text = g.inputControl.ligerComboBox("getText");
  568. }
  569. if(val.indexOf(',')>=0)
  570. {
  571. $.ligerDialog.error("不能包含特殊字符!");
  572. return;
  573. }
  574. g.newItem(val,text);
  575. $(this).parent().hide();
  576. }
  577. });
  578. //添加取消按钮
  579. $("#"+g.textFieldID+"_control_cancle").click(function(){
  580. $(this).parent().hide();
  581. });
  582. },
  583. newItem:function(val,text){
  584. var me = this;
  585. var b = true;
  586. $.each(me.content.find("div"),function(index,item){
  587. var value = $(item).attr("value");
  588. if(value == val)
  589. {
  590. b=false;
  591. return;
  592. }
  593. });
  594. if(b)
  595. {
  596. me.content.append('<div value="'+val+'">'+text+'<a href="javascript:void(0);" onclick="$(this).parent().remove()"></a></div>');
  597. }
  598. },
  599. setWidth:function(){
  600. var me = this;
  601. var option = me.options;
  602. if(option.width!=null)
  603. {
  604. me.wrapper.css({width:option.width});
  605. me.content.css({width:option.width-5});
  606. me.addBtnWrapper.css({width:option.width});
  607. }
  608. },
  609. setValue: function (val,text)
  610. {
  611. var me = this, option = me.options;
  612. if (!val || val == "NaN") val = "";
  613. me.content.find("div").remove();
  614. if(text!=undefined&&text.length>0)
  615. {
  616. var arr = val.split(',');
  617. var arrText = text.split(',');
  618. if(arr.length == arrText.length)
  619. {
  620. for(var i=0;i<arr.length;i++)
  621. {
  622. me.newItem(arr[i],arrText[i]);
  623. }
  624. }
  625. }
  626. else{
  627. if(val.length>0)
  628. {
  629. var arr = val.split(',');
  630. if(option.boxType!="text")
  631. {
  632. $.ajax({ //获取表的字段列表
  633. type: "POST",
  634. url : option.stdDictUrl,
  635. dataType : "json",
  636. data:option.urlParms,
  637. cache:false,
  638. success :function(data){
  639. if(data.successFlg) {
  640. if(data.detailModelList!=null && data.detailModelList.length>0)
  641. {
  642. for(var i=0;i<arr.length;i++)
  643. {
  644. for(var j=0;j<data.detailModelList.length;j++)
  645. {
  646. var code = data.detailModelList[j].code;
  647. if(code==arr[i])
  648. {
  649. me.newItem(code,data.detailModelList[j].value);
  650. break;
  651. }
  652. }
  653. }
  654. }
  655. }
  656. else{
  657. $.ligerDialog.error(data.message);
  658. }
  659. },
  660. error :function(data){
  661. $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
  662. }
  663. });
  664. }
  665. else{
  666. for(var i=0;i<arr.length;i++)
  667. {
  668. me.newItem(arr[i],arr[i]);
  669. }
  670. }
  671. }
  672. }
  673. me.inputValue.val(val);
  674. },
  675. getValue:function()
  676. {
  677. var me = this;
  678. var val = "";
  679. $.each(me.content.find("div"),function(index,item){
  680. var value = $(item).attr("value");
  681. if(val.length==0)
  682. {
  683. val = value;
  684. }
  685. else{
  686. val += ","+value;
  687. }
  688. });
  689. me.inputValue.val(val);
  690. return val;
  691. },
  692. //弹窗选取字典
  693. selectDialog:function(val,fun){
  694. var me = this;
  695. var option = me.options;
  696. if(option.stdDictUrl!=null)
  697. {
  698. me.popupFn = $.ligerui.getPopupFn({
  699. width:550,
  700. /*condition: {
  701. autoEditors:true,
  702. fields: [{ display: "名称", name: "value", type: 'text' }]
  703. },*/
  704. grid: {
  705. columns: [
  706. { display: '代码', name: 'code' },
  707. { display: '名称', name: 'value' },
  708. { display: '属性', name: 'extend' }
  709. ],
  710. switchPageSizeApplyComboBox: false,
  711. url: option.stdDictUrl,
  712. parms:option.urlParms,
  713. pageSize: 50,
  714. checkbox: true
  715. },
  716. valueField: 'code',
  717. textField: 'value',
  718. split: ',',
  719. onSelect: function (e)
  720. {
  721. fun(e.value,e.text);
  722. me.trigger('selected', e);
  723. },
  724. selectInit: function (rowdata)
  725. {
  726. var re =false;
  727. if(val!=undefined&&val.length>0)
  728. {
  729. var arr = val.split(',');
  730. for(var i=0;i<arr.length;i++)
  731. {
  732. if(arr[i]==rowdata.code)
  733. {
  734. re = true;
  735. break;
  736. }
  737. }
  738. }
  739. return re;
  740. }
  741. });
  742. me.popupFn();
  743. }
  744. }
  745. });
  746. /***************** 表单控件 **********************************/
  747. //add by hzp at 20160312
  748. $.fn.ligerAutoForm = function ()
  749. {
  750. return $.ligerui.run.call(this, "ligerAutoForm", arguments);
  751. };
  752. $.ligerDefaults.AutoForm = {
  753. data:null,
  754. readonly: false, //是否只读
  755. validate:null, //校验
  756. message:null //校验提示
  757. };
  758. $.ligerMethos.AutoForm = {
  759. showError:function(control,error){
  760. var dom = $(control).closest(".m-form-control");
  761. if(dom.hasClass('m-from-error'))
  762. {
  763. dom.removeClass('m-from-error').find('.m-from-error-msg').remove();
  764. }
  765. var el = $('<div class="m-from-error-msg"></div>');
  766. dom.addClass('m-from-error').append(el);
  767. el.hover(function ()
  768. {
  769. $(this).ligerTip({content:error});
  770. },function (){
  771. $(this).ligerHideTip();
  772. });
  773. }
  774. };
  775. $.ligerui.controls.AutoForm = function (element, options)
  776. {
  777. $.ligerui.controls.AutoForm.base.constructor.call(this, element, options);
  778. };
  779. $.ligerui.controls.AutoForm.ligerExtend($.ligerui.core.UIComponent, {
  780. controls:[], //表单控件
  781. defaultMessage:{
  782. required: "必填项",
  783. email: "请输入有效的电子邮件地址",
  784. ip: "请输入有效的ip地址",
  785. date: "请输入有效的日期",
  786. dateISO: "请输入有效的日期 (YYYY-MM-DD)",
  787. number: "请输入有效的数字",
  788. digits: "只能输入数字",
  789. equalTo: "你的输入不相同",
  790. extension: "请输入有效的后缀",
  791. maxlength: "最多可以输入{0}个字符",
  792. minlength: "最少要输入{0}个字符",
  793. max: "请输入不大于{0}的数值",
  794. min: "请输入不小于{0}的数值",
  795. custom:"自定义函数出错",
  796. phone:"请输入有效的电话号码"
  797. },
  798. __getType: function ()
  799. {
  800. return 'AutoForm'
  801. },
  802. __idPrev: function ()
  803. {
  804. return 'AutoForm';
  805. },
  806. _init: function ()
  807. {
  808. var g = this, p = this.options;
  809. $.ligerui.controls.AutoForm.base._init.call(this);
  810. },
  811. _render: function ()
  812. {
  813. var me = this, option = this.options;
  814. /********** 初始化控件 ***********/
  815. me.controls = [];
  816. var jform = $(this.element);
  817. $("textarea", jform).each(function () {
  818. try {
  819. var name = $(this).attr("name");
  820. if (name != undefined && name.length > 0) {
  821. me.controls.push({name: name, control: $(this)});
  822. }
  823. }
  824. catch(e){
  825. return;
  826. }
  827. });
  828. $("input", jform).each(function ()
  829. {
  830. try{
  831. var name = $(this).attr("name");
  832. var control = null;
  833. var controlType = "html"; //html为html控件 ui为ligerUI控件
  834. var rule = null; //校验规则
  835. var message = null; //校验提示信息
  836. if(name!=undefined && name.length>0)
  837. {
  838. //是否已存在
  839. for(var i=0;i<me.controls.length;i++)
  840. {
  841. if(me.controls[i].name == name)
  842. {
  843. return;
  844. }
  845. }
  846. var type = $(this).attr("type");
  847. if(type == "radio")//单选
  848. {
  849. control = $('input[name="'+name+'"]').ligerRadio();
  850. controlType = "ui";
  851. }
  852. else if(type == "checkbox")//多选
  853. {
  854. control = $('input[name="'+name+'"]').ligerCheckBox();
  855. controlType = "ui";
  856. }
  857. else if(type=="hidden")
  858. {
  859. if($(this).attr("data-ligerid"))
  860. {
  861. return;
  862. }
  863. else{
  864. control = $(this);
  865. }
  866. }
  867. else{
  868. var wrap = $(this).parent();
  869. if(wrap.hasClass("l-text-combobox")) //下拉控件
  870. {
  871. control = $(this).ligerComboBox();
  872. controlType = "ui";
  873. }
  874. else if(wrap.hasClass("l-text-date"))
  875. {
  876. control = $(this).ligerDateEditor();
  877. controlType = "ui";
  878. }
  879. else{
  880. control = $(this);
  881. }
  882. }
  883. //相关校验规则
  884. if(option.validate!=null && option.validate[name]!=null)
  885. {
  886. rule = option.validate[name];
  887. if(option.message!=null && option.message[name]!=null)
  888. {
  889. message = option.message[name];
  890. }
  891. }
  892. me.controls.push({name:name,controlType:controlType,control:control,rule:rule,message:message});
  893. }
  894. }
  895. catch(e)
  896. {
  897. return;
  898. }
  899. });
  900. /********* 初始化数据 **********/
  901. if(option.data)
  902. {
  903. me.setData(option.data);
  904. }
  905. /********** 只读 ************/
  906. if(option.readonly)
  907. {
  908. me.readOnly();
  909. }
  910. },
  911. //初始化数据
  912. setData:function(data){
  913. try{
  914. var me = this, option = this.options;
  915. for(var i=0;i<me.controls.length;i++)
  916. {
  917. var controlName = me.controls[i].name;
  918. var control = me.controls[i].control;
  919. var controlType = me.controls[i].controlType;
  920. var controlData = data[controlName];
  921. if(controlData!=undefined)
  922. {
  923. if(controlType=="ui"&&typeof(control.setValue)=="function")
  924. {
  925. control.setValue(controlData);
  926. }
  927. else{
  928. if(typeof(control.setValue)=="function")
  929. {
  930. control.setValue(controlData);
  931. }
  932. if(typeof(control.val)=="function")
  933. {
  934. control.val(controlData);
  935. }
  936. else{
  937. control.html(controlData);
  938. }
  939. }
  940. }
  941. }
  942. }
  943. catch(e)
  944. {
  945. return;
  946. }
  947. },
  948. //校验规则
  949. validateRule:function(rule,ruleValue,value){
  950. try{
  951. var me = this;
  952. //字符串格式化方法
  953. String.prototype.format= function() {
  954. var args = arguments;
  955. return this.replace(/\{(\d+)\}/g, function (s, i) {
  956. return args[i];
  957. });
  958. };
  959. var message = me.defaultMessage[rule];
  960. if(rule=="required" && (ruleValue ==true ||ruleValue=="true"))
  961. {
  962. if(value == null || value.length ==0)
  963. {
  964. return message;
  965. }
  966. }
  967. else if(rule== "equalTo")
  968. {
  969. if(ruleValue=="") {
  970. return "密码未输入";
  971. }
  972. else if(ruleValue!=value && value!="") {
  973. return message;
  974. }
  975. }
  976. else{
  977. if(value !=null &&value.length>0)
  978. {
  979. switch (rule)
  980. {
  981. case "email":
  982. {
  983. var re =new RegExp("^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$");
  984. if(!re.test(value))
  985. {
  986. return message;
  987. }
  988. break;
  989. }
  990. case "phone":
  991. {
  992. debugger
  993. var isPhone = /^(0[1-9]{2})-\d{8}$|^(0[1-9]{3}-(\d{7,8}))$/;
  994. var isMobile = /^(13|14|15|17|18)[0-9]{9}$/
  995. if (!isPhone.test(value) && !isMobile.test(value)) {
  996. return message;
  997. }
  998. break;
  999. }
  1000. case "ip":
  1001. {
  1002. var re =new RegExp("^(2[5][0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})$");
  1003. debugger
  1004. if(!re.test(value))
  1005. {
  1006. return message;
  1007. }
  1008. break;
  1009. }
  1010. case "date":
  1011. {
  1012. break;
  1013. }
  1014. case "dateISO":
  1015. {
  1016. break;
  1017. }
  1018. case "number":
  1019. {
  1020. break;
  1021. }
  1022. case "digits":
  1023. {
  1024. var re =new RegExp("^[0-9]*$");
  1025. if(!re.test(value))
  1026. {
  1027. return message;
  1028. }
  1029. break;
  1030. }
  1031. case "extension"://请输入有效的后缀
  1032. {
  1033. break;
  1034. }
  1035. case "maxlength"://最多可以输入 {0} 个字符
  1036. {
  1037. if(value.length>ruleValue)
  1038. {
  1039. return message.format(ruleValue);
  1040. }
  1041. break;
  1042. }
  1043. case "minlength"://最少要输入 {0} 个字符
  1044. {
  1045. if(value.length<ruleValue)
  1046. {
  1047. return message.format(ruleValue);
  1048. }
  1049. break;
  1050. }
  1051. case "max"://请输入不大于 {0} 的数值
  1052. {
  1053. if(value>ruleValue)
  1054. {
  1055. return message.format(ruleValue);
  1056. }
  1057. break;
  1058. }
  1059. case "min"://请输入不小于 {0} 的数值
  1060. {
  1061. if(value<ruleValue)
  1062. {
  1063. return message.format(ruleValue);
  1064. }
  1065. break;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. return "";
  1071. }
  1072. catch(e)
  1073. {
  1074. return e;
  1075. }
  1076. },
  1077. //校验值
  1078. validate:function(){
  1079. try {
  1080. var me = this, option = this.options;
  1081. me.flag = 100;//错误等级
  1082. var suc = true;
  1083. if (me.controls != null) {
  1084. var data = me.getData();
  1085. for (var i = 0; i < me.controls.length; i++) {
  1086. var control = me.controls[i];
  1087. var name = control["name"];
  1088. var rule = control["rule"];
  1089. var message = control["message"];
  1090. var error = "";
  1091. var terror = "";
  1092. if (rule != null) {
  1093. var value = data[name];
  1094. if (typeof(rule) == "string") {
  1095. error = me.validateRule(rule, true, value);
  1096. }
  1097. else {
  1098. for (var o in rule) {
  1099. var val = rule[o];
  1100. //判断相等情况,以赋值替代val
  1101. if (o == "equalTo") {
  1102. val = data[val];
  1103. }
  1104. terror = me.validateRule(o, val, value);
  1105. if (terror.length > 0) {
  1106. if (o == "required") {
  1107. me.flag = 1;
  1108. error = terror;
  1109. }
  1110. else if (o == "minlength") {
  1111. if (me.flag > 2) {
  1112. me.flag = 2;
  1113. error = terror;
  1114. }
  1115. }
  1116. else if (o == "maxlength") {
  1117. if (me.flag > 3) {
  1118. me.flag = 3;
  1119. error = terror;
  1120. }
  1121. }
  1122. //判断相等情况,以赋值替代val
  1123. else if (o == "equalTo") {
  1124. if (me.flag > 4) {
  1125. me.flag = 4;
  1126. error = terror;
  1127. }
  1128. }
  1129. else if (o == "digits") {
  1130. if (me.flag > 5) {
  1131. me.flag = 5;
  1132. error = terror;
  1133. }
  1134. }
  1135. else if (o == "email") {
  1136. if (me.flag > 6) {
  1137. me.flag = 6;
  1138. error = terror;
  1139. }
  1140. }
  1141. else if (o == "ip") {
  1142. if (me.flag > 7) {
  1143. me.flag = 7;
  1144. error = terror;
  1145. }
  1146. }
  1147. //error += ";"+re;
  1148. }
  1149. else {
  1150. }
  1151. }
  1152. }
  1153. }
  1154. //是否报错
  1155. if (error.length > 0) {
  1156. if(message!=undefined&&message!=null)
  1157. {
  1158. if (typeof(message) == "string")
  1159. {
  1160. error = message;//用户自定义消息覆盖默认消息
  1161. }
  1162. else {
  1163. for (var m in message) {
  1164. var value = message[m];
  1165. if (m == "required" && me.flag == 1) {
  1166. error = value;
  1167. }
  1168. else if (m == "minlength" && me.flag == 2) {
  1169. error = value;
  1170. }
  1171. else if (m == "maxlength" && me.flag == 3) {
  1172. error = value;
  1173. }
  1174. //判断相等情况,以赋值替代val
  1175. else if (m == "equalTo" && me.flag == 4) {
  1176. error = value;
  1177. }
  1178. else if (m == "digits" && me.flag == 5) {
  1179. error = value;
  1180. }
  1181. else if (m == "email" && me.flag == 6) {
  1182. error = value;
  1183. }
  1184. else if (m == "ip" && me.flag == 7) {
  1185. error = value;
  1186. }
  1187. }
  1188. }
  1189. }
  1190. me.showError(control, error);
  1191. /*if (me.flag == 1) {
  1192. me.showError(control, error);//required优先级高
  1193. }
  1194. else if (me.flag == 2) {
  1195. me.showError(control, error);//
  1196. }
  1197. else if (me.flag == 3) {
  1198. me.showError(control, error);//
  1199. }
  1200. else if (me.flag == 4) {
  1201. me.showError(control, error);//
  1202. }
  1203. else if (me.flag == 5) {
  1204. me.showError(control, error);//
  1205. }
  1206. else if (me.flag == 6) {
  1207. me.showError(control, error);//
  1208. }
  1209. else if (me.flag == 7) {
  1210. me.showError(control, error);//
  1211. }*/
  1212. //else if(message!=null && message.length > 0){
  1213. // me.showError(control,message);
  1214. // }
  1215. suc = false;
  1216. }
  1217. else
  1218. {
  1219. me.clearError(control);
  1220. }
  1221. }
  1222. return suc;
  1223. }
  1224. }
  1225. catch(e)
  1226. {
  1227. return false;
  1228. }
  1229. },
  1230. //清除某个控件错误提示
  1231. clearError:function(control){
  1232. var me = this;
  1233. var dom;
  1234. if(control.controlType == "ui")
  1235. {
  1236. dom = $(control.control.element).closest(".m-form-control");
  1237. }
  1238. else{
  1239. dom = control.control.closest(".m-form-control");
  1240. }
  1241. dom.removeClass('m-from-error').find('.m-from-error-msg').remove();
  1242. },
  1243. //某个控件错误提示
  1244. showError:function(control,error){
  1245. var me = this;
  1246. var dom;
  1247. if(control.controlType == "ui")
  1248. {
  1249. dom = $(control.control.element).closest(".m-form-control");
  1250. }
  1251. else{
  1252. dom = control.control.closest(".m-form-control");
  1253. }
  1254. if(dom.hasClass('m-from-error'))
  1255. {
  1256. me.clearError(control);
  1257. }
  1258. var el = $('<div class="m-from-error-msg"></div>');
  1259. dom.addClass('m-from-error').append(el);
  1260. el.hover(function ()
  1261. {
  1262. $(this).ligerTip({content:error});
  1263. },function (){
  1264. $(this).ligerHideTip();
  1265. });
  1266. },
  1267. //只读操作
  1268. readOnly:function(){
  1269. },
  1270. //获取数据
  1271. getData:function(){
  1272. var me = this, option = this.options;
  1273. var data = {};
  1274. for(var i=0;i<me.controls.length;i++)
  1275. {
  1276. var controlName = me.controls[i].name;
  1277. var control = me.controls[i].control;
  1278. var controlType = me.controls[i].controlType;
  1279. if(controlType=="ui"&&typeof(control.getValue)=="function")
  1280. {
  1281. data[controlName] = control.getValue();
  1282. }
  1283. else{
  1284. if(typeof(control.getValue)=="function")
  1285. {
  1286. data[controlName] = control.getValue();
  1287. }
  1288. if(typeof(control.val)=="function")
  1289. {
  1290. data[controlName] = control.val();
  1291. }
  1292. else{
  1293. data[controlName] = control.html();
  1294. }
  1295. }
  1296. }
  1297. return data;
  1298. }
  1299. });
  1300. })(jQuery, window);