jQuery web 组件 后台日历价格、库存设置的代码

jQuery web 组件 后台日历价格、库存设置的代码_第1张图片

jQuery web 组件 后台日历价格、库存设置的代码_第2张图片

/* 
* yagizaDate 1.0 
* 
* Yagiza 
* Copyright 2016, MIT License 
* 
* IE 8+, Chrome, fireFox 
*/ 
// * 字段说明 ******************** 
// buyNumMax 最多购买数 
// buyNumMin 最少购买数 
// cashback 返现 
// price 售价、分销价、分销售价 
// priceSettlement 结算价、采购价、分销结算价 
// priceMarket 景区挂牌价 
// priceRetail 建议零售价 
// stock 总库存 
// stockDay 当天库存 
// * END 字段说明 ******************** 
// // 初始化数据 
// var priceData = { 
// callbackId:'#mydemo', // 用于接收回调JSON数据 
// // startDay: null, 
// // endDay: null, 
// priceSettlement: "结算价", 
// priceNormal: "售价", 
// cashback: "返现", 
// stock: "9999", 
// // week: [], 
// dayData: [ 
// { 
// date: "2016-10-21", 
// stockDay: "9000", 
// buyNumMax: "50", 
// buyNumMin: "1", 
// priceNormal: "0.12", 
// priceMarket: "100.00", 
// priceSettlement: "90.00", 
// priceRetail: "99.00" 
// },{ 
// date: "2016-11-12", 
// stockDay: "9000", 
// buyNumMax: "50", 
// buyNumMin: "1", 
// priceNormal: "12.00", 
// priceMarket: "100.00", 
// priceSettlement: "90.00", 
// priceRetail: "99.00" 
// } 
// ] 
// } 
// 
// 调用方法 
// $.yagizaDate('2016-10-08',priceData); 
// 日期格式不合法,自动获取系统时间0000-00-00 
;(function($){ 
var yagizaDate = function(setDay, priceData){ 
var _this_ = this, 
// 数据接收#id 
callbackId = priceData.callbackId, 
priceData = priceData; 
// 系统日期 年月 
var todayDate = new Date(), 
sy = todayDate.getFullYear(), 
sm = todayDate.getMonth(), 
// 今天几号 
d = todayDate.getDate(), 
// 今天 y-m-d 
today = sy + '-'+this.ddf(sm+1)+'-'+this.ddf(d); 
// Datedata 日期价格库存json 
// setDay 设置日期 2016-10-10 
var reg = /^\d{4}-\d{2}-\d{2}$/; 
if(!reg.test(setDay)){ 
console.log('日期格式有误!'); 
// return false; 
setDay = sy + '-' + this.ddf(sm+1) + '-' + this.ddf(d); 
} 
// 默认参数配置 
// 设置年月 
// replace(/-/,'/') 解决IE98及以下版本输出NaN问题 
var setMsec = new Date(setDay.replace(/-/g,'/')), 
y = setMsec.getFullYear(), 
m = setMsec.getMonth()+1, 
// 当月天数 
maxdays = (new Date(Date.parse(new Date(y,m,1)) - 86400000)).getDate(), 
//获取当月(日期对象) 
thisMonthDate = new Date(y,m-1); 
firstDayWeek = thisMonthDate.getDay(); //这个月的第一天是星期几 
// HTML结构 
// td id="2016-10-10" 
var td_id; 
// 传入对象中日期数据设置 
var arr = priceData.dayData, 
arrLen = arr.length; 
// 遮罩 
this.mask = $('
'); // 创建html DOM结构 var html = ''; html += '
'; html += '
'; html += '

'+ y +'年'+ this.ddf(m) +'月

'; if((y+''+this.ddf(m)) > (sy+''+this.ddf(parseInt(sm)+1))) { html += ' '; } html += ' '; html += '
'; html += '
'; html += ' '; html += ' '; html += ' '; var i = 0, j = 0, k = 0, showDay, // tr 行数 row = Math.ceil((maxdays + firstDayWeek)/7); // 创建日期表格 for(j=0;j0&&showDay<=maxdays){ td_id = y +'-'+ this.ddf(m) +'-'+ this.ddf(showDay); // 今天及之后的日期,显示价格、库存 if(td_id>=today){ html+=''; } else { html+=''; } } else { html+=''; } } // for k End html+=''; } // for j End html += ' '; html += '
'+showDay+''+showDay+'
'; html += '
'; html += ' '; html += '
'; this.mask.append(html); $('body').append(this.mask); // 上一月 $('.yagiza-date-selector #yagizaPrevMonth').click(function(){ var newMonth=''; if(parseInt(m)==1){ newMonth = (y - 1)+'-12-01'; } else { newMonth = y + '-' + _this_.ddf(m - 1)+'-01'; } _this_.close(); $.yagizaDate(newMonth,priceData); }); // 下一月 $('.yagiza-date-selector #yagizaNextMonth').click(function(){ var newMonth=''; if(parseInt(m)==12){ newMonth = (y + 1)+'-01-01'; } else { newMonth = y + '-' + _this_.ddf(m + 1)+'-01'; } _this_.close(); $.yagizaDate(newMonth,priceData); }); // 取消 $('.yagiza-date-selector button[type="cancel"]').click(function(){ _this_.close(); }); // 确定 $('.yagiza-date-selector button[type="submit"]').click(function(){ var callbackData = JSON.stringify(priceData); $(callbackId).text(callbackData); _this_.close(); }); // 重置 保留基本信息 $('.yagiza-date-selector button[type="reset"]').click(function(){ priceData = { startDay: null, endDay: null, priceSettlement: priceData.priceSettlement, priceNormal: priceData.priceNormal, cashback: priceData.cashback, stock: priceData.stock, week: null, dayData: [] } _this_.close(); $.yagizaDate(setDay,priceData); }); // 加载库存、售价等数据 $(function(){ // 今天及之后的日期,显示价格、库存 // 含有ID的td标签 var td = $('.yagiza-date-selector #yagizaDateTd td[id]'); // console.log(td) $.each(td, function(i, item){ var list='

分:¥'+_this_.nf(priceData.priceNormal)+'

采:¥'+_this_.nf(priceData.priceSettlement)+'

库:'+_this_.nf(priceData.stock)+'

'; // 独立设置价格、日期 $.each(arr, function(i, item2){ if(item.id===item2.date){ list='

分:¥'+_this_.nf(item2.priceNormal)+'

采:¥'+_this_.nf(item2.priceSettlement)+'

库:'+_this_.nf(item2.stockDay)+'

'; } }); // 将价格、库存写入对应日期 $('#'+item.id).addClass('active').find('b').after(list); list = ''; }) // 点击 显示单日信息设置窗口 td.click(function(){ var id = $(this).attr('id'); var obj = { date: id, stockDay: $(this).find('div p:nth-child(3) span').text(), buyNumMax: $(this).find('div').attr('data-buyNumMax'), buyNumMin: $(this).find('div').attr('data-buyNumMin'), priceNormal: $(this).find('div p:nth-child(1) span').text(), priceMarket: $(this).find('div').attr('data-priceMarket'), priceSettlement: $(this).find('div p:nth-child(2) span').text(), priceRetail: $(this).find('div').attr('data-priceRetail'), startDay: id, endDay: id } // console.log('obj:'+obj) // 创建单日设置项 _this_.dateSet(obj); $('#'+id).closest('.date-selector-box').css('display','none'); }); // 取消 单日信息设置 $('.yagiza-date-selector').on('click', '.close', function(){ $('.yagiza-date-selector .date-set-box').remove(); $('.yagiza-date-selector .date-selector-box').css('display','block'); }); // 设置 日期相关信息 *************** $('.yagiza-date-selector').on('click', '[rel="enable"]', function(){ var thisDate = $(this).attr('data-date'), stockDay = _this_.nf($('#stockDay').val()), buyNumMax = _this_.nf($('#buyNumMax').val()), buyNumMin = _this_.nf($('#buyNumMin').val()), priceNormal = _this_.nf($('#priceNormal').val()), priceMarket = _this_.nf($('#priceMarket').val()), priceSettlement = _this_.nf($('#priceSettlement').val()), priceRetail = _this_.nf($('#priceRetail').val()); // 判断日期格式是否合法 var startDay = $('#startDay').val(), endDay = $('#endDay').val(); // var reg = /^\d{4}-\d{2}-\d{2}$/; if(!reg.test(startDay)){ alert('开始时间格式错误,请使用0000-00-00格式!'); $('#startDay').val(thisDate).focus(); return false; } if( startDay0){ for(var k=(arrLen-1);k>=0;k--){ // 当日数据已存在-》删除 if(arr[k] && arr[k].date === item){ arr.splice(k, 1); } } } }); // each END } else { spDayArr = [thisDate]; } // 如果用户设置了周几 if(wlen){ // 如果用户设置了日期范围 if(spDayArr1.length>0){ var w,wd; $.each(spDayArr1, function(i, item){ w = new Date(item); wd = w.getDay(); if($.inArray(wd, weekArr)>-1 && item){ spDayArr2.push(item); } }) } else { // 设置了周几 // 获取一年的时间设置 var todayMsec = Date.parse(todayDate), newDate; for(var k=0;k<365;k++){ newDate = new Date(todayMsec+k*86400000); if($.inArray(newDate.getDay(), weekArr)>-1){ spDayArr2.push(_this_.dateFYmd(newDate)); } } } } // end 周几设置 // 重组 priceData.dayData // 存在设置日期 if(spDayArr2.length>0){ spDayArr = spDayArr2; } else if(spDayArr1.length>0){ spDayArr = spDayArr1; } if(spDayArr.length>0){ var o; $.each(spDayArr, function(i,item){ var o = { date: item, stockDay: stockDay, buyNumMax: buyNumMax, buyNumMin: buyNumMin, priceNormal: priceNormal, priceMarket: priceMarket, priceSettlement: priceSettlement, priceRetail: priceRetail } // 将新数据写入 priceData.dayData arr.push(o); // delete o; }); // 更新priceData.dayData priceData.dayData = arr; } _this_.close(); $.yagizaDate(setDay,priceData); }); }); // $(function) END } yagizaDate.prototype = { // 毫秒转yyyy-MM-dd msecToYmd: function(item){ var y,m,d, item = new Date(item); y = item.getFullYear(); m = item.getMonth()+1 m = m < 10 ? '0'+ m : m; d = item.getDate(); d = d < 10 ? '0'+ d : d; return y+'-'+m+'-'+d; }, // // yyyy-MM-dd转毫秒 // ymdToMsec: function(item){ // var itemDate = new Date(item); // return itemDate.getTime(); // }, // Date对象格式话 yyyy-mm-dd dateFYmd: function(d){ var y = d.getFullYear(), m = d.getMonth(), d = d.getDate(), ymd = y + '-'+this.ddf(m+1)+'-'+this.ddf(d); return ymd; }, // 两位数格式化,不足两位首位补0 // double-digit fomart ddf: function(n){ n = parseInt(n); return n < 10 ? '0'+n : n; }, // 移除日期设置窗口 close: function(){ this.mask.remove(); }, // 为空或undefined = '' // null fomart nf: function(str){ return str ? str : ''; }, // 创建单日/批量设置窗口DOM dateSet: function(obj){ var _this = this; var setBox = ''; // console.log(obj) setBox += '

'+obj.date+' 价格详细

'; setBox += '
'; setBox += '
最多购买数:
'; setBox += '
最少购买数:
'; setBox += '
分 销 售 价:
'; setBox += '
景区挂牌价:
'; setBox += '
分销结算价:
'; setBox += '
建议零售价:
'; setBox += '
当 天 库 存:
'; setBox += '

'; setBox += '
批量设置
'; setBox += '
开 始 时 间:
'; setBox += '
结 束 时 间:
'; setBox += '
'; setBox += '
'; setBox += '
'; setBox += ' 设 置 星 期:'; setBox += ' '; setBox += ' '; setBox += ' '; setBox += ' '; setBox += ' '; setBox += ' '; setBox += ' '; setBox += '
'; setBox += '
'; setBox += ' '; setBox += '
'; this.mask.append(setBox); } } // window.yagizaDate = yagizaDate; $.yagizaDate = function(month, priceData){ return new yagizaDate(month, priceData); } })(jQuery);

html:

 
 
 
 
YageizaDate Demo 
 
 
 
 
 
 
 
结算价 售价 返点 总库存

style.css

*{padding:0;margin:0}.clearfix:after{content:'';display:block;overflow:hidden;visibility:hidden;font-size:0;line-height:0;width:0;height:0;clear:both}.yagiza-date-selector{font-size:12px !important;background:rgba(0,0,0,0.5);position:fixed;z-index:100000;top:0;left:0;width:100%;height:100%;display:-webkit-flex;-webkit-justify-content:center;-webkit-align-items:center}.yagiza-date-selector .date-selector-box{position:relative;background-color:#FFF;width:640px}.yagiza-date-selector .date-selector-box .header{height:40px;line-height:40px;text-align:center;position:relative;background:#383435}.yagiza-date-selector .date-selector-box .header h2{font-size:1.5em;color:#CCC}.yagiza-date-selector .date-selector-box .header a{display:block;position:absolute;top:0;z-index:1;height:40px;width:40px;text-align:center;cursor:pointer}.yagiza-date-selector .date-selector-box .header a i{display:inline-block;margin-top:6px;width:28px;height:28px;background:url("img/prev-next.png") no-repeat 0 0}.yagiza-date-selector .date-selector-box .header .prev{left:0}.yagiza-date-selector .date-selector-box .header .prev i{background-position:0 -28px}.yagiza-date-selector .date-selector-box .header .next{right:0}.yagiza-date-selector .date-selector-box .date-table table{width:100%}.yagiza-date-selector .date-selector-box .date-table table .week th{color:#999;text-align:center !important;height:24px;font-weight:100;background:#383435}.yagiza-date-selector .date-selector-box .date-table table .week .weekend{color:#F60}.yagiza-date-selector .date-selector-box .date-table table td{border-right:1px solid #DDD;border-bottom:1px solid #DDD;line-height:1.2;height:76px;vertical-align:top;width:14.2%}.yagiza-date-selector .date-selector-box .date-table table td>b{display:block;font-size:1.4em;text-align:right;color:#DDD;font-family:'Arial Regular';margin:4px 4px 4px 0}.yagiza-date-selector .date-selector-box .date-table table td>div{margin-left:4px}.yagiza-date-selector .date-selector-box .date-table table td>div p{color:#F60}.yagiza-date-selector .date-selector-box .date-table table td.active{cursor:pointer}.yagiza-date-selector .date-selector-box .date-table table td.active b{color:#999}.yagiza-date-selector .date-selector-box .date-table table td.active:hover{background:#F60}.yagiza-date-selector .date-selector-box .date-table table td.active:hover b,.yagiza-date-selector .date-selector-box .date-table table td.active:hover div p{color:#FFF}.yagiza-date-selector .date-selector-box .date-table table td.last-child{border-right:0}.yagiza-date-selector .footer{background-color:#383435;padding:10px;text-align:right}.yagiza-date-selector .footer .btn{text-align:center;border-radius:2px;border:0 !important;cursor:pointer;color:#FFF;height:26px;line-height:26px !important;display:inline-block;padding:0 15px;position:relative}.yagiza-date-selector .footer .bg-orange{background:#F60}.yagiza-date-selector .footer .bg-orange:hover{background:#c44e00}.yagiza-date-selector .footer .bg-green{background:#55b526}.yagiza-date-selector .footer .bg-green:hover{background:#408f1a}.yagiza-date-selector .footer .bg-gray{background:#777}.yagiza-date-selector .footer .bg-gray:hover{background:#555}.yagiza-date-selector .footer .bg-cyan{background:#31b0d5}.yagiza-date-selector .footer .bg-cyan:hover{background:#269abc}.yagiza-date-selector .footer button{margin-left:5px}.yagiza-date-selector .date-set-box{position:relative;background-color:#FFF;width:640px}.yagiza-date-selector .date-set-box .header{height:46px;line-height:46px;position:relative;background:#383435}.yagiza-date-selector .date-set-box .header h2{color:#CCC;font-size:1.2em;margin-left:20px;font-weight:500}.yagiza-date-selector .date-set-box .header .close{display:block;position:absolute;z-index:1;right:0;top:0;width:40px;height:46px;text-align:right}.yagiza-date-selector .date-set-box .header .close i{width:24px;height:24px;margin:11px 11px 0 0;background:url("img/close-x-gray.png") no-repeat 0 0;display:inline-block}.yagiza-date-selector .date-set-box .header .close:hover i{background-position:0 -24px}.yagiza-date-selector .date-set-box .yagiza-form{margin:8px 20px;display:block;width:100%}.yagiza-date-selector .date-set-box .yagiza-form dd{position:relative;height:30px;line-height:30px;width:49%;float:left}.yagiza-date-selector .date-set-box .yagiza-form dd .input-text{display:block;position:absolute;z-index:1;height:22px;line-height:22px;vertical-align:middle;padding:0 4px;border:1px solid #CCC;background:#FFF;left:80px;top:3px}.yagiza-date-selector .date-set-box .yagiza-form dt{position:relative;height:30px;line-height:30px;display:block}.yagiza-date-selector .date-set-box .yagiza-form dt label{margin-left:15px;cursor:pointer}.yagiza-date-selector .date-set-box .yagiza-form dt label:first-child{margin-left:4px}.yagiza-date-selector hr{border:0;border-top:1px solid #CCC;border-bottom:1px solid #FFF;margin:0 20px}

style-ie.css

.yagiza-date-selector{background:url("img/bg-black-opacity.png")}.yagiza-date-selector .date-selector-box,.yagiza-date-selector .date-set-box{position:absolute;z-index:1;top:10%;left:50%;margin:0 0 0 -320px}

你可能感兴趣的:(jQuery web 组件 后台日历价格、库存设置的代码)