{% load i18n %}

{% ifequal obj 'Award' %}
<style>
  
    #tb tbody td img{
        height:30px;
        cursor:pointer;
    }


    
</style>
{% endifequal %}
<style> 
    .word-wrap{
        width: 100%;white-space: normal;word-wrap: break-word;word-break: break-all;
    }
    .ant-tag-success {
        color : #52c41a !important;
        background: #f6ffed !important;
        border-color: #b7eb8f;
    }
    .ant-tag-orange {
        color: #d46b08 !important;
        background: #fff7e6 !important;
        border-color: #ffd591;
    }
    .ant-tag-error {
        color: #ff4d4f !important;
        background: #fff2f0 !important;
        border-color: #ffccc7;
    }
    .ant-tag-warning {
        color: #faad14 !important;
        background: #fffbe6 !important;
        border-color: #ffe58f;
    }
    .ant-tag-default {
    }
    .ant-tag {
        box-sizing: border-box;
        margin: 0 8px 0 0;
        color: #000000d9;
        font-size: 14px;
        font-variant: tabular-nums;
        line-height: 1.5715;
        list-style: none;
        font-feature-settings: "tnum";
        display: inline-block;
        height: auto;
        padding: 0 7px;
        font-size: 12px;
        line-height: 20px;
        white-space: nowrap;
        background: #fafafa;
        border: 1px solid #d9d9d9;
        border-radius: 2px;
        opacity: 1;
        transition: all .3s;
    }
</style>



