startFlow.js 10 KB

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