{% if perms.bee_django_user.change_userprofile %}
    <a href="{% url 'bee_django_user:user_update'  user.id %}">修改</a>
{% endif %}
<table class="table">

    <tr>
        <td>头像</td>
        <td>
            {% if user.userprofile.avatar %}
                <img src="{{ user.userprofile.avatar.url }}">
            {% endif %}
        </td>
    </tr>
    <tr>
        <td class="col-xs-3">姓名</td>
        <td>{{ user.first_name }}</td>
    </tr>
    <tr>
        <td class="col-xs-3">统一缦客号</td>
        <td>
            {{ user.userprofile.get_sn }}
            {% if perms.bee_django_user.can_change_user_sn %}
                <a href="{% url 'bee_django_user:user_sn_update' pk=user.userprofile.id %}">修改</a>
            {% endif %}
        </td>
    </tr>
    <tr>
        <td class="col-xs-3">用户名</td>
        <td>{{ user.username }}</td>
    </tr>
    {% if perms.bee_django_user.reset_user_password %}
        <tr>
            <td class="col-xs-3">密码</td>
            <td><a href="{% url 'bee_django_user:user_password_reset' user.id %}">重置密码</a></td>
        </tr>
    {% endif %}
    <tr>
        <td class="col-xs-3">用户组</td>
        <td>{% for group in user.groups.all %}{{ group.name }}{% if not forloop.last %} /
        {% endif %}{% endfor %}
            {% if perms.bee_django_user.can_change_user_group %}
                <a href="{% url 'bee_django_user:user_group_update'  user.id %}">修改</a>
            {% endif %}
        </td>
    </tr>
    <tr>
        <td>班级</td>
        <td>{{ user.userprofile.user_class|default:'' }}
            {% if perms.bee_django_user.add_userclassremoverecord %}
                <a href="{% url 'bee_django_user:user_class_update' user.userprofile.id %}">修改</a>
            {% endif %}
        </td>
    </tr>
    {% if user.userprofile.get_mentor %}
        <tr>
            <td>助教</td>
            <td>{{ user.userprofile.get_mentor.first_name|default:'' }}</td>
        </tr>
    {% endif %}
    {% if user.userprofile.get_lecturer %}
        <tr>
            <td>讲师</td>
            <td>{{ user.userprofile.get_lecturer.first_name|default:'' }}</td>
        </tr>
    {% endif %}
    {% if user.userprofile.get_agent %}
        <tr>
            <td>客服</td>
            <td>{{ user.userprofile.get_agent.first_name|default:'' }}</td>
        </tr>
    {% endif %}

    {% if user.userprofile.is_child %}
        <tr>
            <td>家长助教</td>
            <td>
                {% for parent in  user.userprofile.parents.all %}
                    {{ parent.user.first_name|default:'' }}{% if not forloop.last %}，{% endif %}
                {% endfor %}
                {% if perms.bee_django_user.can_change_user_parent %}
                    <a href="{% url 'bee_django_user:user_parent_update' student_id=user.id %}">修改</a>
                {% endif %}
            </td>
        </tr>
    {% endif %}
    {% if cc %}
        <tr>
            <td>cc直播间id</td>
            <td>{{ user.userprofile.room_id|default:'' }}
                {% if not user.userprofile.room_id and perms.bee_django_user.can_create_user_room %}
                    <button onclick="update_user_room('{{ user.id }}','cc','create')" class="btn btn-default">创建
                    </button>
                {% endif %}
            </td>
        </tr>
    {% endif %}
    {% if gensee %}
        <tr>
            <td>gensee直播间id</td>
            <td>{{ user.userprofile.gensee_room_id|default:'' }}
                {% if not user.userprofile.gensee_room_id and perms.bee_django_user.can_create_user_room %}
                    <button onclick="update_user_room('{{ user.id }}','gensee','create')" class="btn btn-default">创建
                    </button>
                {% endif %}
            </td>
        </tr>
    {% endif %}
    <tr>
        <td>开课日期</td>
        <td>{{ user.userprofile.start_date|default:"" }}</td>
    </tr>
    <tr>
        <td>结课日期</td>
        <td>{{ user.get_expire_date|default:"" }}
            <a href="{% url 'bee_django_user:leave_list' user.id %}">全部记录</a>
            {% if perms.bee_django_user.add_userleaverecord %}
                <a href="{% url 'bee_django_user:leave_add' user.id %}">修改</a>
            {% endif %}
        </td>
    </tr>


</table>

{% block scripts %}
    <script>
        function update_user_room(user_id, provider, t) {
            if (!confirm('确认要创建直播间？')) {
                return false;
            }
            var url = "{% url 'bee_django_user:room_save' %}";
            $.post(url, {"user_id": user_id, "provider": provider, "t": t}).done(function (data) {
                if (provider == 'cc' && data["cc_res"]) {
                    alert("成功");
                    location.reload();
                } else if (provider == 'gensee' && data["gensee_res"]) {
                    alert("成功");
                    location.reload();
                } else {
                    alert("失败");
                }

            });
        }
    </script>
{% endblock %}