(function ($, w, d) { 'use strict'; /** * 上海駒驛須移除選項 * @param {Object} input jquery 物件; */ w.fnKeyUnit = function (input) { input.value = input.value.toUpperCase(); }; /** * 上海駒驛須移除選項 * @param {Object} handle jquery 物件; */ w.fnSGMod = function (handle) { var oHandle = handle || $('.shjy-box'); if (parent.OrgID !== 'SG') { oHandle.remove(); } }; /** * 更新帳單信息 * @param {String} servname 服務端類名稱 * @param {String} xbid 當前資料id * @param {String} billno 帳單號碼 */ w.fnUpdateBillInfo = function (servname, xbid, billno) { var oPm = { Guid: xbid }; if (billno) { oPm.BillNO = billno; } g_api.ConnectLite(servname, 'UpdateBillInfo', oPm, function (res) { if (res.RESULT) { console.log(res); } }); }; /** * 更新帳單信息 * @param {String} billno 帳單號碼 */ w.fnDeleteBillInfo = function (billno) { var oPm = { BillNO: billno }; g_api.ConnectLite('Exhibition', 'DeleteBillInfo', oPm, function (res) { if (res.RESULT) { console.log(res); } }); }; //取得下拉已選的數值 w.getSelectedValues = function (strSelector) { let result = []; let collection = document.querySelectorAll(strSelector + " option"); collection.forEach(function (x) { if (x.selected) { result.push(x.value); } }); return result; }; /** * 驗證是否存在的的有效的帳單資料 * @param {Array} bills 帳單 * @return {Boolean} 是否有效 */ w.fnCheckBillEffective = function (bills) { var saBill_Effective = []; if (bills && bills.length > 0) { saBill_Effective = $.grep(bills, function (bill) { return bill.AuditVal !== '6'; }); } return saBill_Effective.length > 0; }; /** * 驗證是否存在的的有效的帳單資料 * @param {Array} bills 退運帳單 * @return {Boolean} 是否有效 */ w.fnCheckRtnBillEffective = function (bills) { var saBill_Effective = []; if (bills && bills.length > 0) { $.grep(bills, function (_bill) { if (_bill.Bills && _bill.Bills.length > 0) { saBill_Effective.push($.grep(_bill.Bills, function (bill) { return bill.AuditVal !== '6'; })); } }); } return saBill_Effective.length > 0; }; /** * 添加費用明細 * @param {Object} option 配置 */ w.fnStarFeeItems = function (option) { option = option || {}; var oGrid = null, saItems = [], saProfileGets = [], fnSetProfileDrop = function (handle) { return CallAjax(ComFn.W_Com, ComFn.GetList, { Type: '', Params: { profiles: { ProfileType: 'FeeClass', OrgID: parent.OrgID, UserID: parent.UserID }, sort: { SN: 'asc' } } }, function (res) { if (res.d) { saProfileGets = JSON.parse(res.d); handle.html(createOptions(saProfileGets, 'SN', 'ProfileName')); } }); }, fnAddProfile = function (layero) { var oAddPm = {}; oAddPm.OrgID = parent.OrgID; oAddPm.UserID = parent.UserID; oAddPm.ProfileType = 'FeeClass'; oAddPm.ProfileName = layero.find('#ProfileName').val(); oAddPm.ProfileSet = []; layero.find('#lstRight option').each(function () { oAddPm.ProfileSet.push(this.value); }); oAddPm.ProfileSet = JSON.stringify(oAddPm.ProfileSet); oAddPm = packParams(oAddPm); if (!oAddPm.ProfileName) { showMsg(i18next.t("message.ProfileFeesClassName_Required")); //╠message.ProfileFeesClassName_Required⇒請填寫個人化費用類別名稱╣ return false; } CallAjax(ComFn.W_Com, ComFn.GetAdd, { Params: { profiles: oAddPm } }, function (res) { if (res.d > 0) { fnSetProfileDrop(layero.find('#ProfileClass')).done(function () { layero.find('#ProfileClass option').each(function () { if ($(this).text() === oAddPm.ProfileName) { layero.find('#ProfileClass').val(this.value); return false; } }); }); showMsg(i18next.t("message.Save_Success"), 'success'); // ╠message.Save_Success⇒新增成功╣ } else { showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣ } }, function () { showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣ }); }, fnUpdProfile = function (layero) { var oUpdPm = {}, sId = layero.find('#ProfileClass').val(); oUpdPm.ProfileName = layero.find('#ProfileName').val(); oUpdPm.ProfileSet = []; layero.find('#lstRight option').each(function () { oUpdPm.ProfileSet.push(this.value); }); oUpdPm.ProfileSet = JSON.stringify(oUpdPm.ProfileSet); oUpdPm = packParams(oUpdPm, 'upd'); if (!oUpdPm.ProfileName) { showMsg(i18next.t("message.ProfileFeesClassName_Required")); // 請填寫個人化費用類別名稱 return false; } CallAjax(ComFn.W_Com, ComFn.GetUpd, { Params: { profiles: { values: oUpdPm, keys: { SN: sId } } } }, function (res) { if (res.d > 0) { fnSetProfileDrop(layero.find('#ProfileClass')).done(function () { layero.find('#ProfileClass').val(sId); }); showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣ } else { showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣ } }, function () { showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣ }); }, fnDelProfile = function (layero) { var sId = layero.find('#ProfileClass').val(); if (!sId) { showMsg(i18next.t("message.DeleteItem_Required")); //╠message.DeleteItem_Required⇒請選擇要刪除的項目╣ return false; } CallAjax(ComFn.W_Com, ComFn.GetDel, { Params: { profiles: { SN: sId } } }, function (res) { if (res.d > 0) { fnSetProfileDrop(layero.find('#ProfileClass')); layero.find('#ProfileName').val(''); layero.find('#lstRight').html(''); layero.find('#lstLeft').html(createOptions(saItems, 'id', 'text', true)); layero.find('#lstLeft').find('option:first').remove(); showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣ } else { showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣ } }, function () { showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣ }); }; getHtmlTmp('/Page/Pop/ProfileFees.html').done(function (html) { layer.open({ type: 1, title: i18next.t('common.ProfileFees'),// ╠common.ProfileFees⇒個人化費用項目╣ shadeClose: false, shade: 0.1, maxmin: true, //开启最大化最小化按钮 area: ['600px', '500px'], content: html, success: function (layero, index) { var elIistLeft = layero.find('#lstLeft'), elLstRight = layero.find('#lstRight'); fnSetProfileDrop(layero.find('#ProfileClass')); fnSetArgDrop([ { ArgClassID: 'FeeClass', Select: elIistLeft, ShowId: true, CallBack: function (data) { saItems = data; } } ]).done(function () { elIistLeft.find('option:first').remove(); optionListSearch(elIistLeft, elLstRight, layero.find('#ProfileFilter')); }); layero.find('#ProfileClass').on('change', function () { var sProfile = this.value, saProfileSet = []; if (sProfile) { var oProfileGet = $.grep(saProfileGets, function (e) { return e.SN.toString() === sProfile; })[0]; saProfileSet = JSON.parse(oProfileGet.ProfileSet || '[]'); layero.find('#ProfileName').val(oProfileGet.ProfileName); } else { layero.find('#ProfileName').val(''); } elLstRight.html(''); elIistLeft.html(createOptions(saItems, 'id', 'text', true)).find('option:first').remove(); layero.find('#lstLeft option').each(function () { var sId = $(this).val(); if (saProfileSet.indexOf(sId) > -1) { $(this).appendTo(elLstRight); } }); }); layero.find('.cusclass-add').on('click', function () { fnAddProfile(layero); }); layero.find('.cusclass-upd').on('click', function () { fnUpdProfile(layero); }); layero.find('.cusclass-del').on('click', function () { fnDelProfile(layero); }); layero.find('#btnToRight').on('click', function () { optionListMove(elIistLeft, elLstRight); }); layero.find('#btnToLeft').on('click', function () { optionListMove(elLstRight, elIistLeft); }); layero.find('#btnToUp').on('click', function () { optionListOrder(elLstRight, true); }); layero.find('#btnToDown').on('click', function () { optionListOrder(elLstRight, false); }); transLang(layero); }, btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣ yes: function (index, layero) { var saRetn = []; layero.find('#lstRight option').each(function () { var sId = $(this).val(); saRetn.push({ guid: guid(), FinancialCode: $(this).val(), FinancialCostStatement: $(this).text(), Memo: '', FinancialCurrency: 'NTD', FinancialUnitPrice: '0', FinancialNumber: '', FinancialUnit: '', FinancialAmount: '0', FinancialExchangeRate: '1', FinancialTWAmount: '0', FinancialTaxRate: '0', FinancialTax: '0', CreateUser: parent.UserID, CreateDate: newDate() }); }); if (typeof option.Callback === 'function') option.Callback(saRetn); layer.close(index); }, cancel: function () { if (typeof option.CancelCallback === 'function') option.CancelCallback(); } }); }); }; /** * 複製費用項目 * @param {Object} option 配置 */ w.fnCopyFee = function (option) { option = option || {}; var oGrid = null, oBilllist = null, saLastData = [], saFeeList = [], fnGetBillList = function (exhibitionno, billno, flag) { return g_api.ConnectLite(Service.opm, 'GetBillInfos', { ExhibitionNO: exhibitionno || '', BillNO: billno || '' }, function (res) { if (res.RESULT) { var saData = res.DATA.rel; if (saData.length > 0) { saLastData = JSON.parse(saData[0].FeeItems); } else { saLastData = []; } if (flag) { if (saData.length > 0) { var sBilllistHtml = ''; $.each(saData, function (idx, _data) { sBilllistHtml += (idx === 0 ? '
  • ' : '
  • ') + _data.BillNO + '
  • '; }); oBilllist.html(sBilllistHtml).find('li').click(function () { oBilllist.find('li').removeClass('active'); var sBillNO = $(this).addClass('active').text(), sExhibitionNO = $('#ExhibitionName').val(); fnGetBillList(sExhibitionNO, sBillNO, false); }); } else { oBilllist.html(''); } } oGrid.jsGrid("loadData"); } }); }, //╠common.ExhibitionName⇒展覽名稱╣ ╠common.BillNO⇒帳單號碼╣ sContent = '\
    \ \
    \ \
    \ \
    \ \
    \
    \
    \
    \
    \
      \
    \
    \
    \
    \
    \
    \
    \
    '; layer.open({ type: 1, title: i18next.t('common.CopyFeeItems'),//╠common.CopyFeeItems⇒複製費用項目╣ shadeClose: false, shade: 0.1, maxmin: true, //开启最大化最小化按钮 area: ['800px', '500px'], content: sContent, success: function (layero, index) { fnSetEpoDrop({ Select: $('#ExhibitionName'), Select2: true }); oBilllist = layero.find('.bill-list'); oGrid = $("#jsGrid_Fees").jsGrid({ width: "100%", height: "320px", autoload: true, filtering: false, pageLoading: true, pageIndex: 1, pageSize: 10000, fields: [ { name: "OrderBy", title: '#', width: 30, align: "center" }, { width: 50, sorting: false, align: "center", headerTemplate: function () { return [$("", { id: 'SelectAll', type: 'checkbox', click: function () { if (this.checked) { $("#jsGrid_Fees").find('[type=checkbox]').each(function () { this.checked = true; }); saFeeList = clone(saLastData); } else { $("#jsGrid_Fees").find('[type=checkbox]').each(function () { this.checked = false; }); saFeeList = []; } } }), $('