$(function () {
var time = new Date();
var visittime = Date.parse(time);
var year = time.getFullYear(); //获取当前年份
var month = time.getMonth() + 1; //获取当前月份(0-11,0代表1月)
var day = time.getDate(); //获取当前日(1-31)
$('.date .time').text(year + '年' + month + '月' + day + '日');
$('.gender-inp .gender').hover(function () {
if (window.innerWidth > 1024) {
$(this).addClass('on');
$(this).find('.sub').stop().show();
}
}, function () {
if (window.innerWidth > 1024) {
$(this).removeClass('on');
$(this).find('.sub').stop().hide();
}
})
$('.gender-inp .gender .gender-tit').on('click', function () {
var _this = $(this);
var gender = _this.parent();
if (window.innerWidth < 1025) {
if (gender.hasClass('on')) {
gender.removeClass('on');
_this.next().stop().show();
} else {
gender.addClass('on');
_this.next().stop().hide();
}
}
})
$('.gender-inp .gender .sub a').on('click', function () {
var _this = $(this);
var _id = _this.attr('data-id');
var txt = _this.text();
_this.parents('.gender').find('input[type=hidden]').val(_id);
_this.parents('.gender').removeClass('on');
_this.parent().stop().hide();
_this.parent().prev().text(txt);
});
$('.order-box').delegate('.person-table .gender .gender-tit', 'click', function () {
var _this = $(this);
var gender = _this.parents('ul');
if (window.innerWidth < 1025) {
if (gender.hasClass('on')) {
gender.removeClass('on');
_this.next().stop().hide();
} else {
gender.addClass('on').siblings().removeClass('on');
$('.person-table .gender .sub').stop().hide();
_this.next().stop().show();
}
}
})
$('.order-box').delegate('.person-table .gender .sub a', 'click', function () {
var _this = $(this);
var _id = _this.attr('data-id');
var txt = _this.text();
_this.parents('.gender').find('input[type=hidden]').val(_id);
_this.parents('ul').removeClass('on');
_this.parent().stop().hide();
_this.parent().prev().text(txt);
});
$('.order-box').delegate('.gender select', 'change', function () {
var val = $(this).val();
$(this).parents('.gender').find('input[type=hidden]').val(val);
})
var startTime = flatpickr(".start-time", {
enableTime: true,
noCalendar: false,
dateFormat: "m-d-H:i",
time_24hr: true,
onChange: function (selectedDates, dateStr, instance) {
var startTime = Date.parse(selectedDates) / 1000;
$('input[name=start]').val(startTime);
var endTimeval = $('input[name=end]').val();
if (startTime > endTimeval && endTimeval != '') {
swal({
title: "请选择正确开始时间!",
confirmButtonColor: "#d11d26"
}, function (isConfirm) {
if (isConfirm) {
$('.start-time').val(' ');
}
});
}
}
});
var endTime = flatpickr(".end-time", {
enableTime: true,
noCalendar: false,
dateFormat: "m-d-H:i",
time_24hr: true,
onChange: function (selectedDates, dateStr, instance) {
var endTime = Date.parse(selectedDates) / 1000;
//console.log(endTime);
var startTimeval = $('input[name=start]').val();
$('input[name=end]').val(endTime);
if (startTimeval > endTime) {
swal({
title: "请选择正确结束时间!",
confirmButtonColor: "#d11d26"
}, function (isConfirm) {
if (isConfirm) {
$('.end-time').val(' ');
}
});
//console.log($('.end-time').val())
}
}
});
// $('.add-btn').on('click',function(){
// var lastLen = $('.person-table ul').length;
// var html = "";
// html = '
';
// $('.person-table').append(html);
// personHover()
// })
// '
$('.add-btn').on('click', function () {
var lastLen = $('.person-table ul').length;
var html = "";
html = '';
$('.person-table').append(html);
personHover()
})
$('.order-form-box .inp,.textarea').on('click', function () {
if ($(this).data('state') != 1) {
$(this).find('input[type=text],textarea').focus();
}
})
personHover();
function personHover() {
$('.person-table .gender').hover(function () {
if (window.innerWidth > 1024) {
$(this).parents('ul').addClass('on');
$(this).find('.sub').stop().show();
}
}, function () {
if (window.innerWidth > 1024) {
$(this).parents('ul').removeClass('on');
$(this).find('.sub').stop().hide();
}
})
}
$('.order-box').delegate('.person-table .remove-btn', 'click', function () {
var _this = $(this);
swal({
title: "确定删除该条信息吗?",
// type: "warning",
showCancelButton: true,
confirmButtonColor: "#d11d26",
confirmButtonText: "确定",
cancelButtonText: "取消",
closeOnConfirm: false,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
swal({
title: "已删除该条信息!",
type: "success",
confirmButtonText: "OK",
confirmButtonColor: "#d11d26",
});
_this.parents('ul').remove();
$('.person-table ul').each(function (index, el) {
$(el).find('.index').text(index);
personHover()
})
}
});
})
$('.order-form-box input[type=submit]').on('click', function () {
var data = {list: []};
var name = $('.name-inp input[type=text]').val();
var gender = $('.gender-inp .gender input[type=hidden]').val();
var contact = $('.contact-inp input[type=text]').val();
var idCard = $('.card-inp input[type=text]').val();
var work = $('.work-inp input[type=text]').val();
var num = $('.num-inp input[type=text]').val();
var start = $('input[name=start]').val();
var end = $('input[name=end]').val();
var idCar = $('.car-inp input[type=text]').val();
var text = $('.form-top .event-text textarea').val();
var person = $('.person-inp input[type=text]').val();
var work2 = $('.work-inp2 input[type=text]').val();
var depart = $('.depart-inp input[type=text]').val();
var tel = $('.tel-inp input[type=text]').val();
var storey = $('.storey-inp input[type=text]').val();
var room = $('.room-inp input[type=text]').val();
var captcha = $('.form-top .check-inp input[type=text]').val();
//alert(start,end);
if (!name) {
swal({
title: "请填写来访联系人!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (!gender) {
// swal({
// title:"请选择联系人性别!",
// confirmButtonColor: "#d11d26"
// })
// return false;
}
if (!contact) {
swal({
title: "请填写联系电话(手机)!",
confirmButtonColor: "#d11d26"
})
return false;
}
var telphoneTest = /^1[345789]\d{9}$/;
if (!telphoneTest.test(contact) || contact.length != 11) {
alert('请填写正确的手机号码格式!');
return false;
}
// if(idCard){
// if(!IsCard(idCard)){
// swal({
// title:"请填写正确身份证号码!",
// confirmButtonColor: "#d11d26"
// })
// return false;
// }
// }
if (!work) {
swal({
title: "请填写来访人单位!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (num) {
if (!IsNum(num)) {
swal({
title: "请填写正确来访人数!",
confirmButtonColor: "#d11d26"
})
return false;
}
} else {
swal({
title: "请填写来访人数!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (!start) {
swal({
title: "请选择预约来访开始时间!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (!end) {
swal({
title: "请选择预约来访结束时间!",
confirmButtonColor: "#d11d26"
})
return false;
}
// if(start>end){
// swal({
// title:"请选择正确预约时间!",
// confirmButtonColor: "#d11d26"
// })
// return false;
// }
checkEndTime(start, end);
function checkEndTime(startTime, endTime) {
var starArr = startTime.split(':');
var endArr = endTime.split(':');
if (starArr[0] > endArr[0]) {
swal({
title: "请选择正确预约时间!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (starArr[0] == endArr[0]) {
if (starArr[1] > endArr[1]) {
swal({
title: "请选择正确预约时间!",
confirmButtonColor: "#d11d26"
})
return false;
}
}
}
if (!text) {
swal({
title: "请填写来访事项!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (!person) {
swal({
title: "请填写接访人!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (!work2) {
swal({
title: "请填写接访单位!",
confirmButtonColor: "#d11d26"
})
return false;
}
if (!depart) {
swal({
title: "请填写接访部门!",
confirmButtonColor: "#d11d26"
})
return false;
}
// if(!tel){
// swal({
// title:"请填写接访人联系电话!",
// confirmButtonColor: "#d11d26"
// })
// return false;
// }
// if(!storey){
// swal({
// title:"请填写接访人楼层!",
// confirmButtonColor: "#d11d26"
// })
// return false;
// }
// if(!room){
// swal({
// title:"请填写接访人房间号!",
// confirmButtonColor: "#d11d26"
// })
// return false;
// }
data['visittime'] = visittime;
data['exp1'] = name;
data['exp2'] = gender;
data['exp3'] = contact;
data['exp4'] = idCard;
data['exp5'] = work;
data['exp6'] = num;
data['exp7'] = start;
data['exp8'] = end;
data['exp9'] = idCar;
data['exp10'] = text;
data['exp11'] = person;
data['exp12'] = work2;
data['exp13'] = depart;
data['exp14'] = tel;
data['exp15'] = storey;
data['exp16'] = room;
data['captcha'] = captcha;
$('.person-table-box .person-table ul').each(function (index, el) {
if (index > 0) {
var obj = {};
obj['exp1'] = $(el).find('li').eq(1).find('input[type=text]').val();
obj['exp2'] = $(el).find('li').eq(2).find('input[type=text]').val();
obj['exp3'] = $(el).find('li').eq(3).find('input[type=text]').val();
// obj['exp4'] = $(el).find('li').eq(4).find('input[type=text]').val();
// obj['exp5'] = $(el).find('li').eq(5).find('input[type=text]').val();
// obj['exp6'] = $(el).find('li').eq(6).find('input[type=text]').val();
data.list.push(obj);
}
})
$(".order-form-box input[type=submit]").attr("disabled", "disabled");
swal({
title: "提交中",
text: "......",
showCancelButton: false,
showConfirmButton: false,
buttons: false,
});
$.ajax({
url: SITE_URL + "/ajax/saveVisitorRecord",
data: data,
type: 'POST',
success: function (res) {
if (res.status == 1) {
swal({
title: res.msg,
showCancelButton: false,
confirmButtonColor: "#d11d26",
confirmButtonText: "确定"
},
function (isConfirm) {
if (isConfirm) {
location.reload();
}
});
$(".order-form-box input[type=submit]").removeAttr('disabled');
} else if (res.status == 2) {
swal({
title: res.msg,
showCancelButton: false,
confirmButtonColor: "#d11d26",
confirmButtonText: "确定"
},
function (isConfirm) {
if (isConfirm) {
$(".order-form-box input[type=submit]").removeAttr('disabled');
// location.reload();
}
});
$(".order-form-box input[type=submit]").removeAttr('disabled');
}else if (res.status == 3) {
swal({
title: res.msg,
showCancelButton: false,
confirmButtonColor: "#d11d26",
confirmButtonText: "确定"
},
function (isConfirm) {
if (isConfirm) {
$(".order-form-box input[type=submit]").removeAttr('disabled');
// location.reload();
}
});
$(".order-form-box input[type=submit]").removeAttr('disabled');
} else {
if (res.msg.captcha) {
swal({
title: res.msg.captcha,
confirmButtonColor: "#d11d26"
})
return false;
}
}
}
})
})
})
function IsCard(str) {
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
return reg.test(str);
}
function IsNum(str) {
var reg = /^[0-9]*[1-9][0-9]*$/;
return reg.test(str);
}