startFlow.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. function checkForm() {
  2. /*
  3. * var rs = $.validate({ name : "v_ins_name", model : [ { type : "require",
  4. * msg : "流程标题不能为空!", msgBox : "v_ins_name_box" }, { type : "len", min : 1,
  5. * max : 50, msg : "流程标题长度不能超过50个字!", msgBox : "v_ins_name_box" } ] });
  6. */
  7. // 同步标题输入框的值到隐藏字段,确保数据一致性
  8. if($("#insNameText").is(":visible")) {
  9. $("#insName").val($("#insNameText").val());
  10. }
  11. if($.trim($("#insName").val()) == ''){
  12. addError("流程标题不能为空!");
  13. return false;
  14. }
  15. if($.trim($("#insName").val()).length > 100){
  16. addError("流程标题不能超过100个字!");
  17. return false;
  18. }
  19. var rs = true;
  20. var reqOffice = $("#reqOffice").val();
  21. if(reqOffice == "1"){
  22. rs = $.validate({
  23. name : "file_fileId",
  24. model : [ {
  25. type : "require",
  26. msg : "请上传附件!"
  27. }]
  28. }) && rs;
  29. }
  30. var pathJudgeType = $("#pathJudgeType").val();
  31. if (pathJudgeType == "1") {
  32. rs = $.validate({
  33. name : "nextTmodelId",
  34. model : [ {
  35. type : "require",
  36. msg : "下一步环节不能为空!"
  37. } ]
  38. });
  39. }
  40. var usersNames = $("[type='text'][id*='usersName']:visible");
  41. for ( var i = 0; i < usersNames.length; i++) {
  42. rs = $.validate({
  43. name : usersNames[i].id,
  44. model : [ {
  45. type : "require",
  46. msg : "下一步环节操作人不能为空!"
  47. } ]
  48. }) && rs;
  49. }
  50. if (rs) {
  51. return true;
  52. }
  53. return false;
  54. }
  55. function formJs() {
  56. if (formId == "0") { //没有表单
  57. var rs = checkForm();
  58. $("#formInsId").val("0");
  59. if (rs) {
  60. //$('.bsubmit').attr("disabled", "disabled");
  61. preProcess("FlowAction.do", "#insForm");
  62. }
  63. } else {//有表单
  64. var rs = true;
  65. rs = checkForm() && rs;
  66. if (rs) {
  67. var hasGen = $(window.frames["formIns"].document).find(
  68. "#hasGen").val();//查找是否启用软航印章
  69. $('.bsubmit').attr("disabled", "disabled");
  70. if(document.frames == undefined){
  71. window.frames["formIns"].replaceTextarea();
  72. } else {
  73. document.frames.formIns.replaceTextarea();
  74. }
  75. if (hasGen == 0) { //无软航印章文件直接提交表单
  76. $(window.frames["formIns"].document).find("#formIns").attr("action","bpmFormInstanceAction.do?task=saveIns");
  77. $(window.frames["formIns"].document).find("#formIns").submit();
  78. } else {//有软航印章文件调用js方法提交
  79. if(document.frames == undefined){
  80. window.frames["formIns"].save();
  81. } else {
  82. document.frames.formIns.save();
  83. }
  84. }
  85. }
  86. }
  87. }
  88. /**
  89. * 修改流程标题
  90. */
  91. function changeInsName() {
  92. $("#insNameText").show();
  93. $("#insNameEnter").show();
  94. $("#insNameEdit").hide();
  95. $("#insNameFont").hide();
  96. }
  97. /**
  98. * 确认标题修改
  99. */
  100. function confirmInsName() {
  101. if($.trim($("#insNameText").val()) == ''){
  102. addError("流程标题不能为空!");
  103. return;
  104. }
  105. if($.trim($("#insNameText").val()).length > 100){
  106. addError("流程标题不能超过100个字!");
  107. return;
  108. }
  109. $("#insNameText").hide();
  110. $("#insNameEnter").hide();
  111. $("#insNameEdit").show();
  112. $("#insNameFont").show();
  113. $("#insNameFont").text($("#insNameText").val());
  114. $("#insName").val($("#insNameText").val());
  115. }
  116. var officeDialog = null;
  117. var nextTacheDialog = null;
  118. var nextTacheInfoDialog = null;
  119. function ow(owurl, name) {
  120. officeDialog = $.ligerDialog.open({
  121. height : 700,
  122. width : 1000,
  123. url : owurl,
  124. showMax : false,
  125. showToggle : false,
  126. showMin : false,
  127. isResize : false,
  128. modal : true,
  129. title : name,
  130. allowClose : false
  131. });
  132. }
  133. function closeOfficeDialog() {
  134. officeDialog.close();
  135. }
  136. function openOffice() {
  137. var officeId = $("#officeId").val();
  138. ow('${pageContext.request.contextPath}/NtkoAction.do?task=edit&fileId='
  139. + officeId, 'web文档');
  140. }
  141. function setValue(fileId, fileName) {
  142. $("#officeId").val(fileId);
  143. $("#officeName").val(fileName);
  144. $("#createOffice").hide();
  145. $("#editOffice").show();
  146. }
  147. /**
  148. * 点击"提交"展示"选择下一环节信息"
  149. */
  150. function chooseNextTache(buttonName) {
  151. if(!confirm("确认" + buttonName + "该流程?")){
  152. return;
  153. }
  154. var rs = true;
  155. var reqRemark = $("#reqRemark").val();
  156. if (reqRemark == "1") {
  157. rs = $.validate({
  158. name : "remark",
  159. model : [ {
  160. type : "require",
  161. msg : "流程内容不能为空!"
  162. },{
  163. type : "len",
  164. min : 0,
  165. max : 1000,
  166. msg : "流程内容长度不能超过1000个字!"
  167. } ]
  168. });
  169. }else{
  170. rs = $.validate({
  171. name : "remark",
  172. model : [ {
  173. type : "len",
  174. min : 0,
  175. max : 1000,
  176. msg : "流程内容长度不能超过1000个字!"
  177. } ]
  178. });
  179. }
  180. if (formId != "0") {//判断流程是否有表单,有表单则进行表单验证
  181. if(document.frames == undefined){
  182. rs = window.frames["formIns"].checkForm() && rs;
  183. } else {
  184. rs = document.frames.formIns.checkForm() && rs;
  185. }
  186. }
  187. if (!rs) {
  188. return;
  189. }
  190. window.scrollTo(0,0);
  191. //nextTacheDialog.show();
  192. formJs();
  193. }
  194. /**
  195. * 关闭"选择下一环节信息"对话框
  196. */
  197. function closeNextTache() {
  198. nextTacheDialog.hidden();
  199. }
  200. function closeNextTacheInfo() {
  201. nextTacheInfoDialog.hidden();
  202. }
  203. /**
  204. * 初始化"选择下一环节信息"对话框
  205. */
  206. $(function() {
  207. nextTacheInfoDialog = $.ligerDialog.open({
  208. width : 800,
  209. target : $("#nextTacheInfo"),
  210. showMax : false,
  211. showToggle : false,
  212. showMin : false,
  213. show : false,
  214. isResize : false,
  215. modal : true,
  216. title : "后续环节人员查看及选择",
  217. allowClose : true,
  218. containerId : 'insForm'
  219. });
  220. nextTacheInfoDialog.hidden();
  221. });
  222. function preProcess(actionUrl, formName) {
  223. $("#task").val("preProcess");
  224. var x = $(formName).serializeArray();
  225. $.each(x, function(i, field) {
  226. field.value = encodeURI(field.value);
  227. });
  228. $.ajax({
  229. url : actionUrl,
  230. async : true,
  231. type : "post",
  232. data : x,
  233. dataType : 'json',
  234. success : function(data) {
  235. // alert(data);
  236. // addInfo(data);
  237. // var oldTabid = $("#tabid").val();
  238. // window.parent.f_reloadTab(oldTabid);
  239. // window.parent.frames[oldTabid].closeODialog($("#dialogId").val());
  240. // alert(data[0].nextTacheInstances);
  241. var resultState = data[0].resultState;
  242. var submitState = data[0].submitState;
  243. var resultInfo = data[0].resultInfo;
  244. if(!submitState){
  245. $("#sbmbtn").hide();
  246. $("#clsbtn").show();
  247. } else {
  248. $("#sbmbtn").show();
  249. $("#clsbtn").hide();
  250. }
  251. document.body.scrollIntoView();//滚动到页面顶部
  252. if(resultState){
  253. var table= $("#nextTacheInfoTd");
  254. table.html("");
  255. var nextTacheInstances = data[0].nextTacheInstances;
  256. for(var i = 0 ; i < nextTacheInstances.length; i++){
  257. var users = nextTacheInstances[i].users;
  258. var info = nextTacheInstances[i].info;
  259. var isCheck = nextTacheInstances[i].isCheck;
  260. var tacheModel = nextTacheInstances[i].tacheModel;
  261. var html = "<tr><td>";
  262. html += "<input type='hidden' id='tmodelId_" +
  263. tacheModel.tmodelId + "' name='tmodelId_" +
  264. tacheModel.tmodelId + "' value='" + tacheModel.tmodelId + "'>";
  265. html += tacheModel.tmodelName;
  266. html += "</td><td>";
  267. if(isCheck){
  268. html += "<input type='hidden' id='isCheck_" + tacheModel.tmodelId
  269. + "' name='isCheck_" + tacheModel.tmodelId + "' value='1'>";
  270. } else {
  271. html += "<input type='hidden' id='isCheck_" + tacheModel.tmodelId
  272. + "' name='isCheck_" + tacheModel.tmodelId + "' value='0'>";
  273. }
  274. if(info != "" && info != null && info != undefined){
  275. html += "<span style='color:red'>" + info + "</span>";
  276. } else {
  277. var lzCount = 0;
  278. for(var j = 0 ; j < users.length; j++){
  279. var userState = users[j].state;
  280. if(userState == "1"){
  281. html += "<input type='checkbox' id='tmodel_" +
  282. tacheModel.tmodelId + "' name='tmodel_" + tacheModel.tmodelId +
  283. "' value='" + users[j].id + "' checked='checked'>";
  284. html += users[j].userId.username;
  285. } else {
  286. lzCount ++;
  287. }
  288. // else {
  289. // html += "<input type='checkbox' id='tmodel_" +
  290. // tacheModel.tmodelId + "' name='tmodel_" + tacheModel.tmodelId +
  291. // "' value='" + users[j].id + "' readonly='readonly'>";
  292. // html += users[j].userId.username;
  293. // html += "(该用户已离职)&nbsp;";
  294. // }
  295. }
  296. if(users.length == lzCount){
  297. html += "<span style='color:red'>下一环节操作人无人在职!</span>";
  298. }
  299. }
  300. html += "</td></tr>";
  301. table.append(html);
  302. }
  303. } else {
  304. var table= $("#nextTacheInfoTd");
  305. table.html("");
  306. var html = "<td style='text-align: center;' colspan='2'>";
  307. html += "<span style='color: red;'>" + resultInfo + "</span>";
  308. html += "</td>";
  309. table.append(html);
  310. }
  311. //nextTacheDialog.hide();
  312. $("#validateTip").hide();
  313. nextTacheInfoDialog.show();
  314. },
  315. error : function() {
  316. alert("数据处理失败,请检查网络重新登录或联系管理员!");
  317. $("button").removeAttr("disabled");
  318. },
  319. beforeSend : function() {
  320. //$("button").attr("disabled", "disabled");
  321. }
  322. });
  323. }
  324. function saveFlow() {
  325. $("#sbmbtn").attr("disabled", "disabled");
  326. $("#task").val("start");
  327. var x = $("#insForm").serializeArray();
  328. $.each(x, function(i, field) {
  329. field.value = encodeURI(field.value);
  330. });
  331. var tmodelIds = $("[name*='tmodelId_']");
  332. for(var i = 0; i < tmodelIds.length; i++){
  333. var bool = false;
  334. var isCheck = $("#isCheck_" + tmodelIds[i].value).val();
  335. if(isCheck == '1'){
  336. $("input[name='tmodel_" + tmodelIds[i].value + "']").each(function(){
  337. if(this.checked){
  338. bool = true;
  339. }
  340. });
  341. if(!bool){
  342. $("#validateTip").show();
  343. $("#sbmbtn").removeAttr("disabled");
  344. return false;
  345. }
  346. }
  347. }
  348. var result1 = false;
  349. $.ajax({
  350. url : "FlowAction.do",
  351. async : false,
  352. type : "post",
  353. data : x,
  354. dataType : 'json',
  355. success : function(data) {
  356. var resultState = data[0].resultState;
  357. var resultInfo = data[0].resultInfo;
  358. if (!resultState){
  359. addError(resultInfo);
  360. } else {
  361. addInfo("流程发起成功!");
  362. result1 = true;
  363. }
  364. },
  365. error : function() {
  366. alert("数据处理失败,请检查网络重新登录或联系管理员!");
  367. $("button").removeAttr("disabled");
  368. },
  369. beforeSend : function() {
  370. //$("button").attr("disabled", "disabled");
  371. }
  372. });
  373. if(result1){
  374. var closetype = $("#closetype").val();
  375. var dialogId = $("#dialogId").val();
  376. var parentDialogId = "ligerWindow_"+$("#parentDialogId").val();
  377. if(closetype==1){
  378. window.parent.frames['content'].frames[$("#tabid").val()].closeODialog(dialogId);
  379. } else if(closetype==2){
  380. window.parent.frames[parentDialogId].closeODialog(dialogId);
  381. }else {
  382. var oldTabid = $("#tabid").val();
  383. window.parent.f_reloadTab(oldTabid);
  384. window.parent.frames[oldTabid].closeODialog($("#dialogId").val());
  385. }
  386. }else{
  387. $("#sbmbtn").removeAttr("disabled");
  388. }
  389. }
  390. //表单暂存
  391. function tempformJs() {
  392. if(document.frames == undefined){
  393. window.frames["formIns"].replaceTextarea();
  394. } else {
  395. document.frames.formIns.replaceTextarea();
  396. }
  397. $(window.frames["formIns"].document).find("#formIns").attr("action","bpmFormInstanceAction.do?task=tempInsForSave");
  398. $(window.frames["formIns"].document).find("#formIns").submit();
  399. nextTacheInfoDialog.hidden();
  400. }