process.js 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884
  1. function reActive(){
  2. //激活tabpanel
  3. var cls = 'active';
  4. $('.nav-tabs>li>a').click(function(){
  5. if(!$(this).hasClass(cls)) {
  6. var nav = $(this).parent().parent(), bd = nav.next(),
  7. old = nav.children('.' + cls).index(),
  8. index = $(this).parent().index();
  9. $('.tab-pane:eq(' + old + ')', bd).removeClass(cls);
  10. $('.tab-pane:eq(' + index + ')', bd).addClass(cls);
  11. var width = $('#topToolbar').width()-$('.nav-tabs>li:eq('+index+')').attr("oldwidth")-2;
  12. var lis = $('.nav-tabs>li');
  13. for(var j=0; j<lis.length;j++){
  14. if(lis[j].id != $('.nav-tabs>li:eq('+index+')')[0].id){
  15. lis[j].style.width = width/(lis.length-1)+'px';
  16. }
  17. }
  18. $('.nav-tabs>li:eq('+index+')')[0].style.width = $('.nav-tabs>li:eq('+index+')').attr("oldwidth")+'px';
  19. nav.children('.' + cls).removeClass(cls);
  20. $(this).parent().addClass(cls);
  21. }
  22. });
  23. }
  24. function getUrlParam(name){
  25. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  26. var r = window.location.search.substr(1).match(reg);
  27. if (r != null)
  28. return decodeURI(r[2]);
  29. return null;
  30. }
  31. function parseDate(date){
  32. var y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate(),
  33. h = date.getHours(), i = date.getMinutes();
  34. var now = new Date(), _y = now.getFullYear(), _m = now.getMonth() + 1, _d = now.getDate();
  35. if(_y != y) {
  36. return y + '-' + m + '-' + d + ' ' + h + ':' + i;
  37. } else {
  38. if(_m != m) {
  39. return m + '月' + d + '号' + h + '点' + i + '分';
  40. } else {
  41. if(_d != d) {
  42. return d + '号' + h + '点' + i + '分';
  43. } else {
  44. return (h < 12 ? '上午' : '下午' ) + h + '点' + i + '分';
  45. }
  46. }
  47. }
  48. }
  49. function setLoading (isLoading) {
  50. $('.loading-container').css('display', isLoading ? 'block' : 'none');
  51. }
  52. function ValidateNumber(e, pnumber) {
  53. if (!/^\d+[.]?\d*$/.test(pnumber)) {
  54. $(e).val(/^\d+[.]?\d*/.exec($(e).val()));
  55. }
  56. return false;
  57. }
  58. function changeEscapeCharacter(da){
  59. var e = da;
  60. if(isNaN(e)){//不是数字
  61. e = e.replace(/\'/g, "&apos;")
  62. .replace(/\"/g, "&quot;")
  63. .replace(/\>/g, "&gt;")
  64. .replace(/\</g, "&lt;");
  65. }
  66. return e;
  67. }
  68. var ignores = [],items = [],dbfinds = {},pageCaller = '',button = {};
  69. //更新明细行,并且重新加载数据
  70. function updateRow (gridId,rowId,caller,instance,keyName,keyValue,mad_code){
  71. $('#'+gridId).jqGrid('setSelection',rowId);
  72. $('#'+gridId).jqGrid('editGridRow',rowId,{
  73. editCaption:'编辑',bSubmit:'保存',bCancel:'关闭',checkOnSubmit:true,checkOnUpdate:true,
  74. closeAfterEdit:true,closeOnEscape:true,
  75. serializeEditData :function(a,b){//序列化传至服务器的参数
  76. delete a.oper;
  77. delete a.id;
  78. if(items.length !=0 && dbfinds.length != 0){//
  79. $.each(dbfinds,function(key,value){
  80. if(typeof(items[value.dbGridField])!= "undefined" )
  81. a[value.field]= items[value.dbGridField];
  82. });
  83. }
  84. //判断是否存在忽略类型 ignore
  85. if(ignores.length > 0 ){
  86. $.each(ignores,function(key,value){
  87. delete a[value];
  88. });
  89. }
  90. var b = new Object();
  91. b._noc = 1;
  92. b.caller = caller;
  93. b.processInstanceId = instance ;
  94. b.formStore = '{'+keyName+':'+keyValue+'}';
  95. b.param = $.toJSON(a);
  96. return b;
  97. },
  98. errorTextFormat:function(a,b){//錯誤捕獲
  99. if(a.responseJSON.exceptionInfo== 'ERR_NETWORK_SESSIONOUT') {
  100. return '保存信息失败,请先登录!';
  101. } else {
  102. return '错误:'+ a.responseJSON.exceptionInfo;
  103. }
  104. },
  105. afterSubmit : function(response, postdata) {
  106. $.showtip("修改明细成功!", 2000);
  107. setLoading(true);
  108. $.ajax({
  109. url:basePath + 'common/loadNewGridStore.action',
  110. type: 'POST',
  111. data: {caller:caller,condition:mad_code +"='"+keyValue+"'",_noc: 1},
  112. success: function(result){
  113. setLoading(false);
  114. $('#'+gridId)[0].addJSONData(result.data);
  115. },
  116. error:function(){
  117. setLoading(false);
  118. }
  119. });
  120. return true;
  121. }
  122. });
  123. }
  124. var requiredFields = null,instance = null;
  125. function saveForm(keyName,keyValue,caller){
  126. //requiredFields array格式
  127. var d = {};
  128. $("#mainForm select[readonly]").removeProp("disabled");
  129. var t = $('#mainForm').serializeArray();
  130. $("#mainForm select[readonly]").prop("disabled", true);
  131. $.each(t, function() {
  132. if($('#'+this.name).attr("logic") || $('#'+this.name).attr("logic") != 'ignore'){ //判断logic的属性是否为ignore 忽略
  133. d[this.name] = this.value;
  134. }
  135. });
  136. var bool = true;
  137. if (requiredFields != null) {//判断必填项是否填写
  138. $.each(requiredFields, function(key, field){
  139. if (d[field] == null || d[field] == "") {
  140. bool = false;
  141. $('#tips').text('保存之前请先填写必填的信息!');
  142. $('#'+field).focus();
  143. return;
  144. }
  145. });
  146. }
  147. //获取改变了的值
  148. $.each(d,function(key,field){//只将修改的值提交到后台
  149. if(d[key] == bill[key])
  150. delete d[key];
  151. });
  152. if($.isEmptyObject(d)){
  153. $.showtip("还未添加或修改数据!", 2000);
  154. return;
  155. }
  156. if (bool) {//获取编辑的字段值
  157. d[keyName] = keyValue;
  158. var b = new Object();
  159. b._noc = 1;
  160. b.caller = caller;
  161. b.processInstanceId = instance;
  162. b.formStore = $.toJSON(d);
  163. setLoading(true);
  164. $.ajax({
  165. url:basePath+"common/processUpdate.action",
  166. type: 'POST',
  167. data: b,
  168. success: function(result){
  169. setLoading(false);
  170. $.showtip("修改成功!", 2000);
  171. var url = window.location.href;
  172. window.location.href = url.substr(0, url.indexOf('?') + 1) + 'nodeId=' + getUrlParam('nodeId');
  173. },
  174. error:function(){
  175. setLoading(false);
  176. }
  177. });
  178. }
  179. }
  180. function loadNewGridStore (gridId,condition){
  181. setLoading(true);
  182. $.ajax({
  183. url:basePath + 'common/loadNewGridStore.action',
  184. type: 'POST',
  185. data: {caller:pageCaller,condition:condition,_noc: 1},
  186. success: function(result){
  187. setLoading(false);
  188. $('#'+gridId).trigger("reloadGrid");
  189. $('#'+gridId)[0].addJSONData(result.data);
  190. },
  191. error:function(){
  192. setLoading(false);
  193. }
  194. });
  195. }
  196. function orient() {
  197. var orientation = (window.innerWidth > window.innerHeight) ?'portrait':'landscape';
  198. document.body.parentNode.setAttribute('class',orientation);
  199. if (window.orientation == 90 || window.orientation == -90) {
  200. //ipad、iphone竖屏;Andriod横屏
  201. $("body").attr("class", "landscape");
  202. orientation = 'landscape';
  203. return false;
  204. }else if (window.orientation == 0 || window.orientation == 180) {
  205. //ipad、iphone横屏;Andriod竖屏
  206. $("body").attr("class", "portrait");
  207. orientation = 'portrait';
  208. return false;
  209. }
  210. }
  211. function autoTextarea (elem, extra, maxHeight) {
  212. extra = extra || 0;
  213. var isFirefox = !!document.getBoxObjectFor || 'mozInnerScreenX' in window,
  214. isOpera = !!window.opera && !!window.opera.toString().indexOf('Opera'),
  215. addEvent = function (type, callback) {
  216. elem.addEventListener ?
  217. elem.addEventListener(type, callback, false) :
  218. elem.attachEvent('on' + type, callback);
  219. },
  220. getStyle = elem.currentStyle ? function (name) {
  221. var val = elem.currentStyle[name];
  222. if (name === 'height' && val.search(/px/i) !== 1) {
  223. var rect = elem.getBoundingClientRect();
  224. return rect.bottom - rect.top -
  225. parseFloat(getStyle('paddingTop')) -
  226. parseFloat(getStyle('paddingBottom')) + 'px';
  227. };
  228. return val;
  229. } : function (name) {
  230. return getComputedStyle(elem, null)[name];
  231. },
  232. minHeight = parseFloat(getStyle('height'));
  233. elem.style.resize = 'none';
  234. var change = function () {
  235. var scrollTop, height,
  236. padding = 0,
  237. style = elem.style;
  238. if (elem._length === elem.value.length) return;
  239. elem._length = elem.value.length;
  240. if (!isFirefox && !isOpera) {
  241. padding = parseInt(getStyle('paddingTop')) + parseInt(getStyle('paddingBottom'));
  242. };
  243. scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  244. elem.style.height = minHeight + 'px';
  245. if (elem.scrollHeight > minHeight) {
  246. if (maxHeight && elem.scrollHeight > maxHeight) {
  247. height = maxHeight - padding;
  248. style.overflowY = 'auto';
  249. } else {
  250. height = elem.scrollHeight - padding;
  251. style.overflowY = 'hidden';
  252. };
  253. style.height = height + extra + 'px';
  254. scrollTop += parseInt(style.height) - elem.currHeight;
  255. document.body.scrollTop = scrollTop;
  256. document.documentElement.scrollTop = scrollTop;
  257. elem.currHeight = parseInt(style.height);
  258. };
  259. };
  260. addEvent('propertychange', change);
  261. addEvent('input', change);
  262. addEvent('focus', change);
  263. change();
  264. };
  265. $(document).ready(function() {
  266. $.event.special.boxready = {
  267. /**
  268. * 初始化事件处理器 - this指向元素
  269. * @param 附加的数据
  270. * @param 事件类型命名空间
  271. * @param 回调函数
  272. */
  273. setup: function(data, namespaces, eventHandle) {
  274. var elem = this;
  275. $.event.add(elem, 'click', function (event) {
  276. if ($.data(elem, '@loaded') !== true) {
  277. $.event.trigger('boxready', null, elem);
  278. $.data(elem, '@loaded', true);
  279. }
  280. });
  281. },
  282. /**
  283. * 卸载事件处理器 - this指向元素
  284. * @param 事件类型命名空间
  285. */
  286. teardown: function(namespaces) {
  287. var elem = this;
  288. $.event.remove(elem, 'click');
  289. $.removeData(elem, '@loaded');
  290. }
  291. };
  292. var readyTime = new Date();
  293. //激活tabpanel
  294. reActive();
  295. // modal dialog
  296. var dialog = {
  297. show: function(title, content, timeout, callback){
  298. var back = $('.modal-backdrop'), modal = $('.modal'),
  299. tt = $('.modal-title', modal), tb = $('.modal-body', modal);
  300. back.css('display', 'block');
  301. modal.css('display', 'block');
  302. tt.text(title);
  303. if(timeout && timeout > 0) {
  304. content = '<div><strong class="text-success text-xl" id="timeout">' + timeout + '</strong>&nbsp;秒后,' + content + '</div>';
  305. }
  306. tb.html(content);
  307. if(timeout) {
  308. var pre = 1000;
  309. if(timeout <=0 ) {// auto close
  310. pre = 1500;
  311. if(!callback)
  312. callback = dialog.hide;
  313. }
  314. var timer = function(t) {
  315. setTimeout(function(){
  316. if(t > -1) {
  317. $('#timeout').text(t--);
  318. timer(t);
  319. } else {
  320. callback && callback.call();
  321. }
  322. }, pre);
  323. };
  324. timer(timeout);
  325. }
  326. },
  327. hide: function() {
  328. var back = $('.modal-backdrop'), modal = $('.modal');
  329. back.css('display', 'none');
  330. modal.css('display', 'none');
  331. }
  332. };
  333. $("#clearbutton").click(function(){
  334. dialog.hide();
  335. });
  336. var parseBillDetail = function(content,i,detail,field,keyValue,keyName){//field 可编辑的字段,keyValue关联主表字段值
  337. var caller = detail[i].mad_caller;
  338. var mad_code = detail[i].mad_code;
  339. var detno_code = detail[i].mad_detnocode;
  340. var condition ,ok = i;
  341. if(caller == "PayPleaseDet"){
  342. condition = mad_code +"=(select ppd_id from (select ppd_id,row_number() over (order by ppd_detno) rn from paypleasedetail where ppd_ppid="+keyValue+") where rn < 2)"
  343. }else if(caller == "PayPleaseDet!YF"){
  344. condition = mad_code +"=(select ppd_id from (select ppd_id,row_number() over (order by ppd_detno) rn from paypleasedetail where ppd_ppid="+keyValue+") where rn < 2)"
  345. }else{
  346. condition = mad_code +"='"+keyValue+"'";
  347. }
  348. setLoading(true);
  349. //获取表的列名,列值
  350. $.ajax({
  351. url:basePath + 'common/singleGridPanel.action',
  352. type: 'POST',
  353. data: {caller:caller,condition:condition,_noc: 1},
  354. success: function(result){
  355. var i = ok;
  356. setLoading(false);
  357. var colModel = [];
  358. if(field.length != 0){
  359. //增加一列编辑列
  360. colModel.push({"label":'编辑',"name":'act',"index":'act',"sorttype":false,"width":75,"editable":false,"frozen":true,"align":'center'});
  361. }
  362. dbfinds = result.dbfinds;
  363. var limits = result.limits,limitarray=new Array();
  364. if(limits && limits.length>0){
  365. for(var i=0;i<limits.length;i++){
  366. limitarray.push(limits[i].lf_field);
  367. }
  368. }
  369. for(var n=0;n<result.columns.length;n++){
  370. var hidden = false;
  371. if(result.columns[n].hidden || result.columns[n].width == 0){
  372. hidden = true;
  373. }
  374. if($.inArray(result.fields[n].name, limitarray) > -1){
  375. hidden = true;
  376. }
  377. //是否为忽略
  378. if(result.columns[n].logic == 'ignore'){//将忽略的保存起来
  379. ignores.push(result.fields[n].name);
  380. }
  381. var editable = false;//是否可编辑列,//编辑类型
  382. var edittype = '', number = false,required = false;
  383. if($.inArray(result.fields[n].name.toLowerCase(), field) > -1){
  384. required = editable = true;
  385. }
  386. if(result.columns[n].xtype == 'numbercolumn'){ //数字类型
  387. edittype = 'text';
  388. number = true;
  389. }else if(result.columns[n].xtype == '' && result.columns[n].editor && result.columns[n].editor.xtype == 'dbfindtrigger'){//dbfind
  390. edittype = 'custom';
  391. var resultDatas = {};
  392. var name = result.fields[n].name;
  393. if(result.columns[n].dbfind){
  394. var ars = result.columns[n].dbfind.split('|');
  395. editoptions = {
  396. dataInit: function (element) {
  397. $(element).autocomplete({ //dbfind字段模糊查询
  398. minLength:1,
  399. source: function(query, proxy) {
  400. $.ajax({
  401. url: basePath+'common/dbfind.action',
  402. dataType: "json",
  403. data: {
  404. which:'grid',
  405. caller:ars[0],
  406. field:name,
  407. condition:"upper("+ars[1]+") like '%"+query.term.toUpperCase()+"%'",
  408. ob:'',
  409. page:1,
  410. pageSize:13
  411. },
  412. success: function (result) {
  413. resultDatas = $.evalJSON(result.data) ;
  414. proxy($.evalJSON(result.data));
  415. }
  416. });
  417. },
  418. select: function(event, ui) {
  419. items = ui.item;
  420. $.each(dbfinds,function(key,value){
  421. if($('input#'+value.field).length != 0 && typeof(ui.item[value.dbGridField])!= "undefined"){
  422. $('input#'+value.field).val(ui.item[value.dbGridField]);
  423. }
  424. });
  425. return false;
  426. }
  427. }).blur(function(event){
  428. if(resultDatas.length != 0){
  429. var id = $(this)[0].id,val= $(this).val(),field;
  430. $.each(dbfinds,function(key,value){
  431. if(value.field == id){
  432. field = value.dbGridField ;
  433. }
  434. });
  435. $.each(resultDatas,function(key,value){
  436. if(value[field] == val){
  437. items = value;
  438. $.each(dbfinds,function(key,da){
  439. if($('input#'+da.field).length != 0 && typeof(value[da.dbGridField])!= "undefined"){
  440. $('input#'+da.field).val(value[da.dbGridField]);
  441. }
  442. });
  443. }
  444. });
  445. }else{
  446. items = [];
  447. }
  448. }).autocomplete("instance" )._renderItem = function( ul, item ) {
  449. return $( "<li>" )
  450. .append( "<a>" + item[ars[1]] + "</a>" )
  451. .appendTo( ul );
  452. };
  453. }
  454. }
  455. }
  456. }else if(result.columns[n].xtype == ''){//基本类型
  457. edittype = 'text';
  458. }else if(result.columns[n].xtype == 'combocolumn' || result.columns[n].xtype == 'yncolumn'){//下拉框类型
  459. edittype='select';
  460. }
  461. if(caller == 'Inquiry' && result.fields[n].name == 'id_isagreed'){
  462. colModel.push({"label":result.columns[n].header,"name":result.fields[n].name,"index":result.fields[n].name,"sorttype":result.fields[n].type,"width":result.columns[n].width,"editable":editable,"edittype":"select",formatter:'select',editoptions:{value:"0:否; 1:未选择; -1:是"},hidden:hidden});
  463. }else if(result.fields[n].name == detno_code){
  464. colModel.push({"label":result.columns[n].header,"name":result.fields[n].name,"index":result.fields[n].name,"sorttype":result.fields[n].type,"width":result.columns[n].width,"editable":true,editoptions: {readonly: 'readonly'},"align":'center'});
  465. }else if(result.columns[n].logic == 'keyField'){//主鍵字段
  466. colModel.push({"label":result.columns[n].header,"name":result.fields[n].name,"index":result.fields[n].name,"sorttype":result.fields[n].type,"width":result.columns[n].width,"editable":true,editoptions: {readonly: 'readonly',edithidden:true},key:true,hidden:hidden});
  467. }else if(edittype == 'select'){//下拉框
  468. var values = '';
  469. if(result.columns[n].xtype == 'yncolumn'){
  470. values = '0:否;-1:是;1:是';
  471. }else{
  472. var data = result.columns[n].editor.store.data;
  473. $.each(data,function(d,va){
  474. values += va.value+":"+va.display+";";
  475. });
  476. }
  477. colModel.push({"label":result.columns[n].header,"name":result.fields[n].name,"index":result.fields[n].name,"sorttype":result.fields[n].type,"width":result.columns[n].width,"editable":editable,"edittype":edittype,formatter:'select',"editoptions":{value:values},hidden:hidden});
  478. }else if(editable && result.fields[n].type == 'date'){//日期类型
  479. colModel.push({"label":result.columns[n].header,"name":result.fields[n].name,"index":result.fields[n].name,"sorttype":result.fields[n].type,"width":result.columns[n].width,"editable":editable,"edittype":edittype,hidden:hidden,
  480. "editoptions":{dataInit: function (element) {
  481. $(element).datepicker({
  482. id: 'orderDate_datePicker',
  483. dateFormat: 'yy-mm-dd',
  484. showOn: 'focus'
  485. });
  486. }}
  487. });
  488. }else if(edittype == 'custom'){//dbfind
  489. colModel.push({"label":result.columns[n].header,"name":result.fields[n].name,"index":result.fields[n].name,"sorttype":result.fields[n].type,"width":result.columns[n].width,"editable":editable,"edittype":'text',"editoptions": editoptions ,hidden:hidden});
  490. }else{
  491. colModel.push({"label":result.columns[n].header,"name":result.fields[n].name,"index":result.fields[n].name,"sorttype":result.fields[n].type,"width":result.columns[n].width,"editable":editable,"edittype":edittype,"editrules":{required:required,number:number},hidden:hidden});
  492. }
  493. }
  494. var data = $.evalJSON(result.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  495. content.html('<table id="grid'+i+'"class="content"></table><div id="pager'+i+'"></div>');
  496. if(caller == 'Inquiry' && button != null){
  497. inquirydetail(i,data,colModel,condition);
  498. }else{
  499. jQuery('#grid'+i).jqGrid({
  500. "hoverrows":false,
  501. "viewrecords":true,
  502. //"styleUI": 'Bootstrap',
  503. "gridview":true,
  504. "data": data,
  505. "scrollPaging":true,
  506. "shrinkToFit":false,
  507. "autoScroll": true,
  508. "width":$('#topToolbar').width(),
  509. "rowNum":20,
  510. "rowList" : [20,40,60],
  511. "datatype": "local",
  512. "colModel":colModel,
  513. gridComplete : function() {//增加一列编辑列
  514. var grid = $(this);
  515. var ids = grid.getDataIDs();
  516. for ( var i = 0; i < ids.length; i++) {
  517. var cl = ids[i];
  518. var id = $(this)[0].id;
  519. be = "<input type='image' src='img/edit.png' id='image1' onclick=\"updateRow('"+$(this)[0].id+"','"+cl+"','"+caller+"','"+instance+"','"+keyName+"','"+keyValue+"','"+mad_code+"');\"/>";
  520. grid.jqGrid('setRowData', ids[i],
  521. {
  522. act : be
  523. });
  524. grid.setRowData(cl, false, {height: 35} );
  525. }
  526. },
  527. "pager":"#pager"+i,
  528. "editurl":basePath+"common/processUpdate.action"
  529. });
  530. jQuery('#grid'+i).jqGrid('navGrid','#pager'+i,{add:false,edit:false,del:false,refresh:false},{reloadAfterSubmit:false},{},{},{multipleSearch:true});
  531. }
  532. },
  533. error: function(xhr){
  534. setLoading(false);
  535. if(xhr.responseText) {
  536. var response = $.evalJSON(xhr.responseText);
  537. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  538. dialog.show('获取用户信息失败', '请先登录!');
  539. } else {
  540. dialog.show('错误', response.exceptionInfo);
  541. }
  542. }
  543. }
  544. });
  545. };
  546. //包含明细增加tab 切换
  547. var addTabPanel = function(cn,detail,fields,keyValue,keyName){
  548. //增加多个tab,如果有明细行
  549. var html = '',html2 = '';
  550. for(var i=0;i<cn;i++){
  551. html += '<li id="detail-header'+i+'"><a><span class="glyphicon glyphicon-list-alt"></span>&nbsp;'+detail[i].mad_name+'</a></li>';
  552. html2 +='<div id="bill-detail'+i+'" class="tab-pane"><div class="empty"></div></div>';
  553. }
  554. $('.nav-tabs>#main-header').after(html);
  555. $('#bill-main').after(html2);
  556. var width = $('#topToolbar').width()-$('.nav-tabs>li.active').width()-2;
  557. var d = width/(i+1)+'px';
  558. var lis = $('.nav-tabs>li');
  559. for(var j=0; j<lis.length;j++){
  560. $('#'+lis[j].id).attr("oldwidth",$('.nav-tabs>li:eq('+j+')').width());
  561. if(lis[j].id != $('.nav-tabs>li.active')[0].id){
  562. lis[j].style.width = d;
  563. }
  564. }
  565. for(var i=0;i<cn;i++){
  566. //生成明细表grid
  567. $('#detail-header'+i).bind('boxready', function(a){
  568. parseBillDetail($('#bill-detail'+a.target.id.split("header")[1]),a.target.id.split("header")[1],detail,fields,keyValue,keyName);
  569. });
  570. }
  571. };
  572. //获取关联明细表
  573. var getDetail = function(fields,keyValue,caller,keyName){
  574. $.ajax({
  575. url:basePath + 'mobile/common/getAuditDetail.action',
  576. type: 'POST',
  577. data: {caller: caller,_noc: 1},
  578. success: function(result){
  579. var detail = result.detail;
  580. if(detail) {
  581. addTabPanel(detail.length,detail,fields,keyValue,keyName);
  582. reActive();
  583. }
  584. },
  585. error: function(xhr){
  586. if(xhr.responseText) {
  587. var response = $.evalJSON(xhr.responseText);
  588. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  589. dialog.show('获取用户信息失败', '请先登录!');
  590. } else {
  591. dialog.show('错误', response.exceptionInfo);
  592. }
  593. }
  594. }
  595. });
  596. };
  597. // parse bill main
  598. var parseBillMain = function(main,button,cond,caller) {
  599. bill = $.evalJSON(main.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  600. var items = main.items;
  601. var bo = false, ifGroup = false;
  602. var sortItems;
  603. $.each(items, function(key, val){
  604. val['readOnly'] = true;
  605. });
  606. if(button != null){//判断是否有可编辑的字段
  607. var fieldsArray = button.jb_fields.split(";");
  608. var neccessaryField = null;
  609. if(button.jt_neccessaryfield){
  610. neccessaryField = button.jt_neccessaryfield.toLowerCase().split(",") ;
  611. }
  612. requiredFields = neccessaryField;
  613. $.each(items, function(key, val){
  614. if (val.groupName == button.jb_buttonname && button.jb_fields.indexOf("#") > 0) {
  615. val['readOnly'] = false;
  616. bo = true;
  617. } else {
  618. if ($.inArray(val.groupName,fieldsArray) > -1) {
  619. val['readOnly'] = false;
  620. bo = true;
  621. }
  622. if (neccessaryField != null && $.inArray(val.name,neccessaryField) > -1) {//编辑字段中是否有必填字段
  623. val.allowBlank = false;
  624. val.fieldStyle = "background:#fffac0;color:#515151;";
  625. } else val.fieldStyle = "background:#FFFAFA;color:#515151;"
  626. }
  627. });
  628. }
  629. if(bo){//有可编辑字段需要按照可编辑排序,和组别排序,通过引入的thenBy.js实现
  630. sortItems = items.sort(
  631. firstBy(function (v1, v2) {
  632. if(!v1.readOnly){
  633. return -1;
  634. }
  635. }
  636. ).thenBy(function (v1, v2) {
  637. return v1.group - v2.group;
  638. })
  639. );
  640. }else{//没有不要排序,按原有顺序显示
  641. sortItems = items;
  642. }
  643. //分组,按照groupName分组
  644. var getMixedGroups = function (items, fields) {
  645. var data = new Object(), k, o;
  646. $.each(items,function(key,d) {
  647. k = '';
  648. o = new Object();
  649. if(d[fields] != null && d[fields] != ''){
  650. k += fields + ':' + d[fields] + ',';
  651. o[fields] = d[fields];
  652. if (k.length > 0) {
  653. if (!data[k]) {
  654. data[k] = {
  655. keys: o,
  656. groups: [d]
  657. };
  658. } else {
  659. data[k].groups.push(d);
  660. }
  661. }
  662. }
  663. });
  664. return data;
  665. }
  666. var tempItems = getMixedGroups(sortItems,'groupName');
  667. if(! $.isEmptyObject(tempItems)){//有分组
  668. sortItems = tempItems;
  669. ifGroup = true;
  670. }
  671. var html = '<form method="post" id="mainForm"> ' +
  672. ' <table class="table table-condensed table-bordered table-striped"><colgroup><col width="40%"></col><col width="60%"></col></colgroup>';
  673. if(bo){//有可编辑的增加保存按钮
  674. var cd = cond.split("=");
  675. html +='<div class="list-group"> <div class="text-center col-xs-8" id="tips" style="color:#FF0000;"> </div>';
  676. html +="<div class='text-right'><button type='button' class='btn-sm' id='jb_buttonid' name='"+button.jb_buttonname+ "' onclick=\"saveForm('"+cd[0]+"',"+cd[1]+",'"+caller+"');\">"+button.jb_buttonname+"</button></div></div>";
  677. }
  678. $.each(sortItems,function(key,d) {
  679. var strData,seData;
  680. if(d.keys){//有分组
  681. if(d.keys.groupName != null){
  682. html += ' <tbody><tr><td colspan="2" class="text-center text-success" id="'+d.keys.groupName+'"><strong>' + d.keys.groupName + '</strong>&nbsp;<span class="glyphicon glyphicon-chevron-down"></span></td></tr> <tbody>';
  683. html += ' <tbody id="'+d.keys.groupName+'0">';
  684. }
  685. for(var i=0;i<d.groups.length;i++){
  686. if(d.groups[i].id != null && d.groups[i].xtype != "hidden" && d.groups[i].fieldLabel != null){
  687. html += '<tr>';
  688. html += '<td class="text-right special" ><strong><label for='+d.groups[i].id+'>' + d.groups[i].fieldLabel+ '</label></strong></td>';
  689. strData = changeEscapeCharacter(bill[d.groups[i].id]);
  690. if(!d.groups[i].readOnly){//可编辑字段
  691. //编辑的类型,下拉框,dbfind,数字类型【需要新增】
  692. if(d.groups[i].xtype == 'combo'){//下拉框
  693. html +='<td class="text-center"><select name="'+d.groups[i].id+'" id="'+d.groups[i].id+'" class="cellElement form-control" style="'+d.groups[i].fieldStyle+'"'+ (d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '') +(d.groups[i].allowBlank ? '' : 'required') +'>';
  694. html +='<option value=""></option>';
  695. $.each(d.groups[i].store.data,function(key,da){
  696. if(bill[d.groups[i].id] == da.value){
  697. html +='<option value="'+da.value+'" selected="selected">'+changeEscapeCharacter(da.display)+'</option>';
  698. }else{
  699. html +='<option value="'+da.value+'">'+changeEscapeCharacter(da.display)+'</option>';
  700. }
  701. });
  702. html+='</select></td>';
  703. }else if(d.groups[i].xtype == "dbfindtrigger"){//dbfind字段
  704. html += '<td class="text-center">' +
  705. '<input type="text" id="'+d.groups[i].id+'" style='+d.groups[i].fieldStyle+
  706. ' name='+ d.groups[i].id+' style='+d.groups[i].fieldStyle +
  707. ' class="cellElement form-control" dbfind value="'+strData +'"'+ (d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '') +(d.groups[i].allowBlank ? '' : 'required') +'/>' +
  708. '</td>';
  709. }else if (d.groups[i].xtype == "multifield"){//MT类型
  710. seData = changeEscapeCharacter(bill[d.groups[i].secondname]);
  711. html += '<td class="text-center">' +
  712. '<input type="text" id="'+d.groups[i].id+'" style='+d.groups[i].fieldStyle+
  713. ' name='+ d.groups[i].id+' style='+d.groups[i].fieldStyle +
  714. ' class="cellElement form-control" dbfind value="'+strData +'"'+ (d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '') +(d.groups[i].allowBlank ? '' : 'required') +'/>' +
  715. '<textarea id='+ d.groups[i].secondname+' readonly class="cellElement setInput" name='+ d.groups[i].secondname+
  716. ' value="'+seData +'">' +seData+'</textarea>'+
  717. '</td>';
  718. }else if(d.groups[i].xtype == 'numberfield'){//数字类型
  719. html += '<td class="text-center">' +
  720. '<input type="text" id='+ d.groups[i].id+' style='+d.groups[i].fieldStyle+
  721. ' name='+ d.groups[i].id+' style='+d.groups[i].fieldStyle +
  722. ' class="cellElement form-control" value="'+bill[d.groups[i].id] +'"'+ (d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '') +(d.groups[i].allowBlank ? '' : 'required') +'onkeyup="return ValidateNumber($(this),value)"/>' +
  723. '</td>';
  724. }else if(d.groups[i].xtype == "erpYnField"){//YN类型,是否有默认值
  725. html +='<td class="text-center"><select name="'+d.groups[i].id+'" id="'+d.groups[i].id+'" class="cellElement form-control" style="'+d.groups[i].fieldStyle+'"'+ (d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '') +(d.groups[i].allowBlank ? '' : 'required') +'>';
  726. if(d.groups[i].value == '-1' || d.groups[i].value == '0'){
  727. if(bill[d.groups[i].id] == '-1' || bill[d.groups[i].id] == '0'){
  728. html +='<option value="-1"'+(bill[d.groups[i].id] == '-1' ? 'selected="selected"' : '')+'>是</option>';
  729. html +='<option value="0"'+(bill[d.groups[i].id] == '0' ? 'selected="selected"' : '')+'>否</option>';
  730. }else{
  731. html +='<option value="-1"'+(d.groups[i].value == '-1'? 'selected="selected"' : '')+'>是</option>';
  732. html +='<option value="0"'+(d.groups[i].value == '0'? 'selected="selected"' : '')+'>否</option>';
  733. }
  734. }else{
  735. html +='<option value=""></option>';
  736. html +='<option value="-1"'+(bill[d.groups[i].id] == '-1' ? 'selected="selected"' : '')+'>是</option>';
  737. html +='<option value="0"'+(bill[d.groups[i].id] == '0' ? 'selected="selected"' : '')+'>否</option>';
  738. }
  739. html+='</select></td>';
  740. }else {//其他类型字段
  741. html += '<td class="text-center">' +
  742. '<input type="text" id='+ d.groups[i].id+' style='+d.groups[i].fieldStyle+
  743. ' name='+ d.groups[i].id+' style='+d.groups[i].fieldStyle +
  744. ' class="cellElement form-control" value="'+strData +'"'+ (d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '') +(d.groups[i].allowBlank ? '' : 'required') +(d.groups[i].xtype =="datefield" ? ' datefield' : '')+'/>' +
  745. '</td>';
  746. }
  747. }else{//不可编辑字段
  748. if(d.groups[i].xtype == "multifield"){//MT类型
  749. seData = changeEscapeCharacter(bill[d.groups[i].secondname]);
  750. html += '<td class="text-center">' +
  751. ' <input type="text" id='+ d.groups[i].id+' readonly name='+ d.groups[i].id+
  752. ' class="cellElement setInput" value="'+strData +'"'+(d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '')+'/>' +
  753. '<textarea id='+ d.groups[i].secondname+' readonly class="cellElement setInput" name='+ d.groups[i].secondname+
  754. ' value="'+seData +'">' +seData+'</textarea>'+
  755. '</td>';
  756. }else if(d.groups[i].xtype == "erpYnField"){//是否类型
  757. html +='<td class="text-center"><select readonly="readonly" name="'+d.groups[i].id+'" id="'+d.groups[i].id+'" class="cellElement" style="'+d.groups[i].fieldStyle+'"'+ (d.groups[i].logic ? 'logic="' + d.groups[i].logic + '"' : '') +(d.groups[i].allowBlank ? '' : 'required') +'>';
  758. if(bill[d.groups[i].id] == '-1' || bill[d.groups[i].id] == '0'){
  759. html +='<option value="-1"'+(bill[d.groups[i].id] == '-1' ? 'selected="selected"' : '')+'>是</option>';
  760. html +='<option value="0"'+(bill[d.groups[i].id] == '0' ? 'selected="selected"' : '')+'>否</option>';
  761. }else{
  762. html +='<option value=""></option>';
  763. html +='<option value="-1"'+(bill[d.groups[i].id] == '-1' ? 'selected="selected"' : '')+'>是</option>';
  764. html +='<option value="0"'+(bill[d.groups[i].id] == '0' ? 'selected="selected"' : '')+'>否</option>';
  765. }
  766. html+='</select></td>';
  767. }else if(d.groups[i].xtype == "htmleditor" || d.groups[i].xtype == "HrOrgSelectfield"){//html格式的直接显示
  768. html += '<td><div style="overflow-y:scroll;width:100px;" class="htmleditor">' +bill[d.groups[i].id]+'</td>';
  769. }else{
  770. html += '<td class="text-center">' +
  771. '<textarea id='+ d.groups[i].id+' readonly class="cellElement setInput" name='+d.groups[i].id+
  772. ' value="'+strData +'">' +strData+'</textarea>'+
  773. '</td>';
  774. }
  775. }
  776. html += '</tr>';
  777. }
  778. }
  779. html+='</tbody>';
  780. }else{//无分组
  781. strData = changeEscapeCharacter(bill[d.id]);
  782. if(d.id != null && d.xtype != "hidden" && d.fieldLabel != null){
  783. html += '<tr>';
  784. html += '<td class="text-right special"><strong><label for='+d.id+'>' + d.fieldLabel+ '</label></strong></td>';
  785. if(d.xtype == "multifield"){ //MT
  786. seData = changeEscapeCharacter(bill[d.secondname]);
  787. html += '<td class="text-center">' +
  788. '<input type="text" id='+ d.id+' readonly class="cellElement setInput" name='+ d.id+
  789. ' value="'+strData +'"'+(d.logic ? 'logic="' + d.logic + '"' : '')+'/>' +
  790. '<textarea id='+ d.secondname+' readonly class="cellElement setInput" name='+ d.secondname+
  791. ' value="'+seData +'">' +seData+'</textarea>'+
  792. '</td>';
  793. }else if(d.xtype == "erpYnField"){
  794. html +='<td class="text-center"><select readonly name="'+d.id+'" id="'+d.id+'" class="cellElement " style="'+d.fieldStyle+'"'+ (d.logic ? 'logic="' + d.logic + '"' : '') +(d.allowBlank ? '' : 'required') +'>';
  795. if(strData == '-1' || strData == '0'){
  796. html +='<option value="-1"'+(strData == '-1' ? 'selected="selected"' : '')+'>是</option>';
  797. html +='<option value="0"'+(strData == '0' ? 'selected="selected"' : '')+'>否</option>';
  798. }else{
  799. html +='<option value=""></option>';
  800. html +='<option value="-1"'+(strData == '-1' ? 'selected="selected"' : '')+'>是</option>';
  801. html +='<option value="0"'+(strData == '0' ? 'selected="selected"' : '')+'>否</option>';
  802. }
  803. html+='</select></td>';
  804. }else if(d.xtype == "htmleditor" || d.xtype == "HrOrgSelectfield"){//html格式的直接显示
  805. html += '<td><div style="overflow-y:scroll;width:100px;" class="htmleditor">' +bill[d.id]+'<div></td>';
  806. }else{
  807. html += '<td class="text-center">' +
  808. '<textarea id='+ d.id+' readonly class="cellElement setInput" name='+ d.id+
  809. ' value="'+strData +'"'+(d.logic ? 'logic="' + d.logic + '"' : '')+'>' +strData+'</textarea>'
  810. '</td>';
  811. }
  812. html += '</tr>';
  813. }else if(d.id != null){//隐藏字段
  814. html += '<input type="hidden" id='+ d.id+' readonly name='+ d.id+
  815. ' value="'+ strData +'"'+(d.logic ? 'logic="' + d.logic + '"' : '')+'/>';
  816. }
  817. }
  818. });
  819. html += '</table></form>';
  820. $('#bill-main').html(html);
  821. $("#mainForm :input[required]:eq(0)").focus();
  822. $('.htmleditor').width($('.htmleditor').parent().width());
  823. if(ifGroup){//有分组点击收缩
  824. $.each(sortItems,function(key,d){
  825. $("#"+d.keys.groupName).click(function(){
  826. $("#"+d.keys.groupName+"0").slideToggle("normal");
  827. });
  828. });
  829. }
  830. var formDbfinds = {},resultData = {};
  831. var dbs = $("#mainForm :input[dbfind]") ;
  832. $.each(dbs,function(key,value){
  833. $('#'+value.id).autocomplete({ //form表DBfind获取数据
  834. minLength: 1,
  835. source: function(query, proxy) {
  836. $.ajax({
  837. url: basePath+'common/dbfind.action',
  838. dataType: "json",
  839. type:'POST',
  840. data: {
  841. which:'form',
  842. caller:caller,
  843. field:$(this)[0].element[0].id,
  844. condition:"upper("+$(this)[0].element[0].id+") like '%"+query.term.toUpperCase()+"%'",
  845. ob:'',
  846. page:1,
  847. pageSize:13
  848. },
  849. success: function (result) {
  850. resultData = $.evalJSON(result.data);
  851. formDbfinds = result.dbfinds;
  852. proxy($.evalJSON(result.data));
  853. }
  854. });
  855. },
  856. select: function(event, ui) {
  857. $.each(formDbfinds,function(key,value){
  858. if($('#'+value.field).length != 0 && typeof(ui.item[value.dbGridField])!= "undefined"){
  859. $('#'+value.field).val(ui.item[value.dbGridField]);
  860. }
  861. });
  862. return false;
  863. }
  864. })/*.focus(function () {
  865. $(this).autocomplete("search");
  866. })*/.blur(function(event){
  867. if(formDbfinds.length != 0){
  868. var id = $(this)[0].id,val= $(this).val(),field;
  869. $.each(formDbfinds,function(key,value){
  870. if(value.field == id){
  871. field = value.dbGridField ;
  872. }
  873. });
  874. $.each(resultData,function(key,value){
  875. if(value[field] == val){
  876. $.each(formDbfinds,function(key,da){
  877. if($('#'+da.field).length != 0 && typeof(value[da.dbGridField])!= "undefined"){
  878. $('#'+da.field).val(value[da.dbGridField]);
  879. }
  880. });
  881. }
  882. });
  883. }
  884. }).autocomplete("instance" )._renderItem = function( ul, item ) {
  885. var id = $(this)[0].element[0].id;
  886. var data ;
  887. $.each(formDbfinds,function(key,value){
  888. if(value.field == id){
  889. data = value.dbGridField ;
  890. }
  891. });
  892. return $( "<li>" )
  893. .append( "<a>" + item[data]+ "</a>" )
  894. .appendTo( ul );
  895. };
  896. });
  897. var areas = $("#mainForm textarea");
  898. $.each(areas,function(key,value){
  899. autoTextarea(value);
  900. });
  901. $("#mainForm select[readonly]").prop("disabled", true);
  902. $("#mainForm :input[datefield]").datepicker({
  903. dateFormat: 'yy-mm-dd',
  904. showOn: 'focus'
  905. });
  906. };
  907. //获取主表数据字段
  908. var getBillMain = function(caller, url, cond, billId,button) {
  909. $.ajax({
  910. url:basePath + 'common/singleFormItems.action',
  911. type: 'POST',
  912. data: {caller: caller, condition: cond, _noc: 1},
  913. success: function(result){
  914. if(result.data) {
  915. parseBillMain(result,button,cond,caller);
  916. }
  917. },
  918. error: function(xhr){
  919. if(xhr.responseText) {
  920. var response =$.evalJSON(xhr.responseText);
  921. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  922. dialog.show('获取用户信息失败', '请先登录!');
  923. } else {
  924. dialog.show('错误', response.exceptionInfo);
  925. }
  926. }
  927. }
  928. });
  929. };
  930. //根据审批流caller 获取页面caller
  931. var getPageCaller = function(nodeCaller,url,callback) {
  932. $.ajax({
  933. url:basePath + 'common/form/getPageCaller.action',
  934. type: 'POST',
  935. data: {caller : nodeCaller,url:url, _noc: 1},
  936. success: function(result){
  937. callback && callback.call(null, result);
  938. },
  939. error: function(xhr){
  940. if(xhr.responseText) {
  941. var response =$.evalJSON(xhr.responseText);
  942. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  943. dialog.show('获取信息失败', '请先登录!');
  944. } else {
  945. dialog.show('错误', response.exceptionInfo);
  946. }
  947. }
  948. }
  949. });
  950. };
  951. //init extra element when VisitRecord
  952. var initVisitRecord = function(main, billId) {
  953. $('#ex').css('display', 'block');
  954. var data = main.data['评价'], title = data ? (data['评分'] || '良') : '良',
  955. msg = data ? data['评语'] : '';
  956. if(title) {
  957. $('#ex-rating button[title="' + title + '"]').addClass('active');
  958. }
  959. $('#ex-msg').val(msg);
  960. $('#ex-rating button').click(function(){
  961. $('#ex-rating button').each(function(){
  962. $(this).removeClass('active');
  963. });
  964. $(this).addClass('active');
  965. });
  966. $('#ex-confirm').click(function(){
  967. msg = $('#ex-msg').val() || '-';
  968. title = '';
  969. $('#ex-rating button').each(function(){
  970. if($(this).hasClass('active'))
  971. title = $(this).attr('title');
  972. });
  973. setLoading(true);
  974. $.ajax({
  975. url:basePath + 'crm/customermgr/updateVisitRecordPingjia.action',
  976. type: 'POST',
  977. data: {id: billId, vr_newtitle: title, vr_purpose: msg, _noc: 1},
  978. success: function(result){
  979. setLoading(false);
  980. dialog.show('提示', '评价成功', -1);
  981. },
  982. error: function(xhr){
  983. setLoading(false);
  984. if(xhr.responseText) {
  985. var response =$.evalJSON(xhr.responseText);
  986. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  987. dialog.show('获取信息失败', '请先登录!');
  988. } else {
  989. dialog.show('错误', response.exceptionInfo);
  990. }
  991. }
  992. }
  993. });
  994. });
  995. };
  996. // parse main point
  997. var parseMainPoint = function(points) {
  998. var html = '<ul class="list-group">';
  999. html += '<li class="list-group-item disabled"><strong>问题要点</strong></li>';
  1000. $.each(points, function(i, p){
  1001. html += '<li class="list-group-item">';
  1002. html += '<span>' + p.text + '</span>';
  1003. if(p.type === 'B') {//boolean
  1004. html += '<div class="pull-right"><div class="has-switch switch-small"><div class="' + (p.value && p.value != '是' ? 'switch-off' : 'switch-on') + ' switch-animate"><input type="checkbox" ' + (p.value && p.value != '是' ? '' : 'checked') + ' title="' + p.text + '" ' + (p.logic ? 'logic="' + p.logic + '"' : '') +(p.required ? 'required' : '') + '> <span class="switch-left switch-success switch-small">是</span> <label class="switch-small">&nbsp;</label> <span class="switch-right switch-warning switch-small">否</span></div></div></div>';
  1005. } else if(p.type === 'S' ) {//字符串
  1006. html += '<div class="pull-right"><input class="form-control input-xs" type="text" placeholder="..." value="' + (p.value || '') + '" ' + (p.logic ? 'logic="' + p.logic + '"' : '') + ' title="' + p.text + '" ' + (p.required ? 'required' : '') + '></div>';
  1007. } else if(p.type === 'D') {//日期
  1008. html += '<div class="pull-right"><input class="form-control input-xs" type="date" placeholder="..." value="' + (p.value || '') + '" ' + (p.logic ? 'logic="' + p.logic + '"' : '') + ' title="' + p.text + '" ' + (p.required ? 'required' : '') + '></div>';
  1009. }else if(p.type === 'C'){//下拉框
  1010. html += '<div class="pull-right"><select class="form-control input-xs" '+ (p.logic ? 'logic="' + p.logic + '"' : '') + ' title="' + p.text + '" ' + (p.required ? 'required' : '') + ' ><option></option>';
  1011. $.each(p.data,function(i,da){
  1012. html+='<option value="'+da+'"'+(da==p.value ? 'selected="selected"' : ' ')+'>'+da+'</option>'
  1013. });
  1014. html +='</select></div>';
  1015. }else if(p.type === 'N'){//数字型
  1016. html += '<div class="pull-right">'+'<input class="form-control input-xs numbertype" type="text" placeholder="..." value="' + (p.value || '') + '" ' + (p.logic ? 'logic="' + p.logic + '"' : '') + ' title="' + p.text + '" ' + (p.required ? 'required' : '') + ' onkeyup="return ValidateNumber($(this),value)"></div>';
  1017. }
  1018. html += '</li>';
  1019. });
  1020. html += '</ul>';
  1021. $('#points').html(html);
  1022. // toggle switch
  1023. $('#points .has-switch').click(function(){
  1024. var e = $(this), box = e.find('input'), checked = box.is(':checked');
  1025. if(checked)
  1026. box.removeAttr('checked');
  1027. else
  1028. box.attr('checked','checked');
  1029. e.find('>div').removeClass(checked ? 'switch-on' : 'switch-off');
  1030. e.find('>div').addClass(checked ? 'switch-off' : 'switch-on');
  1031. });
  1032. };
  1033. var getMainPoint = function(id) {
  1034. $.ajax({
  1035. url:basePath + 'common/getCustomSetupOfTask.action',
  1036. type: 'POST',
  1037. data: {nodeId: id, _noc: 1},
  1038. success: function(result){
  1039. if(result.cs) {
  1040. var points = [], data = result.data ? result.data.split(';') : [];
  1041. $.each(result.cs, function(i, c){
  1042. var m = c.indexOf('^'), n = c.indexOf('$'), q = c.indexOf('@');
  1043. points.push({
  1044. type: c.substring(m + 1, n),
  1045. text: c.substring(0, m),
  1046. required: c.substr(n + 1, 1) === 'Y',
  1047. value: data[i] ? data[i].substring(data[i].lastIndexOf("(") + 1, data[i].lastIndexOf(")")) : null,
  1048. logic: q > 0 ? c.substring(q + 1) : null,
  1049. data : c.substring(c.indexOf('[')+1,c.indexOf(']')).split(";")
  1050. });
  1051. });
  1052. if(points.length > 0)
  1053. parseMainPoint(points);
  1054. }
  1055. },
  1056. error: function(xhr){
  1057. if(xhr.responseText) {
  1058. var response =$.evalJSON(xhr.responseText);
  1059. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1060. dialog.show('获取信息失败', '请先登录!');
  1061. } else {
  1062. dialog.show('错误', response.exceptionInfo);
  1063. }
  1064. }
  1065. }
  1066. });
  1067. };
  1068. var parseNode = function(node,button) {
  1069. current = node;
  1070. $('#jp_name').text(node.jp_name);
  1071. $('#jp_name').css('margin-left', "-" + node.jp_name.replace(/[^\x00-\xff]/g, 'xx').length * 7 + "px");
  1072. $('#jp_nodeName').text(node.jp_nodeName);
  1073. $('#jp_launcherName').text(node.jp_launcherName);
  1074. $('#jp_launchTime').text(parseDate(new Date(node.jp_launchTime)));
  1075. $('#jp_codevalue').text(node.jp_codevalue);
  1076. getPageCaller(node.jp_caller,node.jp_url,function(caller){
  1077. //根据node
  1078. var fields = [];var bol = false;
  1079. pageCaller = caller;
  1080. if(button != null){//判断编辑字段
  1081. var buttontype = button.jb_fields;
  1082. var neccessaryField = button.jt_neccessaryfield ;
  1083. if(neccessaryField != null){
  1084. neccessaryField = neccessaryField.toLowerCase();
  1085. }
  1086. if(buttontype == 'updatedetail'){
  1087. if (neccessaryField != null){
  1088. fields = neccessaryField.split(",");
  1089. }
  1090. }else if (buttontype.indexOf('#') > 0) {
  1091. }else{//主表编辑字段
  1092. bol = true;
  1093. }
  1094. }
  1095. // get bill main data
  1096. if(node.jp_keyName && node.jp_keyValue && bol) {
  1097. getBillMain(caller, node.jp_url, node.jp_keyName + '=\'' + node.jp_keyValue + '\'', node.jp_keyValue,button);
  1098. }else{
  1099. getBillMain(caller, node.jp_url, node.jp_keyName + '=\'' + node.jp_keyValue + '\'', node.jp_keyValue);
  1100. }
  1101. // has detail
  1102. if(node.jp_formDetailKey) {
  1103. //获取明细表个数
  1104. getDetail(fields,node.jp_keyValue,caller,node.jp_keyName);
  1105. }
  1106. });
  1107. // main point
  1108. getMainPoint(node.jp_nodeId);
  1109. //deal relative
  1110. if(true){
  1111. dealRelative(node.jp_caller);
  1112. }
  1113. };
  1114. //获取审批流设置的信息
  1115. var getProcess = function(id) {
  1116. setLoading(true);
  1117. $.ajax({
  1118. url:basePath + 'common/getCurrentNode.action',
  1119. type: 'POST',
  1120. data: {jp_nodeId: id, _noc: 1},
  1121. success: function(result){
  1122. setLoading(false);
  1123. instance = result.info.InstanceId;
  1124. button = result.info.button;
  1125. parseNode(result.info.currentnode,result.info.button);
  1126. },
  1127. error: function(xhr,a,b,c){
  1128. setLoading(false);
  1129. if(xhr.responseText) {
  1130. var response =$.evalJSON(xhr.responseText);
  1131. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1132. dialog.show('获取信息失败', '请先登录!');
  1133. } else {
  1134. dialog.show('错误', response.exceptionInfo,-1);
  1135. }
  1136. }
  1137. }
  1138. });
  1139. };
  1140. var getHistory = function(instanceId, callback) {
  1141. setLoading(true);
  1142. $.ajax({
  1143. url:basePath + 'common/getAllHistoryNodes.action',
  1144. type: 'POST',
  1145. data: {processInstanceId: instanceId, _noc: 1},
  1146. success: function(result){
  1147. setLoading(false);
  1148. if(callback)
  1149. callback.call(null, result.nodes);
  1150. if(result.nodes && result.nodes.length > 0) {
  1151. parseHistory(result.nodes);
  1152. }
  1153. },
  1154. error: function(xhr){
  1155. setLoading(false);
  1156. if(xhr.responseText) {
  1157. var response =$.evalJSON(xhr.responseText);
  1158. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1159. dialog.show('获取用户信息失败', '请先登录!');
  1160. } else {
  1161. dialog.show('错误', response.exceptionInfo);
  1162. }
  1163. }
  1164. }
  1165. });
  1166. };
  1167. var getAllHistory = function(nodeId, callback) {
  1168. setLoading(true);
  1169. $.ajax({
  1170. url:basePath + 'common/getAllHistoryNodesByNodeId.action',
  1171. type: 'POST',
  1172. data: {nodeId:nodeId, _noc: 1},
  1173. success: function(result){
  1174. setLoading(false);
  1175. if(callback)
  1176. callback.call(null, result.nodes);
  1177. if(result.nodes && result.nodes.length > 0) {
  1178. parseAllHistory(result.nodes);
  1179. }
  1180. },
  1181. error: function(xhr){
  1182. setLoading(false);
  1183. if(xhr.responseText) {
  1184. var response =$.evalJSON(xhr.responseText);
  1185. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1186. dialog.show('获取用户信息失败', '请先登录!');
  1187. } else {
  1188. dialog.show('错误', response.exceptionInfo);
  1189. }
  1190. }
  1191. }
  1192. });
  1193. };
  1194. var getInstance = function(id, callback) {
  1195. $.ajax({
  1196. url:basePath + 'common/getProcessInstanceId.action',
  1197. type: 'POST',
  1198. data: {jp_nodeId: id, _noc: 1},
  1199. success: function(result){
  1200. instance = result.processInstanceId;
  1201. callback && callback.call(null, instance);
  1202. },
  1203. error: function(xhr){
  1204. if(xhr.responseText) {
  1205. var response =$.evalJSON(xhr.responseText);
  1206. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1207. dialog.show('获取信息失败', '请先登录!');
  1208. } else {
  1209. dialog.show('错误', response.exceptionInfo);
  1210. }
  1211. }
  1212. }
  1213. });
  1214. };
  1215. var parseHistory = function(hist) {
  1216. var html = '<ul class="list-unstyled list-inline">';
  1217. $.each(hist, function(i, h){
  1218. var res = h.jn_dealResult == '同意' ? 'success' : (h.jn_dealResult == '不同意' ? 'error' : 'warning');
  1219. html += '<li>';
  1220. html += '<div class="text-top">';
  1221. html += '<span>' + h.jn_name + '</span>';
  1222. html += '</div>';
  1223. html += '<blockquote>';
  1224. html += '<strong>' + h.jn_dealManName + '</strong>';
  1225. html += '<div>审批意见:' + (h.jn_nodeDescription == null ? "无":h.jn_nodeDescription) + '</div>';
  1226. html += '<div class="text-trans ' + res + '">';
  1227. html += '<span>' + h.jn_dealResult + '</span>';
  1228. html += '</div>';
  1229. html += '<footer>' + h.jn_dealTime + '</footer>';
  1230. html += '</blockquote>';
  1231. if(h.jn_operatedDescription || h.jn_infoReceiver) {
  1232. html += '<div class="highlight">';
  1233. if(h.jn_infoReceiver)
  1234. html += '<p class="text-muted"><i>变更处理人:' + h.jn_infoReceiver + '</i></p>';
  1235. if(h.jn_operatedDescription) {
  1236. if(h.jn_operatedDescription.indexOf('(是)') > 0 ||
  1237. h.jn_operatedDescription.indexOf('(否)') > 0) {
  1238. html += '<ul class="list-group">';
  1239. var descs = h.jn_operatedDescription.split(';');
  1240. $.each(descs, function(j, d){
  1241. res = d.substr(d.length - 3) == '(是)' ? 'glyphicon glyphicon-ok text-success' :
  1242. 'glyphicon glyphicon-remove text-warning';
  1243. html += '<li class="list-group-item"><span class="pull-right ' + res + '"></span>' + d.substr(0, d.length-3) + '</li>';
  1244. });
  1245. html += '</ul>';
  1246. } else {
  1247. if("null"!=h.jn_operatedDescription)
  1248. html += '<div>管理要点:' + h.jn_operatedDescription + '</div>';
  1249. }
  1250. }
  1251. html += '</div>';
  1252. }
  1253. html += '</li>';
  1254. });
  1255. html += '</ul>';
  1256. $('#history').html(html);
  1257. };
  1258. var parseAllHistory = function(hist) {
  1259. var html = '<ul class="list-unstyled list-inline">';
  1260. $.each(hist, function(i, h){
  1261. var res = h.jn_dealResult == '同意' ? 'success' : (h.jn_dealResult == '不同意' ? 'error' : 'warning');
  1262. html += '<li>';
  1263. html += '<div width:100% class="text-top">';
  1264. html += '<span>' + h.jn_name + '</span>';
  1265. html += '</div>';
  1266. html += '<blockquote>';
  1267. html += '<strong>' + h.jn_dealManName + '</strong>';
  1268. html += '<div>审批意见:' + (h.jn_nodeDescription == null ? "无":h.jn_nodeDescription) + '</div>';
  1269. html += '<div class="text-trans ' + res + '">';
  1270. html += '<span>' + h.jn_dealResult + '</span>';
  1271. html += '</div>';
  1272. html += '<footer>' + h.jn_dealTime + '</footer>';
  1273. html += '</blockquote>';
  1274. if(h.jn_operatedDescription || h.jn_infoReceiver) {
  1275. html += '<div class="highlight">';
  1276. if(h.jn_infoReceiver)
  1277. html += '<p class="text-muted" ><i> 变更处理人:' + h.jn_infoReceiver + '</i></p>';
  1278. if(h.jn_operatedDescription) {
  1279. if(h.jn_operatedDescription.indexOf('(是)') > 0 ||
  1280. h.jn_operatedDescription.indexOf('(否)') > 0) {
  1281. html += '<ul class="list-group">';
  1282. var descs = h.jn_operatedDescription.split(';');
  1283. $.each(descs, function(j, d){
  1284. res = d.substr(d.length - 3) == '(是)' ? 'glyphicon glyphicon-ok text-success' :
  1285. 'glyphicon glyphicon-remove text-warning';
  1286. html += '<li class="list-group-item"><span class="pull-right ' + res + '"></span>' + d.substr(0, d.length-3) + '</li>';
  1287. });
  1288. html += '</ul>';
  1289. } else {
  1290. if("null"!=h.jn_operatedDescription)
  1291. html += '<div>管理要点:' + h.jn_operatedDescription + '</div>';
  1292. }
  1293. }
  1294. html += '</div>';
  1295. }
  1296. html += '</li>';
  1297. });
  1298. html += '</ul>';
  1299. $('#all-history').html(html);
  1300. };
  1301. // get process by node id
  1302. var nodeId = getUrlParam('nodeId');
  1303. if (nodeId) {
  1304. getProcess(nodeId);
  1305. // get history by instance id
  1306. $('#history-header').bind('boxready', function(){
  1307. if(instance) {
  1308. getHistory(instance);
  1309. } else {
  1310. getInstance(nodeId, function(instanceId){
  1311. getHistory(instanceId);
  1312. });
  1313. }
  1314. });
  1315. $('#all-history-header').bind('boxready',function(){
  1316. getAllHistory(nodeId);
  1317. });
  1318. }
  1319. // get radio,checkbox value
  1320. var getBoxValue = function(selector) {
  1321. var value = null;
  1322. $(selector).each(function(){
  1323. var t = $(this);
  1324. if(t.is(":checked")) {
  1325. value = t.val();
  1326. }
  1327. });
  1328. return value;
  1329. };
  1330. // node next step
  1331. var nextStep = function(callback) {
  1332. $.post(basePath + 'common/dealNextStepOfPInstance.action', {
  1333. processInstanceId: instance,
  1334. _noc: 1
  1335. }, function(result, text) {
  1336. if(result.hasNext) {
  1337. if (result.actorUsers.length > 0 && result.actorUsers[0].JP_CANDIDATES.length>0) {
  1338. var html = '<p>';
  1339. html += "下一步审批节点有多位处理人,请指定一位:";
  1340. html += '</p>';
  1341. html += '<form>';
  1342. html += '<div class="form-group" style="max-height:150px;overflow-y:auto;">';
  1343. $.each(result.actorUsers[0].JP_CANDIDATES, function(i, u){
  1344. html += '<label class="radio-inline" style="margin-bottom:10px;margin-right:20px;">';
  1345. html += '<input type="radio" name="user" value="' + u + '"' +
  1346. (i == 0 ? ' checked="checked"' : '') + ' style="position:static;"> ' + u;
  1347. html += '</label>';
  1348. });
  1349. html += '</div>';
  1350. html += '<div class="btn-group btn-group-xs btn-group-justified">';
  1351. html += '<div class="btn-group"><button type="button" class="btn btn-primary" id="confirm">指定</button></div>';
  1352. html += '<div class="btn-group"><button type="button" class="btn btn-default" id="cancel">暂不指定</button></div>';
  1353. html += '</div>';
  1354. html += '</form>';
  1355. dialog.show('下一步', html);
  1356. // choose one to handle next node
  1357. $('#confirm').click(function(){
  1358. appointNext(result.actorUsers[0].JP_NODEID, getBoxValue('form input[type="radio"]'), callback);
  1359. });
  1360. // notice evenyone to receive next node
  1361. $('#cancel').click(function(){
  1362. noticeNext(result.actorUsers[0].JP_NODEID, result.actorUsers[0].JP_CANDIDATES, callback);
  1363. });
  1364. } else {
  1365. callback && callback.call();
  1366. }
  1367. }
  1368. });
  1369. };
  1370. // appoint one to deal next
  1371. var appointNext = function(nodeId, user, callback) {
  1372. $.ajax({
  1373. url:basePath + 'common/takeOverTask.action',
  1374. type: 'POST',
  1375. data: {em_code: user.substring(user.lastIndexOf('(') + 1, user.length - 1), nodeId: nodeId, _noc: 1},
  1376. success: function(result){
  1377. if(result.success)
  1378. callback && callback.call();
  1379. },
  1380. error: function(xhr){
  1381. if(xhr.responseText) {
  1382. var response =$.evalJSON(xhr.responseText);
  1383. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1384. dialog.show('获取信息失败', '请先登录!');
  1385. } else {
  1386. dialog.show('指派失败', response.exceptionInfo);
  1387. }
  1388. }
  1389. }
  1390. });
  1391. };
  1392. // notice next users
  1393. var noticeNext = function(nodeId, users, callback) {
  1394. $.ajax({
  1395. url:basePath + 'common/processpaging.action',
  1396. type: 'POST',
  1397. data: {persons: unescape(users.join(',')), nodeId: nodeId, _noc: 1},
  1398. success: function(result){
  1399. if(result.success)
  1400. callback && callback.call();
  1401. },
  1402. error: function(xhr){
  1403. if(xhr.responseText) {
  1404. var response =$.evalJSON(xhr.responseText);
  1405. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1406. dialog.show('获取信息失败', '请先登录!');
  1407. } else {
  1408. dialog.show('错误', response.exceptionInfo);
  1409. }
  1410. }
  1411. }
  1412. });
  1413. };
  1414. // load next process
  1415. var processNext = function(id) {
  1416. if(id != '-1') {
  1417. var url = window.location.href;
  1418. window.location.href = url.substr(0, url.indexOf('?') + 1) + 'nodeId=' + id;
  1419. } else {
  1420. dialog.show('提示', '暂时没有新的审批任务了!');
  1421. }
  1422. };
  1423. // is valid
  1424. var isValid = function() {
  1425. var bo = true;
  1426. var deals = $('#points input');
  1427. if(deals.length > 0) {
  1428. $.each(deals, function(i, d){
  1429. var e = $(d), type = e.attr('type'), val = e.val();
  1430. if((type === 'text' || type === 'date') && (e.attr('required') === 'required') && !val ){
  1431. bo = false;
  1432. }
  1433. });
  1434. }
  1435. deals = $('#points select');
  1436. if(deals.length > 0) {
  1437. $.each(deals, function(i, d){
  1438. var e = $(d), val = e.val();
  1439. if((e.attr('required') === 'required') && !val)
  1440. bo = false;
  1441. });
  1442. }
  1443. return bo;
  1444. };
  1445. // get your points
  1446. var getDealPoints = function() {
  1447. var deals = $('#points input');
  1448. if(deals.length > 0) {
  1449. var points = [];
  1450. $.each(deals, function(i, d){
  1451. var e = $(d), text = e.attr('title'), type = e.attr('type'), val = e.val(),
  1452. lg = e.attr('logic');
  1453. val = type == 'checkbox' ? (e.is(':checked') ? '是' : '否') : val;
  1454. points.push(text + '(' + val + ')' + (lg ? '@' + lg + '@' : ''));
  1455. });
  1456. return points.join(';');
  1457. }else {
  1458. deals = $('#points select');
  1459. if(deals.length > 0) {
  1460. var points = [];
  1461. $.each(deals, function(i, d){
  1462. var e = $(d),text = e.attr('title'),val = e.val(),lg = e.attr('logic');
  1463. points.push(text + '(' + val + ')' + (lg ? '@' + lg + '@' : ''));
  1464. });
  1465. return points.join(';');
  1466. }
  1467. }
  1468. return null;
  1469. };
  1470. // agree
  1471. var agree = function() {
  1472. var d = {};
  1473. var bool = true;
  1474. if(document.getElementById("jb_buttonid")){
  1475. $("#mainForm select[readonly]").removeProp("disabled");
  1476. var t = $('#mainForm').serializeArray();
  1477. $("#mainForm select[readonly]").prop("disabled", true);
  1478. $.each(t, function() {
  1479. if($('#'+this.name).attr("logic") || $('#'+this.name).attr("logic") != 'ignore'){ //判断logic的属性是否为ignore 忽略
  1480. d[this.name] = this.value;
  1481. }
  1482. });
  1483. //判断主表是否存在未填写的必填字段
  1484. if (requiredFields != null) {//判断必填项是否填写
  1485. $.each(requiredFields, function(key, field){
  1486. if (d[field] == null || d[field] == "") {
  1487. bool = false;
  1488. $.showtip("保存之前请先填写必填的信息!", 2000);
  1489. $('#'+field).focus();
  1490. return;
  1491. }
  1492. });
  1493. }
  1494. if(!bool){
  1495. return ;
  1496. }
  1497. //获取改变了的值
  1498. var e='';
  1499. var f='';
  1500. $.each(d,function(key,field){//只将修改的值提交到后台
  1501. e = d[key];
  1502. if(isNaN(e)){
  1503. e = e.replace(/\n/g,'').replace(/\r/g,'');
  1504. }
  1505. f = bill[key];
  1506. if(isNaN(f)){
  1507. f = f.replace(/\n/g,'').replace(/\r/g,'');
  1508. }
  1509. if(e == f) {
  1510. delete d[key];
  1511. }
  1512. });
  1513. if(!$.isEmptyObject(d)){
  1514. $.showtip("请先保存修改的数据,再执行后续操作!", 2000);
  1515. return;
  1516. }
  1517. }
  1518. //判断从表是否存在未填写的必填字段
  1519. if(!isValid()) {
  1520. dialog.show(' 警告', '您还有审批要点问题没处理!', -1);
  1521. return;
  1522. }
  1523. setLoading(true);
  1524. $.ajax({
  1525. url:basePath + 'common/review.action',
  1526. type: 'POST',
  1527. data: {taskId: nodeId, nodeName: current.jp_nodeName, nodeLog: $('#deal-msg').val(),
  1528. holdtime: ((new Date() - readyTime) / 1000).toFixed(0),customDes: getDealPoints(),result: true,_noc: 1},
  1529. success: function(result){
  1530. setLoading(false);
  1531. if(result.success) {
  1532. if (result.nextnode == '0') {
  1533. dialog.show('审批成功', '您暂时没有其它的审批任务了。');
  1534. } else {
  1535. if(result.after) {
  1536. if (result.after.trim().substr(0, 12) == 'AFTERSUCCESS') {
  1537. dialog.show('审批出现提示:' + result.after.replace('AFTERSUCCESS', ''),
  1538. '自动为您跳转到下一条...', 5, function(){
  1539. nextStep(function(){
  1540. processNext(result.nextnode);
  1541. });
  1542. });
  1543. } else {
  1544. dialog.show('审批出现异常', result.after);
  1545. }
  1546. } else {
  1547. dialog.show('审批成功', '自动为您跳转到下一条...', 1, function(){
  1548. nextStep(function(){
  1549. processNext(result.nextnode);
  1550. });
  1551. });
  1552. }
  1553. }
  1554. }
  1555. },
  1556. error: function(xhr){
  1557. setLoading(false);
  1558. if(xhr.responseText) {
  1559. var response =$.evalJSON(xhr.responseText);
  1560. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1561. dialog.show('获取用户信息失败', '请先登录!');
  1562. } else {
  1563. dialog.show('无法审批', response.exceptionInfo);
  1564. }
  1565. }
  1566. }
  1567. });
  1568. };
  1569. $('#agree').click(function(){//点击我同意按钮事件
  1570. agree();
  1571. });
  1572. // disagree -> return back
  1573. var disagree = function(backNode, msg){
  1574. setLoading(true);
  1575. $.ajax({
  1576. url:basePath + 'common/review.action',
  1577. type: 'POST',
  1578. data: {taskId: nodeId, nodeName: current.jp_nodeName, backTaskName: backNode, nodeLog: msg,
  1579. holdtime: ((new Date() - readyTime) / 1000).toFixed(0), result: false, _noc: 1},
  1580. success: function(result){
  1581. setLoading(false);
  1582. if(result.success) {
  1583. if(result.after) {
  1584. dialog.show('回退过程出现提示:' + result.after);
  1585. } else {
  1586. dialog.show('回退成功', '自动为您跳转到下一条...', 1, function(){
  1587. nextStep(function(){
  1588. processNext(result.nextnode);
  1589. });
  1590. });
  1591. }
  1592. } else {
  1593. dialog.show('处理结果', "该任务已处理,不能重复操作!");
  1594. }
  1595. },
  1596. error: function(xhr){
  1597. setLoading(false);
  1598. if(xhr.responseText) {
  1599. var response =$.evalJSON(xhr.responseText);
  1600. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1601. dialog.show('获取用户信息失败', '请先登录!');
  1602. } else {
  1603. dialog.show('错误', response.exceptionInfo);
  1604. }
  1605. }
  1606. }
  1607. });
  1608. };
  1609. $('#disagree').click(function(){
  1610. getHistory(instance, function(nodes){
  1611. var html = '<form>';
  1612. html += '<div class="form-group">';
  1613. html += '<label class="radio-inline">';
  1614. html += '<input type="radio" name="node" value="RECORDER" checked="checked"> 制单人';
  1615. html += '</label>';
  1616. $.each(nodes, function(i, n){
  1617. if(n.jn_attach=='T'){
  1618. html += '<label class="radio-inline">';
  1619. html += '<input type="radio" name="node" value="' + n.jn_name + '"> ' + n.jn_name;
  1620. html += '</label>';
  1621. }
  1622. });
  1623. html += '</div>';
  1624. html += '<div class="form-group"><textarea id="back-msg" rows="2" placeholder="填写您不同意的原因..." class="form-control">' + $('#deal-msg').val() + '</textarea><span class="help-block text-lg text-error" id="back_err"></span></div>';
  1625. html += '<div class="btn-group btn-group-xs btn-group-justified">';
  1626. html += '<div class="btn-group"><button type="button" class="btn btn-primary" id="back">回退</button></div>';
  1627. html += '<div class="btn-group"><button type="button" class="btn btn-default" id="cancel2">取消</button></div>';
  1628. html += '</div>';
  1629. html += '</form>';
  1630. dialog.show('回退到节点', html);
  1631. // choose one to back
  1632. $('#back').click(function(){
  1633. var msg = $('#back-msg').val();
  1634. if (!msg) {
  1635. $('#back_err').text('请填写您不同意的原因!');
  1636. $('#back-msg').focus();
  1637. } else {
  1638. disagree(getBoxValue('form input[type="radio"]'), msg);
  1639. }
  1640. });
  1641. // cancel
  1642. $('#cancel2').click(function(){
  1643. dialog.hide();
  1644. });
  1645. });
  1646. });
  1647. // end
  1648. var end = function(){
  1649. setLoading(true);
  1650. $.ajax({
  1651. url:basePath + 'common/endProcessInstance.action',
  1652. type: 'POST',
  1653. data: {processInstanceId: instance, holdtime: ((new Date() - readyTime) / 1000).toFixed(0),
  1654. nodeId: nodeId, _noc: 1},
  1655. success: function(result){
  1656. setLoading(false);
  1657. if(result.success) {
  1658. dialog.show('流程已结束', '自动为您跳转到下一条...', 1, function(){
  1659. nextStep(function(){
  1660. processNext(result.nextnode);
  1661. });
  1662. });
  1663. } else {
  1664. dialog.show('警告', "流程实例不存在!");
  1665. }
  1666. },
  1667. error: function(xhr){
  1668. setLoading(false);
  1669. if(xhr.responseText) {
  1670. var response =$.evalJSON(xhr.responseText);
  1671. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1672. dialog.show('获取用户信息失败', '请先登录!');
  1673. } else {
  1674. dialog.show('错误', response.exceptionInfo);
  1675. }
  1676. }
  1677. }
  1678. });
  1679. };
  1680. $('#end').click(function(){
  1681. end();
  1682. });
  1683. // change
  1684. var change = function(user, msg){
  1685. if(!user) {
  1686. $('#change_err').text('您还没选择变更人!');
  1687. return;
  1688. }
  1689. if(!isValid()) {
  1690. $('#change_err').text('您还有审批要点问题没处理!');
  1691. return;
  1692. }
  1693. setLoading(true);
  1694. $.ajax({
  1695. url:basePath + 'common/setAssignee.action',
  1696. type: 'POST',
  1697. data: {taskId: nodeId, assigneeId: user, processInstanceId: instance,
  1698. ncustomDes: getDealPoints(), description: msg, _noc: 1},
  1699. success: function(result){
  1700. setLoading(false);
  1701. if(result.result) {
  1702. dialog.show('处理结果', '节点已成功变更');
  1703. } else {
  1704. dialog.show('处理结果', "任务不存在,无法变更!");
  1705. }
  1706. },
  1707. error: function(xhr){
  1708. setLoading(false);
  1709. if(xhr.responseText) {
  1710. var response =$.evalJSON(xhr.responseText);
  1711. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1712. dialog.show('获取用户信息失败', '请先登录!');
  1713. } else {
  1714. dialog.show('错误', response.exceptionInfo);
  1715. }
  1716. }
  1717. }
  1718. });
  1719. };
  1720. $('#change').click(function(){
  1721. var html = '<form>';
  1722. html += '<div class="form-group has-feedback dropdown"><input id="em_new" name="em_new" class="form-control dropdown-toggle" type="text" placeholder="新的处理人,点击搜索"/><span id="change_search_icon" class="glyphicon glyphicon-search form-control-feedback"></span><div class="dropdown-menuman dropdown-menu"><div id="em_search" class="list-group"></div></div>' +
  1723. '<span class="help-block text-lg">' +
  1724. '<span id="change_name"></span>' +
  1725. '<span id="em_code"></span>' +
  1726. '</span></div>';
  1727. html += '<div class="form-group"><textarea id="change-msg" rows="2" placeholder="填写您要变更的原因..." class="form-control">' + $('#deal-msg').val() + '</textarea><span class="help-block text-lg text-error" id="change_err"></span></div>';
  1728. html += '<div class="btn-group btn-group-xs btn-group-justified">';
  1729. html += '<div class="btn-group"><button type="button" class="btn btn-primary" id="change3">变更</button></div>';
  1730. html += '<div class="btn-group"><button type="button" class="btn btn-default" id="cancel3">取消</button></div>';
  1731. html += '</div>';
  1732. html += '</form>';
  1733. dialog.show('变更办理人', html);
  1734. // search deal man
  1735. $('#em_new').bind('focus', function(){
  1736. if($(this).val()) {
  1737. $(this).parent().children('.dropdown-menuman').css('display', 'block');
  1738. }
  1739. });
  1740. $('#em_new').bind('change', function(){// 点击获取变更的候选人
  1741. var v = $(this).val();
  1742. var view = $(this).parent().children('.dropdown-menuman');
  1743. if(v) {
  1744. view.css('display', 'block');
  1745. getSearchResult(v);
  1746. } else {
  1747. view.css('display', 'none');
  1748. }
  1749. });
  1750. $('#em_new').bind('keyup', function(event){// 回车获取变更的候选人
  1751. if(event.keyCode == 13) {
  1752. event.preventDefault();
  1753. var v = $(this).val();
  1754. var view = $(this).parent().children('.dropdown-menuman');
  1755. if(v) {
  1756. view.css('display', 'block');
  1757. getSearchResult(v);
  1758. } else {
  1759. view.css('display', 'none');
  1760. }
  1761. }
  1762. });
  1763. $('#change_search_icon').bind('click', function(event){// 变更查询放大镜图标点击获取变更的候选人
  1764. var v = $('#em_new').val();
  1765. var view = $('#em_new').parent().parent().children('.dropdown-menuman');
  1766. if(v) {
  1767. view.css('display', 'block');
  1768. getSearchResult(v);
  1769. } else {
  1770. view.css('display', 'none');
  1771. }
  1772. });
  1773. // change
  1774. $('#change3').click(function(){
  1775. var msg = $('#change-msg').val();
  1776. change($('#em_code').text(), msg);
  1777. });
  1778. // cancel
  1779. $('#cancel3').click(function(){
  1780. dialog.hide();
  1781. });
  1782. });
  1783. // get search result
  1784. var getSearchResult = function(input) {
  1785. setLoading(true);
  1786. $.post(basePath + 'hr/emplmana/search.action', {
  1787. keyword: input
  1788. }, function(result, text){
  1789. setLoading(false);
  1790. if(result.length > 0) {
  1791. parseSearchResult(result);
  1792. }
  1793. });
  1794. };
  1795. // parse search result
  1796. var parseSearchResult = function(datas){
  1797. var html = '';
  1798. $.each(datas, function(i, d){
  1799. var e = d.split('\n');
  1800. html += '<a href="javascript:onItemClick(\'' + e[1] + '\',\'' + e[2] + '\');" class="list-group-item">';
  1801. html += '<span class="left">' + (e[0] || '(空)') + '</span>';
  1802. html += '<span class="right">' + e[2] + '(' + e[1] + ')</span>';
  1803. html += '</a>';
  1804. });
  1805. $('#em_search').html(html);
  1806. };
  1807. //关联查询
  1808. var dealRelative = function(caller) {
  1809. $('#expand').html('展开&nbsp;<span '+
  1810. 'class="glyphicon glyphicon-share-alt"></span>');
  1811. $('#expand').click(function(){
  1812. $('#expand').addClass('hidden');
  1813. $('#re-content').removeClass('hidden');
  1814. $('#shrink').removeClass('hidden');
  1815. });
  1816. $('#expand').bind('boxready', function(){
  1817. setLoading(true);
  1818. $.ajax({
  1819. url:basePath + 'common/form/relativeSearchMobile.action',
  1820. type: 'POST',
  1821. data: {caller: caller},
  1822. success: function(result){
  1823. setLoading(false);
  1824. $('#relative .title .text').css('width', (138+result.data[0].form.title.length*18)+'px');
  1825. $('#relative .title .text').append('-'+result.data[0].form.title);
  1826. var html = '';
  1827. html += '<div class="control-group">'+
  1828. '<label class="control-lable" for="'+result.data[0].form.items[0].name+'">'+
  1829. result.data[0].form.items[0].fieldLabel+':</label>'+
  1830. '<select type="text" id="'+result.data[0].form.items[0].name+'" name="'+
  1831. result.data[0].form.items[0].name+'" class="form-control"></select>'+
  1832. '<button id="re-search" type="button" class="btn btn-success">筛选</button>'+
  1833. '</div>';
  1834. $('#re-filtrate').html(html);
  1835. },
  1836. error: function(xhr){
  1837. setLoading(false);
  1838. if(xhr.responseText) {
  1839. var response =$.evalJSON(xhr.responseText);
  1840. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  1841. dialog.show('获取信息失败', '请先登录!', 1, function(){dialog.hide();})
  1842. } else {
  1843. dialog.show('错误', response.exceptionInfo,1, function(){dialog.hide();});
  1844. }
  1845. }
  1846. }
  1847. });
  1848. });
  1849. $('#shrink').click(function(){
  1850. $('#expand').removeClass('hidden');
  1851. $('#re-content').addClass('hidden');
  1852. $('#shrink').addClass('hidden');
  1853. });
  1854. };
  1855. // touch on mobile need jquery-mobile.js & event 'tap'
  1856. window.onItemClick = function(code, name) {
  1857. $('#em_search').parent().css('display', 'none');
  1858. $('#change_name').text(name + ' - ')
  1859. $('#em_code').text(code);
  1860. };
  1861. });