Blame view

orders/web/js/order.js 3.36 KB
8ad6fbc1   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  $(function() {
      $(document)
          .on('click', '.remove-order-product', function(e) {
              e.preventDefault();
              var current_price = parseInt($(this)
                  .parents('.row-order-product')
                  .data('price'));
              console.log(current_price);
              var number = parseInt($(this)
                  .parents('.row-order-product')
                  .children('.col-md-2')
                  .children('.form-group')
                  .children('input')
                  .val());
              var id = $(this)
                  .data('id');
              var variant = $(this)
                  .data('variant');
              $(this)
                  .parents('.row-order-product')
                  .remove();
              var total_price = parseInt($("#total-sum")
                  .text());
              console.log(total_price);
              total_price = total_price - (current_price * number);
              console.log(number);
              $("#total-sum")
                  .text(total_price);
          });
      $('#count-to-order')
          .keypress(function(e) {
              if (!(e.which == 8 || (e.which > 47 && e.which < 58))) {
                  return false;
              }
          });
      $('#count-to-order')
          .change(function(e) {
              if ($(this)
                      .val() <= 0) {
                  $(this)
                      .val('1')
              }
          });
      $(document)
          .on('click', '.variant-to-order', function(e) {
              e.preventDefault();
              var id = $('#add-to-order');
              var count = $('#count-to-order');
              var order = $(this)
                  .data('id');
              if (id.val()) {
                  console.log(count.val());
                  if (parseInt(count.val()) > 0) {
                      var newCountVal = count.val();
                  } else {
                      var newCountVal = 1;
                  }
  
                  $('.order-goods-th')
                      .css({display: 'block'});
  
                  $.post('/admin/orders/order/add-to-order', {
                      id: id.val(),
                      count: newCountVal,
                      order: order
                  }, function(data) {
                      if (data.success) {
                          var sum = $('#total-sum')
                              .text();
                          $('#total-sum')
                              .html(parseInt(sum) + parseInt(data.price));
                          $('#product-rows')
                              .append(data.row);
                          $('#add-to-order')
                              .select2("val", "");
                      }
  
                  });
              }
          });
      $(document)
          .on('change', '.count', function() {
              var count_old = parseInt(this.defaultValue);
              console.log(count_old);
              var count_new = parseInt(this.value);
              var current_price = parseInt($(this)
                  .parents('.row-order-product')
                  .data('price'));
              var total_price = parseInt($("#total-sum")
                  .text());
              total_price = total_price - (count_old * current_price) + (count_new * current_price);
              this.defaultValue = this.value;
              $("#total-sum")
                  .text(total_price);
          })
  });
  
  function showLoader(container) {
      $(container)
          .prepend('<div class="loader-wrapper"></div>');
  }