From 9acca44c68610f9b897552ebf0dd9b6268e4d7b8 Mon Sep 17 00:00:00 2001 From: Janie <109517022+Janie06@users.noreply.github.com> Date: Wed, 14 Dec 2022 17:27:21 +0800 Subject: [PATCH] =?UTF-8?q?[WHAT]=20=E5=B1=95=E9=A4=A8=E7=AE=A1=E7=90=86?= =?UTF-8?q?=20[WHY]=20fix=20[HOW]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 展館管理: 1. 修正OrderbyValue問題,按照VenueID升冪排序 --- .../Page/ShowEasy/VenueMaintain_Upd.html | 2 +- .../pages/ShowEasy/VenueMaintain_Upd.js | 250 ++++++++++++++++-- 2 files changed, 234 insertions(+), 18 deletions(-) diff --git a/EuroTran/WebApp/Page/ShowEasy/VenueMaintain_Upd.html b/EuroTran/WebApp/Page/ShowEasy/VenueMaintain_Upd.html index 004094c..0b7dfc5 100644 --- a/EuroTran/WebApp/Page/ShowEasy/VenueMaintain_Upd.html +++ b/EuroTran/WebApp/Page/ShowEasy/VenueMaintain_Upd.html @@ -78,7 +78,7 @@
- +
diff --git a/EuroTran/WebApp/Scripts/pages/ShowEasy/VenueMaintain_Upd.js b/EuroTran/WebApp/Scripts/pages/ShowEasy/VenueMaintain_Upd.js index 789cd4a..51aa9ef 100644 --- a/EuroTran/WebApp/Scripts/pages/ShowEasy/VenueMaintain_Upd.js +++ b/EuroTran/WebApp/Scripts/pages/ShowEasy/VenueMaintain_Upd.js @@ -118,7 +118,7 @@ var fnPageInit = function () { $('#VenueID').prop('disabled', true); postArray.push(pargs._getOne()); } - postArray.push(fnSetRegionIDdrop()); + postArray.push(fnSetRegionIDdrop(), fnSetOrderByValueDrop()); $.whenArray(postArray).done(function (res) { if (pargs.action === 'upd' && res[0].RESULT) { var oRes = res[0].DATA.rel; @@ -130,12 +130,14 @@ var fnPageInit = function () { $('#CityID').val(oRes.CityID); }); }); - }; + pargs._setFormVal(oRes); + } + else { pargs._setFormVal(oRes); } - else { - pargs._setFormVal(oRes); + } + }); $('#CountryID').select2(); $('#CityID').select2(); @@ -155,7 +157,6 @@ var fnPageInit = function () { if (saList.length > 0) { $('#CountryID').html(createOptions(saList, 'CountryID', 'CountryName', true)).on('change', function () { $('#CityID').empty(); - $('#OrderByValue').empty(); if ($('#CountryID').val()) { fnSetCityValueDrop(); } @@ -174,12 +175,8 @@ var fnPageInit = function () { function (res) { if (res.RESULT) { var saList = res.DATA.rel; - $('#CityID').html(createOptions(saList, 'CityID', 'CityName', true)).on('change', function () { - $('#OrderByValue').empty(); - if ($('#CityID').val()) { - fnSetOrderByValueDrop(); //若CityID改變,觸發OrderByValue選單 - } - }); + $('#CityID').html(createOptions(saList, 'CityID', 'CityName', true)); + } }); }, @@ -191,21 +188,240 @@ var fnPageInit = function () { if (res.RESULT) { var regionList = res.DATA.rel;; $('#RegionID').html(createOptions(regionList, 'RegionID', 'RegionName', true)).on('change', function () { - //$('#CountryID').empty(); + $('#CountryID').empty(); $('#CityID').empty(); - $('#OrderByValue').empty(); fnCountryDrop(); - //if ($('#RegionID').val()) { + }); + } + }); + }, + + fnSetOrderByValueDrop = function () { + return g_api.ConnectLite(canDo.ProgramId, canDo._api.getcout, {}, + function (res) { + if (res.RESULT) { + + var iCount = res.DATA.rel; + if (canDo.action === 'add') { + iCount++; + } + $('#OrderByValue').html(createOptions(iCount)); + if (canDo.action === 'add') { + $('#OrderByValue').val(iCount); + } + } + }); + }; +}; + +require(['base', 'cando', 'select2'], fnPageInit);'use strict'; +var fnPageInit = function () { + + //連動選單API參數名稱集合 + var canDo = new CanDo({ + + //當前程式所有ID名稱集合 + idKeys: ['OrgID', 'VenueID'], + + //當前程式所有參數名稱集合 + paramKeys: ['VenueID'], + + /**客製化驗證規則 + * @param {Object} pargs CanDo 對象*/ + validRulesCus: function (pargs) { + $.validator.addMethod("venueidrule", function (value) { + var bRetn = true; + if (value) { + g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout, + { + VenueID: value + }, + function (res) { + if (res.RESULT && res.DATA.rel > 0) { + bRetn = false; + } + }, null, false); + } + return bRetn; + }); + + $.validator.addMethod("checkEmail", function (value) { + let validString = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/; + let bRetn = true; + if (value.length < 1) { + return bRetn + } + !validString.test(value) ? bRetn = false : bRetn = true; + return bRetn + }); + + $.validator.addMethod("checkWebsite", function (value) { + let validString = /^(https|http):\/\/.*$/; + let bRetn = true; + if (value.length < 1) { + return bRetn + } + !validString.test(value) ? bRetn = false : bRetn = true; + return bRetn + }); + + $.validator.addMethod("venuenamerule", function (value) { + var bRetn = true; + if (value) { + g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout, + { + VenueName: value + }, + function (res) { + if (res.RESULT && res.DATA.rel > 0) { + bRetn = false; + } + }, null, false); + } + return bRetn; + }); - // fnCountryDrop(); //若RegionID改變,觸發國家選單 - //} + $.validator.addMethod("venueennamerule", function (value) { + var bRetn = true; + if (value) { + g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout, + { + VenueName_EN: value + }, + function (res) { + if (res.RESULT && res.DATA.rel > 0) { + bRetn = false; + } + }, null, false); + } + return bRetn; + }); + }, + + //驗證規則 + validRules: function (pargs) { + return { + onfocusout: false, + rules: { + VenueID: { venueidrule: pargs.action === 'add' ? true : false }, + Email: { checkEmail: true }, + VenueName: { venuenamerule: pargs.action === 'add' ? true : false }, + VenueName_EN: { venueennamerule: pargs.action === 'add' ? true : false }, + Website: { checkWebsite: true } + }, + + messages: { + VenueID: { venueidrule: i18next.t("message.Data_Repeat") }, + Email: { checkEmail: i18next.t("message.IncorrectEmail") }, + VenueName_EN: { venueennamerule: i18next.t("message.Data_Repeat") }, + VenueName: { venuenamerule: i18next.t("message.Data_Repeat") }, + Website: { checkWebsite: i18next.t("message.IncorrectWebsite") }, + } + }; + }, + + getOneBack: function (pargs, data) { + var oRes = data; + oRes.Contactors = $.parseJSON(oRes.Contactors || '[]'); + disableInput(pargs._form, '#VenueID', false); + }, + + /**頁面初始化 + * @param {Object} pargs CanDo 對象*/ + pageInit: function (pargs) { + var postArray = []; + if (pargs.action === 'upd') { + $('#VenueID').prop('disabled', true); + postArray.push(pargs._getOne()); + } + postArray.push(fnSetRegionIDdrop(), fnSetOrderByValueDrop()); + $.whenArray(postArray).done(function (res) { + if (pargs.action === 'upd' && res[0].RESULT) { + var oRes = res[0].DATA.rel; + if (oRes.RegionID) { + $('#RegionID').val(oRes.RegionID); + fnCountryDrop().done(function () { + $('#CountryID').val(oRes.CountryID); + fnSetCityValueDrop().done(function () { + $('#CityID').val(oRes.CityID); + }); + }); + pargs._setFormVal(oRes); + } + else { + pargs._setFormVal(oRes); + } + + } + + }); + //$('#CountryID').select2(); + //$('#CityID').select2(); + + } + }), + + //國家下拉選單 + fnCountryDrop = function () { + + return g_api.ConnectLite(canDo.ProgramId, "GetCountry", { + RegionID: $('#RegionID').val() + }, //依據所選擇的洲別顯示相對應的國家選單 + function (res) { + if (res.RESULT) { + + var saList = res.DATA.rel; + console.log(saList); + if (saList.length > 0) { + $('#CountryID').html(createOptions(saList, 'CountryID', 'CountryName', true)).on('change', function () { + $('#CityID').empty(); + if ($('#CountryID').val()) { + fnSetCityValueDrop(); + } + }); + } + } + }); + + + }, + + //城市下拉選單 + fnSetCityValueDrop = function () { + return g_api.ConnectLite(canDo.ProgramId, "GetCity", + { CountryID: $("#CountryID").val() }, //依據所選擇的國家顯示相對應的城市選單 + function (res) { + if (res.RESULT) { + var saList = res.DATA.rel; + console.log(saList); + $('#CityID').html(createOptions(saList, 'CityID', 'CityName', true)); + + } + }); + }, + + //洲別下拉選單 + fnSetRegionIDdrop = function () { + return g_api.ConnectLite(canDo.ProgramId, "GetRegion", {}, + function (res) { + if (res.RESULT) { + var regionList = res.DATA.rel;; + $('#RegionID').html(createOptions(regionList, 'RegionID', 'RegionName', true)).on('change', function () { + $('#CountryID').empty(); + $('#CityID').empty(); + if ($('#RegionID').val()) { + $('#CountryID').val(""); + fnCountryDrop(); + } + + }); } }); }, fnSetOrderByValueDrop = function () { - return g_api.ConnectLite(canDo.ProgramId, canDo._api.getcout, { CityID: $("#CityID").val() }, + return g_api.ConnectLite(canDo.ProgramId, canDo._api.getcout, {}, function (res) { if (res.RESULT) {