commonForm.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. // @author suntg
  2. // @date 2014年11月19日17:39:28
  3. ;var caller = getUrlParam('caller');
  4. var formCondition = getUrlParam('formCondition')?getUrlParam('formCondition').replace('IS', '='):'';
  5. var gridCondition = getUrlParam('gridCondition')?getUrlParam('gridCondition').replace('IS', '='):'';
  6. var _readOnly = getUrlParam('_readOnly');// 只读标示
  7. var title;
  8. var baseInfo = {};//基本信息存放在这个类
  9. var detailsInfo = [];//明细信息存放在这个数组
  10. var detailInfo = {};//存放原始的一个明细行信息
  11. var detailIndex = 0;//明细索引,方便对明细做操作
  12. var buttons = [];//按钮组,存放当前包含的所有按钮
  13. var mainField;//明细表的主表主键字段
  14. var keyField;//主表中主键字段
  15. var dbfinds;//用于存储明细表中dbfind的字段对照关系,结构与form dbfind请求返回的dbfinds结构一致
  16. $(document).ready(function(){
  17. //与其它页面不同,必须传一个caller
  18. var saveUrl = 'common/saveCommon.action?caller=' +caller;
  19. var deleteUrl = 'common/deleteCommon.action?caller=' +caller;
  20. var updateUrl = 'common/updateCommon.action?caller=' +caller;
  21. var auditUrl = 'common/auditCommon.action?caller=' +caller;
  22. var printUrl = 'common/printCommon.action?caller=' +caller;
  23. var resAuditUrl = 'common/resAuditCommon.action?caller=' +caller;
  24. var submitUrl = 'common/submitCommon.action?caller=' +caller;
  25. var bannedUrl = 'common/bannedCommon.action?caller='+caller;
  26. var resBannedUrl = 'common/resBannedCommon.action?caller='+caller;
  27. var endUrl = 'common/endCommon.action?caller='+caller;
  28. var resEndUrl = 'common/resEndCommon.action?caller='+caller;
  29. var resSubmitUrl = 'common/resSubmitCommon.action?caller=' +caller;
  30. var getIdUrl = 'common/getCommonId.action?caller=' +caller;
  31. var onConfirmUrl = 'common/ConfirmCommon.action?caller=' +caller;
  32. //取编号 result-form的返回结果 table-表名 param-codeField 编号字段
  33. var getRandomNumber = function(result, table, type, codeField) {
  34. table = table == null ? result.tablename : table;
  35. type = type == null ? 2 : type;
  36. codeField = codeField == null ? result.codeField : codeField;
  37. $.ajax({
  38. type: 'POST',
  39. url: basePath + 'common/getCodeString.action',
  40. async: false,
  41. data: {
  42. caller: caller,//如果table==null,则根据caller去form表取对应table
  43. table: table,
  44. type: type
  45. },
  46. success: function(responseText) {
  47. judgeException(responseText, function(){
  48. $('[name="'+codeField+'"]').val(responseText.code);
  49. });
  50. }
  51. });
  52. };
  53. //类 -> JSON
  54. var object2JSON = function(obj) {
  55. var result = '';
  56. result = '{';
  57. $.each(obj, function(b, ba){
  58. if(!ba.ignore) {
  59. result += '"'+b+'":"'+ba.value+'",';
  60. }
  61. });
  62. if(result.length>1) result = result.substr(0, result.length-1);
  63. result += '}';
  64. return result;
  65. };
  66. //数组 -> JSON
  67. var array2JSON = function(arr) {
  68. var result = '';
  69. result += '[';
  70. $.each(arr, function(d, detail){
  71. result += '{';
  72. $.each(detail, function(i, de){
  73. if(!de.ignore) {
  74. result += '"'+i+'":"'+de.value+'",';
  75. }
  76. });
  77. if(result.length>2) result = result.substr(0, result.length-1);
  78. result += '}';
  79. if(i<(arr.length-1)) result += ',';
  80. });
  81. result += ']';
  82. return result;
  83. };
  84. //保存请求
  85. var save = function(base, details){
  86. var formStore = '';
  87. var param = '';
  88. formStore = unescape(escape(object2JSON(base)));
  89. param = unescape(escape(array2JSON(details)));
  90. $.ajax({
  91. type: 'POST',
  92. url: basePath + saveUrl,
  93. async: false,
  94. data: {
  95. formStore: formStore,
  96. param: param
  97. },
  98. success: function(responseText) {
  99. judgeException(responseText, function(){
  100. dialog.show('保存成功', '单据已成功保存,正在跳转...', 2, function() {
  101. dialog.hide();
  102. window.location.href = basePath+'jsps/mobile/commonForm/commonForm.jsp?caller='+
  103. caller+'&formCondition='+keyField+'IS'+responseText.id+'&gridCondition='+
  104. (mainField?mainField:'null')+'IS'+responseText.id;
  105. });
  106. });
  107. }
  108. });
  109. };
  110. //更新请求
  111. var update = function(base, details){
  112. var formStore = '';
  113. var param = '';
  114. formStore = unescape(escape(object2JSON(base)));
  115. param = unescape(escape(array2JSON(details)));
  116. $.ajax({
  117. type: 'POST',
  118. url: basePath + updateUrl,
  119. async: false,
  120. data: {
  121. formStore: formStore,
  122. param: param
  123. },
  124. success: function(responseText) {
  125. judgeException(responseText, function(){
  126. dialog.show('更新成功', '单据已成功更新,正在跳转...', 2, function() {
  127. dialog.hide();
  128. window.location.href = basePath+'jsps/mobile/commonForm/commonForm.jsp?caller='+
  129. caller+'&formCondition='+keyField+'IS'+responseText.id+'&gridCondition='+
  130. (mainField?mainField:'null')+'IS'+responseText.id;
  131. });
  132. });
  133. }
  134. });
  135. };
  136. //指定待处理人
  137. var showAssignWin = function(assins, nodeId) {
  138. $('#dbFindModal').modal('show');
  139. $('#myModalLabel').text('请指定节点处理人');
  140. var html = '';
  141. $.each(assins, function(a, as){
  142. var value = as.substring(as.lastIndexOf('(')+1, as.length-1);
  143. html += '<label class="radio-inline text-center" style="width:80%;margin-left:10px;margin-bottom:5px;">'+
  144. '<input type="radio" name="assiner" value="'+value+'">'+as+
  145. '<span class="glyphicon glyphicon-ok" style="display:none;">'+
  146. '</label>';
  147. });
  148. $('#dbFindModal .modal-body').html(html);
  149. var buttonHtml = '<button type="button" class="btn btn-default" id="assin">指定</button>'+
  150. '<button type="button" class="btn btn-default" id="cancelAssin">取消</button>';
  151. $('#dbFindModal .modal-footer').html(buttonHtml);
  152. radioLabelClick($('.modal-body .radio-inline'));
  153. $('#assin').click(function(){//指定
  154. var value = getRadioValue('assiner');//单选框按钮值
  155. if(value) {
  156. $.ajax({
  157. type: 'POST',
  158. url: basePath + 'common/takeOverTask.action',
  159. async: false,
  160. data: {
  161. em_code: value,
  162. nodeId: nodeId
  163. },
  164. success: function(responseText) {
  165. if(responseText.success){
  166. $('#dbFindModal').modal('hide');
  167. dialog.show('提示', '指定成功',2, function(){
  168. $.ajax({
  169. type: 'POST',
  170. url: basePath + 'common/processpaging.action',
  171. async: false,
  172. data: {
  173. persons: unescape('('+value+')'),
  174. nodeId: nodeId
  175. }
  176. });
  177. window.location.reload();
  178. });
  179. } else {
  180. dialog.show('提示', '指定失败',2, function(){
  181. window.location.reload();
  182. });
  183. }
  184. }
  185. });
  186. } else {//没有选择指定人
  187. $('#dbFindModal').modal('hide');
  188. dialog.show('提示', '请指定节点处理人',1, function(){
  189. dialog.hide();
  190. $('#dbFindModal').modal('show');
  191. });
  192. }
  193. });
  194. $('#cancelAssin').click(function(){//取消按钮
  195. $.ajax({//给所有人发通知
  196. type: 'POST',
  197. url: basePath + 'common/processpaging.action',
  198. async: false,
  199. data: {
  200. persons: unescape(assins.join(',')),
  201. nodeId: nodeId
  202. }
  203. });
  204. $('#dbFindModal').modal('hide');
  205. window.location.reload();
  206. });
  207. };
  208. //getSingleForm 获取form信息
  209. var getSingleForm = function(caller,condition) {
  210. setLoading(true);
  211. // $.post(basePath + 'common/singleFormItems.action', {
  212. // caller: caller,
  213. // condition: formCondition,
  214. // _noc: 1
  215. // }, function(result) {
  216. // setLoading(false);
  217. // judgeException(result, parseSingleForm(result));
  218. // });
  219. $.ajax({
  220. url:basePath + 'common/singleFormItems.action',
  221. type: 'POST',
  222. data: {caller: caller, condition: formCondition, _noc: 1},
  223. success: function(result){
  224. setLoading(false);
  225. judgeException(result, parseSingleForm(result));
  226. },
  227. error: function(xhr){
  228. setLoading(false);
  229. if(xhr.responseJSON) {
  230. var response = xhr.responseJSON;
  231. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  232. dialog.show('获取信息失败', '请先登录!');
  233. } else {
  234. dialog.show('错误', response.exceptionInfo);
  235. }
  236. }
  237. }
  238. });
  239. };
  240. // parseSingleForm
  241. var parseSingleForm = function(result) {
  242. var html = '';
  243. title = result.title;
  244. document.title = result.title + '-优软管理系统';
  245. $('#handler_name').text(result.title);
  246. if(result.fo_detailMainKeyField) mainField = result.fo_detailMainKeyField;
  247. keyField = result.keyField;
  248. var items = result.items, ids = [];
  249. for(i in items) {
  250. var item = items[i];
  251. if(ids.indexOf(item.id) == -1) {//避免出现因多字段出现字段重复
  252. ids.push(item.id);
  253. if(item.secondname && item.secondname != ''){
  254. ids.push(item.secondname);
  255. }
  256. html += parseFormItem(item, result);
  257. }
  258. }
  259. $('#baseinfo form').html(html);
  260. shrinkLabel($('#baseinfo .fieldlabel label'));
  261. radioLabelClick('#baseinfo .radio-inline');
  262. addDatetimepicker();
  263. dbFindButtons($('#baseinfo .dbFind'), 'form');
  264. initFormValidation($('#baseinfo'));
  265. if(result.data) {//查看单据的情况下,加载单据的数据
  266. initBaseInfo(eval('('+result.data+')'));
  267. parseObjToForm($('#baseinfo'), baseInfo, false);
  268. }
  269. // 处理按钮,只读情况下不显示按钮
  270. if (result.buttons && !_readOnly) {
  271. buttons = result.buttons.split('#');
  272. parseButtons(buttons, result);
  273. };
  274. };
  275. //parseButtons 加载按扭组
  276. //params: buttons 按钮字符串数组
  277. var parseButtons = function(buttons, result){
  278. $.each(buttons, function(b, button){
  279. $('#'+button).parent().css('display', 'table-cell');
  280. });
  281. //保存按钮
  282. $('#erpSaveButton').click(function(){
  283. //没有输入编号自动向后台获取并设值
  284. if(result.codeField && $('[name="'+result.codeField+'"]') &&
  285. ($('[name="'+result.codeField+'"]').val()=='' || $('[name="'+result.codeField+'"]').val()==null)) {
  286. getRandomNumber(result);
  287. }
  288. //设ID号
  289. if(result.keyField && $('[name="'+result.keyField+'"]') &&
  290. ($('[name="'+result.keyField+'"]').val()=='' || $('[name="'+result.keyField+'"]').val()==null)) {
  291. var keyId = getSeqId(getIdUrl);
  292. $('[name="'+result.keyField+'"]').val(keyId);
  293. }
  294. if(validateForm($('#baseinfo'))){//验证
  295. //空的数字型字段设值为0
  296. $.each($('input[type="number"], textarea[type="number"]', $('#baseinfo')), function(i, input){
  297. if ($(input).val()=='' || $(input).val()==null) {
  298. $(input).val(0);
  299. };
  300. });
  301. //codeField 值强制大写,自动过滤特殊字符
  302. var codeFieldValue = $('[name="'+result.codeField+'"]').val();
  303. codeFieldValue = codeFieldValue.trim().toUpperCase().replace(/[!@#$%^&*()'":,\/?]/, '');
  304. $('[name="'+result.codeField+'"]').val(codeFieldValue);
  305. baseInfo = parseFormToObj($('#baseinfo'), baseInfo);
  306. if(detailsInfo.length > 0) {
  307. $.each(detailsInfo, function(d, de) {
  308. if(!de[mainField]) de[mainField] = {value:'',nacessary:false,ignore:false};
  309. de[mainField].value = baseInfo[result.keyField].value;
  310. })
  311. }
  312. save(baseInfo, detailsInfo);
  313. }
  314. });
  315. //删除按钮
  316. $('#erpDeleteButton').click(function(){
  317. $.ajax({
  318. type: 'POST',
  319. url: basePath + deleteUrl,
  320. async: false,
  321. data: {
  322. id: baseInfo[keyField].value
  323. },
  324. success: function(responseText) {
  325. judgeException(responseText, function(){
  326. dialog.show('删除成功', '单据已成功删除,请返回!');
  327. });
  328. },
  329. error: function(xhr){
  330. if(xhr.response) {
  331. var response = $.parseJSON(xhr.response);
  332. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  333. dialog('获取用户信息失败', '请先登录!');
  334. } else {
  335. dialog('错误', response.exceptionInfo);
  336. }
  337. }
  338. }
  339. });
  340. });
  341. //更新按钮
  342. $('#erpUpdateButton').click(function(){
  343. if(validateForm($('#baseinfo'))){//验证
  344. //空的数字型字段设值为0
  345. $.each($('input[type="number"], textarea[type="number"]', $('#baseinfo')), function(i, input){
  346. if ($(input).val()=='' || $(input).val()==null) {
  347. $(input).val(0);
  348. };
  349. });
  350. //codeField 值强制大写,自动过滤特殊字符
  351. var codeFieldValue = $('[name="'+result.codeField+'"]').val();
  352. codeFieldValue = codeFieldValue.trim().toUpperCase().replace(/[!@#$%^&*()'":,\/?]/, '');
  353. $('[name="'+result.codeField+'"]').val(codeFieldValue);
  354. baseInfo = parseFormToObj($('#baseinfo'), baseInfo);
  355. if(detailsInfo.length > 0) {
  356. $.each(detailsInfo, function(d, de) {
  357. if(!de[mainField]) de[mainField] = {value:'',nacessary:false,ignore:false};
  358. de[mainField].value = baseInfo[result.keyField].value;
  359. })
  360. }
  361. update(baseInfo, detailsInfo);
  362. }
  363. });
  364. //新增按钮
  365. $('#erpAddButton').click(function(){
  366. window.location.href = basePath+'jsps/mobile/commonForm/commonForm.jsp?caller='+caller;
  367. });
  368. //提交按钮
  369. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'ENTERING') {
  370. $('#erpSubmitButton').parent().css('display', 'none');
  371. }
  372. $('#erpSubmitButton').click(function(){
  373. $.ajax({
  374. type: 'POST',
  375. url: basePath + submitUrl,
  376. async: false,
  377. data: {
  378. id: baseInfo[keyField].value
  379. },
  380. success: function(responseText) {
  381. if(responseText.success){ //跳转之前 若节点指定多人则指定候选人
  382. $.ajax({
  383. type: 'POST',
  384. url: basePath + 'common/getMultiNodeAssigns.action',
  385. async: false,
  386. data: {
  387. id: baseInfo[keyField].value,
  388. caller: caller
  389. },
  390. success: function(responseTextText) {
  391. judgeException(responseTextText, function(){
  392. //下一个节点多处理人,可选定处理人
  393. //选定了下一节点处理人之后发送请求将被选中的人设置为下一个节点,并发送通知
  394. //若取消选定则只向每个候选人发送通知
  395. if(responseTextText.MultiAssign){
  396. showAssignWin(responseTextText.assigns, responseTextText.nodeId);
  397. } else {
  398. dialog.show('提交成功', '单据已成功提交', 2, function(){
  399. window.location.reload();
  400. });
  401. }
  402. });
  403. },
  404. error: function(xhr){
  405. if(xhr.response) {
  406. var response = $.parseJSON(xhr.response);
  407. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  408. dialog('获取用户信息失败', '请先登录!');
  409. } else {
  410. dialog('错误', response.exceptionInfo);
  411. }
  412. }
  413. }
  414. });
  415. } else {
  416. if(responseText.exceptionInfo){
  417. var str = responseText.exceptionInfo;
  418. //特殊情况:操作成功,但是出现警告,允许刷新页面
  419. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  420. str = str.replace('AFTERSUCCESS', '');
  421. dialog.show('操作成功,提示:', str, 2, function(){
  422. dialog.hide();
  423. $.ajax({
  424. type: 'POST',
  425. url: basePath + 'common/getMultiNodeAssigns.action',
  426. async: false,
  427. data: {
  428. id: baseInfo[keyField].value,
  429. caller: caller
  430. },
  431. success: function(responseTextText) {
  432. judgeException(responseTextText, function(){
  433. //下一个节点多处理人,可选定处理人
  434. //选定了下一节点处理人之后发送请求将被选中的人设置为下一个节点,并发送通知
  435. //若取消选定则只向每个候选人发送通知
  436. if(responseTextText.MultiAssign){
  437. showAssignWin(responseTextText.assigns, responseTextText.nodeId);
  438. } else {
  439. dialog.show('提交成功', '单据已成功提交', 2, function(){
  440. window.location.reload();
  441. });
  442. }
  443. });
  444. }
  445. });
  446. });
  447. } else {
  448. dialog.show('出现异常', '请重新尝试!');
  449. }
  450. }
  451. }
  452. }
  453. });
  454. });
  455. //反提交按钮
  456. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'COMMITED') {
  457. $('#erpResSubmitButton').parent().css('display', 'none');
  458. }
  459. $('#erpResSubmitButton').click(function(){
  460. $.ajax({
  461. type: 'POST',
  462. url: basePath + resSubmitUrl,
  463. async: false,
  464. data: {
  465. id: baseInfo[keyField].value
  466. },
  467. success: function(responseText) {
  468. judgeException(responseText, function(){//跳转之前 若节点指定多人则指定候选人
  469. if(responseText.success) {
  470. dialog.show('反提交成功', '正在重新加载页面', 2, function(){
  471. window.location.reload();
  472. });
  473. }
  474. });
  475. },
  476. error: function(xhr){
  477. if(xhr.response) {
  478. var response = $.parseJSON(xhr.response);
  479. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  480. dialog('获取用户信息失败', '请先登录!');
  481. } else {
  482. dialog('错误', response.exceptionInfo);
  483. }
  484. }
  485. }
  486. });
  487. });
  488. //审核按钮
  489. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'COMMITED') {
  490. $('#erpAuditButton').parent().css('display', 'none');
  491. }
  492. $('#erpAuditButton').click(function(){
  493. //清除流程(什么意思我也不懂)
  494. $.ajax({
  495. type: 'POST',
  496. url: basePath + 'common/deleteProcessAfterAudit.action',
  497. async: false,
  498. data: {
  499. keyValue: baseInfo[keyField].value,
  500. caller: caller,
  501. _noc:1
  502. },
  503. success: function(responseText) {
  504. //似乎不用干什么
  505. }
  506. });
  507. $.ajax({
  508. type: 'POST',
  509. url: basePath + auditUrl,
  510. async: false,
  511. data: {
  512. id: baseInfo[keyField].value
  513. },
  514. success: function(responseText) {
  515. if(responseText.success) {
  516. dialog.show('审核成功', '正在重新加载...', 2, function(){
  517. window.location.reload();
  518. });
  519. } else {
  520. if(responseText.exceptionInfo){
  521. var str = responseText.exceptionInfo;
  522. //特殊情况:操作成功,但是出现警告,允许刷新页面
  523. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  524. str = str.replace('AFTERSUCCESS', '');
  525. dialog.show('操作成功,提示:', str, 2, function(){
  526. window.location.reload();
  527. });
  528. } else {
  529. dialog.show('出现异常', '请重新尝试!');
  530. }
  531. }
  532. }
  533. }
  534. });
  535. });
  536. //反审核按钮
  537. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'AUDITED') {
  538. $('#erpResAuditButton').parent().css('display', 'none');
  539. }
  540. $('#erpResAuditButton').click(function(){
  541. $.ajax({
  542. type: 'POST',
  543. url: basePath + resAuditUrl,
  544. async: false,
  545. data: {
  546. id: baseInfo[keyField].value
  547. },
  548. success: function(responseText) {
  549. judgeException(responseText, function() {
  550. dialog.show('反审核成功', '正在重新加载...', 2, function() {
  551. window.location.reload();
  552. })
  553. });
  554. },
  555. error: function(xhr){
  556. if(xhr.response) {
  557. var response = $.parseJSON(xhr.response);
  558. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  559. dialog('获取用户信息失败', '请先登录!');
  560. } else {
  561. dialog('错误', response.exceptionInfo);
  562. }
  563. }
  564. }
  565. });
  566. });
  567. //结案按钮
  568. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'CANUSE' &&
  569. baseInfo[result.statuscodeField].value != 'AUDITED') {
  570. $('#erpEndButton').parent().css('display', 'none');
  571. }
  572. $('#erpEndButton').click(function(){
  573. $.ajax({
  574. type: 'POST',
  575. url: basePath + endUrl,
  576. async: false,
  577. data: {
  578. id: baseInfo[keyField].value
  579. },
  580. success: function(responseText) {
  581. if(responseText.success) {
  582. dialog.show('结案成功', '正在重新加载...', 2, function(){
  583. window.location.reload();
  584. });
  585. } else {
  586. if(responseText.exceptionInfo){
  587. var str = responseText.exceptionInfo;
  588. //特殊情况:操作成功,但是出现警告,允许刷新页面
  589. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  590. str = str.replace('AFTERSUCCESS', '');
  591. dialog.show('操作成功,提示:', str, 2, function(){
  592. window.location.reload();
  593. });
  594. } else {
  595. dialog.show('出现异常', '请重新尝试!');
  596. }
  597. }
  598. }
  599. }
  600. });
  601. });
  602. //反结案按钮
  603. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'FINISH' ) {
  604. $('#erpResEndButton').parent().css('display', 'none');
  605. }
  606. $('#erpResEndButton').click(function(){
  607. $.ajax({
  608. type: 'POST',
  609. url: basePath + resEndUrl,
  610. async: false,
  611. data: {
  612. id: baseInfo[keyField].value
  613. },
  614. success: function(responseText) {
  615. if(responseText.success) {
  616. dialog.show('反结案成功', '正在重新加载...', 2, function(){
  617. window.location.reload();
  618. });
  619. } else {
  620. if(responseText.exceptionInfo){
  621. var str = responseText.exceptionInfo;
  622. //特殊情况:操作成功,但是出现警告,允许刷新页面
  623. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  624. str = str.replace('AFTERSUCCESS', '');
  625. dialog.show('操作成功,提示:', str, 2, function(){
  626. window.location.reload();
  627. });
  628. } else {
  629. dialog.show('出现异常', '请重新尝试!');
  630. }
  631. }
  632. }
  633. }
  634. });
  635. });
  636. //禁用按钮
  637. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'CANUSE' &&
  638. baseInfo[result.statuscodeField].value != 'AUDITED') {
  639. $('#erpBannedButton').parent().css('display', 'none');
  640. }
  641. $('#erpBannedButton').click(function(){
  642. $.ajax({
  643. type: 'POST',
  644. url: basePath + bannedUrl,
  645. async: false,
  646. data: {
  647. id: baseInfo[keyField].value
  648. },
  649. success: function(responseText) {
  650. if(responseText.success) {
  651. dialog.show('禁用成功', '正在重新加载...', 2, function(){
  652. window.location.reload();
  653. });
  654. } else {
  655. if(responseText.exceptionInfo){
  656. var str = responseText.exceptionInfo;
  657. //特殊情况:操作成功,但是出现警告,允许刷新页面
  658. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  659. str = str.replace('AFTERSUCCESS', '');
  660. dialog.show('操作成功,提示:', str, 2, function(){
  661. window.location.reload();
  662. });
  663. } else {
  664. dialog.show('出现异常', '请重新尝试!');
  665. }
  666. }
  667. }
  668. }
  669. });
  670. });
  671. //反禁用按钮
  672. if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'DISABLE') {
  673. $('#erpResBannedButton').parent().css('display', 'none');
  674. }
  675. $('#erpResBannedButton').click(function(){
  676. $.ajax({
  677. type: 'POST',
  678. url: basePath + resBannedUrl,
  679. async: false,
  680. data: {
  681. id: baseInfo[keyField].value
  682. },
  683. success: function(responseText) {
  684. judgeException(responseText, function() {
  685. dialog.show('反禁用成功', '正在重新加载...', 2, function(){
  686. window.location.reload();
  687. });
  688. });
  689. }
  690. });
  691. });
  692. };
  693. //parse form item
  694. var parseFormItem = function(item, result) {
  695. if(_readOnly) item.readOnly = true;// 页面只读模式,所有输入框都是只读
  696. var type, hidden='', html;
  697. switch(item.xtype) {
  698. case 'textfield': type='text'; break;
  699. case 'hidden': hidden='hidden'; type='text'; break;////强制设置隐藏的字段必填为否
  700. case 'numberfield': type='number'; break;
  701. }
  702. if(item.name != null) {
  703. if(item.name == result.statusField){//状态加特殊颜色
  704. item.fieldStyle = item.fieldStyle + ';font-weight:bold;';
  705. } else if(item.name == result.statuscodeField){//状态码字段强制隐藏
  706. hidden = 'hidden';
  707. }
  708. }
  709. if(item.group == '0') {
  710. html = '<div class="field-line" style="font-weight:bold;color:#000;"><div class="control-group">'+
  711. '<div class="fieldlabel">&nbsp;'+ $(item.html).text()+
  712. '</div><div class="field text-center"><span class="glyphicon glyphicon-chevron-down"></span></div>'+
  713. '<div class="fieldremark"></div>'+
  714. '</div></div>';
  715. return html;
  716. }
  717. baseInfo[item.name] = {};
  718. baseInfo[item.name].fieldlabel = item.fieldLabel;
  719. baseInfo[item.name].value = item.value;
  720. baseInfo[item.name].nacessary = !item.allowBlank;
  721. baseInfo[item.name].ignore = (item.logic=='ignore');
  722. html = '<div class="field-line ' + hidden + '">' +
  723. '<div class="control-group">' +
  724. '<div class="fieldlabel">' +
  725. '<label class="control-label text-right" for="'+item.name +'">' + item.fieldLabel + ':</label>' +
  726. '</div>' +
  727. '<div class="field">';
  728. if(item.xtype == 'erpYnField' ) {//是否单选框
  729. html += '<label class="radio-inline text-center" style="width:30%">'+
  730. '<input type="radio" name="'+item.name+'" id="'+item.id+'" value="-1"'+
  731. (item.value=='是'||item.value=='-1'||item.value=='1'?'checked':'')+'>是'+
  732. '<span class="glyphicon glyphicon-ok" style="display:none;">'+
  733. '</label>'+
  734. '<label class="radio-inline text-center" style="width:30%">' +
  735. '<input type="radio" name="'+item.name+'" id="'+item.id+'" value="0"'+
  736. (item.value=='否'||item.value=='0'?'checked':'')+'>否'+
  737. '<span class="glyphicon glyphicon-ok" style="display:none;">'+
  738. '</label>';
  739. if(!item.allowBlank && !item.readOnly) html += '&nbsp;&nbsp;'+
  740. '<span class="required glyphicon glyphicon-exclamation-sign text-danger">必填</span>';
  741. } else if(item.xtype=='datefield'||item.xtype=='datetimefield'||item.xtype=='datehourminutefield') {//时间输入框
  742. html += '<div class="'+(item.readOnly?'':'date')+' form_datetime has-feedback">' +
  743. '<input '+(item.readOnly?'readOnly':'')+' id="'+item.id+'" name="'+item.name+'" type="text" data-date-format="'+
  744. ((item.xtype=='datetimefield'||item.xtype=='datehourminutefield')?'YYYY-MM-DD HH:mm:ss':'YYYY-MM-DD')+
  745. '" value="'+(item.value?item.value:'')+'" class="form-control input-sm">'+
  746. '<span class="add-on form-control-feedback glyphicon glyphicon-calendar"><i class="icon-calendar"></i></span>'+
  747. '</div>';
  748. }else if(item.xtype=='condatefield'||item.xtype=='condatetimefield'||item.xtype=='condatehourminutefield') {//时间端输入框
  749. html += '<div class="'+(item.readOnly?'':'date')+' form_datetime has-feedback">' +
  750. '<input '+(item.readOnly?'readOnly':'')+' id="'+item.id+'" name="'+item.name+'" type="text" data-date-format="'+
  751. ((item.xtype=='datetimefield'||item.xtype=='datehourminutefield')?'YYYY-MM-DD HH:mm:ss':'YYYY-MM-DD')+
  752. '" value="'+(item.value?item.value:'')+'" class="form-control input-sm">'+
  753. '<span class="add-on form-control-feedback glyphicon glyphicon-calendar"><i class="icon-calendar"></i></span>'+
  754. '</div>';
  755. } else if(item.xtype == 'combo') {//下拉单选框
  756. html += '<select type="text" id="'+item.id+'" name="'+item.name+'" class="form-control input-sm"'+(item.readOnly?'readOnly':'')+'>';
  757. for(s in item.store.data) {
  758. var option = item.store.data[s];
  759. html += '<option value="'+option.value+'">'+option.display+'</option>';
  760. }
  761. html += '</select>';
  762. } else if(item.xtype == 'textareafield') {//文本域输入框
  763. html += '<textarea id="'+item.id+'" name="'+item.name+'" row="6" value="'+
  764. (item.value?item.value:'')+'" '+(item.readOnly?'readOnly':'')+' class="form-control input-sm"'+
  765. (item.allowBlank?'':'required placeholder="必填*"')+'></textarea>';
  766. }else if(item.xtype == 'textareatrigger') {//长文本输入框
  767. html += '<textarea id="'+item.id+'" name="'+item.name+'" row="3" value="'+
  768. (item.value?item.value:'')+'" '+(item.readOnly?'readOnly':'')+' class="form-control input-sm"'+
  769. (item.allowBlank?'':'required placeholder="必填*"')+'></textarea>';
  770. }else {
  771. html += '<input type="'+type+'" id="'+item.id+'" name="'+item.name+'" value="'+
  772. (item.value?item.value:'')+'" '+(item.readOnly?'readOnly':'')+' class="form-control input-sm"'+
  773. (item.allowBlank?'':'required placeholder="必填*"')+'>';
  774. }
  775. html += '</div>'+
  776. '<div class="fieldremark">' +
  777. '<div class=""></div>' +
  778. '</div>' +
  779. '</div>' +
  780. '</div>';
  781. if(item.xtype == 'dbfindtrigger') {//dbFind输入框
  782. html = '<div class="field-line ' + hidden + '">' +
  783. '<div class="control-group dropdown">' +
  784. '<div class="fieldlabel">' +
  785. '<label class="control-label text-right" for="'+item.name +'">' + item.fieldLabel + ':</label>' +
  786. '</div>' +
  787. '<div class="field">'+
  788. '<input type="'+type+'" id="'+item.id+'" name="'+item.name+'" value="'+
  789. (item.value?item.value:'')+'" '+(item.readOnly?'readOnly':'')+' class="form-control input-sm"'+
  790. (item.allowBlank?'':'required placeholder="必填*"')+'>'+
  791. '</div>'+
  792. (item.readOnly?'':(/* 只读的dbFind框不需要显示放大镜*/
  793. '<div class="fieldremark dropdown-toggle" data-toggle="dropdown">' +
  794. '<button type="button" fieldname="'+item.name+'" class="btn btn-default btn-xs dbFind"><span class="glyphicon glyphicon-search"></button>'+
  795. '</div>' +
  796. '<div class="dropdown-menu suggest-box">'+
  797. '<div class="">'+
  798. '<ul class="suggest-result">'+
  799. '</ul>'+
  800. '</div>'+
  801. '</div>'))+
  802. '</div>' +
  803. '</div>';
  804. } else if(item.xtype == 'multifield' || item.xtype=='condatefield' ||
  805. item.xtype=='condatetimefield' || item.xtype=='condatehourminutefield') {//合并型的字段
  806. html = '<div class="field-line ' + hidden + '">' +
  807. '<div class="control-group dropdown">' +
  808. '<div class="fieldlabel">' +
  809. '<label class="control-label text-right" for="'+item.name +'">' + item.fieldLabel + ':</label>' +
  810. '</div>';
  811. if(item.xtype=='condatefield'||item.xtype=='condatetimefield'||item.xtype=='condatehourminutefield'){//时间段输入框
  812. html += '<div class="field">';
  813. html += '<div class="'+(item.readOnly?'':'date')+' form_datetime has-feedback">' +
  814. '<input '+(item.readOnly?'readOnly':'')+' id="'+item.id+'" name="'+item.name+'" type="text" data-date-format="'+
  815. ((item.xtype=='condatetimefield'||item.xtype=='condatehourminutefield')?'YYYY-MM-DD HH:mm:ss':'YYYY-MM-DD')+
  816. '" value="'+(item.value?item.value:'')+'" class="form-control input-sm">'+
  817. '<span class="add-on form-control-feedback glyphicon glyphicon-calendar"><i class="icon-calendar"></i></span>'+
  818. '</div>&nbsp;&nbsp;至';
  819. html += '<div class="'+(item.readOnly?'':'date')+' form_datetime has-feedback">' +
  820. '<input '+(item.readOnly?'readOnly':'')+' id="'+item.secondname+'" name="'+item.secondname+'" type="text" data-date-format="'+
  821. ((item.xtype=='condatetimefield'||item.xtype=='condatehourminutefield')?'YYYY-MM-DD HH:mm:ss':'YYYY-MM-DD')+
  822. '" value="'+(item.value?item.value:'')+'" class="form-control input-sm">'+
  823. '<span class="add-on form-control-feedback glyphicon glyphicon-calendar"><i class="icon-calendar"></i></span>'+
  824. '</div>';
  825. } else {//其他
  826. html += '<div class="field">';
  827. html += '<input type="'+type+'" id="'+item.id+'" name="'+item.name+'" value="'+
  828. (item.value?item.value:'')+'" '+(item.readOnly?'readOnly':'')+' class="form-control input-sm"'+
  829. (item.allowBlank?'':'required placeholder="必填*"')+'>';
  830. html += '<input type="'+type+'" name="'+item.secondname+'" readOnly class="form-control input-sm"'+
  831. (item.allowBlank?'':'required placeholder="请先输入'+item.fieldLabel+'"')+'>';
  832. }
  833. html += '</div>';
  834. if(item.readOnly) {
  835. // 只读模式,不需要加放大镜
  836. html += '</div>' +
  837. '</div>';
  838. } else {
  839. html += '<div class="fieldremark dropdown-toggle" data-toggle="dropdown">' ;
  840. //除时间段输入项外
  841. if(!(item.xtype=='condatefield'||item.xtype=='condatetimefield'||item.xtype=='condatehourminutefield')){//
  842. html += '<button type="button" fieldname="'+item.name+'" class="btn btn-default btn-xs dbFind"><span class="glyphicon glyphicon-search"></button>';
  843. }
  844. html += '</div>' +
  845. '<div class="dropdown-menu suggest-box">'+
  846. '<div class="">'+
  847. '<ul class="suggest-result">'+
  848. '</ul>'+
  849. '</div>'+
  850. '</div>'+
  851. '</div>' +
  852. '</div>';
  853. }
  854. baseInfo[item.secondname] = {};
  855. baseInfo[item.secondname].fieldlabel = item.fieldLabel;
  856. baseInfo[item.secondname].value = item.value;
  857. baseInfo[item.secondname].nacessary = !item.allowBlank;
  858. baseInfo[item.secondname].ignore = (item.logic=='ignore');
  859. }
  860. return html;
  861. };
  862. //初始化baseInfo对象,在当前有数据的情况下
  863. var initBaseInfo = function(data) {
  864. $.each(baseInfo, function(b, bi){
  865. bi.value = data[b];
  866. });
  867. };
  868. //初始化detailsInfo对象,在当前有数据的情况下
  869. var initDetailsInfo = function(data) {
  870. $.each(data, function(i, d){
  871. var object = $.extend(true, new Object(), detailInfo);
  872. $.each(object, function(o, obj){
  873. obj.value = d[o];
  874. });
  875. detailsInfo.push(object);
  876. });
  877. };
  878. //通过控制label的字体大小控制fieldLabel的长度
  879. var shrinkLabel = function(labels) {
  880. $.each(labels, function(i, label){
  881. label = $(label);
  882. var labelFontSize = parseInt(label.css('font-size')) + 1;
  883. var labelLength = label.text().length+1;
  884. if(labelFontSize*labelLength>parseInt(label.parent().width())){
  885. label.css('font-size', (parseInt(label.parent().width())/labelLength)+'px');
  886. }
  887. });
  888. };
  889. //根据单选框是否checked修改单选框样式
  890. var initRadio = function(labels){
  891. $.each(labels, function(l, label){
  892. label = $(label);
  893. var checked = label.find('input[type="radio"]').attr('checked');
  894. if(checked) {
  895. label.css('background-color', '#339933').css('color', '#FFFFFF');
  896. label.find('.glyphicon').show();
  897. label.siblings('.radio-inline').css('background-color', '#EEEEEE').css('color', '#333333').
  898. css('font-weight', 'normal').css('border', '1px solid #339933');
  899. label.siblings('.radio-inline').find('.glyphicon').hide();
  900. }
  901. });
  902. };
  903. //添加单选框点击样式
  904. var radioLabelClick = function(radioes){
  905. initRadio($('.radio-inline'));
  906. $(radioes).click(function(){
  907. initRadio($(this));
  908. $(this).siblings('.required').removeClass('text-danger glyphicon-exclamation-sign').
  909. addClass('text-success glyphicon-ok-sign');
  910. });
  911. };
  912. //为所有.date添加datetimepicker
  913. var addDatetimepicker = function(){
  914. $('.date').datetimepicker({
  915. language: 'zh-CN',
  916. pickTime: ($(this).find('input').attr('data-date-format')=='YYYY-MM-DD'?false:true)
  917. });
  918. };
  919. //转换处理dbfind返回的结果
  920. var parseToDbFinds = function(result, which, fieldName) {
  921. var dbFinds = new Array();
  922. var dbPrototype = new Object();
  923. $.each(result.columns, function(c, co) {
  924. dbPrototype[co.dataIndex] = {};
  925. dbPrototype[co.dataIndex].hidden = co.hidden;
  926. });
  927. if (which == 'form') {
  928. $.each(result.dbfinds, function(d, db) {
  929. dbPrototype[db.dbGridField].field = db.field;
  930. });
  931. } else if(which == 'grid') {
  932. $.each(dbfinds, function(d, db) {
  933. if (db.trigger == fieldName) {
  934. console.log(db);
  935. if(dbPrototype[db.dbGridField]) dbPrototype[db.dbGridField].field = db.field;
  936. };
  937. });
  938. }
  939. $.each(eval('('+result.data+')'), function(d, da) {
  940. var object = $.extend(true, {}, dbPrototype);
  941. $.each(da, function(key, value) {
  942. if(object[key]) object[key].value = value;
  943. });
  944. var i = 1;//去前两个不隐藏的值做显示
  945. object.list = '';
  946. $.each(object, function(o, obj) {
  947. if(i > 2) return;
  948. if(!obj.hidden){
  949. if (i>1) {object.list += '&nbsp;|&nbsp;';};
  950. object.list += obj.value;
  951. i++;
  952. }
  953. });
  954. dbFinds.push(object);
  955. });
  956. return dbFinds;
  957. };
  958. //dbFind效果与功能
  959. var dbFindButtons = function(buttons, which){
  960. $.each(buttons, function(b, button) {
  961. $(button).click(function(){
  962. var me = $(this);
  963. var ul = me.parent().parent().find('ul');
  964. var fieldName = me.attr('fieldname');
  965. var input = $('input[name="'+fieldName+'"]');
  966. var keyWord = input.val().toLocaleUpperCase();
  967. var dbfind;//明细表中(which==grid)存储dbfind对应的caller和fieldName值
  968. if (which == 'grid') {
  969. dbfind = me.attr('dbfind');
  970. };
  971. if(keyWord) {
  972. setLoading(true);
  973. $.ajax({
  974. type: 'POST',
  975. url: basePath + 'common/dbfind.action',
  976. data: {
  977. which: which,
  978. caller: (which=='form'?caller:(dbfind.substr(0, dbfind.indexOf('|')))),
  979. field: fieldName,
  980. condition: "upper("+(which=='form'?fieldName:dbfind.substr(dbfind.indexOf('|')+1, dbfind.length))+") like '%"+keyWord+"%' ",
  981. ob: '',
  982. page: 1,
  983. pageSize: 8
  984. },
  985. success: function(result) {
  986. setLoading(false);
  987. ul.empty();
  988. var html = '';
  989. if(!result.exceptionInfo){
  990. var dbFinds = parseToDbFinds(result, which, fieldName);
  991. $.each(dbFinds, function(i, item){
  992. html = '<li>'+item.list+'</li>';
  993. delete item.list;
  994. var html = $(html);
  995. html.click(function() {
  996. $.each(item, function(key, obj) {
  997. $('[name="'+obj.field+'"]').val(obj.value);
  998. if(which == 'grid'){
  999. $.each(dbfinds, function(index, db){
  1000. if(db.dbGridField == key) {
  1001. $('[name="'+db.field+'"').val(obj.value);
  1002. }
  1003. });
  1004. };
  1005. });
  1006. });
  1007. ul.append(html);
  1008. });
  1009. }
  1010. }
  1011. });
  1012. } else {
  1013. ul.html('<li>请先输入关键字</li>');
  1014. }
  1015. });
  1016. })
  1017. }
  1018. //getSingleGrid获取明细表信息
  1019. var getSingleGrid = function(caller, condition){
  1020. setLoading(true);
  1021. $.post(basePath + 'common/singleGridPanel.action', {
  1022. caller: caller,
  1023. condition: gridCondition,
  1024. _noc: 1
  1025. }, function(result) {
  1026. setLoading(false);
  1027. judgeException(result, parseSingleGrid(result));
  1028. });
  1029. };
  1030. //parseSingleGrid处理展现对明细表
  1031. var parseSingleGrid = function(result){
  1032. if(_readOnly) {
  1033. $('#add-detail').remove();
  1034. $('#detail-handlers').remove();
  1035. }
  1036. dbfinds = result.dbfinds;
  1037. if(result.columns && result.columns.length){//明细表有列-有明细表
  1038. parseDeForm(result);
  1039. $('#details').removeClass('hidden');
  1040. $('#add-detail').click(function() {//添加明细行按钮
  1041. setLoading(true);
  1042. $('#baseinfo form').hide();
  1043. $('.spread-baseinfo').show();
  1044. $('#add-detail').hide();
  1045. $('#de-form').show();
  1046. $('#detail-handlers').show();
  1047. $('#detno').val(detailsInfo.length+1);
  1048. $('#de-delete').attr('disabled', true);
  1049. $('#de-modify').attr('disabled', true);
  1050. $('#de-add').removeAttr('disabled');
  1051. setLoading(false);
  1052. $('#de-form input:first').focus();
  1053. });
  1054. $('.spread-baseinfo').click(function(){//基本信息中的展开按钮
  1055. setLoading(true);
  1056. $('.spread-baseinfo').hide();
  1057. $('#baseinfo form').show();
  1058. $('#de-form').hide();
  1059. $('#detail-handlers').hide();
  1060. $('#add-detail').show();
  1061. setLoading(false);
  1062. // 平滑移到'明细信息'头部
  1063. $('html,body').animate({scrollTop:$('#title').offset().top}, 200);
  1064. });
  1065. $('#de-cancle').click(function(){//明细信息中的取消按钮
  1066. setLoading(true);
  1067. $('#baseinfo form').show();
  1068. $('#de-form').hide();
  1069. $('#detail-handlers').hide();
  1070. $('#add-detail').show();
  1071. $('.spread-baseinfo').hide();
  1072. setLoading(false);
  1073. });
  1074. $('#de-add').click(function() {
  1075. if(validateForm($('#de-form'))){
  1076. var item = parseFormToObj($('#de-form'), detailInfo);
  1077. detailsInfo.push(item);
  1078. parseCurrentDetails();
  1079. $('#detno').val(detailsInfo.length+1);
  1080. }
  1081. });
  1082. if(result.data) {
  1083. initDetailsInfo(eval('('+result.data+')'));
  1084. parseCurrentDetails();
  1085. };
  1086. }
  1087. };
  1088. //初始化明细行表单
  1089. var parseDeForm = function(result) {
  1090. var columns = result.columns;
  1091. var html = '';
  1092. $.each(columns, function(c, column) {
  1093. html += dealDeFormItem(column, result);
  1094. });
  1095. $('#de-form form').html(html);
  1096. radioLabelClick($('#de-form .radio-inline'));
  1097. addDatetimepicker();
  1098. initFormValidation($('#de-form'));
  1099. dbFindButtons($('#de-form .dbFind'), 'grid');
  1100. }
  1101. //处理明细行的每一个输入框
  1102. var dealDeFormItem = function(item, result){
  1103. var hidden = item.hidden?'hidden': '';
  1104. if(_readOnly) item.readOnly = true;// 只读模式所有
  1105. var readOnly = item.readOnly?'readOnly': '';
  1106. var required = null;
  1107. var ignore = false;
  1108. var type = 'text';
  1109. var html = '';
  1110. // column有取别名
  1111. if(item.dataIndex.indexOf(' ') > -1) {
  1112. item.dataIndex = item.dataIndex.split(' ')[1];
  1113. }
  1114. if(item.logic == 'necessaryField') required = 'required';
  1115. // if(hidden) required = null;//强制设置隐藏的字段必填为否
  1116. if(item.xtype == 'numbercolumn') {
  1117. type = 'number';
  1118. } else if (item.xtype == 'datecolumn') {
  1119. type = 'date';
  1120. }
  1121. if(item.logic == 'ignore') ignore = true;
  1122. if(!mainField && item.logic == 'mainField') mainField = item.dataIndex;
  1123. detailInfo[item.dataIndex] = {};
  1124. detailInfo[item.dataIndex].fieldlabel = item.header;
  1125. detailInfo[item.dataIndex].value = item.value;
  1126. detailInfo[item.dataIndex].nacessary = required?true:false;
  1127. detailInfo[item.dataIndex].ignore = ignore;
  1128. html = '<div class="field-line ' + hidden + '">' +
  1129. '<div class="control-group">' +
  1130. '<div class="fieldlabel">' +
  1131. '<label class="control-label text-right" for="'+item.dataIndex +'">'+item.header+':</label>' +
  1132. '</div>' +
  1133. '<div class="field">';
  1134. if(item.editor && item.editor.xtype){//需要显示输入框的
  1135. if(item.editor.xtype == 'erpYnField' ) {//是否单选框
  1136. html += '<label class="radio-inline text-center" style="width:40%">'+
  1137. '<input ignore="'+ignore+'" type="radio" name="'+item.dataIndex+'" value="-1">是'+
  1138. '<span class="glyphicon glyphicon-ok" style="display:none;">'+
  1139. '</label>'+
  1140. '<label class="radio-inline text-center" style="width:40%">' +
  1141. '<input ignore="'+ignore+'" type="radio" name="'+item.dataIndex+'" value="0" checked>否'+
  1142. '<span class="glyphicon glyphicon-ok" style="display:none;">'+
  1143. '</label>';
  1144. if(required && !item.readOnly) html += '&nbsp;&nbsp;'+
  1145. '<span class="required glyphicon glyphicon-exclamation-sign text-danger">必填</span>';
  1146. } else if(item.editor.xtype=='datefield'||item.editor.xtype=='datetimefield'||item.editor.xtype=='datehourminutefield') {//时间输入框
  1147. html += '<div class="'+(readOnly?'':'date')+' form_datetime has-feedback">' +
  1148. '<input ignore="'+ignore+'" '+(readOnly?'readOnly':'')+' id="'+item.dataIndex+'" name="'+item.dataIndex+'" type="text" data-date-format="'+
  1149. ((item.xtype=='datetimecolumn'||item.xtype=='datehourminutecolumn')?'YYYY-MM-DD HH:mm:ss':'YYYY-MM-DD')+
  1150. '" value="'+(item.value?item.value:'')+'" '+required+' class="form-control input-sm">'+
  1151. '<span class="add-on form-control-feedback glyphicon glyphicon-calendar"><i class="icon-calendar"></i></span>'+
  1152. '</div>';
  1153. } else if(item.editor.xtype == 'dbfindtrigger') {//dbFind输入框
  1154. html += '<input ignore="'+ignore+'" type="'+type+'" id="'+item.dataIndex+'" name="'+item.dataIndex+'" value="'+
  1155. (item.value?item.value:'')+'" '+readOnly+' class="form-control input-sm"'+
  1156. (!required?'':'required placeholder="必填*"')+'>';
  1157. } else if(item.logic=='detno') {//序号
  1158. html += '<input ignore="'+ignore+'" type="'+type+'" id="detno" name="'+item.dataIndex+'" value="'+
  1159. (detailsInfo.length+1)+'" readOnly class="form-control input-sm">';
  1160. detailInfo[item.dataIndex].detno = 'detno';//序号特有的特殊标志
  1161. } else if(item.editor.xtype == 'combo') {//下拉选择框
  1162. html += '<select ignore="'+ignore+'" name="'+item.dataIndex+'"class="form-control input-sm">';
  1163. $.each(item.editor.store.data, function(d, da) {
  1164. html += '<option value="' + da.value + '" >'+ da.display + '</option>';
  1165. });
  1166. html += '</select>';
  1167. } else {
  1168. html += '<input ignore="'+ignore+'" type="'+type+'" id="'+item.dataIndex+'" name="'+item.dataIndex+'" value="'+
  1169. (item.value?item.value:'')+'" '+readOnly+' class="form-control input-sm"'+
  1170. (!required?'':'required placeholder="必填*"')+'>';
  1171. }
  1172. } else {
  1173. html += '<input ignore="'+ignore+'" type="'+type+'" id="'+item.dataIndex+'" name="'+item.dataIndex+'" value="'+
  1174. (item.value?item.value:'')+'" '+readOnly+' class="form-control input-sm"'+
  1175. (!required?'':'required placeholder="必填*"')+'>';
  1176. }
  1177. html += '</div>'+
  1178. '<div class="fieldremark">' +
  1179. '<div class=""></div>' +
  1180. '</div>' +
  1181. '</div>' +
  1182. '</div>';
  1183. if(item.dbfind) {//dbFind输入框
  1184. html = '<div class="field-line ' + hidden + '">' +
  1185. '<div class="control-group dropdown">' +
  1186. '<div class="fieldlabel">' +
  1187. '<label class="control-label text-right" for="'+item.dataIndex+'">' +item.header+ ':</label>' +
  1188. '</div>' +
  1189. '<div class="field">'+
  1190. '<input ignore="'+ignore+'" type="'+type+'" id="'+item.dataIndex+'" name="'+item.dataIndex+'" value="'+
  1191. (item.value?item.value:'')+'" '+readOnly+' class="form-control input-sm"'+
  1192. (!required?'':'required placeholder="必填*"')+'>'+
  1193. '</div>'+
  1194. (item.readOnly ? '' : (
  1195. '<div class="fieldremark dropdown-toggle" data-toggle="dropdown">' +
  1196. '<button type="button" dbfind="'+item.dbfind+'" fieldname="'+item.dataIndex+'" class="btn btn-default btn-xs dbFind"><span class="glyphicon glyphicon-search"></button>'+
  1197. '</div>' +
  1198. '<div class="dropdown-menu suggest-box">'+
  1199. '<div class="">'+
  1200. '<ul class="suggest-result">'+
  1201. '</ul>'+
  1202. '</div>'+
  1203. '</div>' )) +
  1204. '</div>' +
  1205. '</div>';
  1206. }
  1207. return html;
  1208. };
  1209. //初始化验证表单输入是否符合条件
  1210. var initFormValidation = function(form) {
  1211. $('input, textarea', form).each(function(i, input){
  1212. var me = $(input);
  1213. if(me.attr('required')) {
  1214. me.blur(function(){
  1215. if(me.val() == '') {
  1216. me.parent('.field').addClass(' has-error');
  1217. } else {
  1218. me.parent('.field').removeClass('has-error');
  1219. }
  1220. });
  1221. }
  1222. });
  1223. }
  1224. //验证表单,通过返回true,不通过返回false,定位到不合格的输入框
  1225. var validateForm = function(form) {
  1226. var validated = true;
  1227. $('input, textarea', form).each(function(i, input){
  1228. var me = $(input);
  1229. if(me.attr('required')) {
  1230. if(me.val() == '') {
  1231. me.parent('.field').addClass(' has-error');
  1232. me.focus();
  1233. validated = false;
  1234. return false;
  1235. } else {
  1236. me.parent('.field').removeClass('has-error');
  1237. }
  1238. }
  1239. });
  1240. return validated;
  1241. };
  1242. //获取radio输入框的值
  1243. var getRadioValue = function(name){
  1244. var value;
  1245. $.each($('[name="'+name+'"]'), function(r, radio){
  1246. if($(radio).attr('checked')) value=$(radio).val();
  1247. return;
  1248. });
  1249. return value;
  1250. };
  1251. // 把表单转换成object
  1252. // item = {'de_no':{'field':'序号','value':'1','ignore':'false','nacessary':'true'},
  1253. // 'de_name':{'field':'编号','value':'xxxxxx','ignore':'false','nacessary':'true}...}
  1254. var parseFormToObj = function(form, obj) {
  1255. if(obj){
  1256. var object = $.extend(true, {}, obj);
  1257. $('input, textarea, select', form).each(function(i, input){
  1258. var me = $(input);
  1259. if(me.attr('type') == 'radio'){//是否选择框
  1260. if(me.attr('checked')) object[me.attr('name')].value = me.val();
  1261. } else {
  1262. object[me.attr('name')].value=me.val();
  1263. }
  1264. });
  1265. } else {
  1266. var object = {}
  1267. $('input, textarea, select', form).each(function(i, input){
  1268. var me = $(input);
  1269. object[me.attr('name')] = {value:'', fieldlabel:'', nacessary: false, ignore:false};
  1270. if(me.attr('type') == 'radio'){//是否选择框
  1271. if(me.attr('checked')) object[me.attr('name')].value = me.val();
  1272. } else {
  1273. object[me.attr('name')].value = me.val();
  1274. }
  1275. });
  1276. }
  1277. return object;
  1278. };
  1279. //将对应的对象显示在表单中
  1280. var parseObjToForm = function(form, obj, isDetail) {
  1281. $('input, textarea, select', form).each(function(i, input){
  1282. var attrName = $(input).attr('name');
  1283. if(_readOnly && !obj[attrName].value) {// 只读模式下所有无值的字段不显示
  1284. $(input).parent().parent().parent().addClass('hidden');
  1285. } else {
  1286. // 只读模式下所有有值的字段都显示
  1287. // 明细行会出现个别名字在某个字段没有值,但不能影响到其他明细行
  1288. if(_readOnly && isDetail) $(input).parent().parent().parent().removeClass('hidden');
  1289. if($(input).attr('type')=='radio'){//是否单选框
  1290. if(obj[attrName].value == $(input).val()) {
  1291. $(input).attr('checked', true);
  1292. } else {
  1293. $(input).removeAttr('checked');
  1294. }
  1295. } else {
  1296. $(input).val(obj[attrName].value);//其他输入框
  1297. }
  1298. }
  1299. });
  1300. initRadio($('.radio-inline'));
  1301. }
  1302. //展现所有的已添加的明细行快照(所谓快照就是只显示一点点东西哦。。)
  1303. var parseCurrentDetails = function(){
  1304. var html = '';
  1305. $.each(detailsInfo, function (d, de) {
  1306. html += '<div class="detail-sub">'+
  1307. '<div class="sub-order"><span class="number">'+(d+1)+'</span></div>';
  1308. $.each(de, function(i, o) {
  1309. if(o.detno){
  1310. o.value = (d+1);
  1311. }
  1312. if(o.nacessary){
  1313. html+= '<b>'+o.fieldlabel+':</b>'+o.value+'&nbsp;&nbsp;&nbsp;&nbsp'
  1314. }
  1315. });
  1316. html += '<br><div class="text-center text-info">点击查看详情</div></div>';
  1317. });
  1318. $('#de-content').html(html);
  1319. $('.detail-sub').click(function(){//展现单个明细行
  1320. var i = parseInt($(this).find('.number').text())-1;
  1321. var de = detailsInfo[i];
  1322. detailIndex = i;
  1323. setLoading(true);
  1324. $('#baseinfo form').hide();
  1325. $('.spread-baseinfo').show();
  1326. $('#add-detail').hide();
  1327. $('#de-form').show();
  1328. $('#detail-handlers').show();
  1329. parseObjToForm($('#de-form'), de, true);
  1330. $('#de-delete').removeAttr('disabled');//删除按钮
  1331. $('#de-modify').removeAttr('disabled');//修改按钮
  1332. $('#de-add').attr('disabled', true);
  1333. setLoading(false);
  1334. // 平滑移到'明细信息'头部
  1335. $('html,body').animate({scrollTop:$('#details').offset().top}, 200);
  1336. });
  1337. };
  1338. $('#de-delete').click(function(){//删除按钮
  1339. detailsInfo.splice(detailIndex, 1);
  1340. parseCurrentDetails();
  1341. $('#detno').val(detailsInfo.length+1);
  1342. $('#de-delete').attr('disabled', true);
  1343. $('#de-modify').attr('disabled', true);
  1344. $('#de-add').removeAttr('disabled');
  1345. });
  1346. $('#de-modify').click(function(){//修改按钮
  1347. detailsInfo[detailIndex] = parseFormToObj($('#de-form'), detailInfo);
  1348. parseCurrentDetails();
  1349. });
  1350. if(caller) {
  1351. getSingleForm(caller, formCondition);//主表
  1352. getSingleGrid(caller, gridCondition);//明细表
  1353. };
  1354. if(username){
  1355. $('#username').text(username);
  1356. }
  1357. });