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

104 lines
3.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  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. var is_load = false;
  7. $('.spec-sync').click(function () {
  8. if (is_load) {
  9. Dcat.confirm('本次载入将清除上次载入的所有数据,是否继续?', null, function () {
  10. Dcat.loading();
  11. post();
  12. });
  13. } else {
  14. Dcat.loading();
  15. post();
  16. is_load = true;
  17. }
  18. function post() {
  19. $.ajax({
  20. url: '`{{url}}`',
  21. method: 'POST',
  22. data: {
  23. product_id: `{{product_id}}`,
  24. agent_product_id: `{{agent_product_id}}`,
  25. _form_: '`{{class}}`',
  26. },
  27. success: function (res) {
  28. var fields = ['supplier_name', 'supplier_date', 'supplier_price', 'supplier_stock',
  29. 'price', 'stock', 'original_price', 'product_spec_id'];
  30. var data = res.data;
  31. var forms = $('.has-many-spec-forms');
  32. //只remove掉上次载入的,原来数据库保存的记录(.field_id不为空)不处理
  33. forms.children().each(function () {
  34. if (!$(this).find('.field_id').val()) {
  35. $(this).remove();
  36. }
  37. //清理供应商已删除的规格
  38. else if ($(this).find('.field_supplier_stock').val() == 0 && $(this).find('.field_supplier_price').val() == 0) {
  39. $(this).find('.remove.btn').click();
  40. }
  41. });
  42. for (var key in data) {
  43. var row = $(template.replace(/new___LA_KEY__/g, key));
  44. for (var i=0; i<fields.length; i++) {
  45. var field = fields[i];
  46. row.find('input.field_' + field).val(data[key][field]);
  47. }
  48. forms.append(row);
  49. }
  50. Dcat.loading(false);
  51. },
  52. error: function () {
  53. Dcat.loading(false);
  54. Dcat.error('服务器出现未知错误,获取供应商产品规格失败');
  55. }
  56. });
  57. }
  58. });
  59. //批量库存
  60. $('.batch-stock').click(function () {
  61. var num = prompt('请输入你的库存(注:库存不能多于供应商库存)');
  62. if (!/^\d+$/.test(num)) {
  63. return;
  64. }
  65. $('.has-many-spec input.field_stock').each(function () {
  66. var value = $(this).parents('tr').find('.field_supplier_stock').val();
  67. var result = parseFloat(num) > parseFloat(value) ? value : num;
  68. $(this).val(result);
  69. });
  70. });
  71. //批量设置原价
  72. $('.batch-original-price').click(function () {
  73. var num = prompt('请输入加价金额(在供应商售价基础上加)');
  74. if (!/^\d+$/.test(num)) {
  75. return;
  76. }
  77. $('.has-many-spec input.field_original_price').each(function () {
  78. var value = $(this).parents('tr').find('.field_supplier_price').val();
  79. var result = parseFloat(value) + parseFloat(num);
  80. $(this).val(result.toFixed(2));
  81. });
  82. });
  83. //批量售价
  84. $('.batch-price').click(function () {
  85. var num = prompt('请输入加价金额(在供应商售价基础上加)');
  86. if (!/^\d+$/.test(num)) {
  87. return;
  88. }
  89. $('.has-many-spec input.field_price').each(function () {
  90. var value = $(this).parents('tr').find('.field_supplier_price').val();
  91. var result = parseFloat(value) + parseFloat(num);
  92. $(this).val(result.toFixed(2));
  93. });
  94. });
  95. });