{% 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:source_add' %}">添加来源</a>
    </div>
    <div>共{{ paginator.count }}个来源，其中海报类型为{{ poster_source|length }}个，用户海报显示{{ show_poster_count }}张</div>
    <table class="table">
        <thead>
        <tr>
            <th></th>
            <th>渠道名</th>
            <th>显示名称</th>
            <th>是否为海报类型</th>
            <th>添加时间</th>

        </tr>
        </thead>
        <tbody>
        {% for source in source_list %}
            <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ source.name }}</td>
                <td>{{ source.reg_name|default:"" }}</td>
                <td>{{ source.get_is_poster }} {% if source.is_poster %}（共{{ source.poster_set.all|length }}张图片，显示
                    {{ source.get_show_posters|length }}张）{% endif %}</td>
                <td>{{ source.created_at|local_datetime|date:"Y-m-d H:i:s" }}</td>
                <td>
                    <a href="{% url 'bee_django_crm:source_detail' source.id %}  ">详情</a>
                    <a href="{% url 'bee_django_crm:source_update' source.id %}  ">修改</a>
{#                    <a href="#" id="delete_{{ source.id }}"#}
{#                       data-confirm="{% url "bee_django_crm:source_delete" source.id %}"#}
{#                       onclick="click_del(this)">删除</a>#}
                </td>
            </tr>

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