<script type="text/javascript">    
    $(document).ready(function(){   
        var clss,act,app_id;

        $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
        $('.datepicker').datepicker('setDate',new Date());
        setDatePickerZh();

        $('#custom-url-modal .btn-act').unbind('click').bind('click',function(){  
            clss=$(this).attr('class').split(' ');
            act='';
            msg='';
            app_id=$('#custom-url-modal .app_id').val();
            var dt_paid=$('#dt_paid').val();
            var amt_paid=$('#amt_paid').val();
            $(this).hide();
            if (clss.indexOf('btn-cancel')>-1){
                var ck=$("#tb_lv1 tbody tr[pid='"+app_id+"']").find('td input[type="checkbox"]');
                console.log(ck);
                ck.attr("checked", false);       

                
                $('#custom-url-modal').modal('hide');                
            } else{
                
                if(dt_paid=='' || amt_paid==''){
                    alert('付款日期和货返金额不能为空');                
                    $(this).show();
                }else{                 
                    $.ajax({
                        type:'POST',
                        url:'/sales/channelretate/period/action/lv1_pay/',
                        dataType:'json',
                        contentType: "application/json; charset=utf-8",   
                        data:JSON.stringify({"id":app_id,"dt_paid":dt_paid,'amt_paid':amt_paid}),
                        success: function(data) {  
                            $(this).show();
                            if(data.e!=''){
                                toastr.error(data.e); 
                            }else{                        
                                toastr.success('当前应付已'+data.status);                           
                                //$('#'+app_id).find('td:nth-child(9)').text(data.status);   
                                //$('#'+app_id).find('td:nth-child(11)').text('');  
                                //$('#'+app_id).find('td:nth-child(12)').text('');  
                                $('#tb_lv1 tr[pid="'+app_id+'"]').find('td:nth-child(6)').html('');  
                            };
                            $('#custom-url-modal').modal('hide');
                        },                
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            alert('连接服务器失败');
                            $(this).show();
                            return;                        
                        }  
                    });                
                };
            };           
            
        });
    });
</script>


<div class="row">
    <input class='app_id' type='hidden' value='{{id}}' />
    <div style="display: flex;padding: 1rem;font-size: 1.4rem;border-bottom: 1px solid #d5d5d5;">
        <div>
            本期奖励: <b>{{amount}}</b> 
        </div>
        <div style="margin-left:2rem;">
            上期余额: <b>{{amount_balance|default_if_none:'0.00'}}</b>
        </div>
        <div style="margin-left:1.5rem;">
            付款金额: ￥ <b>{{amount_topay}}</b> 
        </div>               
    </div>    
</div>

<div class='clearfix'></div>
<div class="form-group row" style='margin-top:10px;'>
    <label class="col-sm-1 control-label">付款日期</label>
    <div class="col-sm-11"><input id='dt_paid' class='form-control datepicker' required="required" /> </div>        
</div>  
    

<div class="form-group row" style='margin-top:10px;'>
    <label class="col-sm-1 control-label">货返金额</label>
    <div class="col-sm-11"><input id='amt_paid' class='form-control' required="required" value='' /> </div>        
</div>    
        
