'use strict'; var sProgramId = getProgramId(), sQueryPrgId = 'Leave_Qry', sEditPrgId = 'Leave_Upd', sAction = getUrlParam('Action') || 'Add', sDataId = getUrlParam('Guid'), sCheckId = sDataId, fnPageInit = function () { var oCurData = { CheckFlows: [], HandleFlows: [] }, oForm = $('#form_main'), saCheckOrder_Push = [], saUsers = [], sCurAuditFlowId = null, sCurHandleFlowId = null, bGoNext = true, /** * 獲取當前審核人員 * @param {Object} data 當前審核資料 */ fnGetCurAuditor = function (data) { var saCheckFlows = $.parseJSON(data.CheckFlows), saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray(), bAuditor = false, bHandle = false, bAllAudit = false; if ('B,E'.indexOf(data.Status) > -1) {//只有審核中或者待經辦的資料才可以出現審核區塊 $.each(saNewList, function (idx, _data) { var sSignedWay = _data.source[0].SignedWay, iCount = Enumerable.From(_data.source).Where(function (e) { return (e.SignedDecision === 'Y' || e.SignedDecision === 'O'); }).Count(), sCurAuditor = Enumerable.From(_data.source).ToString(",", "$.SignedId"); if ((('flow1,flow3'.indexOf(sSignedWay) > -1 && iCount === 0) || (sSignedWay === 'flow2' && iCount !== _data.source.length))) { if (sCurAuditor.indexOf(parent.UserID) > -1) { var oCurUser = Enumerable.From(_data.source).Where(function (e) { return e.SignedId === parent.UserID; }).First(); if (sSignedWay === 'flow2' && iCount < _data.source.length - 1) { bGoNext = false; } if (!oCurUser.SignedDecision) { sCurAuditFlowId = oCurUser.FlowId; bAuditor = true; } } if (!bAllAudit) {//只要有需要審核的人,就不要檢核是否簽辦 bAllAudit = true; } return false; } }); if (!bAuditor && !bAllAudit) {//當沒有要審核的人員並且審核全部完成時才會檢核簽辦 var saHandleFlows = $.parseJSON(data.HandleFlows), sCurAuditor = saHandleFlows[0].SignedId; if (saHandleFlows[0].SignedDecision !== 'Y' && sCurAuditor === parent.UserID) { sCurHandleFlowId = saHandleFlows[0].FlowId bHandle = true; } } } return { IsAuditor: bAuditor, IsHandler: bHandle }; }, /** * 註冊加簽事件 * @param {Number} _grididx當前Gird 序號 */ fnRegisterAddFlows = function (_grididx) { $('.flowlink' + _grididx).on('click', function () { var oOption = {}; oOption.SignedWay = $(this).data('id'); oOption.Callback = function (data) { if (data.Users.length > 0) { var oFlow = {}; if (data.FlowType === 'flow1') { $.each(data.Users, function (idx, user) { oFlow = {}; oFlow.id = guid(); oFlow.Order = saCheckOrder_Push.length + 1; oFlow.SignedWay = data.FlowType; oFlow.SignedMember = [{ id: user.id, name: user.name, deptname: user.deptname, jobname: user.jobname }]; saCheckOrder_Push.push(oFlow); }); } else { var saUsers = []; $.each(data.Users, function (idx, user) { saUsers.push({ id: user.id, name: user.name, deptname: user.deptname, jobname: user.jobname }); }); oFlow.id = guid(); oFlow.Order = saCheckOrder_Push.length + 1; oFlow.SignedWay = data.FlowType; oFlow.SignedMember = saUsers; saCheckOrder_Push.push(oFlow); } saCheckOrder_Push = releaseGridList(saCheckOrder_Push); $("#jsGrid" + _grididx).jsGrid("loadData"); } }; oPenUserListPop(oOption); }); }, /** * 獲取資料 */ fnGet = function () { return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne, { Guid: sDataId }, function (res) { if (res.RESULT) { var oRes = res.DATA.rel, saFlowsText = [], sStatus = ''; if (oRes.Status === 'C-O') { sStatus = '(' + i18next.t("common.HasReEdited") + ')';// ╠common.HasReEdited⇒已抽單╣ } else if (oRes.Status === 'D-O') { sStatus = '(' + i18next.t("common.HasReturned") + ')';// ╠common.HasReturned⇒已退件╣ } else if (oRes.Status === 'X') { sStatus = '(' + i18next.t("common.HasVoid") + ')';// ╠common.HasVoid⇒已作廢╣ } //根據帳單狀態,移除抽單按鈕(扣除已經辦只能admin抽單) fnCheckReEdit(oRes.Status, oRes.AskTheDummy); if (oRes.AskTheDummy !== parent.UserID) { $('#Toolbar_Copy').remove(); } if ('B,Y'.indexOf(oRes.Status) === -1) { $('#Toolbar_Void').remove(); } var oCheck = fnGetCurAuditor(oRes); if (oCheck.IsAuditor) { $('#IsAuditor').show(); } if (oCheck.IsHandler) { $('#IsHandler').show(); } if (oCheck.IsAuditor || oCheck.IsHandler) { $('.submitdecision').click(function () { var sSubmitAction = $(this).data('id'); fnSubmitDecision(sSubmitAction); }); } if (oRes.VoidReason) { $('#VoidReason').text(oRes.VoidReason); $('.VoidReason').show(); } if (oRes.CrosssignTurn === 'N') { $('.crosssignturn').remove(); } oCurData = oRes; oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder); oCurData.CheckFlows = $.parseJSON(oCurData.CheckFlows); oCurData.HandleFlows = $.parseJSON(oCurData.HandleFlows); setFormVal(oForm, oRes); $('#StartDate').val(newDate(oCurData.StartDate)); $('#EndDate').val(newDate(oCurData.EndDate)); $('.AskTheDummy').text(oCurData.AskTheDummyName + '(' + oCurData.AskTheDummy + ') ' + oCurData.DeptName); $('.eip-note').text(oCurData.KeyNote); $('#status').text(sStatus); $('#Applicant,#AskTheDummy').text(oCurData.DeptName + ' ' + oCurData.AskTheDummyName); $('#Handle_Person').text(oCurData.Handle_PersonName);// ╠common.Important_1⇒普通╣ ╠common.Important_2⇒重要╣ ╠common.Important_3⇒很重要╣ $('#Important').text(oCurData.Important === '1' ? i18next.t("common.Important_1") : oCurData.Important === '2' ? i18next.t("common.Important_2") : i18next.t("common.Important_3")); $('#SignedNumber').text(oCurData.SignedNumber); $.each(oCurData.CheckOrder, function (idx, order) { var sFlowType = i18next.t('common.' + order.SignedWay); if (order.SignedWay !== 'flow1') { saFlowsText.push(sFlowType + '(' + Enumerable.From(order.SignedMember).ToString(",", "$.name") + ')'); } else { saFlowsText.push(Enumerable.From(order.SignedMember).ToString(",", "$.name")); } }); $('#Recipient').text($('#Agent_Person option:selected').text() + '->' + saFlowsText.join('->')); fnGetFiles($('#AdditionalFiles'), oCurData.Guid, oCurData.RelationId, oCurData.ExFeild1, sProgramId);//加載附件 fnUpload();//初始化上傳控件(審批與簽辦) fnRead();//如果是被通知的人,則修改為已閱讀狀態 $("#jsGrid1").jsGrid("loadData"); $("#jsGrid2").jsGrid("loadData"); $('[name="SignedDecision"]').click(function () { if (this.value === 'O') { $('#addotheraudit').slideDown(); } else { $('#addotheraudit').slideUp(); } }); $('[name="HandleDecision"]').click(function () { if (this.value === 'O') { $('#addotherhandle').slideDown(); } else { $('#addotherhandle').slideUp(); } }); } }); }, /** * 複製 */ fnCopy = function () { var data = oCurData; data = packParams(data); if (data.Status === 'D-O') { data.RelationId = data.Guid; } else { delete data.RelationId; } data.OrgID = parent.OrgID; data.Guid = guid(); data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|QJ|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode; data.CheckFlows = fnCheckFlows(data, true, true, saUsers); data.HandleFlows = fnHandleFlows(data, saUsers); data.CheckOrder = JSON.stringify(data.CheckOrder); data.Status = 'A'; data.IsHandled = 'N'; data.Inspectors = ''; data.Reminders = ''; data.VoidReason = ''; data.Flows_Lock = data.Flows_Lock || 'N'; data.Handle_Lock = data.Handle_Lock || 'N'; delete data.AnnualLeaveMemo; delete data.RowIndex; delete data.AskTheDummyName; delete data.Agent_PersonName; delete data.Handle_PersonName; delete data.HolidayCategoryName; delete data.DeptName; delete data.WenZhongAcount; delete data.CreateUserName; delete data.ModifyUserName; CallAjax(ComFn.W_Com, ComFn.GetAdd, { Params: { leave: data } }, function (res) { if (res.d > 0) { showMsgAndGo(i18next.t("message.Copy_Success"), sEditPrgId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Copy_Success⇒複製成功╣ } else { showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣ } }, function () { showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣ }); }, /** * 複製 */ fnRead = function () { var bToUpd = false; $.each(oCurData.CheckFlows, function (idx, _data) { if (_data.SignedId === parent.UserID && _data.SignedWay === 'flow4' && _data.SignedDecision === 'T') { _data.SignedDecision = 'R'; bToUpd = true; return false; } }); if (bToUpd) { CallAjax(ComFn.W_Com, ComFn.GetUpd, { Params: { leave: { values: { CheckFlows: JSON.stringify(oCurData.CheckFlows) }, keys: { Guid: sDataId } } } }); } }, /** * 資料作廢 */ fnVoid = function () { layer.open({ type: 1, title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣ shade: 0.75, maxmin: true, //开启最大化最小化按钮 area: ['500px', '250px'], content: '