{% load i18n %}


<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,
            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();
                }
            });
        });
        $('.btn-save').click(function () {
            $.SubmitForm('#form_brand', '{{request.path}}');
        });
    });
    $("#select1").change(function (){
        console.log($(this).val())
        cat_id = $(this).val();
        if (cat_id ==='1'){
            $("#discount_con").show();
        }
    })

    function deleteData(id) {
        var r = confirm('您确定要删除这条数据吗？');
        if (r) {
            $.RefreshContent('{{request.path}}delete/'+id+'/');
        }
    }
</script>


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


{% if perms.company.sys_admin %}

<form role="form" method='POST' enctype="multipart/form-data" class="form-horizontal" id="form_brand"> {% csrf_token %}
    <div class="form-group">
        <label for="select1" class="col-sm-1 control-label">规则类型</label>
        <div class="col-sm-11" >
            <select name="rule_category" id="select1" class="form-control">
                <option value="">请选择</option>
                {% for c in cats %}
                <option value="{{c.id}}">{{c.name}}</option>
                {% endfor %}

            </select>
        </div>
    </div>

    <div class="form-group">
        <label for="inputName" class="col-sm-1 control-label">规则名称</label>
        <div class="col-sm-11">
            <input id="inputName" name="name" type="text" class="form-control" placeholder="请输入规则名称"
                   maxlength="50"/>
        </div>
    </div>

    <div class="form-group" id="discount_con" style="display: none">
        <label for="inputMoney" class="col-sm-1 control-label">折扣</label>
        <div class="col-sm-11">
            <input id="inputMoney" name="discount" type="number" class="form-control" placeholder="输入折扣(如:95)"/>
        </div>
    </div>


    <div class="form-group">
        <label for="inputRemark" class="col-sm-1 control-label">备注信息</label>
        <div class="col-sm-11">
            <input id="inputRemark" name="remark" type="text" class="form-control" placeholder="备注信息" maxlength="50"/>
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-1 col-sm-11">
            <a class="btn btn-default btn-save">添加</a>
        </div>
    </div>
</form>

{% endif%}

<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>