You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1108 lines
58 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = 'BillChangeApply_Qry',
  4. sEditPrgId = 'BillChangeApply_Upd',
  5. sAction = getUrlParam('Action') || 'Add',
  6. sDataId = getUrlParam('Guid'),
  7. sCheckId = sDataId,
  8. fnPageInit = function () {
  9. var oCurData = { CheckFlows: [], HandleFlows: [], BillChanges: [] },
  10. oForm = $('#form_main'),
  11. saCheckOrder_Push = [],
  12. saUsers = [],
  13. sCurAuditFlowId = null,
  14. sCurHandleFlowId = null,
  15. oTR = null,
  16. bGoNext = true,
  17. /**
  18. * 獲取當前審核人員
  19. * @param {Object} data當前審核資料
  20. */
  21. fnGetCurAuditor = function (data) {
  22. var saCheckFlows = $.parseJSON(data.CheckFlows),
  23. saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray(),
  24. bAuditor = false,
  25. bHandle = false,
  26. bAllAudit = false;
  27. if ('B,E'.indexOf(data.Status) > -1) {//只有審核中或者待經辦的資料才可以出現審核區塊
  28. $.each(saNewList, function (idx, _data) {
  29. var sSignedWay = _data.source[0].SignedWay,
  30. iCount = Enumerable.From(_data.source).Where(function (e) { return (e.SignedDecision === 'Y' || e.SignedDecision === 'O'); }).Count(),
  31. sCurAuditor = Enumerable.From(_data.source).ToString(",", "$.SignedId");
  32. if ((('flow1,flow3'.indexOf(sSignedWay) > -1 && iCount === 0) || (sSignedWay === 'flow2' && iCount !== _data.source.length))) {
  33. if (sCurAuditor.indexOf(parent.UserID) > -1) {
  34. var oCurUser = Enumerable.From(_data.source).Where(function (e) { return e.SignedId === parent.UserID; }).First();
  35. if (sSignedWay === 'flow2' && iCount < _data.source.length - 1) {
  36. bGoNext = false;
  37. }
  38. if (!oCurUser.SignedDecision) {
  39. sCurAuditFlowId = oCurUser.FlowId;
  40. bAuditor = true;
  41. }
  42. }
  43. if (!bAllAudit) {//只要有需要審核的人,就不要檢核是否簽辦
  44. bAllAudit = true;
  45. }
  46. return false;
  47. }
  48. });
  49. if (!bAuditor && !bAllAudit) {//當沒有要審核的人員並且審核全部完成時才會檢核簽辦
  50. var saHandleFlows = $.parseJSON(data.HandleFlows),
  51. sCurAuditor = saHandleFlows[0].SignedId;
  52. if (saHandleFlows[0].SignedDecision !== 'Y' && sCurAuditor === parent.UserID) {
  53. sCurHandleFlowId = saHandleFlows[0].FlowId
  54. bHandle = true;
  55. }
  56. }
  57. }
  58. return {
  59. IsAuditor: bAuditor,
  60. IsHandler: bHandle
  61. };
  62. },
  63. /**
  64. * 註冊加簽事件
  65. * @param {Number} _grididx當前Gird 序號
  66. */
  67. fnRegisterAddFlows = function (_grididx) {
  68. $('.flowlink' + _grididx).on('click', function () {
  69. var oOption = {};
  70. oOption.SignedWay = $(this).data('id');
  71. oOption.Callback = function (data) {
  72. if (data.Users.length > 0) {
  73. var oFlow = {};
  74. if (data.FlowType === 'flow1') {
  75. $.each(data.Users, function (idx, user) {
  76. oFlow = {};
  77. oFlow.id = guid();
  78. oFlow.Order = saCheckOrder_Push.length + 1;
  79. oFlow.SignedWay = data.FlowType;
  80. oFlow.SignedMember = [{
  81. id: user.id,
  82. name: user.name,
  83. deptname: user.deptname,
  84. jobname: user.jobname
  85. }];
  86. saCheckOrder_Push.push(oFlow);
  87. });
  88. }
  89. else {
  90. var saSignedMembers = [];
  91. $.each(data.Users, function (idx, user) {
  92. saSignedMembers.push({
  93. id: user.id,
  94. name: user.name,
  95. deptname: user.deptname,
  96. jobname: user.jobname
  97. });
  98. });
  99. oFlow.id = guid();
  100. oFlow.Order = saCheckOrder_Push.length + 1;
  101. oFlow.SignedWay = data.FlowType;
  102. oFlow.SignedMember = saSignedMembers;
  103. saCheckOrder_Push.push(oFlow);
  104. }
  105. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  106. $("#jsGrid" + _grididx).jsGrid("loadData");
  107. }
  108. };
  109. oPenUserListPop(oOption);
  110. });
  111. },
  112. /**
  113. * 獲取資料
  114. */
  115. fnGet = function () {
  116. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  117. {
  118. Guid: sDataId
  119. },
  120. function (res) {
  121. console.log(res);
  122. if (res.RESULT) {
  123. var oRes = res.DATA.rel,
  124. saFlowsText = [],
  125. sStatus = '';
  126. if (oRes.Status === 'C-O') {
  127. sStatus = '(' + i18next.t("common.HasReEdited") + ')';// ╠common.HasReEdited⇒已抽單╣
  128. }
  129. else if (oRes.Status === 'D-O') {
  130. sStatus = '(' + i18next.t("common.HasReturned") + ')';// ╠common.HasReturned⇒已退件╣
  131. }
  132. else if (oRes.Status === 'X') {
  133. sStatus = '(' + i18next.t("common.HasVoid") + ')';// ╠common.HasVoid⇒已作廢╣
  134. }
  135. //根據帳單狀態,移除抽單按鈕(扣除已經辦只能admin抽單)
  136. fnCheckReEdit(oRes.Status, oRes.Applicant);
  137. if (oRes.Applicant !== parent.UserID) {
  138. $('#Toolbar_Copy').remove();
  139. }
  140. if ('B,Y'.indexOf(oRes.Status) === -1) {
  141. $('#Toolbar_Void').remove();
  142. }
  143. var SuperAuditor = parent.SysSet.InvoiceApplySuperAuditor.indexOf(parent.UserID) > -1;
  144. var oCheck = fnGetCurAuditor(oRes);
  145. if (oCheck.IsAuditor) {
  146. $('#IsAuditor').show();
  147. }
  148. if (oCheck.IsHandler) {
  149. $('#IsHandler').show();
  150. }
  151. if (oCheck.IsAuditor || oCheck.IsHandler) {
  152. $('.submitdecision').click(function () {
  153. var sSubmitAction = $(this).data('id');
  154. fnSubmitDecision(sSubmitAction);
  155. });
  156. }
  157. //條件:經辦中、SuperAuditor、未經辦(最後一關)
  158. if ("B".indexOf(oRes.Status) > -1 && SuperAuditor && !oCheck.IsHandler) {
  159. if (!oCheck.IsAuditor) {
  160. $('#SuperAuditor').show();
  161. $('.submitdecisionforall').click(function () {
  162. fnSubmitDecisionForAll();
  163. });
  164. }
  165. }
  166. if (oRes.VoidReason) {
  167. $('#VoidReason').text(oRes.VoidReason);
  168. $('.VoidReason').show();
  169. }
  170. if (oRes.CrosssignTurn === 'N') {
  171. $('.crosssignturn').remove();
  172. }
  173. oCurData = oRes;
  174. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  175. oCurData.CheckFlows = $.parseJSON(oCurData.CheckFlows);
  176. oCurData.HandleFlows = $.parseJSON(oCurData.HandleFlows);
  177. oCurData.BillChanges = $.parseJSON(oCurData.BillChanges);
  178. setFormVal(oForm, oRes);
  179. $('#Applicant').text(oCurData.ApplicantName + '(' + oCurData.Applicant + ') ' + oCurData.DeptName);
  180. $('.eip-note').text(oCurData.KeyNote);
  181. $('#status').text(sStatus);
  182. $('#Handle_Person').text(oCurData.Handle_PersonName);// ╠common.Important_1⇒普通╣ ╠common.Important_2⇒重要╣ ╠common.Important_3⇒很重要╣
  183. $('#Important').text(oCurData.Important === '1' ? i18next.t("common.Important_1") : oCurData.Important === '2' ? i18next.t("common.Important_2") : i18next.t("common.Important_3"));
  184. $('#SignedNumber').text(oCurData.SignedNumber);
  185. $.each(oCurData.CheckOrder, function (idx, order) {
  186. var sFlowType = i18next.t('common.' + order.SignedWay);
  187. if (order.SignedWay !== 'flow1') {
  188. saFlowsText.push(sFlowType + '(' + Enumerable.From(order.SignedMember).ToString(",", "$.name") + ')');
  189. }
  190. else {
  191. saFlowsText.push(Enumerable.From(order.SignedMember).ToString(",", "$.name"));
  192. }
  193. });
  194. $('#Recipient').text(saFlowsText.join('->'));
  195. fnGetFiles($('#AdditionalFiles'), oCurData.Guid, oCurData.RelationId, oCurData.ExFeild1, sProgramId);//加載附件
  196. fnUpload();//初始化上傳控件(審批與簽辦)
  197. fnRead();//如果是被通知的人,則修改為已閱讀狀態
  198. $("#jsGrid").jsGrid("loadData");
  199. $("#jsGrid1").jsGrid("loadData");
  200. $("#jsGrid2").jsGrid("loadData");
  201. $('[name="SignedDecision"]').click(function () {
  202. if (this.value === 'O') {
  203. $('#addotheraudit').slideDown();
  204. }
  205. else {
  206. $('#addotheraudit').slideUp();
  207. }
  208. });
  209. $('[name="HandleDecision"]').click(function () {
  210. if (this.value === 'O') {
  211. $('#addotherhandle').slideDown();
  212. }
  213. else {
  214. $('#addotherhandle').slideUp();
  215. }
  216. });
  217. $('[class="data-item"]').remove();
  218. $.each(oCurData.BillChanges.ChangeInfo || [], function (idx, item) {
  219. var oTrNew = oTR.clone(true);
  220. oTrNew.find('[data-id="OldItem"]').val(item.OldItem);
  221. oTrNew.find('[data-id="OldAmountCurrency"]').val(item.OldAmountCurrency);
  222. oTrNew.find('[data-id="OldAmount"]').val(item.OldAmount);
  223. oTrNew.find('[data-id="NewItem"]').val(item.NewItem);
  224. oTrNew.find('[data-id="NewAmountCurrency"]').val(item.NewAmountCurrency);
  225. oTrNew.find('[data-id="NewAmount"]').val(item.NewAmount);
  226. $('.billchangeinfo tr:last').before(oTrNew);
  227. });
  228. }
  229. });
  230. },
  231. /**
  232. * 設定客戶下拉選單
  233. */
  234. setCustomersDrop = function () {
  235. return g_api.ConnectLite(Service.sys, 'GetCustomerlist', {}, function (res) {
  236. if (res.RESULT) {
  237. var saCustomers = res.DATA.rel,
  238. sCustomersOptionsHtml = createOptions(saCustomers, 'id', 'text');
  239. $('#BillChanges_CustomerID').html(sCustomersOptionsHtml);
  240. }
  241. });
  242. },
  243. /**
  244. * 複製
  245. */
  246. fnCopy = function () {
  247. var data = oCurData;
  248. data = packParams(data);
  249. if (data.Status === 'D-O') {
  250. data.RelationId = data.Guid;
  251. }
  252. else {
  253. delete data.RelationId;
  254. }
  255. data.OrgID = parent.OrgID;
  256. data.Guid = guid();
  257. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|BCA|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  258. data.CheckFlows = fnCheckFlows(data, false, true, saUsers);
  259. data.HandleFlows = fnHandleFlows(data, saUsers);
  260. data.CheckOrder = JSON.stringify(data.CheckOrder);
  261. data.BillChanges = JSON.stringify(data.BillChanges);
  262. data.Status = 'A';
  263. data.IsHandled = 'N';
  264. data.Inspectors = '';
  265. data.Reminders = '';
  266. data.VoidReason = '';
  267. data.Flows_Lock = data.Flows_Lock || 'N';
  268. data.Handle_Lock = data.Handle_Lock || 'N';
  269. delete data.RowIndex;
  270. delete data.ApplicantName;
  271. delete data.Handle_PersonName;
  272. delete data.DeptName;
  273. delete data.CreateUserName;
  274. delete data.ModifyUserName;
  275. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  276. Params: {
  277. billchangeapply: data
  278. }
  279. }, function (res) {
  280. if (res.d > 0) {
  281. showMsgAndGo(i18next.t("message.Copy_Success"), sEditPrgId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Copy_Success⇒複製成功╣
  282. }
  283. else {
  284. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  285. }
  286. }, function () {
  287. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  288. });
  289. },
  290. /**
  291. * 資料作廢
  292. */
  293. fnVoid = function () {
  294. layer.open({
  295. type: 1,
  296. title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣
  297. shade: 0.75,
  298. maxmin: true, //开启最大化最小化按钮
  299. area: ['500px', '250px'],
  300. content: '<div class="pop-box">\
  301. <textarea name="VoidContent" id="VoidContent" style="min-width:300px;" class="form-control" rows="5" cols="20"></textarea>\
  302. </div>',
  303. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  304. success: function (layero, index) {
  305. },
  306. yes: function (index, layero) {
  307. var data = {
  308. Status: 'X',
  309. VoidReason: $('#VoidContent').val()
  310. };
  311. if (!$('#VoidContent').val()) {
  312. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  313. return false;
  314. }
  315. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  316. Params: {
  317. billchangeapply: {
  318. values: data,
  319. keys: { Guid: sDataId }
  320. }
  321. }
  322. }, function (res) {
  323. if (res.d > 0) {
  324. DelTask(sDataId);
  325. showMsgAndGo(i18next.t('message.Void_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  326. }
  327. else {
  328. showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  329. }
  330. });
  331. layer.close(index);
  332. }
  333. });
  334. },
  335. /**
  336. * 複製
  337. */
  338. fnRead = function () {
  339. var bToUpd = false;
  340. $.each(oCurData.CheckFlows, function (idx, _data) {
  341. if (_data.SignedId === parent.UserID && _data.SignedWay === 'flow4' && _data.SignedDecision === 'T') {
  342. _data.SignedDecision = 'R';
  343. bToUpd = true;
  344. return false;
  345. }
  346. });
  347. if (bToUpd) {
  348. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  349. Params: {
  350. billchangeapply: {
  351. values: { CheckFlows: JSON.stringify(oCurData.CheckFlows) },
  352. keys: { Guid: sDataId }
  353. }
  354. }
  355. });
  356. }
  357. },
  358. /**
  359. * 抽單
  360. */
  361. fnReEdit = function () {
  362. var data = {};
  363. data.Status = 'C-O';
  364. data = packParams(data, 'upd');
  365. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  366. Params: {
  367. billchangeapply: {
  368. values: data,
  369. keys: { Guid: sDataId }
  370. }
  371. }
  372. }, function (res) {
  373. if (res.d > 0) {
  374. showMsg(i18next.t("message.ReEdit_Success"), 'success'); // ╠message.ReEdit_Success⇒抽單成功╣
  375. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  376. Params: {
  377. task: {
  378. values: { Status: 'O' },
  379. keys: { SourceID: sDataId }
  380. }
  381. }
  382. });
  383. fnGet();
  384. }
  385. else {
  386. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  387. }
  388. }, function () {
  389. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  390. });
  391. },
  392. /**
  393. * 提交決定
  394. * @param {String} action 簽核 or 經辦
  395. */
  396. fnSubmitDecision = function (action) {
  397. var data = getFormSerialize(oForm),
  398. saNewCheckFlows = clone(oCurData.CheckFlows),
  399. saNewHandleFlows = clone(oCurData.HandleFlows),
  400. saNewCheckOrderPush = clone(saCheckOrder_Push),
  401. saAdds = [],//加簽核順序
  402. saNextUsers = [],//下組簽核人員
  403. saTipsUsers = [],//需要通知的人員
  404. saNextSignedWays = [],//下組需要處理的動作
  405. iCurOder = 0,//當前順序
  406. sHandlePerson = "";//經辦人
  407. if (action === 'Signed') {
  408. if (data.SignedDecision === 'N' && !data.SignedOpinion) {
  409. showMsg(i18next.t("message.SignedOpinion_required")); // ╠message.SignedOpinion_required⇒請填寫簽核意見╣
  410. return false;
  411. }
  412. else if (data.SignedDecision === 'O' && saCheckOrder_Push.length === 0) {
  413. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  414. return false;
  415. }
  416. var oCurFlow = Enumerable.From(oCurData.CheckFlows).Where(function (e) { return e.FlowId == sCurAuditFlowId; }).First(),
  417. oNewCurFlow = clone(oCurFlow);
  418. iCurOder = oCurFlow.Order;
  419. $.each(saNewCheckOrderPush, function (idx, _push) {
  420. _push.Order = idx + 1 + iCurOder;
  421. });
  422. $.each(saNewCheckFlows, function (idx, _flow) {
  423. if (sCurAuditFlowId === _flow.FlowId) {
  424. _flow.SignedDecision = data.SignedDecision;
  425. _flow.SignedOpinion = data.SignedOpinion;
  426. _flow.SignedDate = newDate();
  427. if (data.SignedDecision === 'O') {
  428. _flow.SignedPush = saCheckOrder_Push;
  429. }
  430. }
  431. if (data.SignedDecision === 'O' && _flow.Order > iCurOder) {
  432. _flow.Order = _flow.Order + saNewCheckOrderPush.length;
  433. if (data.NoreTurn) {//如果再回傳給自己的話排序再增加一個值
  434. _flow.Order++;
  435. }
  436. else {//如果加簽核流程最後一個是通知,並且原流程下一個也是通知的話就合併新舊排序
  437. if (saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay === 'flow4' && saNewCheckFlows[iCurOder + 1].SignedWay === saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay) {
  438. _flow.Order--;
  439. }
  440. }
  441. }
  442. });
  443. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  444. if (data.SignedDecision === 'O' && data.NoreTurn) {
  445. oNewCurFlow.Order = oNewCurFlow.Order + saNewCheckOrderPush.length + 1;
  446. oNewCurFlow.FlowId = guid();
  447. saAdds.push(oNewCurFlow);
  448. }
  449. }
  450. else {
  451. if (data.HandleDecision === 'O' && saCheckOrder_Push.length === 0) {
  452. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  453. return false;
  454. }
  455. iCurOder = saNewCheckFlows[saNewCheckFlows.length - 1].Order;//如果是签辦的話當前順序就是原本流程的最大順序
  456. $.each(saNewHandleFlows, function (idx, _flow) {
  457. if (sCurHandleFlowId === _flow.FlowId) {
  458. _flow.SignedDecision = data.HandleDecision;
  459. _flow.SignedOpinion = data.HnadleOpinion;
  460. _flow.SignedDate = newDate();
  461. if (data.HandleDecision === 'O') {
  462. _flow.SignedPush = saCheckOrder_Push;
  463. }
  464. if (data.HandleDecision === 'Y') {
  465. _flow.SignedPush = null;
  466. }
  467. }
  468. });
  469. if (data.HandleDecision === 'O') {
  470. $.each(saNewCheckOrderPush, function (idx, _push) {
  471. _push.Order = idx + saNewCheckFlows[saNewCheckFlows.length - 1].Order + 1;
  472. });
  473. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  474. }
  475. }
  476. saNewCheckFlows = saNewCheckFlows.concat(saAdds);
  477. saNewCheckFlows = Enumerable.From(saNewCheckFlows).OrderBy("$.Order").ToArray();
  478. var _List = Enumerable.From(saNewCheckFlows).GroupBy("$.Order").ToArray();
  479. saNewCheckFlows = [];
  480. $.each(_List, function (idx, _list) {
  481. //找到要通知的人
  482. var sSignedWay = _list.source[0].SignedWay;
  483. var LastOne = iCurOder >= _List.length
  484. if (idx === iCurOder && !LastOne) {
  485. switch (sSignedWay) {
  486. case "flow1":
  487. case "flow2":
  488. case "flow3":
  489. {
  490. saNextUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  491. saNextSignedWays.push(sSignedWay);
  492. }
  493. break;
  494. case "flow4":
  495. { //不能算通知到
  496. $.each(_list.source, function (i, _source) {
  497. _source.SignedDecision = 'T';
  498. _source.SignedDate = newDate();
  499. });
  500. saTipsUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  501. saNextSignedWays.push(sSignedWay);
  502. ++iCurOder
  503. }
  504. break;
  505. default:
  506. break;
  507. }
  508. }
  509. saNewCheckFlows = saNewCheckFlows.concat(_list.source);
  510. });
  511. //Flow => Handle => END
  512. if (action != 'Handle') {
  513. var CheckNextUser = saNextUsers.length === 0;
  514. if (CheckNextUser && iCurOder === _List.length) {
  515. sHandlePerson = saNewHandleFlows[0].SignedId;
  516. saNextSignedWays.push("flow5");
  517. }
  518. }
  519. g_api.ConnectLite(sEditPrgId, 'BillChangeApplyAudit', {
  520. Guid: oCurData.Guid,
  521. Action: action,
  522. GoNext: bGoNext ? 'Y' : 'N',
  523. HandlePerson: sHandlePerson,
  524. NextSignedWays: JSON.stringify(saNextSignedWays),
  525. NextUsers: JSON.stringify(saNextUsers),
  526. TipsUsers: JSON.stringify(saTipsUsers),
  527. CheckFlows: JSON.stringify(saNewCheckFlows),
  528. HandleFlows: JSON.stringify(saNewHandleFlows),
  529. SignedDecision: data.SignedDecision,
  530. HandleDecision: data.HandleDecision
  531. }, function (res) {
  532. if (res.RESULT) {
  533. showMsgAndGo(i18next.t('message.' + action + '_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  534. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  535. }
  536. else {
  537. showMsg(i18next.t('message.' + action + '_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  538. }
  539. }, function () {
  540. showMsg(i18next.t('message.' + action + '_Failed'), 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  541. });
  542. },
  543. /*
  544. * 提交決定謙和所有人(該使用者之前)
  545. */
  546. fnSubmitDecisionForAll = function () {
  547. var data = getFormSerialize(oForm);
  548. g_api.ConnectLite(sEditPrgId, 'BillChangeApplyAuditAll', {
  549. Guid: oCurData.Guid,
  550. AutoSignedDecision: data.AutoSignedDecision,
  551. AutoSignedOpinion: data.AutoSignedOpinion
  552. }, function (res) {
  553. var action = 'SubmitDecisionForAll'
  554. if (res.RESULT) {
  555. showMsgAndGo(i18next.t('message.' + action + '_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  556. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  557. }
  558. else {
  559. showMsg(i18next.t('message.' + action + '_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  560. }
  561. }, function () {
  562. showMsg(i18next.t('message.' + action + '_Failed'), 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  563. });
  564. },
  565. /**
  566. * 上傳附件
  567. * @param {Array} files 上傳的文件
  568. */
  569. fnUpload = function (files) {
  570. var option = {};
  571. option.input = $('#fileInput1');
  572. option.theme = 'dragdropbox';
  573. option.folder = 'BillChangeApply';
  574. option.type = 'list';
  575. option.parentid = sCurAuditFlowId;
  576. if (files) {
  577. option.files = files;
  578. }
  579. fnUploadRegister(option);
  580. option.input = $('#fileInput2');
  581. option.parentid = sCurHandleFlowId;
  582. fnUploadRegister(option);
  583. },
  584. /**
  585. * ToolBar 按鈕事件 function
  586. * @param {Object}inst 按鈕物件對象
  587. * @param {Object} e 事件對象
  588. */
  589. fnButtonHandler = function (inst, e) {
  590. var sId = inst.id;
  591. switch (sId) {
  592. case "Toolbar_Qry":
  593. break;
  594. case "Toolbar_Save":
  595. break;
  596. case "Toolbar_ReAdd":
  597. break;
  598. case "Toolbar_Clear":
  599. clearPageVal();
  600. break;
  601. case "Toolbar_Leave":
  602. pageLeave();
  603. break;
  604. case "Toolbar_Add":
  605. break;
  606. case "Toolbar_Upd":
  607. break;
  608. case "Toolbar_Copy":
  609. fnRefreshFlowsThenCopy(oCurData, fnCopy);
  610. break;
  611. case "Toolbar_Void":
  612. fnVoid();
  613. break;
  614. case "Toolbar_ReEdit":
  615. // ╠message.CheckReEdit⇒確定要抽單嗎?╣ ╠common.Tips⇒提示╣
  616. layer.confirm(i18next.t('message.CheckReEdit'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  617. fnReEdit();
  618. layer.close(index);
  619. });
  620. break;
  621. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  622. break;
  623. case "Toolbar_Print":
  624. fnPrePrint($(".panel-info"));
  625. break;
  626. default:
  627. alert("No handle '" + sId + "'");
  628. break;
  629. }
  630. },
  631. /**
  632. * 初始化 function
  633. */
  634. init = function () {
  635. var saCusBtns = null;
  636. if (sAction === 'Upd') {
  637. saCusBtns = [
  638. {
  639. id: 'Toolbar_ReEdit',
  640. value: 'common.ReEdit'// ╠common.ReEdit⇒抽單╣
  641. },
  642. {
  643. id: 'Toolbar_Copy',
  644. value: 'common.Toolbar_Copy'// ╠common.Toolbar_Copy⇒複製╣
  645. }];
  646. }
  647. commonInit({
  648. PrgId: sProgramId,
  649. ButtonHandler: fnButtonHandler,
  650. Buttons: saCusBtns,
  651. GoTop: true
  652. });
  653. moneyInput($('[data-type="int"]'), 2, true);
  654. $.whenArray([
  655. setCustomersDrop(),
  656. fnSetEpoDrop({
  657. Select: $('#BillChanges_ExhibitionNO'),
  658. IdName: 'ExhibitionCode',
  659. TextName: 'ExhibitioShotName_TW'
  660. }),
  661. fnSetUserDrop([
  662. {
  663. Select: $('#BillChanges_ResponsiblePerson'),
  664. CallBack: function (data) {
  665. saUsers = data;
  666. }
  667. }
  668. ]),
  669. fnSetArgDrop([
  670. {
  671. ArgClassID: 'Currency',
  672. CallBack: function (data) {
  673. $('.select_currency').html(createOptions(data, 'id', 'id'))[0].remove(0);
  674. }
  675. }
  676. ])])
  677. .done(function () {
  678. oTR = $('.billchangeinfo tr').eq(1).clone(true);
  679. fnGet();
  680. });
  681. $("#jsGrid1").jsGrid({
  682. width: "100%",
  683. height: "auto",
  684. autoload: true,
  685. pageLoading: true,
  686. pageIndex: 1,
  687. pageSize: 10000,
  688. rowClass: function (item, itemIndex) {
  689. var sRowClass = '';
  690. if (oCurData.CheckFlows.length !== itemIndex + 1) {
  691. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  692. }
  693. else {
  694. sRowClass = 'last-cell';
  695. }
  696. return sRowClass;
  697. },
  698. fields: [
  699. {
  700. type: "Icon", width: 50, align: "center",
  701. itemTemplate: function (val, item) {
  702. var oIcon = {
  703. flow2: '<img src="../../images/flow2_View.gif">',
  704. flow3: '<img src="../../images/flow3_View.gif">',
  705. flow4: '<img src="../../images/flow4.gif">'
  706. };
  707. return item.Icon ? oIcon[item.SignedWay] || '' : '';
  708. }
  709. },
  710. {
  711. name: "Order", title: 'common.Order', width: 50, align: "center",
  712. itemTemplate: function (val, item) {
  713. return val < 10 ? '0' + val : val;
  714. }
  715. },
  716. {
  717. name: "SignedMember", title: 'common.SignedMember', width: 150,
  718. itemTemplate: function (val, item) {
  719. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  720. }
  721. },
  722. {
  723. name: "SignedDecision", title: 'common.Decision', width: 100,
  724. itemTemplate: function (val, item) {
  725. var sVal = val;
  726. if (val === 'Y') {
  727. sVal = i18next.t("common.Agree");// ╠common.Agree⇒同意╣
  728. }
  729. else if (val === 'N') {
  730. sVal = i18next.t("common.NotAgree");// ╠common.NotAgree⇒不同意╣
  731. }
  732. else if (val === 'O') {
  733. sVal = i18next.t("common.AddOther");// ╠common.AddOther⇒先加簽╣
  734. }
  735. else if (val === 'T') {
  736. sVal = i18next.t("common.HasNotice");// ╠common.HasNotice⇒已通知╣
  737. }
  738. else if (val === 'R') {
  739. sVal = i18next.t("common.HasRead");// ╠common.HasRead⇒已閱讀╣
  740. }
  741. return $('<a>', { html: sVal });
  742. }
  743. },
  744. {
  745. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  746. itemTemplate: function (val, item) {
  747. var saVal = [],
  748. oDiv = $('<div>');
  749. if (item.SignedPush) {
  750. var saFlowsPush = item.SignedPush,
  751. saFlowsPushText = [],
  752. sFlowsPushText = '';
  753. $.each(saFlowsPush, function (idx, flow) {
  754. var sFlowType = i18next.t('common.' + flow.SignedWay);
  755. if (flow.SignedWay !== 'flow1') {
  756. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  757. }
  758. else {
  759. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  760. }
  761. });
  762. sFlowsPushText = saFlowsPushText.join(' → ');
  763. saVal.push($('<a>', { html: sFlowsPushText }));
  764. saVal.push('<br />');
  765. }
  766. if (val) {
  767. saVal.push(val);
  768. saVal.push('<br />');
  769. }
  770. fnGetFiles(oDiv.append(saVal), item.FlowId);
  771. return oDiv;
  772. }
  773. },
  774. {
  775. name: "SignedDate", title: 'common.SignedDate', width: 120,
  776. itemTemplate: function (val, item) {
  777. return val;
  778. }
  779. }
  780. ],
  781. controller: {
  782. loadData: function (args) {
  783. return {
  784. data: oCurData.CheckFlows,
  785. itemsCount: oCurData.CheckFlows.length //data.length
  786. };
  787. }
  788. }
  789. });
  790. $("#jsGrid2").jsGrid({
  791. width: "100%",
  792. height: "auto",
  793. autoload: true,
  794. pageLoading: true,
  795. pageIndex: 1,
  796. pageSize: 10000,
  797. rowClass: function (item, itemIndex) {
  798. var sRowClass = '';
  799. if (oCurData.HandleFlows.length !== itemIndex + 1) {
  800. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  801. }
  802. else {
  803. sRowClass = 'last-cell';
  804. }
  805. return sRowClass;
  806. },
  807. fields: [
  808. {
  809. name: "SignedMember", title: 'common.HandleMembers', width: 150,
  810. itemTemplate: function (val, item) {
  811. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  812. }
  813. },
  814. {
  815. name: "SignedDecision", title: 'common.Status', width: 100,
  816. itemTemplate: function (val, item) {
  817. var sVal = val;
  818. if (val === 'Y') {
  819. sVal = i18next.t("common.Hashandle");// ╠common.Hashandle⇒已經辦╣
  820. }
  821. else if (val === 'N') {
  822. sVal = i18next.t("common.Nothandle");// ╠common.Nothandle⇒未處理╣
  823. }
  824. else if (val === 'O') {
  825. sVal = i18next.t("common.AddOtherAudit");// ╠common.AddOtherAudit⇒轉呈其它主管審批╣
  826. }
  827. return $('<a>', { html: sVal });
  828. }
  829. },
  830. {
  831. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  832. itemTemplate: function (val, item) {
  833. var saVal = [],
  834. oDiv = $('<div>');
  835. if (item.SignedPush) {
  836. var saFlowsPush = item.SignedPush,
  837. saFlowsPushText = [],
  838. sFlowsPushText = '';
  839. $.each(saFlowsPush, function (idx, flow) {
  840. var sFlowType = i18next.t('common.' + flow.SignedWay);
  841. if (flow.SignedWay !== 'flow1') {
  842. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  843. }
  844. else {
  845. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  846. }
  847. });
  848. sFlowsPushText = saFlowsPushText.join(' → ');
  849. saVal.push($('<a>', { html: sFlowsPushText }));
  850. saVal.push('<br />');
  851. }
  852. if (val) {
  853. saVal.push(val);
  854. saVal.push('<br />');
  855. }
  856. fnGetFiles(oDiv.append(saVal), item.FlowId);
  857. return oDiv;
  858. }
  859. },
  860. {
  861. name: "SignedDate", title: 'common.HandleDate', width: 120,
  862. itemTemplate: function (val, item) {
  863. return val;
  864. }
  865. }
  866. ],
  867. controller: {
  868. loadData: function (args) {
  869. return {
  870. data: oCurData.HandleFlows,
  871. itemsCount: oCurData.HandleFlows.length //data.length
  872. };
  873. }
  874. }
  875. });
  876. $.each([3, 4], function (idx, _grididx) {
  877. fnRegisterAddFlows(_grididx);
  878. $("#jsGrid" + _grididx).jsGrid({
  879. width: "100%",
  880. height: "auto",
  881. autoload: true,
  882. filtering: false,
  883. pageLoading: true,
  884. pageIndex: 1,
  885. pageSize: 10000,
  886. fields: [
  887. {
  888. name: "Order", title: 'common.Order', width: 50, align: "center",
  889. itemTemplate: function (val, item) {
  890. return val < 10 ? '0' + val : val;
  891. }
  892. },
  893. {
  894. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  895. itemTemplate: function (val, item) {
  896. return i18next.t('common.' + val);
  897. }
  898. },
  899. {
  900. type: "Icon", width: 50, align: "center",
  901. itemTemplate: function (val, item) {
  902. var oIcon = {
  903. flow1: '<img src="../../images/flow_check.gif">',
  904. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  905. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  906. flow4: '<img src="../../images/flow4.gif">'
  907. },
  908. sIcon = oIcon[item.SignedWay];
  909. if (item.Order !== saCheckOrder_Push.length) {
  910. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  911. }
  912. return sIcon;
  913. }
  914. },
  915. {
  916. name: "SignedMember", title: 'common.SignedMember', width: 500,
  917. itemTemplate: function (val, item) {
  918. return Enumerable.From(val).ToString(",", "$.name");
  919. }
  920. },
  921. {
  922. type: "control", title: 'common.Action', width: 200,
  923. itemTemplate: function (val, item) {
  924. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  925. class: 'glyphicon glyphicon-pencil',
  926. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  927. click: function () {
  928. var oOption = {};
  929. oOption.SignedWay = item.SignedWay;
  930. oOption.SignedMember = item.SignedMember;
  931. oOption.Callback = function (data) {
  932. if (data.Users.length > 0) {
  933. var oFlow = {};
  934. if (data.FlowType === 'flow1') {
  935. $.each(data.Users, function (idx, user) {
  936. var oFlow = {};
  937. oFlow.id = guid();
  938. oFlow.Order = item.Order + idx;
  939. oFlow.SignedWay = data.FlowType;
  940. oFlow.SignedMember = [{
  941. id: user.id,
  942. name: user.name,
  943. deptname: user.deptname,
  944. jobname: user.jobname
  945. }];
  946. saCheckOrder_Push.insert(item.Order + idx, oFlow);
  947. });
  948. }
  949. else {
  950. var saSignedMembers = [];
  951. $.each(data.Users, function (idx, user) {
  952. saSignedMembers.push({
  953. id: user.id,
  954. name: user.name,
  955. deptname: user.deptname,
  956. jobname: user.jobname
  957. });
  958. });
  959. oFlow.id = guid();
  960. oFlow.Order = item.Order;
  961. oFlow.SignedWay = data.FlowType;
  962. oFlow.SignedMember = saSignedMembers;
  963. saCheckOrder_Push.insert(item.Order, oFlow);
  964. }
  965. var iOrder = 1;
  966. $.each(saCheckOrder_Push, function (idx, _data) {
  967. if (item.id !== _data.id) {
  968. _data.Order = iOrder;
  969. iOrder++;
  970. }
  971. });
  972. saCheckOrder_Push = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  973. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  974. $("#jsGrid" + _grididx).jsGrid("loadData");
  975. }
  976. };
  977. oPenUserListPop(oOption);
  978. }
  979. })),
  980. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  981. class: 'glyphicon glyphicon-trash',
  982. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  983. click: function () {
  984. var saNewList = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  985. saCheckOrder_Push = saNewList;
  986. $.each(saCheckOrder_Push, function (idx, _data) {
  987. _data.Order = idx + 1;
  988. });
  989. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  990. $("#jsGrid" + _grididx).jsGrid("loadData");
  991. }
  992. }))];
  993. if (saCheckOrder_Push.length !== item.Order) {
  994. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  995. class: 'glyphicon glyphicon-arrow-down',
  996. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  997. click: function () {
  998. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  999. iOrder = sOrder * 1;
  1000. $.each(saCheckOrder_Push, function (idx, _data) {
  1001. if (iOrder === _data.Order) {
  1002. _data.Order++;
  1003. }
  1004. else if ((iOrder + 1) === _data.Order) {
  1005. _data.Order--;
  1006. }
  1007. });
  1008. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  1009. $("#jsGrid" + _grididx).jsGrid("loadData");
  1010. }
  1011. })));
  1012. }
  1013. else {
  1014. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  1015. }
  1016. if (1 !== item.Order) {
  1017. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1018. class: 'glyphicon glyphicon-arrow-up',
  1019. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  1020. click: function () {
  1021. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  1022. iOrder = sOrder * 1;
  1023. $.each(saCheckOrder_Push, function (idx, _data) {
  1024. if (iOrder === _data.Order) {
  1025. _data.Order--;
  1026. }
  1027. else if ((iOrder - 1) === _data.Order) {
  1028. _data.Order++;
  1029. }
  1030. });
  1031. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  1032. $("#jsGrid" + _grididx).jsGrid("loadData");
  1033. }
  1034. })));
  1035. }
  1036. return oBtns;
  1037. }
  1038. }
  1039. ],
  1040. controller: {
  1041. loadData: function (args) {
  1042. return {
  1043. data: saCheckOrder_Push,
  1044. itemsCount: saCheckOrder_Push.length //data.length
  1045. };
  1046. }
  1047. }
  1048. });
  1049. });
  1050. };
  1051. init();
  1052. };
  1053. require(['base', 'formatnumber', 'jsgrid', 'jqprint', 'filer', 'common_eip', 'util'], fnPageInit);