диапазон ввода и расчет - PullRequest
       18

диапазон ввода и расчет

0 голосов
/ 20 декабря 2018

У меня проблема с тем, что у меня есть диапазон ввода, поэтому я использовал скидку к моей общей цене, и когда я изменяю диапазон ввода, я также хочу изменить общий расчет, потому что диапазон ввода - это процент от первоначального итога.Таким образом, при изменении входного диапазона большинство скидок также меняются, и цена также изменяется.

Мой html:

<div class="slider2">
    <div class="range2">
        <input type="range" name="date3" id="date3" min="0" max="100" step="1" ng-model="ctrl2.inputAge2" value="Please enter the year of build" required>
        <P class="setyear2">15000 </P>
    </div>
</div>
<div>
    <p>INITIAL TOTAL</p>
    <P>{{totalPrice | number}} $</P>
</div>
<div>
    <p>discount</p>
    <P>{{ ctrl2.inputAge2 }} %</P>
</div>
<div>
    <p>TOTAL price</p>
    <P>{{getTotal1()  | number}} $</P>
</div>

и javascript:

$scope.totalPrice = 170 ; 
var ctrl2 = this;
    ctrl2.inputAge2 = 10;

    $.fn.WBslider3 = function () {
      return this.each(function () {
        var $_this = $(this),
          $_date3 = $('input', $_this),
          $_title3 = $('.setyear3', $_this),
          thumbwidth = 50, // set this to the pixel width of the thumb
          yrnow3 = 100;

        // set range max to current year
        $_date3.attr('max', yrnow3);
        $('.endyear3', $_this).text(yrnow3);
        $_date3.val(yrnow3 - 10); // -10 years, just because...

        $_date3.on('input change keyup', function () {
          var $_this = $(this),
            val = parseInt($_date3.val(), 10);




          $_title3.text(val);

          var pos = (val - $_date3.attr('min')) / ($_date3.attr('max') - $_date3.attr('min'));

          // position the title with the thumb
          var thumbCorrect = thumbwidth * (pos - 0.5) * -1,
            titlepos = Math.round((pos * $_date3.width()) - thumbwidth / 4 + thumbCorrect);

          $_title3.css({
            'left': titlepos
          });

          // show "progress" on the track
          pos = Math.round(pos * 99); // to hide stuff behide the thumb
          var grad = 'linear-gradient(90deg, #A7A7A7 ' + pos + '%,#FFE014 ' + (pos + 1) + '%)';
          $_date3.css({
            'background': grad
          });

        }).on('focus', function () {
          if (isNaN($(this).val())) {
            $(this).val(0);
          }
        }).trigger('change');

        $(window).on('resize', function () {
          $_date3.trigger('change');
        });
      });
    };

    $(function () {

      $('.slider3').WBslider3();

    });



    $scope.getTotal1 = function () {
      var total1 = 0;
      total1 = ($scope.totalPrice + ctrl2.inputAge2);
      return total1;
    }

Как мне этого добиться?

1 Ответ

0 голосов
/ 20 декабря 2018

Вы можете рассчитать его в основном в html, также используйте метод toFixed of Number.:

<div class="slider2">
      <div class="range2">
          <input type="range" name="date3" id="date3" min="0" max="100" step="1" ng-model="discount"
              value="Please enter the year of build" required>
          <P class="setyear2">15000 </P>
      </div>
  </div>

<div>
 <b >INITIAL TOTAL</b>
  <P>{{totalPrice }} $</P>
</div>
<div>
    <b>discount</b>
  <P>{{ discount }} %</P>
</div>
<div>
 <b>TOTAL price</b>
  <P>{{(totalPrice - (totalPrice*discount)/100).toFixed(2)}} $</P>
</div>

Рабочий плункер: http://plnkr.co/edit/E3uHDQpdE8e9HoDbiivs?p=preview

...