hn_cloud_web/smz-web/js/work/person/wagesManage/wagesInfoReceiptUploadEnclo...

260 lines
9.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var form, layer, laydate, upload, personnelType,idNumber,delId,contractId,proId;
var fileList = new Array(), imgListUp = new Array();
var id = localStorage.getItem("id");
var month = localStorage.getItem("month");
var proId = localStorage.getItem("proId");
var subId = localStorage.getItem("subId");
var teamId = localStorage.getItem("teamId");
var securityMaymentsFileId = '';
layui.use(['form', 'layer', 'laydate', 'upload'], function () {
layer = layui.layer;
form = layui.form;
laydate = layui.laydate;
upload = layui.upload;
form.render();
var uploadcom1 = upload.render({
elem: '#test1',
url: smz_ht_url + '/wagesInfoReceipt/uploadReceipt', //改成您自己的上传接口
multiple: true,
dataType: "json",
exts: 'jpg|png|jpeg',
// acceptMime: 'image/pdf',
auto: false, //是否自动上传 默认为true
number: 10, //最大上传数量
size: 1024 * 100, //最大文件大小单位k
auto: false, //是否自动上传 默认为true
bindAction: '#hideUpload1', //绑定的按钮
field: 'file', //传到后台的字段名,默认file
choose: function (obj) {
CODE_1 = 1;
uploadcom1.config.elem.next()[0].value = '';
files = obj.pushFile();
obj.preview(function (index, file, result) {
var length = $('#demo1 img').length;
if (length > 9) {
return layer.msg("附件为1-10张请勿过多上传", {icon: 5});
}
$('#demo1').append('<img src="' + result + '" id="' + index + '" alt="' + file.name + '" style="height: 80px;width: 80px;margin-right: 10px" class="layui-upload-img ">');
$('#' + index).bind('dblclick', function () {//双击删除指定预上传图片
delete files[index];//删除指定图片
$(this).remove();
});
});
},
before: function (obj) {
this.data = {
id: id,
month:month,
proId:proId,
subId:subId,
teamId:teamId
};
if ($("[name='brand']").val() == '') {
return false;
} else {
console.log(files);
var names = '';
layui.each(files, function (index, file) {
console.log(file.name)
names += file.name + ',';
});
$("[name='image']").val(names)
console.log(names);
}
return true;
},
done: function (data) {
},
allDone: function (data) {
num++;
console.log("num:"+num)
if (num == photoCount) {
num = 0;
top.layer.close(loadingMsg);
top.layer.msg('文件保存成功', {icon: 1, time: 2000});
setTimeout("reloading()", 2100);
}
},
error: function (e) {
//请求异常回调
console.log(e)
}
});
$("#month").val(month);
$("#proId").val(proId);
$("#subId").val(subId);
$("#teamId").val(teamId);
form.on('submit(formDemo)', function (data) {
var id = $("#id").val();
if (id == '') {
saveData(data);
}else{
updateData(data);
}
});
});
// 提交数据
function saveData(data) {
if($("#demo1").children().length==0){
return layer.msg("请上传回执单附件", {icon: 5})
}
// 加载提示
var loadingMsg = layer.msg('数据上传中,请稍候...', {icon: 16, scrollbar: false, time: 0});
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: smz_ht_url + '/wagesInfoReceipt/add',
contentType: "application/json; charset=utf-8",
dataType: 'json', // 服务器返回数据类型
data: JSON.stringify(data.field), //获取提交的表单字段
success: function (result) {
console.log(result)
layer.close(loadingMsg); // 关闭提示层
if (result.resMsg == "保存成功") {
id = result.obj.id;
parent.layer.msg('数据已保存,上传文件中。。。', {icon: 1, time: 3000},function () {
$("#hideUpload1").trigger("click");
setTimeout("reloading()", 1100);
});
}else{
parent.layer.msg(result.resMsg, {icon: 5});
setTimeout("reloading()", 1100);
}
},
error: function (result) {
layer.close(loadingMsg); // 关闭提示层
layer.msg('数据上传发生异常,请稍后重试', {icon: 16, scrollbar: false,time:2000});
}
});
}
// 修改数据
function updateData(data) {
if($("#demo1").children().length==0){
return layer.msg("请上传回执单附件", {icon: 5})
}
// 加载提示
var loadingMsg = layer.msg('数据上传中,请稍候...', {icon: 16, scrollbar: false, time: 0});
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: smz_ht_url + '/wagesInfoReceipt/update?securityMaymentsFileId=' + securityMaymentsFileId,
contentType: "application/json; charset=utf-8",
dataType: 'json', // 服务器返回数据类型
data: JSON.stringify(data.field), //获取提交的表单字段
success: function (result) {
console.log(result)
layer.close(loadingMsg); // 关闭提示层
if (result.obj == "修改成功") {
id = $("#id").val();
parent.layer.msg('数据已保存,上传文件中。。。', {icon: 1, time: 3000},function () {
let num = 0;
$("#demo1").find("img").each(function () {
let newPhoto = $(this).attr("newPhoto");
if (newPhoto === undefined) {
num++;
}
})
if (num > 0) {
$("#hideUpload1").trigger("click");
}
setTimeout("reloading()", 1100);
});
}else{
parent.layer.msg(result.obj, {icon: 5});
setTimeout("reloading()", 1100);
}
},
error: function (result) {
layer.close(loadingMsg); // 关闭提示层
layer.msg('数据上传发生异常,请稍后重试', {icon: 16, scrollbar: false,time:2000});
}
});
}
$(document).on("mouseenter mouseleave", ".file-iteme", function (event) {
if (event.type === "mouseenter") {
//鼠标悬浮
$(this).children(".info").fadeIn("fast");
$(this).children(".handle").fadeIn("fast");
} else if (event.type === "mouseleave") {
//鼠标离开
$(this).children(".info").hide();
$(this).children(".handle").hide();
}
});
function setDisableWagesInfoReceipt() {
$("#spanFont").css("display", "none");
$("#test1").css("display", "none");
}
// 表单赋值
function setDataWagesInfoReceipt(data) {
$("#id").val(data.id);
var securityMaymentsFilePaths = data.securityMaymentsFilePaths;
if (securityMaymentsFilePaths != '' && securityMaymentsFilePaths != null && securityMaymentsFilePaths != 'null') {
var photos = securityMaymentsFilePaths.split(",");
var securityMaymentsFileIds = data.securityMaymentsFileId.split(',');
var html = '';
for (var i = 0; i < photos.length; i++) {
var path = '';
if (photos[i].indexOf("http") != -1) {
path = photos[i];
} else {
path = smz_ht_url +"/" + photos[i];
}
html += '<img newPhoto="1" src="' + path + '" name="' + photos[i] + '" ondblclick="delPhoto(\'' + i + 'securityMaymentsFile\',\'' + securityMaymentsFileIds[i] + '\')" id="' + i + 'securityMaymentsFile" style="height: 80px;width: 80px;margin-right: 10px" class="layui-upload-img ">';
}
$('#demo1').append(html);
}
}
// 表单赋值
function setDataWagesInfoReceiptView(data) {
$("#id").val(data.id);
var securityMaymentsFilePaths = data.securityMaymentsFilePaths;
if (securityMaymentsFilePaths != '' && securityMaymentsFilePaths != null && securityMaymentsFilePaths != 'null') {
var photos = securityMaymentsFilePaths.split(",");
var securityMaymentsFileIds = data.securityMaymentsFileId.split(',');
var html = '';
for (var i = 0; i < photos.length; i++) {
var path = '';
if (photos[i].indexOf("http") != -1) {
path = photos[i];
} else {
path = smz_ht_url +"/" + photos[i];
}
html += '<img newPhoto="1" src="' + path + '" name="' + photos[i] + '" id="' + i + 'securityMaymentsFile" style="height: 80px;width: 80px;margin-right: 10px" class="layui-upload-img ">';
}
$('#demo1').append(html);
}
}
function delPhoto(id, photoId) {
$('#' + id).remove();
if (id.indexOf('securityMaymentsFile') != -1) {
securityMaymentsFileId += photoId + ',';
}
}
// 关闭页面
function closePage(type) {
// let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.closeAll(); //再执行关闭
if (type === 1) {
parent.reloadData();
}
}
//设置弹窗关闭
function reloading() {
var index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.close(index); //再执行关闭
window.parent.example.ajax.reload( null, false ); // 刷新页面
}