{% 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}}');
        });
        $('#btn_save2').click(function () {
            $.SubmitForm('#form_brand2', '{{request.path}}', function () {
                $('.modal-backdrop').remove();
            });
        })
        $('#btn_save3').click(function () {
            $.SubmitForm('#form_brand3', '{{request.path}}', function () {
                $('.modal-backdrop').remove();
            });
        })

    });

    function editLevel(level_id) {
        var levels = JSON.parse($("#h_brand_levels").val());
        for (var i = 0; i < levels.length; i++) {
            if (parseInt(level_id) === levels[i].pk) {
                $("#level_id").val(levels[i].pk);
                $("#inputName2").val(levels[i].fields.name);
                $("#inputLevel2").val(levels[i].fields.level);
                $("#inputImg2").attr('src', '/media/' + levels[i].fields.photo);
                $("#inputNum2").val(levels[i].fields.need_num);
                $("#inputMoney2").val(levels[i].fields.need_money);
                $("#inputRemark2").val(levels[i].fields.remark);
                $('#level_model').modal('show')
                break;
            }
        }
    }

    function deleteLevel(level_id) {
        var r = confirm('您确定要删除这条数据吗？');
        if (r) {
            $("#level_id").val(level_id);
            $.SubmitForm('#form_brand2', '{{request.path}}delete/');
        }
    }

    function bindBenefit(level_id) {
        var levels = JSON.parse($("#h_brand_levels").val());
        for (var i = 0; i < levels.length; i++) {
            if (parseInt(level_id) === levels[i].pk) {
                $("#level_id_2").val(levels[i].pk);
                $("#inputName3").val(levels[i].fields.name);
                $("#inputLevel3").val(levels[i].fields.level);
                $("#inputImg3").attr('src', '/media/' + levels[i].fields.photo);
                $("#inputNum3").val(levels[i].fields.need_num);
                $("#inputMoney3").val(levels[i].fields.need_money);
                $("#inputRemark3").val(levels[i].fields.remark);
                $('#level_model_2').modal('show')
                break;
            }
        }
    }
</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="inputMethod" class="col-sm-1 control-label">升级方式</label>
        <div class="col-sm-11">
            <input id="inputMethod" type="text" class="form-control" value="{{level_up_method}}" readonly="readonly"/>
        </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">
        <label for="inputLevel" class="col-sm-1 control-label">等级级别</label>
        <div class="col-sm-11">
            <input id="inputLevel" name="level" type="number" class="form-control" placeholder="请输入等级级别（例：1、2、3）"/>
        </div>
    </div>

    <div class="form-group">
        <label for="inputLevel" class="col-sm-1 control-label">等级图片</label>
        <div class="col-sm-11">
            <input type="file" name="photo" accept="image/*" class="form-control">
        </div>
    </div>
    {% ifequal level_up_method_id 1 %}
    <div class="form-group">
        <label for="inputNum" class="col-sm-1 control-label">销售数量</label>
        <div class="col-sm-11">
            <input id="inputNum" name="need_num" type="number" class="form-control" placeholder="请输入等级所需销售数量"/>
        </div>
    </div>
    {% else %}
    <div class="form-group">
        <label for="inputMoney" class="col-sm-1 control-label">销售金额</label>
        <div class="col-sm-11">
            <input id="inputMoney" name="need_money" type="number" class="form-control" placeholder="请输入等级所需销售金额"/>
        </div>
    </div>
    {% endifequal %}


    <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>
<input type="hidden" id="h_brand_levels" value="{{list}}">
<div class="modal fade" tabindex="-1" role="dialog" id="level_model">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <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 role="form" method='POST' enctype="multipart/form-data" class="form-horizontal" id="form_brand2">
                    {% csrf_token %}
                    <div class="form-group">
                        <label for="inputMethod2" class="col-sm-1 control-label">升级方式</label>
                        <div class="col-sm-11">
                            <input id="inputMethod2" type="text" class="form-control" value="{{level_up_method}}"
                                   readonly="readonly"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputName2" class="col-sm-1 control-label">等级名称</label>
                        <div class="col-sm-11">
                            <input id="inputName2" name="name" type="text" class="form-control"
                                   placeholder="请输入等级名称（例：青铜、黄金、一级）" maxlength="50"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputLevel2" class="col-sm-1 control-label">等级级别</label>
                        <div class="col-sm-11">
                            <input id="inputLevel2" name="level" type="number" class="form-control"
                                   placeholder="请输入等级级别（例：1、2、3）"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="inputImg2" class="col-sm-1 control-label">等级图片</label>
                        <div class="col-sm-11">
                            <img id="inputImg2" style="width:60px;margin-bottom: 10px;"/>
                            <input type="file" name="photo" accept="image/*" class="form-control">
                        </div>
                    </div>
                    {% ifequal level_up_method_id 1 %}
                    <div class="form-group">
                        <label for="inputNum2" class="col-sm-1 control-label">销售数量</label>
                        <div class="col-sm-11">
                            <input id="inputNum2" name="need_num" type="number" class="form-control"
                                   placeholder="请输入等级所需销售数量"/>
                        </div>
                    </div>
                    {% else %}
                    <div class="form-group">
                        <label for="inputMoney2" class="col-sm-1 control-label">销售金额</label>
                        <div class="col-sm-11">
                            <input id="inputMoney2" name="need_money" type="number" class="form-control"
                                   placeholder="请输入等级所需销售金额"/>
                        </div>
                    </div>
                    {% endifequal %}


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

                    <div class="form-group">
                        <div>

                        </div>
                        <div class="col-sm-offset-1 col-sm-11">
                            <a class="btn btn-primary" id="btn_save2" style="margin-right: 10px;">修改</a>
                        </div>
                    </div>


                    <input type="hidden" name="level_id" id="level_id">


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


<div class="modal fade" tabindex="-1" role="dialog" id="level_model_2">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <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 role="form" method='POST' enctype="multipart/form-data" class="form-horizontal" id="form_brand3">
                    {% csrf_token %}


                    <input id="inputMethod3" type="hidden" class="form-control" value="{{level_up_method}}" readonly="readonly"/>
                    <input id="inputName3" name="name" type="hidden" class="form-control"/>
                    <input id="inputLevel3" name="level" type="hidden" class="form-control"/>
                    <input id="inputNum3" name="need_num" type="hidden" class="form-control" />
                    <input id="inputMoney3" name="need_money" type="hidden" class="form-control"/>
                    <input id="inputRemark3" name="remark" type="hidden" class="form-control"/>
                    <div class="form-group">
                        <label for="inputLevel" class="col-sm-2 control-label">权益设定</label>
                        <div class="col-sm-10">
                            <select name="benefit" id="select_benefit" class="form-control">
                                <option value="">请选择---</option>
                                {% for b in benefits %}
                                <option value="{{b.pk}}">{{b.fields.name}}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <input type="hidden" name="level_id" id="level_id_2">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="btn_save3">绑定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

