HEX
Server: nginx/1.22.1
System: Linux VM-16-9-centos 3.10.0-1160.99.1.el7.x86_64 #1 SMP Wed Sep 13 14:19:20 UTC 2023 x86_64
User: www (1001)
PHP: 7.3.31
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/oa.sanjiangapp.com/app/crm/contract/js/team.js
$(function()
{
    $(document).on('click', '#teamTable .addItem', function()
    {
        var $tr = $(this).parents('tr');
        $tr.after(v.itemRow.replace(/KEY/g, v.key));
        $tr.next().find('input,select').val('');
        $tr.next().find('.chosen').chosen();
        v.key++;
    });

    $(document).on('click', '#teamTable .delItem', function()
    {
        if($('.delItem').length == 1)
        {
            $(this).parents('tr').find('input,select').val('');
            $(this).parents('tr').find('select').trigger('chosen:updated');

            return false;
        }

        $(this).parents('tr').remove();
        computeTotal();
    });

    $(document).on('click', '#teamTable .chosen-container[id^=account]', function()
    {
        var users   = JSON.parse(v.users);
        var $select = $(this).prev('select');
        var account = $select.find('option:selected').val();
        var id      = $select.attr('id');

        $('#teamTable .chosen-container[id^=account]').each(function()
        {
            if($(this).prev('select').attr('id') != id)
            {
                var selected = $(this).prev('select').find('option:selected').val();
                if(selected && selected != account)
                {
                    delete users[selected];
                }
            }
        });

        $select.empty();
        for(var i in users) $select.append("<option value='" + i + "'>" + users[i] + '</option>');
        $select.val(account).trigger('chosen:updated');
    });

    $(document).on('change', '#teamTable [name^=account]', function()
    {
        if($(this).val() == '') $(this).parents('tr').find('input').val('').change();
    });

    $(document).on('change', '#teamTable [name^=contribution]', function()
    {
        var contribution = $(this).val() == '' ? 0 : $(this).val();
        if(!$.isNumeric(contribution)) return;

        var money = Math.round(parseFloat(contribution) * parseFloat(v.amount)) / 100;
            money = money == 0 ? '' : money;
        $(this).parents('tr').find('[name^=money]').val(money);

        computeTotal();
    });

    $(document).on('change', '#teamTable [name^=rate]', function()
    {
        var rate = $(this).val() == '' ? 0 : $(this).val();
        if(!$.isNumeric(rate)) return;

        computeTotal();
    });

    $(document).on('change', '#teamTable [name^=money]', function()
    {
        if(!$.isNumeric(v.amount) || v.amount == 0) return;

        var money = $(this).val() == '' ? 0 : $(this).val();
        if(!$.isNumeric(money)) return;

        var contribution = Math.round(parseFloat(money) / parseFloat(v.amount) * 100);
            contribution = contribution == 0 ? '' : contribution;
        $(this).parents('tr').find('[name^=contribution]').val(contribution);

        computeTotal();
    });
});

function computeTotal()
{
    var totalContribution = 0;
    var totalRate         = 0;
    var totalMoney        = 0;
    var $contributionList = $('#teamTable [name^=contribution]');
    var $rateList         = $('#teamTable [name^=rate]');
    var $moneyList        = $('#teamTable [name^=money]');
    for(var i = 0; i < $contributionList.length; i++)
    {
        if($.isNumeric($contributionList[i].value)) totalContribution += parseFloat($contributionList[i].value);
        if($.isNumeric($rateList[i].value))         totalRate         += parseFloat($rateList[i].value);
        if($.isNumeric($moneyList[i].value))        totalMoney        += parseFloat($moneyList[i].value);
    }

    totalContribution = Math.round(totalContribution * 100) / 100;
    totalRate         = Math.round(totalRate * 100) / 100;
    totalMoney        = Math.round(totalMoney * 100) / 100;

    totalContribution = totalContribution == 0 ? '' : totalContribution + '%';
    totalRate         = totalRate == 0 ? '' : totalRate + '%';
    totalMoney        = totalMoney == 0 ? '' : totalMoney;

    $('#teamTable #totalContribution').html(totalContribution);
    $('#teamTable #totalRate').html(totalRate);
    $('#teamTable #totalMoney').html(totalMoney);
    $('#teamTable #totalContributionLabel').remove();
    $('#teamTable #totalRateLabel').remove();
    $('#teamTable #totalMoneyLabel').remove();
}