commonForm.js 48 KB

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