{% load i18n %}






<script src="/static/js/echarts.min.js"></script>
<script type="text/javascript" src="/static/js/datetimepicker-master/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="/static/js/datetimepicker-master/bootstrap-datetimepicker.zh-CN.js"></script>
<link rel="stylesheet" href="/static/js/datetimepicker-master/bootstrap-datetimepicker.css" />



<style>
    .charts{
        height:86%;
        width:100%;
    }
    #qty{
        height:40%;
        margin-bottom:20px;
    }
    .pie-charts{
        height:60%;
        width:100%;
    }
    #prd{
        display:inline-block;
        width:49%;
        height:100%;
    }
    #agt{
        display:inline-block;
        width:49%;
        height:100%;
    }

    .ui-datepicker-calendar
    {display: none;}
</style>


<div class="subtitle">
    <ol class="breadcrumb">
        <li>{% trans "图表数据" %}</li>
        <li>{% trans "时间段内销量分析" %} </li>
    </ol>
</div>

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

        $('.datepicker').datetimepicker({
           format: 'yyyy-mm',
           weekStart: 1,
           autoclose: true,
           startView: 3,
           minView: 3,
           forceParse: false,
           language: 'zh-CN'
    });
        $('.datepicker').datepicker('setDate',new Date());
        setDatePickerZh();

        $('#date_from').val('{{date_from}}');
        $('#date_to').val('{{date_to}}');
        console.log('{{date_from}}','{{date_to}}',)
        console.log(new Date())


        var myChart = echarts.init(document.getElementById('qty'));
            var option = {
                title :{
                    text:'月度发货柱状图'
                },
                toolbox:{
                    feature:{
                        saveAsImage:{
                            pixelRatio:2
                        }
                    }
                },
                tooltip:{
                    trigger:'item',

                },
                xAxis:{
                    type:'category',
                    data:[]
                },
                yAxis:{
                    type:'value',
                    format:'{a} :::: {c}',
                },
                series:{
                    data:[],
                    type:'bar',
                },
                legend: {
                    type:'plain',
                    data:['柱状图']
                }

            }
            var qty_option={
            grid: {
                left: '60px',
                right: '1%',
                top: '10%',
                bottom: '10%'
            },
            title : {
                text: '库存与销售图',
                x:'right'
            },
            xAxis: {
                type: 'category',
                data: {{quantitys.list_category|safe}}
            },
            yAxis: {
                type: 'value',
                axisLabel:{
                    show: true,
                    interval: 'auto',
                    formatter: '{value}% '//纵坐标百分比
                 }
            },
            legend:{
                data:['库存余量','销售量']
            },
            tooltip: {
                trigger: 'axis',
                //formatter: '{b0}<br/>{a0}: {c0}%<br />{a1}: {c1}%<br />'//展示百分比
                //formatter: function(value,index){
                //  return value +"%"
                //}//展示百分比
            },
            series: [{
                name:['库存余量'],
                data: {{quantitys.kucun_data|safe}},
                type: 'line',
                smooth: true
                },
                {
                name:['销售量'],
                data: {{quantitys.sell_data|safe}},
                type: 'line',
                smooth: true
            },]
        };
        {#refreshChart()#}

        function refreshChart() {
                myChart.showLoading();
                $.ajax({
                    url:"/product/inventory/in/?date_from="+$('#date_from').val()+"&date_to="+$('#date_to').val(),
                    type:"GET",
                    async:true,
                    success:function(data){
                        console.log("data:",data)
                        myChart.setOption({
                        legend: {
                             data: ['security code matched', 'security code not match']
                                },
                        xAxis: {
                            type: 'category',
                            data: data[0].category
                        },
                        series: [{
                            name:"security code matched",
                            type: 'line',
                            data: data[0].data,
                            smooth: true
                        },
                            {
                            name:"security code not match",
                            type: 'line',
                            data: data[1].data,
                            smooth: true
                            }
                        ]
                    })
                    },
                    error: function(){
                        console.log('ajax failure')}
                })
        }
        myChart.setOption(qty_option);

        $('.btn-qry').click(function(){
            var date_from=$('#date_from').val();
            var date_to=$('#date_to').val();
            var company = $('#company').val();
            var sdiv = $('#sdiv').val();
            $.RefreshContent('{{request.path}}?date_from='+date_from+'&date_to='+date_to+'&company='+company+'&sdiv='+sdiv);
        });

    });
</script>


<form role="form"  class="form-inline" >
    <div class='col-sm-2 input-group'>
        <span class="input-group-addon"> {% trans "开始日期" %} </span>
        <input class="datepicker form-control" id="date_from" />
    </div>
    <div class='col-sm-2 input-group'>
        <span class="input-group-addon"> {% trans "结束日期" %} </span>
        <input class="datepicker form-control" id="date_to" />

    </div>

{% ifequal  filter  True %}
    <div class='col-sm-2 input-group'>
        <span class="input-group-addon"> {% trans "经销商" %} </span>
        <select class=" form-control" id="company" >
                {% ifequal now.0 null%}
                    <option value=""> --经销商--</option>
                {% else %}
                    <option value="{{ now.0 }}" >{{ now.1 }}</option>
                {% endifequal %}

            {% for i in  com %}
                <option value="{{ i.0 }}">{{ i.1 }}</option>
            {% endfor %}
        </select>
    </div>

    <div class='col-sm-2 input-group'>
        <span class="input-group-addon"> {% trans "战区" %} </span>
        <select class=" form-control" id="sdiv" >
                <option value=""> --战区--</option>
            {% for i in  sdiv %}
                <option value="{{ i.0 }}">{{ i.1 }}</option>
            {% endfor %}
        </select>
    </div>
{% endifequal %}
    <div class='col-sm-2 input-group' style='margin-left:20px;'>
        <span>
            <a type="button" class='btn btn-primary btn-qry'>
                <span class='glyphicon glyphicon-search' style='padding-right:15px;'></span>{% trans '查看' %}
            </a>
        </span>
    </div>


</form>
<div class="clearfix"></div>
<div class="charts">   
    <div id='qty' style="width:100%;height:350px;"></div>
    <div class='pie-charts'>
        <div id='agt' style="width:48%;height:500px;"></div>
        <div id='prd' style="width:48%;height:500px;"></div>
    </div>
</div>



