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.
175 lines
5.1 KiB
175 lines
5.1 KiB
'use strict';
|
|
var fnPageInit = function () {
|
|
var canDo = new CanDo({
|
|
/**
|
|
* 當前程式所有ID名稱集合
|
|
*/
|
|
idKeys: ['OrgID', 'ExhibInfoID', 'ExhibitionID'],
|
|
//idKeys: ['OrgID', 'ExhibInfoID', 'CategoryID'],
|
|
/**
|
|
* 當前程式所有參數名稱集合
|
|
*/
|
|
paramKeys: ['CategoryID'],
|
|
//paramKeys: ['ExhibInfoID', 'CategoryID'],
|
|
|
|
/**
|
|
* 客製化驗證規則
|
|
* @param {Object} pargs CanDo 對象
|
|
*/
|
|
|
|
validRulesCus: function (pargs) {
|
|
$.validator.addMethod("yearrule", function (value) {
|
|
var bRetn = true;
|
|
if (value) {
|
|
g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout,
|
|
{
|
|
Year: $('#Year').val(),
|
|
ExhibitionID: $('#ExhibitionID').val()
|
|
},
|
|
function (res) {
|
|
if (res.RESULT && res.DATA.rel > 0) {
|
|
bRetn = false;
|
|
}
|
|
}, null, false);
|
|
}
|
|
return bRetn;
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 驗證規則
|
|
*/
|
|
validRules: function (pargs) {
|
|
return {
|
|
onfocusout: false,
|
|
rules: {
|
|
Year: { yearrule: pargs.action === 'add' ? true : false },
|
|
},
|
|
messages: {
|
|
Year: { yearrule: i18next.t("message.Data_Repeat") }// ╠message.Data_Repeat⇒此筆資料已建檔╣
|
|
}
|
|
};
|
|
},
|
|
|
|
|
|
/**
|
|
* 頁面初始化
|
|
* @param {Object} pargs CanDo 對象
|
|
*/
|
|
|
|
pageInit: function (pargs) {
|
|
var postArray = [];
|
|
|
|
if (pargs.action === 'upd') {
|
|
$('#ExhibInfoID').prop('disabled', true);
|
|
postArray.push(pargs._getOne());
|
|
}
|
|
|
|
if (pargs.action === 'add') {
|
|
|
|
var current_date = new Date().toJSON().slice(0, 10);
|
|
|
|
$('#StartDate').val(current_date);
|
|
$('#EndDate').val(current_date);
|
|
|
|
}
|
|
|
|
postArray.push(fnCategoryDrop(), fnSetOrderByValueDrop());
|
|
|
|
$.whenArray(postArray).done(function (res) {
|
|
if (pargs.action === 'upd' && res[0].RESULT) {
|
|
var oRes = res[0].DATA.rel;
|
|
|
|
if (oRes.CategoryID) {
|
|
|
|
$('#CategoryID').val(oRes.CategoryID);
|
|
fnExhibDrop().done(function () {
|
|
$('#ExhibitionID').val(oRes.ExhibitionID);
|
|
});
|
|
|
|
}
|
|
|
|
pargs._setFormVal(oRes);
|
|
|
|
var start_date = oRes.StartDate.split('T');
|
|
$('#StartDate').val(start_date[0]);
|
|
|
|
var end_date = oRes.EndDate.split('T');
|
|
$('#EndDate').val(end_date[0]);
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
/**
|
|
* 類別下拉選單
|
|
*/
|
|
fnCategoryDrop = function () {
|
|
return g_api.ConnectLite(canDo.ProgramId, "QueryCategoryList", {
|
|
|
|
//RegionID: $("#RegionID").val()
|
|
|
|
},
|
|
function (res) {
|
|
|
|
if (res.RESULT) {
|
|
var saCategoryList = res.DATA.rel;
|
|
$('#CategoryID').html(createOptions(saCategoryList, 'CategoryID', 'CategoryName', false)).on('change', function () {
|
|
if ($('#CategoryID').val()) {
|
|
fnExhibDrop();
|
|
}
|
|
});
|
|
|
|
}
|
|
});
|
|
},
|
|
|
|
fnExhibDrop = function () {
|
|
return g_api.ConnectLite(canDo.ProgramId, "QueryExhibList", {
|
|
|
|
CategoryID: $("#CategoryID").val()
|
|
|
|
},
|
|
function (res) {
|
|
|
|
if (res.RESULT) {
|
|
var saCategoryList = res.DATA.rel;
|
|
var sOptionHtml = createOptions(saCategoryList, 'ExhibitionID', 'ExhibitionName', false);
|
|
$('#ExhibitionID').html(sOptionHtml);
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 設定排序下拉選單
|
|
*/
|
|
fnSetOrderByValueDrop = function () {
|
|
|
|
return g_api.ConnectLite(canDo.ProgramId, canDo._api.getcout, {
|
|
|
|
ExhibInfoID: $("#ExhibInfoID").val(),
|
|
|
|
},
|
|
|
|
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'], fnPageInit);
|