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
						
					
					
						
							3.6 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							104 lines
						
					
					
						
							3.6 KiB
						
					
					
				
								$(function () {
							 | 
						|
									$('.has-many-spec .add.btn')
							 | 
						|
										.after('<div class="btn btn-spec spec-sync btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i> 同步供应商最新规格</div><div class="btn btn-spec batch-stock btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i> 批量设置库存</div><div class="btn btn-spec batch-original-price btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i> 批量设置原价</div><div class="btn btn-spec batch-price btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i> 批量设置售价</div>');
							 | 
						|
								
							 | 
						|
									//同步最新规格
							 | 
						|
									var template = $('template.spec-tpl').html();
							 | 
						|
									var is_load = false;
							 | 
						|
									$('.spec-sync').click(function () {
							 | 
						|
										if (is_load) {
							 | 
						|
											Dcat.confirm('本次载入将清除上次载入的所有数据,是否继续?', null, function () {
							 | 
						|
												Dcat.loading();
							 | 
						|
												post();
							 | 
						|
											});
							 | 
						|
										} else {
							 | 
						|
											Dcat.loading();
							 | 
						|
											post();
							 | 
						|
											is_load = true;
							 | 
						|
										}
							 | 
						|
										function post() {
							 | 
						|
											$.ajax({
							 | 
						|
												url: '`{{url}}`',
							 | 
						|
												method: 'POST',
							 | 
						|
												data: {
							 | 
						|
													product_id: $('input[name="product_id"]').val(),
							 | 
						|
													agent_product_id: `{{agent_product_id}}`,
							 | 
						|
													_form_: '`{{class}}`',
							 | 
						|
												},
							 | 
						|
												success: function (res) {
							 | 
						|
													var fields = ['supplier_name', 'supplier_date', 'supplier_price', 'supplier_stock',
							 | 
						|
														'price', 'stock', 'original_price', 'product_spec_id'];
							 | 
						|
													var data = res.data;
							 | 
						|
													var forms = $('.has-many-spec-forms');
							 | 
						|
								
							 | 
						|
													//只remove掉上次载入的,原来数据库保存的记录(.field_id不为空)不处理
							 | 
						|
													forms.children().each(function () {
							 | 
						|
														if (!$(this).find('.field_id').val()) {
							 | 
						|
															$(this).remove();
							 | 
						|
														}
							 | 
						|
														//清理供应商已删除的规格
							 | 
						|
														else if ($(this).find('.field_supplier_stock').val() == 0 && $(this).find('.field_supplier_price').val() == 0) {
							 | 
						|
															$(this).find('.remove.btn').click();
							 | 
						|
														}
							 | 
						|
													});
							 | 
						|
								
							 | 
						|
													for (var key in data) {
							 | 
						|
														var row = $(template.replace(/new___LA_KEY__/g, key));
							 | 
						|
														for (var i=0; i<fields.length; i++) {
							 | 
						|
															var field = fields[i];
							 | 
						|
															row.find('input.field_' + field).val(data[key][field]);
							 | 
						|
														}
							 | 
						|
														forms.append(row);
							 | 
						|
													}
							 | 
						|
													Dcat.loading(false);
							 | 
						|
												},
							 | 
						|
												error: function () {
							 | 
						|
													Dcat.loading(false);
							 | 
						|
													Dcat.error('服务器出现未知错误,获取供应商产品规格失败');
							 | 
						|
												}
							 | 
						|
											});
							 | 
						|
										}
							 | 
						|
									});
							 | 
						|
								
							 | 
						|
									//批量库存
							 | 
						|
									$('.batch-stock').click(function () {
							 | 
						|
										var num = prompt('请输入你的库存(注:库存不能多于供应商库存)');
							 | 
						|
										if (!/^\d+$/.test(num)) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										$('.has-many-spec input.field_stock').each(function () {
							 | 
						|
											var value = $(this).parents('tr').find('.field_supplier_stock').val();
							 | 
						|
											var result = parseFloat(num) > parseFloat(value) ? value : num;
							 | 
						|
											$(this).val(result);
							 | 
						|
										});
							 | 
						|
									});
							 | 
						|
								
							 | 
						|
									//批量设置原价
							 | 
						|
									$('.batch-original-price').click(function () {
							 | 
						|
										var num = prompt('请输入加价金额(在供应商售价基础上加)');
							 | 
						|
										if (!/^\d+$/.test(num)) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										$('.has-many-spec input.field_original_price').each(function () {
							 | 
						|
											var value = $(this).parents('tr').find('.field_supplier_price').val();
							 | 
						|
											var result = parseFloat(value) + parseFloat(num);
							 | 
						|
											$(this).val(result.toFixed(2));
							 | 
						|
										});
							 | 
						|
									});
							 | 
						|
								
							 | 
						|
									//批量售价
							 | 
						|
									$('.batch-price').click(function () {
							 | 
						|
										var num = prompt('请输入加价金额(在供应商售价基础上加)');
							 | 
						|
										if (!/^\d+$/.test(num)) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										$('.has-many-spec input.field_price').each(function () {
							 | 
						|
											var value = $(this).parents('tr').find('.field_supplier_price').val();
							 | 
						|
											var result = parseFloat(value) + parseFloat(num);
							 | 
						|
											$(this).val(result.toFixed(2));
							 | 
						|
										});
							 | 
						|
									});
							 | 
						|
								});
							 |