{% extends "bee_django_crm/base.html" %}
{% load bee_django_crm_filter %}

{% block content %}
    {% include 'bee_django_crm/logo.html' %}
    {% include 'bee_django_crm/nav.html' %}
    <div class="text-center"><h3>
        缴费明细
    </h3>
    </div>
    <div class="text-right">
        <a class="btn btn-default" href="{% url 'bee_django_crm:preuser_contract_add' preuser_id %}">添加缴费</a>
    </div>
    <div>共{{ paginator.count }}条</div>
    <table class="table">
        <thead>
        <tr>
            <th></th>
            <th>合同名称</th>
            <th>缴费时间</th>
            <th>实际缴费金额</th>
            <th></th>
            <th></th>

        </tr>
        </thead>
        <tbody>
        {% for user_contract in preuser_contract_list %}
            <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ user_contract.contract.name }}</td>
                <td>{{ user_contract.paid_at|local_datetime|date:"Y-m-d" }}</td>
                <td>{{ user_contract.price }}</td>
                <td><a href="{% url 'bee_django_crm:preuser_contract_detail' user_contract.id %}">详情</a></td>
                <td>
                    {% if not user_contract.is_checked %}
                        <a href="{% url 'bee_django_crm:preuser_contract_update' user_contract.id %}">修改</a>
                        <a href="#"
                           data-confirm="{% url "bee_django_crm:preuser_contract_delete" user_contract.id %}"
                           onclick="click_del(this)">删除</a>
                        <a href="#" id="check_{{ user_contract.id }}"
                           data-confirm="{% url "bee_django_crm:preuser_contract_update_check" user_contract.id %}"
                           onclick="click_check(this)">审核</a>
                    {% else %}已审核
                    {% endif %}

                </td>
            </tr>

        {% endfor %}
        </tbody>
    </table>
    {% include 'bee_django_crm/paginator.html' %}
{% endblock %}
{% block scripts %}
    <script>
        function click_check(_this) {
            if (!confirm('确认要执行这个操作？')) {
                return false;
            }
            var url = $(_this).attr('data-confirm');
            $.post(url).done(function (data) {
                alert('审核成功!');

                location.href = data.url;
            });
        }
    </script>
{% endblock %}