From e2ce249c6a1478c90efdb11b81a2d21ee50b4ac6 Mon Sep 17 00:00:00 2001 From: liapples Date: Sat, 25 Sep 2021 00:10:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/batch-add-spec.js | 102 ++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/resources/js/batch-add-spec.js b/resources/js/batch-add-spec.js index 037b357..66aa08c 100644 --- a/resources/js/batch-add-spec.js +++ b/resources/js/batch-add-spec.js @@ -1,78 +1,98 @@ -Date.prototype.format = function(fmt) { +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)); + if (/(y+)/.test(fmt)) { + 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))); + 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))); } } return fmt; } -$(function() { - $(".has-many-spec .add.btn") +$(function () { + $('.has-many-spec .add.btn') .after('
 删除所有
') .after('
 批量新增
'); //批量新增 - $(".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}; - for(var key in fields) { + 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); } - for(var i=0; i