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

132 lines
4.9 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");
layui.use(['form', 'layer', 'laydate', 'upload'], function () {
layer = layui.layer;
form = layui.form;
laydate = layui.laydate;
upload = layui.upload;
form.render();
var uploadObj = upload.render({
elem: '#test2',
multiple: true,
dataType: "json",
exts: 'pdf',
acceptMime: 'image/pdf',
number: 3, //最大上传数量
size: 1024 * 6, //最大文件大小单位k
auto: false, //是否自动上传 默认为true
bindAction: '#hideUpload', //绑定的按钮
choose: function (obj) {
uploadObj.config.elem.next()[0].value = '';
obj.preview(function (index, file, result) {
var viewPath = "../../../../img/fileIcon/pdf.png";
var length = $('#uploader-list .file-iteme').length;
if (length > 2) {
return layer.msg("回执单附件为1-3张请勿过多上传", {icon: 5});
}
console.error(fileList);
$('#uploader-list').append(
'<div id="" class="file-iteme">' +
'<div class="handle"><i class="layui-icon layui-icon-delete"></i></div>' +
'<img class="img" style="width: 100px;height: 100px;" data-index=' + index + ' data-name=' + file.name + ' src=' + viewPath + '>' +
'</div>'
);
var map = new Map();//将选择的图片索引和图片写成对象存入集合
map.index = index;
map.file = file;
fileList.push(map);
});
}
});
form.on('submit(formDemo)', function (data) {
saveData(data);
});
});
// 提交数据
function saveData(data) {
console.log(data);
if (fileList.length === 0) {
return layer.msg("请上传回执单附件", {icon: 5})
}
var formData = new FormData();
//遍历最终集合
for (var i = 0; i < fileList.length; i++) {
formData.append("file[]", fileList[i].file)
}
data.field.id = id;
formData.append("params",JSON.stringify(data.field))
// 加载提示
var loadingMsg = layer.msg('数据上传中,请稍候...', {icon: 16, scrollbar: false, time: 0});
$('.save').addClass("layui-btn-disabled").attr("disabled", true);
$('.cancel').addClass("layui-btn-disabled").attr("disabled", true);
$.ajax({
url: ctxPath + '/wagesInfoReceipt/uploadReceipt',
type: 'POST',
data: formData,
dataType: 'json',
processData: false,
contentType: false,
beforeSend: function () {
},
success: function (result) {
console.log(result);
layer.close(loadingMsg); // 关闭提示层
if(result.resMsg === 'success'){
top.layer.msg(result.obj, {icon: 1});
closePage(1);
}else{
parent.layer.msg(result.obj, {icon: 5});
$('.save').removeClass("layui-btn-disabled").attr("disabled", false);
$('.cancel').removeClass("layui-btn-disabled").attr("disabled", false);
}
},
error: function (result) {
layer.close(loadingMsg); // 关闭提示层
layer.msg('数据上传发生异常,请稍后重试', {icon: 16, scrollbar: false,time:2000});
$('.save').removeClass("layui-btn-disabled").attr("disabled", false);
$('.cancel').removeClass("layui-btn-disabled").attr("disabled", false);
}
});
}
$(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();
}
});
// 删除图片
$(document).on("click", ".file-iteme .handle", function (event) {
imgListUp.splice(0,imgListUp.length);
var index = $(this).next().attr('data-index');
$.each(fileList, function (inx, ele) {
//对比删除图片索引
//将未删除的存入新集合
if (index != ele.index) {
imgListUp.push(ele);
}
});
$(this).parent().remove();
//将新图片集合替换老集合
fileList.splice(0,fileList.length);
$.each(imgListUp, function (inx, ele) {
fileList.push(ele)
});
});
// 关闭页面
function closePage(type) {
// let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.closeAll(); //再执行关闭
if (type === 1) {
parent.reloadData();
}
}