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

98 lines
3.5 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. var is_load = false;
  7. $('.spec-sync').click(function () {
  8. if (is_load) {
  9. Dcat.confirm('本次载入将清除上次载入的所有数据,是否继续?', null, post());
  10. } else {
  11. post();
  12. is_load = true;
  13. }
  14. function post() {
  15. $.ajax({
  16. url: '`{{url}}`',
  17. method: 'POST',
  18. data: {
  19. product_id: `{{product_id}}`,
  20. agent_product_id: `{{agent_product_id}}`,
  21. _form_: '`{{class}}`',
  22. },
  23. success: function (res) {
  24. var fields = ['supplier_name', 'supplier_date', 'supplier_price', 'supplier_stock',
  25. 'price', 'stock', 'original_price', 'product_spec_id'];
  26. var data = res.data;
  27. var forms = $('.has-many-spec-forms');
  28. //只remove掉上次载入的,原来数据库保存的记录(.field_id不为空)不处理
  29. forms.children().each(function () {
  30. if (!$(this).find('.field_id').val()) {
  31. $(this).remove();
  32. }
  33. //清理供应商已删除的规格
  34. else if ($(this).find('.field_supplier_stock').val() == 0 && $(this).find('.field_supplier_price').val() == 0) {
  35. $(this).find('.remove.btn').click();
  36. }
  37. });
  38. for (var key in data) {
  39. var row = $(template.replace(/new___LA_KEY__/g, key));
  40. for (var i=0; i<fields.length; i++) {
  41. var field = fields[i];
  42. row.find('input.field_' + field).val(data[key][field]);
  43. }
  44. forms.append(row);
  45. }
  46. },
  47. error: function () {
  48. Dcat.error('服务器出现未知错误,获取供应商产品规格失败');
  49. }
  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 = parseFloat(num) > parseFloat(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. });