<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="__CSS__/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="__CSS__/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="__CSS__/style.css" media="all">
    <link rel="stylesheet" type="text/css" href="__CSS__/default_color.css" media="all">
    <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />

    <script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="__JS__/select2.min.js"></script>
    <script type="text/javascript" src="__STATIC__/layer3/layer.js"></script>
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"charset="UTF-8"></script>
    <script src="__STATIC__/juicer-min.js" type="text/javascript"></script>
    <script src="__STATIC__/table2excel.js"></script>
</head>
<style>
    html {
        min-width:100%;
    }
    body {
        padding: 0px 10px 150px 10px;
        /* width: 960px; */
        margin: auto;
    }
    /* .tabcon1711 table{
        width: 480px;
    } */
    table{
        
        margin: auto;
    }
    tr{
        border-bottom: dotted 1px #c7c7c7;
    }
    .hidebox{
        display: none;
    }
    .r{
        width: 300px;
    }
    .l{
        width: 180px;
    }
    .select2-container--default .select2-selection--single {
        color: #000;
        resize: none;
        border-width: 1px;
        border-style: solid;
        border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
        box-shadow: 0px 3px 3px #F7F8F9 inset;
        height: 35px;
        height: 28px;
        border-radius: 3px;
        font-size: 12px;
    }

    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 35px;
        line-height: 28px;
    }

    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 26px;
    }

    .select2-container--default .select2-search--dropdown .select2-search__field {
        height: 26px;
        line-height: 26px;
        font-size: 12px;
    }

    .select2-results__option[aria-selected] {
        font-size: 12px;
    }
    .input-list, .i_list {
        float: left;
        margin: 0;
    }
    #statementShow td{
        line-height: 1.5;
        padding: 8px 0;
    }
