海南旅游SAAS
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.

100 lines
3.4 KiB

  1. $(function () {
  2. $('.has-many-spec .add.btn')
  3. .after('<div class="btn btn-spec spec-sync btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i>&nbsp;同步最新规格</div><div class="btn btn-spec batch-stock btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i>&nbsp;批量设置库存</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>&nbsp;批量设置原价</div><div class="btn btn-spec batch-price btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i>&nbsp;批量设置售价</div>');
  4. //同步最新规格
  5. var template = $('template.spec-tpl').html();
  6. $('.spec-sync').click(function () {
  7. $.ajax({
  8. url: '`{{url}}`',
  9. method: 'POST',
  10. data: {product_id: $(this).val(), _form_: '`{{class}}`'},
  11. success: function (res) {
  12. var fields = {
  13. supplier_name: 'name',
  14. supplier_date: 'date',
  15. supplier_price: 'price',
  16. supplier_stock: 'stock',
  17. price: 'price',
  18. stock: 'stock',
  19. original_price: 'original_price',
  20. product_spec_id: 'id'
  21. };
  22. var data = res.data;
  23. var forms = $('.has-many-spec-forms');
  24. //如果是原来数据库已经保存有id,调用click,提交的时候会同时删除数据库,否则直接remove掉,减小HTML体积
  25. forms.children().each(function () {
  26. if ($(this).find('.field_id').val()) {
  27. $(this).find('.remove.btn').click();
  28. } else {
  29. $(this).remove();
  30. }
  31. });
  32. for (var key in data) {
  33. var row = $(template.replace(/new___LA_KEY__/g, key));
  34. for(var key2 in fields) {
  35. var value = fields[key2], insert_value;
  36. if (key2 === 'original_price') {
  37. insert_value = (data[key][value] * 2).toFixed(2);
  38. } else if (key2 === 'price') {
  39. insert_value = (data[key][value] * 1.5).toFixed(2);
  40. } else {
  41. insert_value = data[key][value];
  42. }
  43. row.find('input.field_' + key2).val(insert_value);
  44. }
  45. forms.append(row);
  46. }
  47. },
  48. error: function () {
  49. Dcat.error('服务器出现未知错误,获取供应商产品规格失败');
  50. }
  51. });
  52. });
  53. //批量库存
  54. $('.batch-stock').click(function () {
  55. var num = prompt('请输入你的库存(注:库存不能多于供应商库存)');
  56. if (!/^\d+$/.test(num)) {
  57. return;
  58. }
  59. $('.has-many-spec input.field_stock').each(function () {
  60. var value = $(this).parents('tr').find('.field_supplier_stock').val();
  61. var result = num > value ? value : num;
  62. $(this).val(result);
  63. });
  64. });
  65. //批量设置原价
  66. $('.batch-original-price').click(function () {
  67. var num = prompt('请输入加价金额(在供应商售价基础上加)');
  68. if (!/^\d+$/.test(num)) {
  69. return;
  70. }
  71. $('.has-many-spec input.field_original_price').each(function () {
  72. var value = $(this).parents('tr').find('.field_supplier_price').val();
  73. var result = parseFloat(value) + parseFloat(num);
  74. $(this).val(result.toFixed(2));
  75. });
  76. });
  77. //批量售价
  78. $('.batch-price').click(function () {
  79. var num = prompt('请输入加价金额(在供应商售价基础上加)');
  80. if (!/^\d+$/.test(num)) {
  81. return;
  82. }
  83. $('.has-many-spec input.field_price').each(function () {
  84. var value = $(this).parents('tr').find('.field_supplier_price').val();
  85. var result = parseFloat(value) + parseFloat(num);
  86. $(this).val(result.toFixed(2));
  87. });
  88. });
  89. //
  90. });