{% extends 'obj_form.html' %}
{% load i18n %}
{% load tj_filters %}

{% block subtitle-1 %}
{% trans "营销活动" %}
{% endblock %}
{% block subtitle-2 %}
{% trans "单枚布奖" %}
{% endblock %}


{% block form_content %}
{{ block.super }}

<style>
    input[type=radio],
    input[type=checkbox] {
        display: inline-block;
        width: auto;
        height: auto;
        border: none;
        box-shadow: none;
    }

    .input-num {
        display: inline-block;
        width: 100px;
        border: none;
        border-bottom: 1px solid gray;
    }
</style>

<div class="alert alert-success" role="alert" style="display: none">保存成功！</div>
<div class="form-group ">
    <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'label_code' %} </label>
    <div class="col-sm-10"> 
		<input type="text" name="label_codes" required="" id="id_label_codes" class="form-control">
	</div>
</div> 
<div class="form-group ">
    <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'activity' %} </label>
    <div class="col-sm-10">{{ form.activity }}</div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'award' %} </label>
	<div class="col-sm-10">
		<select class="form-control" name="award" id="awards_select"></select/>
	</div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'award2' %} </label>
	<div class="col-sm-10">
		<select class="form-control" name="award2" id="awards2_select"></select/>
	</div>
</div>
<!--<div class="form-group ">
    <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'product' %} </label>
    <div class="col-sm-10">
        <input type="text" class="form-control" id="product_label" placeholder="所有产品">
        <input type="hidden" id="product_id" />
	</div>
</div>-->
<div class="form-group ">
    <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'remark' %} </label>
    <div class="col-sm-10">{{ form.remark }}</div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">标签类型</label>
    <div class="col-sm-10">
        <label for="input_radio_0">默认<input id="input_radio_0" type="radio" value="default" name="label_type" checked/></label>
        <label for="input_radio_1" style="margin-left: 20px;">A标<input id="input_radio_1" type="radio" value="a" name="label_type"/></label>
    </div>
</div>
<input type="hidden" name="label_code" required="" id="id_label_code" class="form-control" value="1">
<div>
    <a class="btn btn-primary btn-save" type="submit" style="float:right;">{% trans '保存' %}</a>
</div>

<script>
    $(document).ready(function () {
	
	
		$("#id_activity").change(function(){ 
			var activity_id = $(this).val();
			$.ajax({
				url:'obj/ajax/autoselect/activityawards/?id='+activity_id,
				success:function(res){
					console.log(res);
					var html = '';
					for(var i =0;i<res.length; i++){
						
						html+='<option value="'+res[i].value+'">'+res[i].label+'</option>';
					
					}
					$("#awards_select").html(html);
					
					html = '<option value="">无</option>'+html;
					$("#awards2_select").html(html);
				}
			})
		})
		
        
        $('#product_label').autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: '/obj/ajax/autocomplete/product/',
                    dataType: "json",
                    data: {
                        term:   $("#product_label").val()  
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },
            select: function (event, ui) {
                $("#product_id").val(ui.item.value);
                $("#product_label").val(ui.item.label);
                return false;
            }
        });
		
        $('.btn-save').click(function () {
            $.SubmitForm('#obj_form form', '{{request.path}}',function (){
                //$('.alert').fadeIn();
            });
        });
    })


</script>

{% endblock %}