{% 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-qry').click(function () {
            var code = $.trim($('#code').val());
            if (code.length < 10) {
                toastr.error(
                    "{% trans '请先输入您要查询的标签号码!' %}",
                    "操作错误：",
                    { timeOut: 800, positionClass: "toast-center-center" }
                );
                return;
            };
            searchCode(code);
        });

        function searchCode(code) {
            $.ajax({
                url: '/banquet/ajax/code_search',
                data: {
                    code
                },
                success: function (res) {
                    if (res.e === '') {
                        searchApply(res.apply_id)
                    }
                }
            })
        }

        var status_dict = {
			0: ['未审核','blue'],
			1: ['已通过','#07c160'],
			2: ['未通过','red'],
			3: ['结算审核中','blue'],
			4: ['结算中','blue'],
			5: ['已结算','#07c160'],
			6: ['开瓶数量不足，未通过结算奖励','red'],
			7: ['宴席资料异常','red'],
        }

        function searchApply(apply_id) {
            $.ajax({
                url: '/banquet/ajax/detail',
                data: {
                    id: apply_id
                },
                success: function (res) {
                    if (res.e === '') {
                        console.log(res)
                        var info = res.detail.info
                        $("#apply_content").html(`
                            <div>
                                <p><b>宴会类别：</b>${info.category_name}</p>
                                <p><b>申请门店：</b>${info.company_name}</p>
                                <p><b>宴会地址：</b>${info.address}</p>
                                <p><b>宴会政策：</b>${info.policy}</p>
                                <p><b>宴会产品：</b>${info.product_name}</p>
                                <p><b>奖励政策：</b>${info.strategy_name}</p>
                                <p><b>宴会桌数：</b>${info.table_num}</p>
                                <p><b>宴会时间：</b>${info.use_tm}</p>
                                <p><b>结束时间：</b>${info.end_tm}</p>
                                <p><b>宴会联系人：</b>${info.user_name} ${info.user_phone}</p>
                                <p><b>申请人：</b>${info.applyer_name}</p>
                                <p><b>申请时间：</b>${info.tm}</p>
                                <p><b>审核时间：</b>${info.permit_tm}</p>
                                <p><b>宴会状态：</b><span style="color: ${status_dict[info.status][1]}">${status_dict[info.status][0]}</span></p>
                            </div>
                        `)
                        $("#btns").html(`
                            <a href="/banquet/list/apply_codes/?id=${info.id}" target="_blank" class="btn btn-default btn-sm btn-only-dlg">申请扫码详情</a>
                            <a href="/banquet/list/writeoff/?id=${info.id}" target="_blank" class="btn btn-default btn-sm btn-only-dlg">核销详情</a>
                            <a href="/banquet/list/apply_photos/?id=${info.id}" target="_blank" class="btn btn-default btn-sm btn-only-dlg">查看照片</a>
                        `)
                    }
                }
            })
        }


        $('#btns').on("click", "a", function (event) {
            event.preventDefault();
            $.OpenDlg($(this).attr('href'), '信息弹窗', 1000, 700);
        });
    })

</script>
<style>

</style>
<div class="form-group">
    <div class='col-sm-6'>
        <input id='code' class='datepicker form-control' placeholder="{% trans '请输入标签号码，点击查询按钮或按回车键查询' %}" />
    </div>
    <div class='input-group col-sm-3'>
        <button type="button" class='btn btn-primary btn-qry'>
            <span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans "查询" %}
        </button>
    </div>

    <div class="col-md-12">
        <div id="apply_content" class="col-sm-6" style="margin-top: 20px;">

        </div>
    </div>

    <div id="btns" class="col-sm-6">
    </div>
</div>
{% endblock %}