</style>
<body>
    <!-- <div style="width: 100%;line-height: 100px;font-size: 25px;font-weight: 600;text-align: center;">
        海南万盟天下科技有限公司
    </div> -->

    <div class="data_list box_mt" style="margin-top: 10px;">
        <div class="">
            <table id="exporttable">
                <!-- 表头 -->
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>下游名称</th>
<!--                        <th>结算时间</th>-->
                        <th>会长账号</th>

                        <th>内外团</th>
                        <th>开发类型</th>

                        <th>市场专员</th>
                        <th>所属市场部</th>
                        <th>下游性质</th>
                        <th>产品</th>
                        <th>产品类型</th>
                        <th>结算时间</th>
                        <th>推广流水</th>
                        <th>退款</th>
                        <th>分成比例</th>
                        <th>补点</th>
                        <th>分成结算金额</th>
                        <th>奖励</th>
                        <th>罚款</th>
                        <th>其他扣款</th>
                        <th>周结算金额</th>
                        <th>结算金额</th>

                        <th>户名</th>
                        <th>帐号</th>
                        <th>开户行</th>
                        <th>是否支付宝打款</th>
                        <if condition="!$is_special_export"><th>是否结算</th></if>
                        <if condition="!$is_special_export"><th>备注</th></if>

                         <if condition="!$is_export">
                            <th>操作</th>
                        </if>

                    </tr>
                </thead>
                <tbody id="statementShow">
                <if condition = "empty($data)">
                    <tr>
                        <td colspan="50" class="text-center">aOh! 暂时还没有内容!</td>
                    </tr>
                </if>
                        <foreach name="data" item="com">
                            <tr>
                                <td rowspan="{$com.row}">{$key-0+1}</td>
                                <td rowspan="{$com.row}">{$com.company_name}</td>


                                <notempty name="com['statement_info']">
                                    <td rowspan="{$com['statement_info'][0]['row']}">{$com['statement_info'][0]['account']}</td>
                                <else />
                                    <td>-</td>
                                </notempty>

                                <td rowspan="{$com.row}">{$com.company_info.company_belong_str}</td>
                                <td rowspan="{$com.row}">{$com.company_info.company_relation_str}</td>

                                <td rowspan="{$com.row}">{$com.company_info.nickname}</td>
                                <notempty name="com['statement_info']">
                                    <td rowspan="{$com.row}">{:getAdminDepartmentNameByPromoteAccount($com['statement_info'][0]['account'])}</td>
                                <else />
                                    <td rowspan="{$com.row}">-</td>
                                </notempty>
                                <td rowspan="{$com.row}">{$com.company_info.company_type_str}</td>

                                <notempty name="com['statement_info'][0]['game_list']">
                                    <td>{$com['statement_info'][0]['game_list'][0]['game_name']}</td>
                                    <td>{$com['statement_info'][0]['game_list'][0]['game_type_name']}</td>
                                    <td rowspan="{$com['statement_info'][0]['time_row']}">{$com['statement_info'][0]['time']}</td>

                                    <td><span class="pay_amount">{$com['statement_info'][0]['game_list'][0]['pay_amount']}</span></td>
                                    <td>{$com['statement_info'][0]['game_list'][0]['refund']|default=0}</td>
                                    <td>{$com['statement_info'][0]['game_list'][0]['ratio']}%</td>
                                    <td>{$com['statement_info'][0]['game_list'][0]['increment_ratio']}%</td>
                                    <td><span class="sum_money_span">{$com['statement_info'][0]['game_list'][0]['sum_money']}</span></td>

                                    <td rowspan="{$com['statement_info'][0]['time_row']}">{$com['statement_info'][0]['game_list'][0]['reward']||default="0"}</td>
                                    <td rowspan="{$com['statement_info'][0]['time_row']}">{$com['statement_info'][0]['game_list'][0]['fine']||default="0"}</td>
                                    <td rowspan="{$com['statement_info'][0]['time_row']}">{$com['statement_info'][0]['game_list'][0]['withhold']|default=0}</td>
                                    <td rowspan="{$com['statement_info'][0]['time_row']}">{$com['statement_info'][0]['week_amount']||default="0"}</td>
                                    <td rowspan="{$com.row}">{$com['statement_money']}</td>

                                <else />
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td>-</td>
                                    <td rowspan="{$com.row}">-</td>
                                    <td rowspan="{$com.row}">-</td>
                                    <td rowspan="{$com.row}">-</td>

                                </notempty>

                                <if condition="$com['is_payment'] eq 2">
                                    <td rowspan="{$com.row}">{$com.company_info.payee_name}</td>
                                    <td rowspan="{$com.row}">&nbsp;{$com.company_info.bank_account}</td>
                                    <td rowspan="{$com.row}">{$com.company_info.opening_bank}</td>
                                </if>

                                <if condition="$com['is_payment'] eq 1">
                                    <td rowspan="{$com.row}">{$com.company_info.ali_user}</td>
                                    <td rowspan="{$com.row}">{$com.company_info.ali_account}</td>
                                    <td rowspan="{$com.row}"></td>
                                </if>
                                <td rowspan="{$com.row}"><if condition="$com['is_payment'] eq 1">是 <else /> 否 </if></td>
                                <if condition="!$is_special_export"><td rowspan="{$com.row}"><if condition="$com['st'] eq 0">否 <else /> 是 </if></td></if>
                                <if condition="!$is_special_export"><td rowspan="{$com.row}" style="text-align: left;max-width: 370px;">{$com.remark}</td></if>

                                <if condition="!$is_export">
                                    <td rowspan="{$com.row}">
                                        <if condition="($com['st'] eq 1 ) AND ($pool_status lt 1) AND ($com.is_reward_fine_split eq 0)">
                                            <a data-id="{$com['id']}" class='butn no_statement' style="cursor:pointer">不结算</a>
                                        </if>
                                    </td>
                                </if>

                            </tr>

                            <if condition="$com['statement_info'][0]['row'] gt 1">
                                <foreach name="com['statement_info'][0]['game_list']" item="game" key="gamekey">
                                    <if condition="$gamekey gt 0">
                                        <tr>
                                            <td>{$game['game_name']}</td>
                                            <td>{$game['game_type_name']}</td>

                                            <td><span class="pay_amount">{$game['pay_amount']}</span></td>
                                            <td>{$game['refund']|default=0}</td>
                                            <td>{$game['ratio']}%</td>
                                            <td>{$game['increment_ratio']}%</td>
                                            <td><span class="sum_money_span">{$game['sum_money']}</span></td>


                                        </tr>
                                    </if>
                                </foreach>
                            </if>


                            <notempty name="com['statement_info'][1]">

                                <foreach name="com['statement_info']" item="account" key="akey">
                                    <if condition="$akey gt 0">
                                        <tr>


                                            <td rowspan="{$account['row']}">{$account['account']}</td>

                                            <notempty name="account['game_list']">
                                                <td>{$account['game_list'][0]['game_name']}</td>
                                                <td>{$account['game_list'][0]['game_type_name']}</td>
                                                <notempty name="account['time']">
                                                    <td rowspan="{$account['time_row']}">{$account['time']|default="-----"}</td>
                                                </notempty>

                                                <td><span class="pay_amount">{$account['game_list'][0]['pay_amount']}</span></td>

                                                <td>{$account['game_list'][0]['refund']|default=0}</td>
                                                <td>{$account['game_list'][0]['ratio']}%</td>
                                                <td>{$account['game_list'][0]['increment_ratio']}%</td>
                                                <td><span class="sum_money_span">{$account['game_list'][0]['sum_money']}</span></td>
                                                <notempty name="account['time']">
                                                    <td rowspan="{$account['time_row']}">{$account['reward']|default=0}</td>
                                                    <td rowspan="{$account['time_row']}">{$account['fine']|default=0}</td>
                                                </notempty>

                                                <notempty name="account['time']">
                                                    <td rowspan="{$account['time_row']}">{$account['withhold_amount']|default=0}</td>
                                                    <td rowspan="{$account['time_row']}">{$account['week_amount']}</td>
                                                </notempty>

                                            <else />
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                                <td>-</td>
                                            </notempty>
                                        </tr>

                                        <if condition="$account['row'] gt 1">
                                            <foreach name="account['game_list']" item="game" key="gamekey">
                                                <if condition="$gamekey gt 0">
                                                    <tr>
                                                        <td>{$game['game_name']}</td>
                                                        <td>{$game['game_type_name']}</td>

                                                        <td><span class="pay_amount">{$game['pay_amount']}</span></td>

                                                        <td>{$game['refund']|default=0}</td>
                                                        <td>{$game['ratio']}%</td>
                                                        <td>{$game['increment_ratio']}%</td>
                                                        <td><span class="sum_money_span">{$game['sum_money']}</span></td>


                                                    </tr>
                                                </if>
                                            </foreach>
                                        </if>

                                    </if>
                                </foreach>

                            </notempty>
                        </foreach>
                        <if condition="$withdraw_type LT 2">
                            <tr>
                                <td colspan="10" rowspan="3"></td>
                                <td>上周数据合计:</td>
                                <td>{$count.pool_week_count}</td>
                                <td colspan="5" rowspan="3"></td>
                                <td colspan="3">打款合计:</td>
                                <td>{$count.sum_money}</td>

                                <td></td>
                                <td>线上支付:</td>
                                <td>{$count.online_pay}</td>

                                <td colspan="3" rowspan="3"></td>
                                <if condition="!$is_export">
                                    <td rowspan="3"></td>
                                </if>
                            </tr>

                            <tr>
                                <td>本周未结算流水合计:</td>
                                <td>{$count.pool_lack_count}</td>
                                <td colspan="3">本周暂不结算合计:</td>
                                <td>{$count.st_lack_count}</td>

                                <td></td>
                                <td>线下支付:</td>
                                <td>{$count.offline_pay}</td>

                            </tr>

                            <tr>
                                <td></td>
                                <td></td>
                                <td colspan="3">本次应支付:</td>
                                <td>{$count.st_count}</td>

                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>

                        <else />
                            <tr>
                                <td colspan=11 >合计:</td>
                                <td>{$count.platform_amount}</td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>{$count.week_money}</td>
                                <td>{$count.sum_money}</td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <if condition="!$is_export">
                                    <td></td>
                                </if>
                            </tr>
                        </if>

                        <if condition="$is_export and $show_verify">
                            <tr>
                                <td >初审状态:</td>
                                <td>
                                    <if condition="$pool_data.verify_status eq -3 ">
                                        <div style="line-height: 2;color: red;">
                                            {$pool_data.firstverify}
                                        </div>
                                        <else />
                                        <div style="line-height: 2;">
                                            {$pool_data.firstverify}
                                        </div>
                                    </if>
                                </td>
                            </tr>
                            <tr>
                                <td >审批状态:</td>
                                <td>
                                    <if condition="$pool_data.verify_status eq -1 ">
                                        <div style="line-height: 2;color: red;">
                                            {$pool_data.verify}
                                        </div>
                                        <else />
                                        <div style="line-height: 2;">
                                            {$pool_data.verify}
                                        </div>
                                    </if>
                                </td>
                            </tr>
                            <!-- <tr>
                                <td >打款状态:</td>
                                <td>
                                    <if condition="$pool_data.verify_status eq -2 ">
                                        <div style="line-height: 2;color: red;">
                                            {$pool_data.payment}
                                        </div>
                                        <else />
                                        <div style="line-height: 2;">
                                            {$pool_data.payment}
                                        </div>
                                    </if>
                                </td>
                            </tr> -->

                        </if>

                    <tr>
                        <td colspan=40 >线下打款:{$payed_data.offline_amount}&nbsp&nbsp&nbsp&nbsp线上打款:{$payed_data.online_amount}</td>
                    </tr>
                        
                </tbody>
            </table>
        </div>
    </div>
