<script src="$!webPath/resources/js/laydate/laydate.js"></script>
<script src="$!webPath/resources/js/ajaxfileupload.js"></script>
<script src="$!webPath/resources/js/jquery.zh.cn.js" charset="utf-8"></script>
<script>
jQuery(document).ready(function(){ jQuery.validator.methods.amount = function(e) {
var coupon_order_amount=jQuery("#coupon_order_amount").val();
var coupon_amount=jQuery("#coupon_amount").val();
if(parseInt(coupon_order_amount) > parseInt(coupon_amount)){
return true;
}else{
return false;
}
}; jQuery("#theForm").validate({
rules:{
coupon_description:{required:true},
coupon_name:{required:true},
coupon_begin_time:{required:true},
coupon_end_time:{required:true,endTime:"#coupon_begin_time"},
coupon_count:{digits:true},
coupon_amount:{required:true},
coupon_img:{accept:"图片格式只能为$!config.imageSuffix"},
coupon_order_amount:{required:true,digits:true}
},
messages:{
coupon_description:{required:"优惠券信息描述不能为空"},
coupon_name:{required:"优惠券名称不能为空"},
coupon_begin_time:{required:"开始时间不能为空"},
coupon_end_time:{required:"结束时间不能为空",endTime:"结束日期必须大于开始日期"},
coupon_count:{digits:"优惠券只能为整数"},
coupon_amount:{required:"优惠券金额不能为空"},
coupon_img:{accept:"图片格式只能为$!config.imageSuffix"},
coupon_order_amount:{required:"可使用订单金额不能为空",digits:"可使用订单金额只能为整数",min:"可使用订单金额必须大于优惠券金额",amount:"可使用订单金额必须大于优惠券金额"}
},
submitHandler:function(){
var params = jQuery("#theForm").serializeArray();
var formData= {};
jQuery.each(params, function(i, param){
formData[param.name] = param.value;
});
jQuery(".seller_save").attr("disabled","disabled");
jQuery.ajaxFileUpload({
url:'$!webPath/seller/coupon_save.htm',
dataType:'json',
fileElementId:['coupon_img'],
data:formData,
success:function(data){
var lin = ""+data.url;
if(data.ret==true){
showDialog("msg_info","",data.op_title,0,"succeed",3,function(arg){window.location.href=arg},lin,function(){
window.location.href = "$!webPath/seller/coupon.htm";
});
}
jQuery(".seller_save").removeAttr("disabled");
}
});
}
});
var isIE = ((navigator.userAgent.indexOf("compatible") > -1 && navigator.userAgent.indexOf("MSIE") > -1 && !isOpera)||navigator.userAgent.indexOf("Trident") > -1)?true:false;
jQuery.validator.methods.endTime = function(value, element, param) { debugger; var startDate = jQuery("#coupon_begin_time").val(); var date1=new Date(Date.parse(startDate)); var date2=new Date(Date.parse(value)); if(isIE){ date1 = new Date(Date.parse(startDate.replace("-", "/"))); date2 = new Date(Date.parse(value.replace("-", "/"))); } return date1 <= date2; };
});
具体间隔天数的比较
var isIE = ((navigator.userAgent.indexOf("compatible") > -1 && navigator.userAgent.indexOf("MSIE") > -1 && !isOpera)||navigator.userAgent.indexOf("Trident") > -1)?true:false;
function timeRule(cur){
if(parseInt(cur)<10){
cur = "0"+cur;
}
return cur
}
function curDate(){
var date = new Date(),
year = date.getFullYear(),
mouth = date.getMonth()+1,
datec = date.getDate(),
hour = date.getHours(),
minite = date.getMinutes(),
seconds = date.getSeconds(),
millsieconds = date.getMilliseconds(); mouth = timeRule(mouth);
datec = timeRule(datec);
hour = timeRule(hour);
minite = timeRule(minite);
seconds = timeRule(seconds); return (year+'-'+mouth+"-"+datec+" "+hour+":"+minite+":"+seconds)
} jQuery.each(jQuery('.coupon-card.active'),function(i,item){
var startTime = curDate(),
endTime = jQuery(item).find('.s-end-time').text(),
date1 = new Date(Date.parse(startTime)),
date2 = new Date(Date.parse(endTime));
if(isIE){
date1 = new Date(Date.parse(startTime.replace("-", "/")));
date2 = new Date(Date.parse(endTime.replace("-", "/")));
}
if(((date2-date1)/(1000*60*60*24))<3){
jQuery(item).removeClass('active').addClass('must-use');
};
})