You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							104 lines
						
					
					
						
							2.9 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							104 lines
						
					
					
						
							2.9 KiB
						
					
					
				
								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()             //毫秒
							 | 
						|
									};
							 | 
						|
									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)));
							 | 
						|
										}
							 | 
						|
									}
							 | 
						|
									return fmt;
							 | 
						|
								};
							 | 
						|
								
							 | 
						|
								$(function () {
							 | 
						|
									$('.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;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										var date = new Date();
							 | 
						|
										date = prompt('请输入起始日期', date.format('yyyy-MM-dd'));
							 | 
						|
										if (!date || isNaN(new Date(date).getTime())) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										var num = parseInt(prompt('请输入新增数量,最多不超过180', '30'));
							 | 
						|
										if (isNaN(num) || !num) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
										if (num > 180) {
							 | 
						|
											num = 180;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										var stock = prompt('请输入默认库存', '9999');
							 | 
						|
										if (!stock) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										var original_price = prompt('请输入默认市场价');
							 | 
						|
										if (!original_price) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										var price = prompt('请输入默认销售价');
							 | 
						|
										if (!price) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										var cost_price = prompt('请输入默认成本价');
							 | 
						|
										if (!cost_price) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										$('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,
							 | 
						|
											'cost_price': cost_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;
							 | 
						|
								
							 | 
						|
										function replaceNestedFormIndex(value) {
							 | 
						|
											return String(value).replace(/__LA_KEY__/g, nestedIndex);
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										for (var i = 0; i < num; i++) {
							 | 
						|
											nestedIndex++;
							 | 
						|
								
							 | 
						|
											var d = new Date(date);
							 | 
						|
											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 .batch-sub').click(function () {
							 | 
						|
										$('.has-many-spec-forms .remove.btn').click();
							 | 
						|
									});
							 | 
						|
								});
							 |