</body>
<script>
    <if condition="$is_export">
        $(function(){
            $("#exporttable").table2excel({
                filename: "{$title}.xls", // do include extension
                preserveColors: false // set to true if you want background colors and font colors preserved
            });
        });
    </if>
    $(".no_statement").on("click",function(){
        var id = $(this).data('id');
        $.ajax({
            type: "POST",
            url: "{:U('cancelStatement')}",
            dataType: 'json',
            async: false,
            data: {id:id},
            success:function(data){
                if(data.status==1){
                    layer.msg("<font style='color:white'>" + data.info + "</font>");
                    setTimeout(function(){
                        window.location.reload();
                    },1500);
                }else{
                    layer.msg("<font style='color:white'>" + data.info + "</font>");
                    return false;
                }
            }
        });
    });

    $(".refund").on("blur",function () {
        caculate_sum_money(this);
    });

    $(".ratio").on("blur",function () {
        caculate_sum_money(this);
    });

    $(".increment_ratio").on("blur",function () {
        caculate_sum_money(this);
    });
    
    function caculate_sum_money(_this) {

        var pay_money = $(_this).parent().parent().find(".pay_amount").text();

        var ratio = $(_this).parent().parent().find(".ratio").val();

        if (!ratio || ratio < 0) {
            ratio = 0;
            $(_this).parent().parent().find(".ratio").val(ratio);
        } else if (ratio > 100) {
            ratio = 100;
            $(_this).parent().parent().find(".ratio").val(ratio);
        }

        var refund = $(_this).parent().parent().find(".refund").val();
        if (!refund  || refund < 0) {
            refund = 0;
            $(_this).parent().parent().find(".refund").val(refund);
        }

        var increment_ratio = $(_this).parent().parent().find(".increment_ratio").val();
        if (!increment_ratio || increment_ratio < 0) {
            increment_ratio = 0;
            $(_this).parent().parent().find(".increment_ratio").val(increment_ratio);
        } else if(increment_ratio > 100) {
            increment_ratio = 100;
            $(_this).parent().parent().find(".increment_ratio").val(increment_ratio);
        }

        pay_money = parseFloat(pay_money) - parseFloat(refund);

        var value = parseFloat(pay_money)*(parseFloat(ratio)/100) + parseFloat(pay_money)*(parseFloat(increment_ratio)/100);

        $(_this).parent().parent().find(".sum_money_span").text(value.toFixed(2));
        $(_this).parent().parent().find(".sum_money").val(value.toFixed(2));

    }
</script>
</html>