<script type="text/javascript">
    $(document).ready(function(){
        var page_length=10;

        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,
{#            {% if days %}#}
{#                columnDefs:[{#}
{#                    "targets":4,#}
{#                    "createdCell": function (td, cellData, rowData, row, col) {#}
                                {#var x = cellData.split(">")[1].split("<")[0];#}
{#                                var color = cellData.split("-")[1];#}
{##}
                                {#$(td).parent().css('background', color);#}
{#                            }#}
{#                }],#}
{#            {% endif %}#}
			{% if order %}
            order: {{order|safe}},
			{% endif %}
			
            data:{{data|safe}}
        });      
        table.columns().every( function () {                        
            var that = this;             
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        });    


    //$('#data-content').on("click", ".btn-obj-add", function () {
         
    //});  
    $(".btn-obj-add").click(function () { 
        event.preventDefault();
        $.RefreshContent($(this).attr('href'));        
    })

        $('#tb').on("click","td a",function(event){
			
            event.preventDefault();    
			if($(this).hasClass('btn-dlg')){
				$.OpenDlg($(this).attr('href'),'信息弹窗',1000,700);
				return;
			}
            $.RefreshContent($(this).attr('href'));            
        });     

       
        $('#tb tbody').on('click','img',function(){            
            var src=$(this).attr('src');
            var tt=$(this).closest('tr').find('a').text();
            if(tt==''){                
                tt=$(this).attr('tt');
            };
            var i="<div style='text-align:center;'><img src='"+src+"' style='height:400px;'></img></div>";
            $.OpenCfmDlg(tt,i);       
        });

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

        $('#dt_fr').val('{{date_from}}');
        $('#dt_to').val('{{date_to}}');

        $('.btn-qry').click(function(){
            var date_from,date_to;
            date_fr=$('#dt_fr').val();
            date_to=$('#dt_to').val();
            var params=[];
            if(date_fr!=''){params.push('date_from='+date_fr)};
            if(date_to!=''){params.push('date_to='+date_to)};

            if(params.length==0){
                bootbox.alert("{% trans '请先输入查询条件！'%}");
            }else{
                $.RefreshContent('{{request.path}}?'+params.join('&'));
            }
        });


        //2020-11-07
        $("[data-toggle='popover']").popover({
            html:true,
            placement:'bottom'
        });

		$('.btn-dlg').off('click')
        $('.btn-dlg').click(function(event){

            $(event.target.parentNode).addClass('row_selected');

             event.preventDefault();
             $.OpenDlg($(this).attr('href'),'信息弹窗',1000,700);


            //$.RefreshContent($(this).attr('href'));  
            //return false;
            //$("#dlgDiv").dialog("open")
        }); 
		
		$('.btn-photo').click(function(){            
            var src=$(this).data('src'); 
            var i="<div style='text-align:center;'><img src='"+src+"' style='height:400px;'></img></div>";
            $.OpenCfmDlg('图片',i);       
        });
    });

    function  catDetails(){
        event.preventDefault();
        $('#modal1').modal('show')
    }

    $("#amount").on("input",function(e){
        　　e.target.value = e.target.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
        　　e.target.value = e.target.value.replace(/^\./g,""); //验证第一个字符是数字而不是.
        　　e.target.value = e.target.value.replace(/^\./g,""); //验证第一个字符不是0
        　　e.target.value = e.target.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
        　　e.target.value = e.target.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");//只允许输入一个小数点
        　　e.target.value = e.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
        });
    $(".btn_insert").click(function (){
        event.preventDefault()
        var r = confirm('您确定要调整吗？');
        var remark = $('#remark').val();
        var value_type = $('#value_type').val();
        var amount = $('#amount').val();
        if (r) {
            if (amount) {
                $.ajax({
                    url: `/sales/wallent/amount/update/`,
                    type: 'POST',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    data: JSON.stringify({remark: remark, value_type: value_type, amount: amount}),
                    success: function (res) {
                        if (res.e == '') {
                            $('#modal1').modal('hide')
                        }
                    }
                })
            } else {
                alert('请输入有效金额！')
            }

        }
    })

</script>



<ol class="breadcrumb">
        <li>{{subtt.0}}</li>
        <li>{{subtt.1}}</li>     
</ol>



<form role="form"  class="form-inline" style="margin-top:0px;padding-left:10px;">
    <div class="col-sm-2 input-group">
        <span class="input-group-addon">{% trans "开始日期"%}</span>
        <input class="datepicker form-control" id="dt_fr" />
    </div>
    <div class="col-sm-2 input-group">
        <span class="input-group-addon">{% trans "结束日期"%}</span>
        <input class="datepicker form-control" id="dt_to" />
    </div>
    <div  class="col-sm-2 input-group">
        <span class='input-group-btn'>
            <a type="button" class='btn btn-primary btn-qry'>
                <span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans '查找' %}
            </a>
        </span>
    </div>
    <div class="col-sm-4 input-group">
            <div class="form-group">
                <label>当前剩余额度(元):</label>
                <strong style="margin: 0 10px">{{ amount }}</strong>
            </div>
             <button class="update btn btn-default" onclick="catDetails()" style="margin-bottom:0px">调整</button>
    </div>
</form>
<div class="clearfix"></div>



<div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
        <div  class="table-responsive">
            <table id='tb'  class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
            <thead>
                {% for c in clmns %}
                    <th>{{c}}</th>
                {% endfor %}
            </thead>
            <tbody></tbody>
            <tfoot>
                {% for c in clmns %}
                    <th><input type="text" placeholder="{{c}}"></th>            
                {% endfor %}            
            </tfoot>
            </table>
        </div>
    </div>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="modal1" style="margin: 100px auto;">
    <div class="modal-dialog" role="document" >
        <div class="modal-content" style="width: 600px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">金额调整</h4>
            </div>
            <div class="modal-body">
                <form class="form-inline">
                    <div class="form-group">
                        <div class="input-group">
                            <div>
                                <select style="margin: 0 15px;" id="value_type" class="form-control">
                                    <option value="1" selected >充值</option>
                                    <option value="0">扣减</option>
                                </select>
                            </div>
                            <div class="input-group-addon">¥</div>
                            <input type="number" min="1" onpaste="return false" class="form-control" id="amount" placeholder="单位（元）">
                            <div class="input-group-addon">.00</div>
                        </div>

                    </div>
                     <div style="margin: 0 15px;" class="form-group">
                        <label for="remark">备注：</label>
                        <input type="text" class="form-control" id="remark" >
                      </div>
                    <button  class="btn btn-primary btn_insert"  >确认调整</button>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
