$(document).on('click', '#processResultAddBtn', function () {
getProcessResultEditModal(null);
});
$(document).on('click', '#processResultEditBtn', function () {
$("#processResultViewModal").modal('hide');
getProcessResultEditModal(Number($("#processResultViewBody").find("[name='prKey']").val()));
});
$(document).on('click', '#saveProcessResultBtn', function (){
saveProcessResult('N')
});
$(document).on('click', '#saveTempBtn', function (){
saveProcessResult('Y')
});
$(document).on('click', '.tr', function (){
getProcessResultViewModal($(this).data('key'));
});
$(document).on('click', '#violationAddBtn', function (){
let violation = '';
commonCode.VT.forEach(function (item){
violation += '';
})
$('#violationDiv').append(
'
'
+ ''
+ ''
+ '
'
)
});
$(document).on('click', '#violationRemoveBtn', function (){
$(this).parent().remove();
let deleteKey = $(this).parent().children("input[name='violationKey']").val();
$("#processResultEditForm").append('');
});
$(document).on('change', '.violation', function (){
if ($(this).val() == 'etc') {
$(this).after(
''
+ ''
+ '
'
);
} else {
$(this).next('.etcDiv').remove();
}
});
$(document).on('change', '#crackdownPolice', function (){
if ($(this).val() == 'etc') {
$(this).after(
''
+ ''
+ '
'
);
} else {
$(this).next().remove();
}
});
$(document).on('change', '#executionDetail', function (){
if ($(this).val() == 'etc') {
$(this).after(
''
+ ''
+ '
'
);
} else {
$(this).next().remove();
}
});
$(document).on('click', '#processResultDownExcel', function (){
exportExcel('불법조업 불법어선 처리현황');
});
function getProcessResultViewModal(prKey){
$.ajax({
url: '/faStatistics/processResult/processResultViewModal',
data: {prKey: prKey},
type: 'GET',
dataType:"html",
success: function(html){
$("#processResultViewBody").empty().append(html)
$("#processResultViewModal").modal('show');
},
error:function(){
}
});
}
function getProcessResultEditModal(prKey){
$.ajax({
url: '/faStatistics/processResult/processResultEditModal',
data: {
prKey: prKey
},
type: 'GET',
dataType:"html",
success: function(html){
$("#processResultViewBody").empty();
$("#processResultEditModalContent").empty().append(html);
$("#processResultEditModal").modal('show');
$("#consignmentStartDt").datepicker({
format: "yyyy-mm-dd",
language: "ko"
});
$("#consignmentEndDt").datepicker({
format: "yyyy-mm-dd",
language: "ko"
});
$("#returnDt").datepicker({
format: "yyyy-mm-dd",
language: "ko"
});
$("#confiscationDt").datepicker({
format: "yyyy-mm-dd",
language: "ko"
});
$("#boatDisposalDt").datepicker({
format: "yyyy-mm-dd",
language: "ko"
});
},
error:function(){
}
});
}
function saveProcessResult(saveYn){
$('input[name="warrantReqTakeTime"]').val(dateTimeCalc($("#consignmentStartDt").val(), $("#consignmentEndDt").val()));
if(contentCheck()){
if(confirm("저장하시겠습니까?")){
$("#saveYn").val(saveYn);
contentFade("in");
const formData = new FormData($("#processResultEditForm")[0]);
let violationList = [];
$(".violation").each(function (){
violationList.push({
violationKey: $(this).parent().find('input[name="violationKey"]').val() != undefined ? Number($(this).parent().find('input[name="violationKey"]').val()) : null,
fbKey: $("#cdsEditForm").find('input[name="fbKey"]').val() != undefined ? Number($("#cdsEditForm").find('input[name="fbKey"]').val()) : null,
violation: $(this).val() != '' ? $(this).val() : null,
violationEtc: $(this).parent().find('input[name="violationEtc"]').val() != undefined ? $(this).parent().find('input[name="violationEtc"]').val() : null
});
});
for (let i=0; i < violationList.length; i++) {
if (violationList[i].violationKey != null) {
formData.append(`violationList[${i}].violationKey`, violationList[i].violationKey);
}
if (violationList[i].fbKey != null) {
formData.append(`violationList[${i}].fbKey`, violationList[i].fbKey);
}
if (violationList[i].violation != null) {
formData.append(`violationList[${i}].violation`, violationList[i].violation);
}
if (violationList[i].violationEtc != null) {
formData.append(`violationList[${i}].violationEtc`, violationList[i].violationEtc);
}
}
$.ajax({
type : 'POST',
data : formData,
url : "/faStatistics/processResult/saveProcessResult",
processData: false,
contentType: false,
success : function(result) {
alert("저장되었습니다.");
contentFade("out");
$("#processResultEditModal").modal('hide');
},
error : function(xhr, status) {
alert("저장에 실패하였습니다.")
contentFade("out");
}
})
}
}
}
function contentCheck(){
let flag = true;
return flag;
}
function exportExcel(name){
var excelHandler = {
getExcelFileName : function(){
return name+getToday()+'.xlsx'; //파일명
},
getSheetName : function(){
return name;
},
getExcelData : function(){
return document.getElementById('prTable'); //TABLE id
},
getWorksheet : function(){
return XLSX.utils.table_to_sheet(this.getExcelData());
}
}
// step 1. workbook 생성
var wb = XLSX.utils.book_new();
// step 2. 시트 만들기
var newWorksheet = excelHandler.getWorksheet();
// step 3. workbook에 새로만든 워크시트에 이름을 주고 붙인다.
XLSX.utils.book_append_sheet(wb, newWorksheet, excelHandler.getSheetName());
// step 4. 엑셀 파일 만들기
var wbout = XLSX.write(wb, {bookType:'xlsx', type: 'binary'});
// step 5. 엑셀 파일 내보내기
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), excelHandler.getExcelFileName());
}
function s2ab(s) {
var buf = new ArrayBuffer(s.length); //convert s to arrayBuffer
var view = new Uint8Array(buf); //create uint8array as viewer
for (var i=0; i