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


{% block subtitle %}
<ol class="breadcrumb">
        <li>{% trans '宴会管理' %}</li>
        <li>{% trans '宴会审核' %}</li>
</ol>
{% endblock %}

{% block form_content %}
<script>

    $(document).ready(function () {

        $('#btn_permit').click(function (event) { 
            event.preventDefault();
            var status = $("#status_select option:selected").val();
            var remark = $("#txt_remark").val();
            
            $.ajax({
                url: '/banquet/ajax/permit',
                data:{
                    status,
                    remark,
                    id:"{{id}}",
                    uid:"{{uid}}"
                },
                success:function(res){
                    if(res.e === ''){
                        $(".alert-success").fadeIn();
                        changeTableData(status)
                        //$.RefreshContent("/banquet/list/apply/"); 
                        setTimeout(function(){ 
                            $(".alert-success").fadeOut();
                        },2000)
                    }
                    else{
                        alert(res.e);
                    }
                },
                error:function(){
                    alert('网络超时！请稍后再试！')
                }
            })
        }); 
		
        var status = {{status}}
        if(status >= 3){
            $("#status_select").html(`
                <option value="2">驳回</option>
                <option value="4">通过</option>
            `)
        }

        function changeTableData(status){
            var status_dict = {
                0: ['未审核','blue'],
                1: ['已通过','#07c160'],
                2: ['未通过','red'],
                3: ['结算审核中','blue'],
                4: ['结算中','blue'],
                5: ['已结算','#07c160'],
            }
            var firstLink = $(window.click_row).find('td:first a');
            $(firstLink).text(status_dict[status][0])
            $(firstLink).css({'color': status_dict[status][1]})
        }
    })

</script>
<style>
    input[type=checkbox]{
        display: inline-block;
        width: auto;
        height: auto;
        margin-top: 10px;
    }
</style>
<div class="alert alert-success" role="alert" style="display: none">提示：保存成功！</div>
<div class="form-group">
    <label class="col-sm-2 control-label ">审核状态</label>
    <div class="col-sm-8">
		<select id="status_select">
			<option value="0">未审核</option>
			<option value="1">通过</option>
			<option value="2">未通过</option>
		</select>
	</div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label ">备注</label>
    <div class="col-sm-8">
        <textarea id="txt_remark" cols="30" rows="10" placeholder="填写备注" style="width: 100%;"></textarea>
    </div>
</div>
<div>
    <button class="btn btn-primary" id="btn_permit" style="float:right;">保存</button>
</div>
{% endblock %}