HnRealNameBmwWeb/js/work/person/templateManage/contractWitnessForm.js

196 lines
7.3 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.

let form, layer, laydate, upload, personnelType,idNumber,delId,contractId,proId;
let fileList = new Array(), imgListUp = new Array();
function setParam(value,idNumberParam,delIdParam,proIdParam,contractIdParam) {
personnelType = value;
idNumber = idNumberParam;
delId = delIdParam;
contractId = contractIdParam;
proId = proIdParam;
if (value === 1) {
$('.basic-info-box').eq(0).removeAttr('style');
let obj = $('.basic-info-box').eq(1);
obj.remove('.foreman');
} else if (value === 2) {
$('.basic-info-box').eq(1).removeAttr('style');
let obj = $('.basic-info-box').eq(0);
obj.remove('.ordinary-personnel');
}
layui.use(['form', 'layer', 'laydate', 'upload'], function () {
layer = layui.layer;
form = layui.form;
laydate = layui.laydate;
upload = layui.upload;
form.render();
laydate.render({
elem: '#effectDate',
type: 'date'
});
let uploadObj = upload.render({
elem: '#test2',
// ,url: 'ERP/imageList.do' //改成自己的上传入口(这一块可以后台随便写一个,只要不报错就行) 后端代码A
multiple: true,
dataType: "json",
exts: 'jpg|png|jpeg',
acceptMime: 'image/jpg,image/png,image/jpeg',
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) {
let 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=' + result + '>' +
'</div>'
);
let 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})
}
let formData = new FormData();
//遍历最终图片集合
for (let i = 0; i < fileList.length; i++) {
formData.append("file[]", fileList[i].file)
}
data.field.idNumber = idNumber;
data.field.delId = delId;
data.field.contractId = contractId;
data.field.contractTemplateType = personnelType;
data.field.proId = proId;
formData.append("params",JSON.stringify(data.field))
// 加载提示
let 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 + '/contract/test',
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);
}
});
}
// 判断工资核定标准、绩效奖金区间是否在范围
function isRange(type, _that) {
let value = $(_that).val();
if (type === 1 && value) {
if (parseInt(value) < 60 || parseInt(value) > 600) {
$(_that).val('');
return layer.msg('工资核定标准为60~600范围之内', {icon: 5})
}else{
$(_that).val(parseInt(value));
}
} else if (type === 2 && value) {
if (parseInt(value) > 600) {
$(_that).val('');
return layer.msg('绩效奖金区间为0~600', {icon: 5})
}
let value2 = $(_that).next().val();
if (value2) {
if (parseInt(value) > parseInt(value2)) {
$(_that).val('');
return layer.msg('绩效奖金区间输入不正确', {icon: 5})
}
}
$(_that).val(parseInt(value));
$(_that).next().val(parseInt(value2));
} else if (type === 3 && value) {
if (parseInt(value) > 600) {
$(_that).val('');
return layer.msg('绩效奖金区间为0~600', {icon: 5})
}
let value2 = $(_that).prev().val();
if (value2) {
if (parseInt(value) < parseInt(value2)) {
$(_that).val('');
return layer.msg('绩效奖金区间输入不正确', {icon: 5})
}
}
$(_that).val(parseInt(value));
$(_that).prev().val(parseInt(value2));
}
}
$(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);
let 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();
}
}