$(function(){
initImageList();
initCS1File1Img();
initCS1File2Img();
initCS1File3Img();
initCS1File4Img();
initCS1File5Img();
syncBaseinfoImg();
clickradio();
});
//定义回显图片数组
var Image1List = [];
var Image2List = [];
var Image3List = [];
var Image4List = [];
var Image5List = [];
/**
* 初始化回显图片数组
*/
function initImageList(){
if ($("#downUrl").val()) {
Image1List.push(getImageByDownUrl($("#downUrl").val()));
// $("#initCS1File1").fileinput("refresh",{initialPreview: Image1List});
}
if ($("#downUrl2").val()) {
Image2List.push(getImageByDownUrl($("#downUrl2").val()));
// $("#initCS1File2").fileinput("refresh",{initialPreview: Image2List});
}
if ($("#downUrl3").val()) {
Image3List.push(getImageByDownUrl($("#downUrl3").val()));
// $("#initCS1File3").fileinput("refresh",{initialPreview: Image3List});
}
if ($("#downUrl4").val()) {
Image4List.push(getImageByDownUrl($("#downUrl4").val()));
// $("#initCS1File4").fileinput("refresh",{initialPreview: Image4List});
}
if ($("#downUrl5").val()) {
Image5List.push(getImageByDownUrl($("#downUrl5").val()));
// $("#initCS1File5").fileinput("refresh",{initialPreview: Image5List});
}
}
/**
* 根据下载路径获取回显图片数组中的图片
*/
function getImageByDownUrl(downUrl){
url = boot + '/common/downloadfilebyDownUrl.do?downUrl=' + downUrl;
return '
';
}
function initCS1File1Img() {
$("#initCS1File1").fileinput({
uploadUrl: boot + '/common/upload.do',
maxFileCount: 1,
maxFileSize: 100000,
autoReplace: true,
showClose: false, //右上角小×
showRemove: false,
initialPreview: Image1List, //回显图片
layoutTemplates:{
footer: ' ',
actions: '\n' +
' {indicator}\n' +
' \n' +
'',
},
initialPreviewConfig:[{url:boot+'/common/deleteImage.do',key: $("#cscch1Id").val()}], //原图片点击删除图标后的请求路径 参数为附件id
}).on("fileclear",function(event, data, msg){ //点击右上角小×或者Remove删除前
// debugger
}).on("filecleared",function(event, data, msg){ //点击右上角小×或者Remove删除后
// debugger
}).on('filepredelete', function(event, key, jqXHR, data) { //原图片点击删除图标前
// debugger
}).on('filedeleted', function(vKey, jqXHR, extraData){ //原图片点击删除图标后
//将数据表中对该id的引用设置为null并清除图片id
clearImgId($("#image1Id").val());
$("#image1Id").val("");
// debugger
}).on('filepreremove', function(event, id, index) { //重新选择图片点击删除图标
if ($("#downUrl").val()) { //如果原来有图片则还原回原来的图片
//先获取图片然后刷新,否则刷新时可能图片还未成功获取
var img1 = getImageByDownUrl($("#downUrl").val());
setTimeout(function(){
$("#initCS1File1").fileinput("refresh",{initialPreview: img1});
},1000);
}
// debugger
}).on("filepreajax",function(previewId, index){ //点击Upload上传图片前
// debugger
}).on('fileuploaded', function (event, data, id, index) { //点击Upload上传图片后
$("#image1Id").val(data.response.id);
});
}
function initCS1File2Img() {
$("#initCS1File2").fileinput({
uploadUrl: boot + '/common/upload.do',
maxFileCount: 1,
maxFileSize: 100000,
autoReplace: true,
showClose: false, //右上角小×
showRemove: false,
initialPreview: Image2List, //回显图片
layoutTemplates:{
footer: ' \n' +
' {drag}\n' +
' ',
actions: '\n' +
' {indicator}\n' +
' \n' +
'',
},
initialPreviewConfig:[{url:boot+'/common/deleteImage.do',key: $("#cscch2Id").val()}], //原图片点击删除图标后的请求路径 参数为附件id
}).on("fileclear",function(event, data, msg){ //点击右上角小×或者Remove删除前
// debugger
}).on("filecleared",function(event, data, msg){ //点击右上角小×或者Remove删除后
// debugger
}).on('filepredelete', function(event, key, jqXHR, data) { //原图片点击删除图标前
// debugger
}).on('filedeleted', function(vKey, jqXHR, extraData){ //原图片点击删除图标后
//将数据表中对该id的引用设置为null并清除图片id
clearImgId($("#image2Id").val());
$("#image2Id").val("");
// debugger
}).on('filepreremove', function(event, id, index) { //重新选择图片点击删除图标
if ($("#downUrl2").val()) { //如果原来有图片则还原回原来的图片
//先获取图片然后刷新,否则刷新时可能图片还未成功获取
var img2 = getImageByDownUrl($("#downUrl2").val());
setTimeout(function(){
$("#initCS1File2").fileinput("refresh",{initialPreview: img2});
},1000);
}
// debugger
}).on("filepreajax",function(previewId, index){ //点击Upload上传图片前
// debugger
}).on('fileuploaded', function (event, data, id, index) { //点击Upload上传图片后
$("#image2Id").val(data.response.id);
});
}
function initCS1File3Img() {
$("#initCS1File3").fileinput({
uploadUrl: boot + '/common/upload.do',
maxFileCount: 1,
maxFileSize: 100000,
autoReplace: true,
showClose: false, //右上角小×
showRemove: false,
initialPreview: Image3List, //回显图片
layoutTemplates:{
footer: ' \n' +
' {drag}\n' +
' ',
actions: '\n' +
' {indicator}\n' +
' \n' +
'',
},
initialPreviewConfig:[{url:boot+'/common/deleteImage.do',key: $("#cscch3Id").val()}], //原图片点击删除图标后的请求路径 参数为附件id
}).on("fileclear",function(event, data, msg){ //点击右上角小×或者Remove删除前
// debugger
}).on("filecleared",function(event, data, msg){ //点击右上角小×或者Remove删除后
// debugger
}).on('filepredelete', function(event, key, jqXHR, data) { //原图片点击删除图标前
// debugger
}).on('filedeleted', function(vKey, jqXHR, extraData){ //原图片点击删除图标后
//将数据表中对该id的引用设置为null并清除图片id
clearImgId($("#image3Id").val());
$("#image3Id").val("");
// debugger
}).on('filepreremove', function(event, id, index) { //重新选择图片点击删除图标
if ($("#downUrl3").val()) { //如果原来有图片则还原回原来的图片
//先获取图片然后刷新,否则刷新时可能图片还未成功获取
var img3 = getImageByDownUrl($("#downUrl3").val());
setTimeout(function(){
$("#initCS1File3").fileinput("refresh",{initialPreview: img3});
},1000);
}
// debugger
}).on("filepreajax",function(previewId, index){ //点击Upload上传图片前
// debugger
}).on('fileuploaded', function (event, data, id, index) { //点击Upload上传图片后
$("#image3Id").val(data.response.id);
});
}
function initCS1File4Img() {
$("#initCS1File4").fileinput({
uploadUrl: boot + '/common/upload.do',
maxFileCount: 1,
maxFileSize: 100000,
autoReplace: true,
showClose: false, //右上角小×
showRemove: false,
initialPreview: Image4List, //回显图片
layoutTemplates:{
footer: ' \n' +
' {drag}\n' +
' ',
actions: '\n' +
' {indicator}\n' +
' \n' +
'',
},
initialPreviewConfig:[{url:boot+'/common/deleteImage.do',key: $("#cscch4Id").val()}], //原图片点击删除图标后的请求路径 参数为附件id
}).on("fileclear",function(event, data, msg){ //点击右上角小×或者Remove删除前
// debugger
}).on("filecleared",function(event, data, msg){ //点击右上角小×或者Remove删除后
// debugger
}).on('filepredelete', function(event, key, jqXHR, data) { //原图片点击删除图标前
// debugger
}).on('filedeleted', function(vKey, jqXHR, extraData){ //原图片点击删除图标后
//将数据表中对该id的引用设置为null并清除图片id
clearImgId($("#image4Id").val());
$("#image4Id").val("");
// debugger
}).on('filepreremove', function(event, id, index) { //重新选择图片点击删除图标
if ($("#downUrl4").val()) { //如果原来有图片则还原回原来的图片
//先获取图片然后刷新,否则刷新时可能图片还未成功获取
var img4 = getImageByDownUrl($("#downUrl4").val());
setTimeout(function(){
$("#initCS1File4").fileinput("refresh",{initialPreview: img4});
},1000);
}
// debugger
}).on("filepreajax",function(previewId, index){ //点击Upload上传图片前
// debugger
}).on('fileuploaded', function (event, data, id, index) { //点击Upload上传图片后
$("#image4Id").val(data.response.id);
});
}
function initCS1File5Img() {
$("#initCS1File5").fileinput({
uploadUrl: boot + '/common/upload.do',
maxFileCount: 1,
maxFileSize: 100000,
autoReplace: true,
showClose: false, //右上角小×
showRemove: false,
initialPreview: Image5List, //回显图片
layoutTemplates:{
footer: ' \n' +
' {drag}\n' +
' ',
actions: '\n' +
' {indicator}\n' +
' \n' +
'',
},
initialPreviewConfig:[{url:boot+'/common/deleteImage.do',key: $("#cscch5Id").val()}], //原图片点击删除图标后的请求路径 参数为附件id
}).on("fileclear",function(event, data, msg){ //点击右上角小×或者Remove删除前
// debugger
}).on("filecleared",function(event, data, msg){ //点击右上角小×或者Remove删除后
// debugger
}).on('filepredelete', function(event, key, jqXHR, data) { //原图片点击删除图标前
// debugger
}).on('filedeleted', function(vKey, jqXHR, extraData){ //原图片点击删除图标后
//将数据表中对该id的引用设置为null并清除图片id
clearImgId($("#image5Id").val());
$("#image5Id").val("");
// debugger
}).on('filepreremove', function(event, id, index) { //重新选择图片点击删除图标
if ($("#downUrl").val()) { //如果原来有图片则还原回原来的图片
//先获取图片然后刷新,否则刷新时可能图片还未成功获取
var img5 = getImageByDownUrl($("#downUrl5").val());
setTimeout(function(){
$("#initCS1File5").fileinput("refresh",{initialPreview: img5});
},1000);
}
// debugger
}).on("filepreajax",function(previewId, index){ //点击Upload上传图片前
// debugger
}).on('fileuploaded', function (event, data, id, index) { //点击Upload上传图片后
$("#image5Id").val(data.response.id);
});
}
/**
* 将名义值对应的图片映射到baseinfo
*/
function syncBaseinfoImg(){
var cchm=$("#cchLength").val();
var cscch1height=$("#cscch1height").val();
var cscch2height=$("#cscch2height").val();
var cscch3height=$("#cscch3height").val();
var cscch4height=$("#cscch4height").val();
var cscch5height=$("#cscch5height").val();
if(parseFloat(cscch1height)==parseFloat(cchm)&&$("#downUrl").val()){
$("#crossSectionImg").attr("src",boot + '/common/downloadfilebyDownUrl.do?downUrl=' + $("#downUrl").val());
}else if(parseFloat(cscch2height)==parseFloat(cchm)&&$("#downUrl2").val()){
$("#crossSectionImg").attr("src",boot + '/common/downloadfilebyDownUrl.do?downUrl=' + $("#downUrl2").val());
}else if(parseFloat(cscch3height)==parseFloat(cchm)&&$("#downUrl3").val()){
$("#crossSectionImg").attr("src",boot + '/common/downloadfilebyDownUrl.do?downUrl=' + $("#downUrl3").val());
}else if(parseFloat(cscch4height)==parseFloat(cchm)&&$("#downUrl4").val()){
$("#crossSectionImg").attr("src",boot + '/common/downloadfilebyDownUrl.do?downUrl=' + $("#downUrl4").val());
}else if(parseFloat(cscch5height)==parseFloat(cchm)&&$("#downUrl5").val()){
$("#crossSectionImg").attr("src",boot + '/common/downloadfilebyDownUrl.do?downUrl=' + $("#downUrl5").val());
}
}
/**
* 设定单选框点击事件
*/
function clickradio(){
$(":radio").click(function(){
for(var i=1;i<6;i++){
if($("input[name='cscch"+i+".conclusion']:checked").val()=="1"){
$("#baseInfocch"+i+"Conclusion_cs1").val("OK");
$("#baseInfocch"+i+"Conclusion_cs1").css("color","green");
}else if($("input[name='cscch"+i+".conclusion']:checked").val()=="2"){
$("#baseInfocch"+i+"Conclusion_cs1").val("NG");
$("#baseInfocch"+i+"Conclusion_cs1").css("color","red");
}
}
})
}
/**
* 保存截面积数据
*/
function saveCrossSection1(){
$.ajax({
url: boot + "/crossSection/saveCrossSection1",
data: formUrl($("#crossSectionForm").serialize()),
type: "post",
async:false,
success: function (result) {
if (result.success) {
//window.location.reload();
//helper.alertDialog(result.message, "success");
} else {
helper.alertDialog(result.message, "danger");
}
}
});
}
/*
* 当原图片被删除时将数据表中对该图片id的引用设置为null
*/
function clearImgId(imgId){
$.ajax({
url: boot + "/crossSection/clearImgId",
data: {imgId:imgId},
type: "post",
async:false,
success: function (result) {
if (result.success) {
//window.location.reload();
//helper.alertDialog(result.message, "success");
} else {
//helper.alertDialog(result.message, "danger");
}
}
});
}
\n' +
' {drag}\n' +
'