4 changed files with 112 additions and 6 deletions
-
7app/AdminAgent/Controllers/AgentProductController.php
-
5app/AdminAgent/Forms/LoadSupplierSpec.php
-
100resources/js/agent-spec-edit.js
-
6resources/js/select-supplier-product-change.js
@ -0,0 +1,100 @@ |
|||||
|
$(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(); |
||||
|
$('.spec-sync').click(function () { |
||||
|
$.ajax({ |
||||
|
url: '`{{url}}`', |
||||
|
method: 'POST', |
||||
|
data: {product_id: $(this).val(), _form_: '`{{class}}`'}, |
||||
|
success: function (res) { |
||||
|
var fields = { |
||||
|
supplier_name: 'name', |
||||
|
supplier_date: 'date', |
||||
|
supplier_price: 'price', |
||||
|
supplier_stock: 'stock', |
||||
|
price: 'price', |
||||
|
stock: 'stock', |
||||
|
original_price: 'original_price', |
||||
|
product_spec_id: 'id' |
||||
|
}; |
||||
|
var data = res.data; |
||||
|
var forms = $('.has-many-spec-forms'); |
||||
|
|
||||
|
//如果是原来数据库已经保存有id,调用click,提交的时候会同时删除数据库,否则直接remove掉,减小HTML体积
|
||||
|
forms.children().each(function () { |
||||
|
if ($(this).find('.field_id').val()) { |
||||
|
$(this).find('.remove.btn').click(); |
||||
|
} else { |
||||
|
$(this).remove(); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
for (var key in data) { |
||||
|
var row = $(template.replace(/new___LA_KEY__/g, key)); |
||||
|
for(var key2 in fields) { |
||||
|
var value = fields[key2], insert_value; |
||||
|
if (key2 === 'original_price') { |
||||
|
insert_value = (data[key][value] * 2).toFixed(2); |
||||
|
} else if (key2 === 'price') { |
||||
|
insert_value = (data[key][value] * 1.5).toFixed(2); |
||||
|
} else { |
||||
|
insert_value = data[key][value]; |
||||
|
} |
||||
|
row.find('input.field_' + key2).val(insert_value); |
||||
|
} |
||||
|
forms.append(row); |
||||
|
} |
||||
|
}, |
||||
|
error: function () { |
||||
|
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 = num > 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)); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
//
|
||||
|
}); |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue