startFlow.js 11 KB

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