186 lines
4.6 KiB
JavaScript
186 lines
4.6 KiB
JavaScript
let pageLoading = 0;
|
||
let apiKey = 'c38903157cbffc30961f50bc29d0991a6cd8af495ab3009b05c5f98e82b2e61b94ba2d5c0a48fc518b1cd74c9e427b01051a228f670f3c5282544dfbec93db87';
|
||
|
||
let userList = JSON.parse($('#userList').val()) || {};
|
||
|
||
window.addEventListener('load', function () {
|
||
if (pageLoading == 0) {
|
||
console.log('load Event');
|
||
onLoad();
|
||
}
|
||
});
|
||
|
||
$p.events.on_editor_load = function () {
|
||
if (pageLoading == 1) {
|
||
console.log('on Editor Load');
|
||
onLoad();
|
||
}
|
||
|
||
};
|
||
|
||
function onLoad() {
|
||
$p.ex.createSearchButton();
|
||
$p.ex.KeikaNissu();
|
||
$p.ex.createReportButton();
|
||
|
||
pageLoading = 1;
|
||
}
|
||
|
||
$p.ex.searchKeiyakuData = function () {
|
||
let resultsId = $('#Results_Class009').val();
|
||
if (resultsId) {
|
||
$p.apiGet({
|
||
'id': resultsId,
|
||
//'async': true,
|
||
'data': {
|
||
'ApiVersion': 1.1,
|
||
'ApiKey': apiKey,
|
||
},
|
||
'done': function (data) {
|
||
console.log(data);
|
||
//邸名:ClassJ to ClassD
|
||
//住所 ClassL to ClassE
|
||
//契約会社:ClassF to Class020
|
||
//施工エリア:ClassG to Class021
|
||
|
||
if (data.Response.TotalCount) {
|
||
let ClassJ = data.Response.Data[0].ClassHash.ClassJ; //邸名
|
||
let ClassL = data.Response.Data[0].ClassHash.ClassL; //住所
|
||
let ClassF = data.Response.Data[0].ClassHash.ClassF; //契約会社
|
||
let ClassG = data.Response.Data[0].ClassHash.ClassG; //施工エリア
|
||
|
||
$p.set($('#Results_ClassD'), ClassJ);
|
||
$p.set($('#Results_ClassE'), ClassL);
|
||
$p.set($('#Results_Class020'), ClassF);
|
||
$p.set($('#Results_Class021'), ClassG);
|
||
}
|
||
|
||
},
|
||
'fail': function (data) {
|
||
console.log(data);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
let companyData = {};
|
||
|
||
$p.ex.getcompanyData = function () {
|
||
//契約会社マスタを事前取得して変数に保存
|
||
let tableId = 96235;
|
||
if (tableId) {
|
||
$p.apiGet({
|
||
'id': tableId,
|
||
//'async': true,
|
||
'data': {
|
||
'ApiVersion': 1.1,
|
||
'ApiKey': 'c38903157cbffc30961f50bc29d0991a6cd8af495ab3009b05c5f98e82b2e61b94ba2d5c0a48fc518b1cd74c9e427b01051a228f670f3c5282544dfbec93db87',
|
||
},
|
||
'done': function (data) {
|
||
//console.log(data);
|
||
$.each(data.Response.Data, function (index, value) {
|
||
companyData[value.ResultId] = value;
|
||
});
|
||
|
||
console.log(companyData);
|
||
},
|
||
'fail': function (data) {
|
||
console.log(data);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
$p.ex.getcompanyData();
|
||
|
||
//送信ボタンの作成
|
||
$p.ex.createSearchButton = () => {
|
||
let div = document.createElement('div');
|
||
let button = document.createElement('button');
|
||
|
||
button.type = 'button';
|
||
button.id = 'searchKeiyakuCodeBtn';
|
||
button.innerHTML = '契約情報を検索';
|
||
//button.setAttribute('onclick', '$p.ex.searchKeiyakuData()');
|
||
button.style.marginLeft = '120px';
|
||
button.style.marginBottom = '15px';
|
||
div.style.clear = 'both';
|
||
div.append(button);
|
||
$('#Results_Class009Field').after(div);
|
||
$('#searchKeiyakuCodeBtn').button({
|
||
icon: 'ui-icon-lightbulb'
|
||
});
|
||
$('#searchKeiyakuCodeBtn').on('click', function () {
|
||
//console.log('button click');
|
||
$p.ex.searchKeiyakuData();
|
||
});
|
||
}
|
||
|
||
$p.on('change', 'ClassH', function () {
|
||
let recordId = $('#Results_ClassH').val();
|
||
$p.set($('#Results_Description001'), JSON.stringify(companyData[recordId]));
|
||
});
|
||
|
||
//経過日数計算
|
||
$p.on('change', 'DateA', function () {
|
||
$p.ex.KeikaNissu();
|
||
});
|
||
|
||
|
||
$p.ex.KeikaNissu = function () {
|
||
let dateAstr = $('#Results_DateA').val();
|
||
let now = new Date();
|
||
let passDays = 0;
|
||
|
||
if (dateAstr) {
|
||
let dateA = new Date(dateAstr);
|
||
if (now.getTime() > dateA.getTime()) {
|
||
passDays = Math.floor((now.getTime() - dateA.getTime()) / (1000 * 60 * 60 * 24));
|
||
}
|
||
}
|
||
|
||
if ($('#passedDays')) {
|
||
$('#passedDays').remove();
|
||
}
|
||
let div = document.createElement('div');
|
||
let pYear = Math.floor(passDays / 365);
|
||
let pDays = passDays - (pYear * 365);
|
||
div.innerHTML = '経過日数:' + passDays + '日(' + pYear + '年 ' + pDays + '日)';
|
||
div.id = 'passedDays';
|
||
$('#Results_DateAField').after(div);
|
||
|
||
$('#passedDays').css({
|
||
'float': 'left',
|
||
'color': 'red',
|
||
'margin': '3px 0px',
|
||
'font-size': '1.5em',
|
||
'font-weight': 'bold',
|
||
});
|
||
}
|
||
|
||
$p.ex.createReportButton = function () {
|
||
let reportData = JSON.parse($('#reportData').val());
|
||
|
||
let div = document.createElement('div');
|
||
div.id = 'reportButtons';
|
||
$('#Guide').after(div);
|
||
|
||
|
||
if (reportData) {
|
||
console.log(reportData);
|
||
$.each(reportData, function (index, value) {
|
||
let fileName = value.reportName;
|
||
let guid = value.guid;
|
||
|
||
let button = document.createElement('button');
|
||
button.type = 'button';
|
||
button.id = 'guid_' + guid;
|
||
button.innerHTML = fileName;
|
||
button.setAttribute('onclick', '$p.ex.createReportData("' + fileName + '","' + guid + '")');
|
||
button.style.margin = '5px';
|
||
div.append(button);
|
||
$('#guid_' + guid).button({
|
||
icon: 'ui-icon-document'
|
||
});
|
||
});
|
||
}
|
||
} |