389 lines
15 KiB
JavaScript
389 lines
15 KiB
JavaScript
|
|
var num = 0;
|
|||
|
|
var nosignalTeamApplyId;
|
|||
|
|
var boardFileId = '';
|
|||
|
|
$(function () {
|
|||
|
|
layui.use(['form', 'laydate', 'upload'], function () {
|
|||
|
|
var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
|
|||
|
|
var laydate = layui.laydate;
|
|||
|
|
var upload = layui.upload;
|
|||
|
|
form.render();
|
|||
|
|
form.verify();
|
|||
|
|
form.on('select(subId)', function (data) {
|
|||
|
|
getPro(data.value,"");
|
|||
|
|
getTeam(data.value,"");
|
|||
|
|
});
|
|||
|
|
var uploadcom = upload.render({
|
|||
|
|
elem: '#test2',
|
|||
|
|
url: ctxPath + '/noSignalTeamApply/uploadFile', //改成您自己的上传接口
|
|||
|
|
multiple: true, //是否允许多文件上传,默认未false
|
|||
|
|
dataType: "json",
|
|||
|
|
// data: {"pickId": id},
|
|||
|
|
exts: 'jpg|png|jpeg',
|
|||
|
|
//acceptMime: 'image/jpg,image/png,image/jpeg,file/pdf,file/xlsx',
|
|||
|
|
auto: false, //是否自动上传 ,默认为true
|
|||
|
|
number: 6, //最大上传数量
|
|||
|
|
size: 1024 * 5, //最大文件大小,单位k
|
|||
|
|
bindAction: '#hideUpload', //绑定的按钮
|
|||
|
|
field: 'projectInsuranceFile', //传到后台的字段名,默认file
|
|||
|
|
choose: function (obj) {
|
|||
|
|
var suffixType = ''; //后缀类型
|
|||
|
|
uploadcom.config.elem.next()[0].value = '';
|
|||
|
|
files = obj.pushFile();
|
|||
|
|
obj.preview(function (index, file, result) {
|
|||
|
|
console.log(index); //得到文件索引
|
|||
|
|
console.log(file.name); //得到文件对象
|
|||
|
|
var number = $('.layui-upload-img').length;
|
|||
|
|
if(number>=6){
|
|||
|
|
layer.msg("最多只允许上传6张", {time: 1000});
|
|||
|
|
return delete files[index];
|
|||
|
|
}
|
|||
|
|
$('#demo').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: nosignalTeamApplyId
|
|||
|
|
};
|
|||
|
|
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) {
|
|||
|
|
top.layer.msg('文件保存成功', {icon: 1, time: 2000});
|
|||
|
|
setTimeout("reloading()", 2100);
|
|||
|
|
},
|
|||
|
|
error: function (e) {
|
|||
|
|
//请求异常回调
|
|||
|
|
console.log(e)
|
|||
|
|
},
|
|||
|
|
progress:function (n, elem) {
|
|||
|
|
alert("请联系管理员")
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 验证成功后才会执行下面的操作
|
|||
|
|
form.on('submit(formDemo)', function (data) {
|
|||
|
|
var id = $("#id").val();
|
|||
|
|
if (id == '') {
|
|||
|
|
addNoSignalTeamApply(data); // 新增无信号打卡
|
|||
|
|
} else {
|
|||
|
|
updateSubcontractor(data);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
var minListDate = $('#hidMinListDate').val();//最小可选时间,例:1990-02-01
|
|||
|
|
var maxListDate = $('#hidMaxListDate').val();//最大可选时间,例:2200-12-31
|
|||
|
|
$('#startTime').val(getNowTime());
|
|||
|
|
|
|||
|
|
$('#stopTime').val(getNowTime());
|
|||
|
|
|
|||
|
|
var begin = "#startTime", end = "#stopTime";//开始时间选择框、结束时间选择框:文本框
|
|||
|
|
var startDate = laydate.render({
|
|||
|
|
elem: begin,
|
|||
|
|
trigger: 'click',
|
|||
|
|
max:maxListDate,//设置一个默认最大值
|
|||
|
|
done: function(value, date) {
|
|||
|
|
// 结束时间大于开始时间
|
|||
|
|
endDate.config.min ={
|
|||
|
|
year:date.year,
|
|||
|
|
month:date.month-1, //关键
|
|||
|
|
date: date.date,
|
|||
|
|
hours: 0,
|
|||
|
|
minutes: 0,
|
|||
|
|
seconds : 0
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
var endDate = laydate.render({
|
|||
|
|
elem: end,
|
|||
|
|
min:minListDate,//设置min默认最小值
|
|||
|
|
trigger: 'click',
|
|||
|
|
done: function(value, date) {
|
|||
|
|
// 开始时间小于结束时间
|
|||
|
|
startDate.config.max={
|
|||
|
|
year:date.year,
|
|||
|
|
month:date.month-1,//关键
|
|||
|
|
date: date.date,
|
|||
|
|
hours: 0,
|
|||
|
|
minutes: 0,
|
|||
|
|
seconds : 0
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
//新增无信号打卡
|
|||
|
|
function addNoSignalTeamApply(formData) {
|
|||
|
|
if ($("#subId").val()=="-1"){
|
|||
|
|
parent.layer.msg("请选择分包商", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#proId").val()=="-1"){
|
|||
|
|
parent.layer.msg("请选择工程", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#teamId").val()=="-1"){
|
|||
|
|
parent.layer.msg("请选择班组", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#demo").children().length == 0){
|
|||
|
|
parent.layer.msg("请选择附件", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#demo").children().length >6){
|
|||
|
|
parent.layer.msg("最多上传6张图片", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#remark").val() == ""){
|
|||
|
|
parent.layer.msg("请填写备注描述", {icon: 2, time: 2000});
|
|||
|
|
}else{
|
|||
|
|
var formUrl = ctxPath + "/noSignalTeamApply/addNoSignalTeamApply";
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'POST',
|
|||
|
|
async: true, // 默认异步true,false表示同步
|
|||
|
|
url: formUrl, // 请求地址
|
|||
|
|
contentType: "application/json; charset=utf-8",
|
|||
|
|
dataType: 'json', // 服务器返回数据类型
|
|||
|
|
data: JSON.stringify(formData.field), //获取提交的表单字段
|
|||
|
|
success: function (data) {
|
|||
|
|
if (data.resMsg == "保存成功") {
|
|||
|
|
nosignalTeamApplyId = data.obj;
|
|||
|
|
$("#hideUpload").trigger("click");
|
|||
|
|
setTimeout("reloading()", 2100);
|
|||
|
|
} else if (data.resMsg == "保存失败") {
|
|||
|
|
parent.layer.msg('保存失败', {icon: 2, time: 2000});
|
|||
|
|
setTimeout("reloading()", 2100);
|
|||
|
|
} else {
|
|||
|
|
parent.layer.msg(data, {icon: 2, time: 2000});
|
|||
|
|
setTimeout("reloading()", 2100);
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
error: function (XMLHttpRequest, textStatus, e) {
|
|||
|
|
layer.msg('数据请求发生异常,请稍后重试', {icon: 16, scrollbar: false});
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//修改分包商
|
|||
|
|
function updateSubcontractor(formData) {
|
|||
|
|
if ($("#subId").val()=="-1"){
|
|||
|
|
parent.layer.msg("请选择分包商", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#proId").val()=="-1"){
|
|||
|
|
parent.layer.msg("请选择工程", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#teamId").val()=="-1"){
|
|||
|
|
parent.layer.msg("请选择班组", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#demo").children().length == 0){
|
|||
|
|
parent.layer.msg("请选择附件", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#demo").children().length >6){
|
|||
|
|
parent.layer.msg("最多上传6张图片", {icon: 2, time: 2000});
|
|||
|
|
}else if($("#remark").val() == ""){
|
|||
|
|
parent.layer.msg("请填写备注描述", {icon: 2, time: 2000});
|
|||
|
|
}else{
|
|||
|
|
|
|||
|
|
formData.field.fileId = boardFileId;
|
|||
|
|
var formUrl = ctxPath + "/noSignalTeamApply/updNoSignalTeamApply";
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'POST',
|
|||
|
|
async: true, // 默认异步true,false表示同步
|
|||
|
|
url: formUrl, // 请求地址
|
|||
|
|
contentType: "application/json; charset=utf-8",
|
|||
|
|
data: JSON.stringify(formData.field), //获取提交的表单字段
|
|||
|
|
success: function (data) {
|
|||
|
|
nosignalTeamApplyId = $("#id").val();
|
|||
|
|
if (data.resMsg == "保存成功") {
|
|||
|
|
var number = 0;
|
|||
|
|
$("#demo").find("img").each(function () {
|
|||
|
|
var newPhoto = $(this).attr("newPhoto");
|
|||
|
|
if (newPhoto === undefined) {
|
|||
|
|
number++;
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if (number > 0) {
|
|||
|
|
$("#hideUpload").trigger("click");
|
|||
|
|
}
|
|||
|
|
if(!number>0){
|
|||
|
|
parent.layer.msg('修改成功', {icon: 1, time: 2000});
|
|||
|
|
setTimeout("reloading()", 2100);
|
|||
|
|
}
|
|||
|
|
} else if (data.resMsg == "保存失败") {
|
|||
|
|
parent.layer.msg('保存失败', {icon: 2, time: 2000});
|
|||
|
|
} else {
|
|||
|
|
parent.layer.msg(data, {icon: 2, time: 2000});
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
error: function (e) {
|
|||
|
|
console.log("########");
|
|||
|
|
console.log(e);
|
|||
|
|
console.log("########");
|
|||
|
|
layer.msg('数据请求发生异常,请稍后重试', {icon: 16, scrollbar: false});
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 表单赋值
|
|||
|
|
function setData(data) {
|
|||
|
|
$("#id").val(data[0].id);
|
|||
|
|
getSub(data[0].subId);
|
|||
|
|
getPro(data[0].subId,data[0].proId);
|
|||
|
|
getTeam("",data[0].teamId);
|
|||
|
|
$("#startTime").val(data[0].startTime);
|
|||
|
|
$("#stopTime").val(data[0].stopTime);
|
|||
|
|
|
|||
|
|
$("#remark").val(data[0].remark);
|
|||
|
|
var filePath = data[0].filePath;
|
|||
|
|
if (filePath != "" && filePath != null && filePath != 'null') {
|
|||
|
|
var demo = $("#demo");
|
|||
|
|
var html = '';
|
|||
|
|
var photoT = filePath.split(",");
|
|||
|
|
var ids = data[0].fileId.split(",");
|
|||
|
|
for (var j = 0; j < photoT.length; j++) {
|
|||
|
|
var path = '';
|
|||
|
|
if (photoT[j].indexOf("http") != -1) {
|
|||
|
|
path = photoT[j];
|
|||
|
|
} else {
|
|||
|
|
path = dataPath + "/" + photoT[j];
|
|||
|
|
}
|
|||
|
|
html += '<img newPhoto="1" src="' + path + '" BoardFileId="' + j + '" name="' + photoT[j] + '" ondblclick="delPhoto(\'' + j + 'BoardFile\',\'' + ids[j] + '\')" id="' + j + 'BoardFile" style="height: 80px;width: 80px;margin-right: 10px" class="layui-upload-img ">';
|
|||
|
|
}
|
|||
|
|
demo.append(html);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function delPhoto(id, photoId) {
|
|||
|
|
$('#' + id).remove();
|
|||
|
|
boardFileId += photoId + ',';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//设置弹窗关闭
|
|||
|
|
function reloading() {
|
|||
|
|
var index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
|
|||
|
|
parent.layer.close(index); //再执行关闭
|
|||
|
|
window.parent.example.ajax.reload( null, false ); // 刷新页面
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获得当前时间 yyyy-MM-dd
|
|||
|
|
* @returns {string}
|
|||
|
|
*/
|
|||
|
|
function getNowTime() {
|
|||
|
|
var time = new Date();
|
|||
|
|
var year = time.getFullYear();
|
|||
|
|
var month = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
|
|||
|
|
var day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
|
|||
|
|
return year + "-" + month + "-" + day;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取当月第一天
|
|||
|
|
* @returns {string}
|
|||
|
|
*/
|
|||
|
|
function getCurrentMonthFirst() {
|
|||
|
|
var date = new Date();
|
|||
|
|
date.setDate(1);
|
|||
|
|
var year = date.getFullYear();
|
|||
|
|
var month = date.getMonth() + 1 > 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
|
|||
|
|
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
|||
|
|
return year + "-" + month + "-" + day;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
function getSub(subId) {
|
|||
|
|
$("#subId").empty();
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'POST',
|
|||
|
|
url: ctxPath + '/noSignalTeamApply/getSub',
|
|||
|
|
data: {},
|
|||
|
|
dataType: 'json',
|
|||
|
|
success: function (data) {
|
|||
|
|
if(data.length>0){
|
|||
|
|
var str = '<option selected value="-1">请选择分包商</option>';
|
|||
|
|
for(var i = 0; i < data.length; i++) {
|
|||
|
|
if(subId == data[i].id) {
|
|||
|
|
str += '<option selected value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
|||
|
|
} else {
|
|||
|
|
str += '<option value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$("#subId").append(str);
|
|||
|
|
layui.form.render('select'); //这里就是我们要渲染的地方了
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
function getPro(subId,proId) {
|
|||
|
|
$("#proId").empty();
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'POST',
|
|||
|
|
url: ctxPath + '/noSignalTeamApply/getPro',
|
|||
|
|
data: {subId:subId},
|
|||
|
|
dataType: 'json',
|
|||
|
|
success: function (data) {
|
|||
|
|
if(data.length>0){
|
|||
|
|
var str = '<option selected value="-1">请选择工程</option>';
|
|||
|
|
for(var i = 0; i < data.length; i++) {
|
|||
|
|
if(proId == data[i].id) {
|
|||
|
|
str += '<option selected value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
|||
|
|
} else {
|
|||
|
|
str += '<option value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$("#proId").append(str);
|
|||
|
|
layui.form.render('select'); //这里就是我们要渲染的地方了
|
|||
|
|
}else{
|
|||
|
|
var str = '<option selected value="-1">请选择工程</option>';
|
|||
|
|
$("#proId").append(str);
|
|||
|
|
layui.form.render('select'); //这里就是我们要渲染的地方了
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
function getTeam(subId,teamId) {
|
|||
|
|
$("#teamId").empty();
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'POST',
|
|||
|
|
url: ctxPath + '/noSignalTeamApply/getTeam',
|
|||
|
|
data: {
|
|||
|
|
subId: subId,
|
|||
|
|
teamId: teamId
|
|||
|
|
},
|
|||
|
|
dataType: 'json',
|
|||
|
|
success: function (data) {
|
|||
|
|
if(data.length>0){
|
|||
|
|
var str = '<option selected value="-1">请选择班组</option>';
|
|||
|
|
for(var i = 0; i < data.length; i++) {
|
|||
|
|
if(teamId == data[i].id) {
|
|||
|
|
str += '<option selected value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
|||
|
|
} else {
|
|||
|
|
str += '<option value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$("#teamId").append(str);
|
|||
|
|
layui.form.render('select'); //这里就是我们要渲染的地方了
|
|||
|
|
}else{
|
|||
|
|
var str = '<option selected value="-1">请选择班组</option>';
|
|||
|
|
$("#teamId").append(str);
|
|||
|
|
layui.form.render('select'); //这里就是我们要渲染的地方了
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|