|
|
|
@ -1,60 +1,81 @@ |
|
|
|
Date.prototype.format = function (fmt) { |
|
|
|
var o = { |
|
|
|
"M+" : this.getMonth()+1, //月份
|
|
|
|
"d+" : this.getDate(), //日
|
|
|
|
"h+" : this.getHours(), //小时
|
|
|
|
"m+" : this.getMinutes(), //分
|
|
|
|
"s+" : this.getSeconds(), //秒
|
|
|
|
"q+" : Math.floor((this.getMonth()+3)/3), //季度
|
|
|
|
"S" : this.getMilliseconds() //毫秒
|
|
|
|
'M+': this.getMonth() + 1, //月份
|
|
|
|
'd+': this.getDate(), //日
|
|
|
|
'h+': this.getHours(), //小时
|
|
|
|
'm+': this.getMinutes(), //分
|
|
|
|
's+': this.getSeconds(), //秒
|
|
|
|
'q+': Math.floor((this.getMonth() + 3) / 3), //季度
|
|
|
|
'S': this.getMilliseconds() //毫秒
|
|
|
|
}; |
|
|
|
if (/(y+)/.test(fmt)) { |
|
|
|
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); |
|
|
|
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)); |
|
|
|
} |
|
|
|
for (var k in o) { |
|
|
|
if(new RegExp("("+ k +")").test(fmt)){ |
|
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); |
|
|
|
if (new RegExp('(' + k + ')').test(fmt)) { |
|
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))); |
|
|
|
} |
|
|
|
} |
|
|
|
return fmt; |
|
|
|
} |
|
|
|
|
|
|
|
$(function () { |
|
|
|
$(".has-many-spec .add.btn") |
|
|
|
$('.has-many-spec .add.btn') |
|
|
|
.after('<div class="btn btn-spec batch-sub btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-minus"></i> 删除所有</div>') |
|
|
|
.after('<div class="btn btn-spec batch-add btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i> 批量新增</div>'); |
|
|
|
|
|
|
|
//批量新增
|
|
|
|
$(".has-many-spec .batch-add").click(function() { |
|
|
|
var name = prompt("请输入规格名称"); |
|
|
|
if(!name) return; |
|
|
|
$('.has-many-spec .batch-add').click(function () { |
|
|
|
var name = prompt('请输入规格名称'); |
|
|
|
if (!name) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var num = parseInt(prompt("请输入新增数量,最多只能是100", 30)); |
|
|
|
if(isNaN(num) || !num) return; |
|
|
|
if(num > 100) num = 100; |
|
|
|
var num = parseInt(prompt('请输入新增数量,最多不超过180', '30')); |
|
|
|
if (isNaN(num) || !num) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (num > 180) { |
|
|
|
num = 180; |
|
|
|
} |
|
|
|
|
|
|
|
var date = new Date(); |
|
|
|
date = prompt("请输入起始日期", date.format("yyyy-MM-dd")); |
|
|
|
if(!date) return; |
|
|
|
date = prompt('请输入起始日期', date.format('yyyy-MM-dd')); |
|
|
|
if (!date) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var stock = prompt("请输入默认库存", 9999); |
|
|
|
if(!stock) return; |
|
|
|
var stock = prompt('请输入默认库存', '9999'); |
|
|
|
if (!stock) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var original_price = prompt("请输入默认原价"); |
|
|
|
if(!original_price) return; |
|
|
|
var original_price = prompt('请输入默认原价'); |
|
|
|
if (!original_price) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var price = prompt("请输入默认售价"); |
|
|
|
if(!price) return; |
|
|
|
var price = prompt('请输入默认售价'); |
|
|
|
if (!price) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
$("template.spec-tpl .field_name").prop("value", name); |
|
|
|
var html = $("template.spec-tpl").html() |
|
|
|
$('template.spec-tpl .field_name').prop('value', name); |
|
|
|
var html = $('template.spec-tpl').html(); |
|
|
|
|
|
|
|
var fields = {'name' : name, 'date' : date, 'stock' : stock, 'original_price' : original_price, 'price' : price}; |
|
|
|
var fields = { |
|
|
|
'name': name, |
|
|
|
'date': date, |
|
|
|
'stock': stock, |
|
|
|
'original_price': original_price, |
|
|
|
'price': price |
|
|
|
}; |
|
|
|
for (var key in fields) { |
|
|
|
html = html.replace('name="spec[new___LA_KEY__][' + key + ']" value=""', 'name="spec[new___LA_KEY__][' + key + ']" value="' + fields[key] + '"'); |
|
|
|
} |
|
|
|
|
|
|
|
var nestedIndex = $(".has-many-spec-forms tr").length - 1; |
|
|
|
var nestedIndex = $('.has-many-spec-forms tr').length - 1; |
|
|
|
|
|
|
|
function replaceNestedFormIndex(value) { |
|
|
|
return String(value).replace(/__LA_KEY__/g, nestedIndex); |
|
|
|
} |
|
|
|
@ -66,13 +87,12 @@ $(function() { |
|
|
|
d.setDate(d.getDate() + i); |
|
|
|
|
|
|
|
var template = replaceNestedFormIndex(html.replace(date, d.format('yyyy-MM-dd'))); |
|
|
|
$(".has-many-spec-forms").append(template); |
|
|
|
$('.has-many-spec-forms').append(template); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
//清空全部
|
|
|
|
$(".has-many-spec .batch-sub").click(function() { |
|
|
|
$(".has-many-spec-forms .remove.btn").click(); |
|
|
|
console.log(123213) |
|
|
|
$('.has-many-spec .batch-sub').click(function () { |
|
|
|
$('.has-many-spec-forms .remove.btn').click(); |
|
|
|
}); |
|
|
|
}); |