// @author suntg // @date 2014年11月19日17:39:28 ;var caller = getUrlParam('caller'); var formCondition = getUrlParam('formCondition')?getUrlParam('formCondition').replace('IS', '='):''; var gridCondition = getUrlParam('gridCondition')?getUrlParam('gridCondition').replace('IS', '='):''; var _readOnly = getUrlParam('_readOnly');// 只读标示 var title; var baseInfo = {};//基本信息存放在这个类 var detailsInfo = [];//明细信息存放在这个数组 var detailInfo = {};//存放原始的一个明细行信息 var detailIndex = 0;//明细索引,方便对明细做操作 var buttons = [];//按钮组,存放当前包含的所有按钮 var mainField;//明细表的主表主键字段 var keyField;//主表中主键字段 var dbfinds;//用于存储明细表中dbfind的字段对照关系,结构与form dbfind请求返回的dbfinds结构一致 $(document).ready(function(){ //与其它页面不同,必须传一个caller var saveUrl = 'common/saveCommon.action?caller=' +caller; var deleteUrl = 'common/deleteCommon.action?caller=' +caller; var updateUrl = 'common/updateCommon.action?caller=' +caller; var auditUrl = 'common/auditCommon.action?caller=' +caller; var printUrl = 'common/printCommon.action?caller=' +caller; var resAuditUrl = 'common/resAuditCommon.action?caller=' +caller; var submitUrl = 'common/submitCommon.action?caller=' +caller; var bannedUrl = 'common/bannedCommon.action?caller='+caller; var resBannedUrl = 'common/resBannedCommon.action?caller='+caller; var endUrl = 'common/endCommon.action?caller='+caller; var resEndUrl = 'common/resEndCommon.action?caller='+caller; var resSubmitUrl = 'common/resSubmitCommon.action?caller=' +caller; var getIdUrl = 'common/getCommonId.action?caller=' +caller; var onConfirmUrl = 'common/ConfirmCommon.action?caller=' +caller; //取编号 result-form的返回结果 table-表名 param-codeField 编号字段 var getRandomNumber = function(result, table, type, codeField) { table = table == null ? result.tablename : table; type = type == null ? 2 : type; codeField = codeField == null ? result.codeField : codeField; $.ajax({ type: 'POST', url: basePath + 'common/getCodeString.action', async: false, data: { caller: caller,//如果table==null,则根据caller去form表取对应table table: table, type: type }, success: function(responseText) { judgeException(responseText, function(){ $('[name="'+codeField+'"]').val(responseText.code); }); } }); }; //类 -> JSON var object2JSON = function(obj) { var result = ''; result = '{'; $.each(obj, function(b, ba){ if(!ba.ignore) { result += '"'+b+'":"'+ba.value+'",'; } }); if(result.length>1) result = result.substr(0, result.length-1); result += '}'; return result; }; //数组 -> JSON var array2JSON = function(arr) { var result = ''; result += '['; $.each(arr, function(d, detail){ result += '{'; $.each(detail, function(i, de){ if(!de.ignore) { result += '"'+i+'":"'+de.value+'",'; } }); if(result.length>2) result = result.substr(0, result.length-1); result += '}'; if(i<(arr.length-1)) result += ','; }); result += ']'; return result; }; //保存请求 var save = function(base, details){ var formStore = ''; var param = ''; formStore = unescape(escape(object2JSON(base))); param = unescape(escape(array2JSON(details))); $.ajax({ type: 'POST', url: basePath + saveUrl, async: false, data: { formStore: formStore, param: param }, success: function(responseText) { judgeException(responseText, function(){ dialog.show('保存成功', '单据已成功保存,正在跳转...', 2, function() { dialog.hide(); window.location.href = basePath+'jsps/mobile/commonForm/commonForm.jsp?caller='+ caller+'&formCondition='+keyField+'IS'+responseText.id+'&gridCondition='+ (mainField?mainField:'null')+'IS'+responseText.id; }); }); } }); }; //更新请求 var update = function(base, details){ var formStore = ''; var param = ''; formStore = unescape(escape(object2JSON(base))); param = unescape(escape(array2JSON(details))); $.ajax({ type: 'POST', url: basePath + updateUrl, async: false, data: { formStore: formStore, param: param }, success: function(responseText) { judgeException(responseText, function(){ dialog.show('更新成功', '单据已成功更新,正在跳转...', 2, function() { dialog.hide(); window.location.href = basePath+'jsps/mobile/commonForm/commonForm.jsp?caller='+ caller+'&formCondition='+keyField+'IS'+responseText.id+'&gridCondition='+ (mainField?mainField:'null')+'IS'+responseText.id; }); }); } }); }; //指定待处理人 var showAssignWin = function(assins, nodeId) { $('#dbFindModal').modal('show'); $('#myModalLabel').text('请指定节点处理人'); var html = ''; $.each(assins, function(a, as){ var value = as.substring(as.lastIndexOf('(')+1, as.length-1); html += ''; }); $('#dbFindModal .modal-body').html(html); var buttonHtml = ''+ ''; $('#dbFindModal .modal-footer').html(buttonHtml); radioLabelClick($('.modal-body .radio-inline')); $('#assin').click(function(){//指定 var value = getRadioValue('assiner');//单选框按钮值 if(value) { $.ajax({ type: 'POST', url: basePath + 'common/takeOverTask.action', async: false, data: { em_code: value, nodeId: nodeId }, success: function(responseText) { if(responseText.success){ $('#dbFindModal').modal('hide'); dialog.show('提示', '指定成功',2, function(){ $.ajax({ type: 'POST', url: basePath + 'common/processpaging.action', async: false, data: { persons: unescape('('+value+')'), nodeId: nodeId } }); window.location.reload(); }); } else { dialog.show('提示', '指定失败',2, function(){ window.location.reload(); }); } } }); } else {//没有选择指定人 $('#dbFindModal').modal('hide'); dialog.show('提示', '请指定节点处理人',1, function(){ dialog.hide(); $('#dbFindModal').modal('show'); }); } }); $('#cancelAssin').click(function(){//取消按钮 $.ajax({//给所有人发通知 type: 'POST', url: basePath + 'common/processpaging.action', async: false, data: { persons: unescape(assins.join(',')), nodeId: nodeId } }); $('#dbFindModal').modal('hide'); window.location.reload(); }); }; //getSingleForm 获取form信息 var getSingleForm = function(caller,condition) { setLoading(true); $.post(basePath + 'common/singleFormItems.action', { caller: caller, condition: formCondition, _noc: 1 }, function(result) { setLoading(false); judgeException(result, parseSingleForm(result)); }); }; // parseSingleForm var parseSingleForm = function(result) { var html = ''; title = result.title; document.title = result.title + '-优软管理系统'; $('#handler_name').text(result.title); if(result.fo_detailMainKeyField) mainField = result.fo_detailMainKeyField; keyField = result.keyField; var items = result.items, ids = []; for(i in items) { var item = items[i]; if(ids.indexOf(item.id) == -1) {//避免出现因多字段出现字段重复 ids.push(item.id); if(item.secondname && item.secondname != ''){ ids.push(item.secondname); } html += parseFormItem(item, result); } } $('#baseinfo form').html(html); shrinkLabel($('#baseinfo .fieldlabel label')); radioLabelClick('#baseinfo .radio-inline'); addDatetimepicker(); dbFindButtons($('#baseinfo .dbFind'), 'form'); initFormValidation($('#baseinfo')); if(result.data) {//查看单据的情况下,加载单据的数据 initBaseInfo(eval('('+result.data+')')); parseObjToForm($('#baseinfo'), baseInfo, false); } // 处理按钮,只读情况下不显示按钮 if (result.buttons && !_readOnly) { buttons = result.buttons.split('#'); parseButtons(buttons, result); }; }; //parseButtons 加载按扭组 //params: buttons 按钮字符串数组 var parseButtons = function(buttons, result){ $.each(buttons, function(b, button){ $('#'+button).parent().css('display', 'table-cell'); }); //保存按钮 $('#erpSaveButton').click(function(){ //没有输入编号自动向后台获取并设值 if(result.codeField && $('[name="'+result.codeField+'"]') && ($('[name="'+result.codeField+'"]').val()=='' || $('[name="'+result.codeField+'"]').val()==null)) { getRandomNumber(result); } //设ID号 if(result.keyField && $('[name="'+result.keyField+'"]') && ($('[name="'+result.keyField+'"]').val()=='' || $('[name="'+result.keyField+'"]').val()==null)) { var keyId = getSeqId(getIdUrl); $('[name="'+result.keyField+'"]').val(keyId); } if(validateForm($('#baseinfo'))){//验证 //空的数字型字段设值为0 $.each($('input[type="number"], textarea[type="number"]', $('#baseinfo')), function(i, input){ if ($(input).val()=='' || $(input).val()==null) { $(input).val(0); }; }); //codeField 值强制大写,自动过滤特殊字符 var codeFieldValue = $('[name="'+result.codeField+'"]').val(); codeFieldValue = codeFieldValue.trim().toUpperCase().replace(/[!@#$%^&*()'":,\/?]/, ''); $('[name="'+result.codeField+'"]').val(codeFieldValue); baseInfo = parseFormToObj($('#baseinfo'), baseInfo); if(detailsInfo.length > 0) { $.each(detailsInfo, function(d, de) { if(!de[mainField]) de[mainField] = {value:'',nacessary:false,ignore:false}; de[mainField].value = baseInfo[result.keyField].value; }) } save(baseInfo, detailsInfo); } }); //删除按钮 $('#erpDeleteButton').click(function(){ $.ajax({ type: 'POST', url: basePath + deleteUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { judgeException(responseText, function(){ dialog.show('删除成功', '单据已成功删除,请返回!'); }); } }); }); //更新按钮 $('#erpUpdateButton').click(function(){ if(validateForm($('#baseinfo'))){//验证 //空的数字型字段设值为0 $.each($('input[type="number"], textarea[type="number"]', $('#baseinfo')), function(i, input){ if ($(input).val()=='' || $(input).val()==null) { $(input).val(0); }; }); //codeField 值强制大写,自动过滤特殊字符 var codeFieldValue = $('[name="'+result.codeField+'"]').val(); codeFieldValue = codeFieldValue.trim().toUpperCase().replace(/[!@#$%^&*()'":,\/?]/, ''); $('[name="'+result.codeField+'"]').val(codeFieldValue); baseInfo = parseFormToObj($('#baseinfo'), baseInfo); if(detailsInfo.length > 0) { $.each(detailsInfo, function(d, de) { if(!de[mainField]) de[mainField] = {value:'',nacessary:false,ignore:false}; de[mainField].value = baseInfo[result.keyField].value; }) } update(baseInfo, detailsInfo); } }); //新增按钮 $('#erpAddButton').click(function(){ window.location.href = basePath+'jsps/mobile/commonForm/commonForm.jsp?caller='+caller; }); //提交按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'ENTERING') { $('#erpSubmitButton').parent().css('display', 'none'); } $('#erpSubmitButton').click(function(){ $.ajax({ type: 'POST', url: basePath + submitUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { if(responseText.success){ //跳转之前 若节点指定多人则指定候选人 $.ajax({ type: 'POST', url: basePath + 'common/getMultiNodeAssigns.action', async: false, data: { id: baseInfo[keyField].value, caller: caller }, success: function(responseTextText) { judgeException(responseTextText, function(){ //下一个节点多处理人,可选定处理人 //选定了下一节点处理人之后发送请求将被选中的人设置为下一个节点,并发送通知 //若取消选定则只向每个候选人发送通知 if(responseTextText.MultiAssign){ showAssignWin(responseTextText.assigns, responseTextText.nodeId); } else { dialog.show('提交成功', '单据已成功提交', 2, function(){ window.location.reload(); }); } }); } }); } else { if(responseText.exceptionInfo){ var str = responseText.exceptionInfo; //特殊情况:操作成功,但是出现警告,允许刷新页面 if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){ str = str.replace('AFTERSUCCESS', ''); dialog.show('操作成功,提示:', str, 2, function(){ dialog.hide(); $.ajax({ type: 'POST', url: basePath + 'common/getMultiNodeAssigns.action', async: false, data: { id: baseInfo[keyField].value, caller: caller }, success: function(responseTextText) { judgeException(responseTextText, function(){ //下一个节点多处理人,可选定处理人 //选定了下一节点处理人之后发送请求将被选中的人设置为下一个节点,并发送通知 //若取消选定则只向每个候选人发送通知 if(responseTextText.MultiAssign){ showAssignWin(responseTextText.assigns, responseTextText.nodeId); } else { dialog.show('提交成功', '单据已成功提交', 2, function(){ window.location.reload(); }); } }); } }); }); } else { dialog.show('出现异常', '请重新尝试!'); } } } } }); }); //反提交按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'COMMITED') { $('#erpResSubmitButton').parent().css('display', 'none'); } $('#erpResSubmitButton').click(function(){ $.ajax({ type: 'POST', url: basePath + resSubmitUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { judgeException(responseText, function(){//跳转之前 若节点指定多人则指定候选人 if(responseText.success) { dialog.show('反提交成功', '正在重新加载页面', 2, function(){ window.location.reload(); }); } }); } }); }); //审核按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'COMMITED') { $('#erpAuditButton').parent().css('display', 'none'); } $('#erpAuditButton').click(function(){ //清除流程(什么意思我也不懂) $.ajax({ type: 'POST', url: basePath + 'common/deleteProcessAfterAudit.action', async: false, data: { keyValue: baseInfo[keyField].value, caller: caller, _noc:1 }, success: function(responseText) { //似乎不用干什么 } }); $.ajax({ type: 'POST', url: basePath + auditUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { if(responseText.success) { dialog.show('审核成功', '正在重新加载...', 2, function(){ window.location.reload(); }); } else { if(responseText.exceptionInfo){ var str = responseText.exceptionInfo; //特殊情况:操作成功,但是出现警告,允许刷新页面 if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){ str = str.replace('AFTERSUCCESS', ''); dialog.show('操作成功,提示:', str, 2, function(){ window.location.reload(); }); } else { dialog.show('出现异常', '请重新尝试!'); } } } } }); }); //反审核按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'AUDITED') { $('#erpResAuditButton').parent().css('display', 'none'); } $('#erpResAuditButton').click(function(){ $.ajax({ type: 'POST', url: basePath + resAuditUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { judgeException(responseText, function() { dialog.show('反审核成功', '正在重新加载...', 2, function() { window.location.reload(); }) }); } }); }); //结案按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'CANUSE' && baseInfo[result.statuscodeField].value != 'AUDITED') { $('#erpEndButton').parent().css('display', 'none'); } $('#erpEndButton').click(function(){ $.ajax({ type: 'POST', url: basePath + endUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { if(responseText.success) { dialog.show('结案成功', '正在重新加载...', 2, function(){ window.location.reload(); }); } else { if(responseText.exceptionInfo){ var str = responseText.exceptionInfo; //特殊情况:操作成功,但是出现警告,允许刷新页面 if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){ str = str.replace('AFTERSUCCESS', ''); dialog.show('操作成功,提示:', str, 2, function(){ window.location.reload(); }); } else { dialog.show('出现异常', '请重新尝试!'); } } } } }); }); //反结案按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'FINISH' ) { $('#erpResEndButton').parent().css('display', 'none'); } $('#erpResEndButton').click(function(){ $.ajax({ type: 'POST', url: basePath + resEndUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { if(responseText.success) { dialog.show('反结案成功', '正在重新加载...', 2, function(){ window.location.reload(); }); } else { if(responseText.exceptionInfo){ var str = responseText.exceptionInfo; //特殊情况:操作成功,但是出现警告,允许刷新页面 if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){ str = str.replace('AFTERSUCCESS', ''); dialog.show('操作成功,提示:', str, 2, function(){ window.location.reload(); }); } else { dialog.show('出现异常', '请重新尝试!'); } } } } }); }); //禁用按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'CANUSE' && baseInfo[result.statuscodeField].value != 'AUDITED') { $('#erpBannedButton').parent().css('display', 'none'); } $('#erpBannedButton').click(function(){ $.ajax({ type: 'POST', url: basePath + bannedUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { if(responseText.success) { dialog.show('禁用成功', '正在重新加载...', 2, function(){ window.location.reload(); }); } else { if(responseText.exceptionInfo){ var str = responseText.exceptionInfo; //特殊情况:操作成功,但是出现警告,允许刷新页面 if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){ str = str.replace('AFTERSUCCESS', ''); dialog.show('操作成功,提示:', str, 2, function(){ window.location.reload(); }); } else { dialog.show('出现异常', '请重新尝试!'); } } } } }); }); //反禁用按钮 if(baseInfo[result.statuscodeField] && baseInfo[result.statuscodeField].value != 'DISABLE') { $('#erpResBannedButton').parent().css('display', 'none'); } $('#erpResBannedButton').click(function(){ $.ajax({ type: 'POST', url: basePath + resBannedUrl, async: false, data: { id: baseInfo[keyField].value }, success: function(responseText) { judgeException(responseText, function() { dialog.show('反禁用成功', '正在重新加载...', 2, function(){ window.location.reload(); }); }); } }); }); }; //parse form item var parseFormItem = function(item, result) { if(_readOnly) item.readOnly = true;// 页面只读模式,所有输入框都是只读 var type, hidden='', html; switch(item.xtype) { case 'textfield': type='text'; break; case 'hidden': hidden='hidden'; type='text'; break;////强制设置隐藏的字段必填为否 case 'numberfield': type='number'; break; } if(item.name != null) { if(item.name == result.statusField){//状态加特殊颜色 item.fieldStyle = item.fieldStyle + ';font-weight:bold;'; } else if(item.name == result.statuscodeField){//状态码字段强制隐藏 hidden = 'hidden'; } } if(item.group == '0') { html = '