iks: virtonomica покупка оборудования. Смеситель.

Расчитывает нужное качество из двух представленых вариантов

当前为 2015-05-07 提交的版本,查看 最新版本

// ==UserScript==
// @name        iks: virtonomica покупка оборудования. Смеситель.
// @namespace   virtonomica
// @description Расчитывает нужное качество из двух представленых вариантов
// @include     http://*virtonomica*.*/*/window/unit/equipment/*
// @version     1.12
// @grant       none
// ==/UserScript==

var run = function() {
  $('#headerWithSeparator').after('<div class="headerContainer">'
                                  +'<table class="blendingTable" cellpadding="4">'
                                  +'<tr style="text-align:center">'
                                    +'<th></th>'
                                    +'<th>Требуемое</th>'
                                    +'<th>В наличии</th>'
                                    +'<th>Продавец 1</th>'
                                    +'<th>Продавец 2</th>'
                                  +'</tr><tr>'
                                    +'<th style="text-align:left">Количество:</th>'
                                    +'<th><input type="text" value="0" id="quantityCorner" /></th>'
                                    +'<th><input type="text" value="0" id="quantityCorner1" /></th>'
                                    +'<th><span id="quantityCorner2">0</span></th>'
                                    +'<th><span id="quantityCorner3">0</span></th>'
                                  +'</tr><tr>'
                                    +'<th style="text-align:left">Качество:</th>'
                                    +'<th><input type="text" value="0.00" id="topRightQuality" /></th>'
                                    +'<th><input type="text" value="0.00" id="topRightQuality1" /></th>'
                                    +'<th><input type="text" value="0.00" id="topRightQuality2" class="blendingTableBlue" /></th>'
                                    +'<th><input type="text" value="0.00" id="topRightQuality3" /></th>'
                                  +'</tr></table>'
                                  +'<div class="headerSeparator" style="width:100%"><img src="/img/1.gif" width="1" height="1" border="0"/></div>'
                                  +'<style> .blendingTable{ width:100%; text-align:left; background-color: #EEE; border-collapse: collapse }'
                                  +' .blendingTable th{ border:2px solid #fff }'
                                  +' .blendingTable input{ width: 100px; text-align:right; float:right }'
                                  +' .blendingTable span{ float:right }'
                                  +' .blendingTableBlue{ border-color: blue }'
                                  +'</style>');
  $('#quantityCorner1').val( $('#quantity_corner').html().replace(/\s+/g, '') );
  $('#topRightQuality1').val( $('#top_right_quality').html() );
  
  $('div.content > table#mainTable.list.main_table > tbody > tr > td:nth-child(9).digits').each(function() {
    $(this).css('cursor', 'pointer');
    $(this).click(function() {
      var n = parseFloat( $(this).html().replace(/\s+/g, '') ).toFixed(2);
      if( $('#topRightQuality2').hasClass('blendingTableBlue') ) {
        $('#topRightQuality2').removeClass('blendingTableBlue');
        $('#topRightQuality2').val(n);
        $('#topRightQuality3').addClass('blendingTableBlue');
      } else {
        $('#topRightQuality2').addClass('blendingTableBlue');
        $('#topRightQuality3').removeClass('blendingTableBlue');
        $('#topRightQuality3').val(n);
      }
    
      work();
    });
  });
  
  $('table.blendingTable input').bind("change keyup input click", function() {
    var n = 0;
    if( $(this).attr('id').indexOf('quantityCorner') + 1 ) $(this).val( parseInt( $(this).val().replace(/[^0-9]/g, '') ) | 0 );
    else {
      n = parseFloat( $(this).val() );
      if(!n)  n = 0;
      $(this).val( n.toFixed(2) );
    }
    
    work();
  });
  
  function work() {
    // Требуемое
    kol_t = parseFloat( $('#quantityCorner').val().replace(/\$/g, '') );
    kach_t = parseFloat( $('#topRightQuality').val() );
    // В наличии
    kol_n = parseFloat( $('#quantityCorner1').val().replace(/\$/g, '') );
    kach_n = parseFloat( $('#topRightQuality1').val().replace(/\$/g, '') );
    // Продавцы
    kach_p1 = parseFloat( $('#topRightQuality2').val().replace(/\$/g, '') );
    kach_p2 = parseFloat( $('#topRightQuality3').val().replace(/\$/g, '') );
    
    n = (kol_t * ( kach_t - kach_p1 ) - kol_n * ( kach_n - kach_p1 ) ) / ( kach_p2 - kach_p1 );
    if(!n || n == 'Infinity')  n = 0;
		$('#quantityCorner3').html(n.toFixed(1));
    
    n = ( kol_t * ( kach_t - kach_p2 ) - kol_n * ( kach_n - kach_p2 ) ) / ( kach_p1 - kach_p2 );
    if(!n || n == 'Infinity')  n = 0;
		$('#quantityCorner2').html(n.toFixed(1));
  }
}

if(window.top == window) {
    var script = document.createElement("script");
    script.textContent = '(' + run.toString() + ')();';
    document.documentElement.appendChild(script);
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址