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


    {% block js %}
        {{ block.super }}

    $('#data-content div.award_photo br').remove();
    $('#photo-clear_id,#id_photo').removeClass('form-control');



        $('.btn-save').click(function(){
            $.SubmitForm('#obj_form form','{{request.path}}');
        });
        {% if form.instance %}
            $('#co').val('{{form.instance.company.id}}');
        {% endif %}

        $('#co').change(function(){
            $('#id_company').val($('#co').val());
        });

        $("#id_awardcat").on('change',function (){
            console.log($(this).val());
            let id = $(this).val();
            catChoose(id);
        })
        var select_id = $("#id_awardcat option:selected").val();
        catChoose(select_id);
        function catChoose(id){
            if (id ==='1' || id === '7'){
                $("#hexiao_choose").show();
                $('#points').show()
                $('#amount').show()
                $('#fg_redpack').hide()
                $('#chance_price').hide()
            }
            else if (id == 9){//概率红包
              $('#chance_price').show()
              $('#fg_redpack').hide()
              $('#points').hide()
              $('#amount').hide()
            }
            else if (id == 10){//复购红包
              $('#fg_redpack').show()
              $('#chance_price').hide()
              $('#points').hide()
              $('#amount').hide()
            }
            else{
                $('#points').show()
                $('#amount').show()
                $('#fg_redpack').hide()
                $('#chance_price').hide()
                $("#hexiao_choose").hide();
                $("#id_is_need_hexiao").prop("checked",false)
            }
        }

        $('#obj_form .award_photo a').click(function(event){      
        event.preventDefault();
        var src=$(this).attr('href');
        var i="<div style='text-align:center;'><img src='"+src+"' style='height:400px;'></img></div>";
        $.OpenCfmDlg($('#id_name').val(),i);                   
    });
    {% endblock %}


    {% block subtitle-1 %}
        {% trans "营销活动" %}
    {% endblock %}
    {% block subtitle-2 %}
        {% trans "奖品设置" %}
    {% endblock %}

    <span style="margin-left:10px; color:green; ">
        {% block subtitle-3 %}
            {% if form.instance.id %}
                {% trans "修改" %}
            {% else %}
                {% trans "新建" %}
            {% endif %}
        {% endblock %}

    </span>



{% block form_content %}
    {{ block.super }}    
    <div class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'company' %} </label>
        <div class="col-sm-10">
            <select id='co'>
                <option value=''>-----------------------------</option>
                {% for c in companys %}
                    <option value='{{c.0}}'>{{c.1}}</option>
                {% endfor %}
            </select>
        </div>
    </div>
    <div class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'name' %} </label>
        <div class="col-sm-10">{{ form.name }}</div>
    </div>
    <div class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'awardcat' %} </label>
        <div class="col-sm-10">{{ form.awardcat }}</div>
    </div>
    <!-- 概率红包 -->
    <div id="chance_price" class="form-group " style="display: none;">
      <label class="col-sm-2 control-label ">金额范围（元）</label>
      <div class="" style="display: inline-block;width: 10%; padding-left: 10px;">{{ form.chance_price_min }}</div>
      <span>至</span>
      <div class="" style="display: inline-block;width: 10%;">{{ form.chance_price_max }}</div>
    </div>
    <!-- 复购红包 -->
    <diiv id="fg_redpack" style="display: none; padding-bottom: 20px;">
        <div class="form-group award_photo">
          <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'fg_redpack_price' %} </label>
          <div class="col-sm-10">{{ form.fg_redpack_price }}</div>
        </div>
        <div class="form-group award_photo"></div>
          <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'fg_num' %} </label>
          <div class="col-sm-10">{{ form.fg_num }}</div>
        </div>
    </diiv>
    <div class="form-group award_photo">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'photo' %} </label>
        <div class="col-sm-10">{{ form.photo }}</div>
    </div>
    <div id="points" class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'points' %} </label>
        <div class="col-sm-10">{{ form.points }}</div>
    </div>
    <div id="amount" class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name  form.instance 'amount' %} </label>
        <div class="col-sm-10">{{ form.amount }}</div>
    </div>  
    <div class="form-group">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name  form.instance 'is_usein_banquet' %} </label>
        <div class="col-sm-1">{{ form.is_usein_banquet }}</div>
    </div>
	<div id="hexiao_choose" style="display: none">
		<div class="form-group">
			<label class="col-sm-2 control-label ">{% get_verbose_field_name  form.instance 'is_need_hexiao' %} </label>
			<div class="col-sm-1">{{ form.is_need_hexiao }}</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label ">{% get_verbose_field_name  form.instance 'hexiao_level_id' %} </label>
			<div class="col-sm-1">{{ form.hexiao_level_id }}</div>
		</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>
        <a class="btn btn-primary btn-save" type="button" style="float:right;">{% trans '保存' %}</a>
    </div>
{% endblock %}
