<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>群管理</title>
    <!-- 引入 WeUI -->
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css"/>
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.0/css/jquery-weui.css"/>
    <style type="text/css">
        body, html {
            height: 100%;
            background-color: #f4f4f4;
            -webkit-tap-highlight-color: transparent;
        }

        .margin_top_30px {
            margin-top: 30px;
        }

        .basic-color {
            background-color: #1E88E5;
            color: #FFFFFF;
        }

        footer {
            text-align: center;
            font-size: 14px;
            padding: 20px;
        }

        .weui-loadmore_line .weui-loadmore__tips {
            background-color: #f4f4f4;
        }

        footer a {
            color: #999;
            text-decoration: none;
        }

    </style>
</head>

<body ontouchstart="">
<div class="bd margin_top_30px">
    <div class="page__bd">
        <div class="weui-cells__title"></div>
        <div class="weui-cells">
            <a class="weui-cell weui-cell_access update-group-info-html" th:attr="group-id=${group_id}"
               url-data="/group/profile" href="javascript:;">
                <div class="weui-cell__bd">
                    <p>修改群信息</p>
                </div>
                <div class="weui-cell__ft">
                </div>
            </a>
            <a class="weui-cell weui-cell_access group-add-member" th:attr="group-id=${group_id}"
               url-data="/group/siteUser" href="javascript:;">
                <div class="weui-cell__bd">
                    <p>添加群成员</p>
                </div>
                <div class="weui-cell__ft">
                </div>
            </a>
            <a class="weui-cell weui-cell_access manage-group-member-html" url-data="/group/toMemberList"
               th:attr="group-id=${group_id}" href="javascript:;">
                <div class="weui-cell__bd">
                    <p>群成员管理</p>
                </div>
                <div class="weui-cell__ft">
                </div>
            </a>

            <div class="weui-cell weui-cell_access"></div>
            <div class="weui-btn-area">
                <a class="weui-btn basic-weui-btn basic-color weui-btn_warn group_default"
                   url-data="/group/setUserDefaultGroup" href="javascript:" id="group_default"
                   th:if="${defaultState}==0" th:attr="defaultState=${defaultState},group-id=${group_id}">设为默认添加群</a>

                <a class="weui-btn basic-weui-btn basic-color weui-btn_warn group_default"
                   url-data="/group/deleteUserDefaultGroup" href="javascript:" id="group_default"
                   th:if="${defaultState}==1" th:attr="defaultState=${defaultState},group-id=${group_id}">取消默认添加群</a>

                <a href="javascript:;" url-data="/group/dissmiss"
                   class="weui-btn basic-weui-btn weui-btn_warn disband-group"
                   th:attr="group-id=${group_id}">解散群</a>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/libs/weuijs/1.1.3/weui.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery-weui/1.2.0/js/jquery-weui.js"></script>
<script type="text/javascript">
    function getOsType() {
        var u = navigator.userAgent;
        if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 || u.indexOf('Windows Phone') > -1) {
            return 'Android';
        } else if (u.indexOf('iPhone') > -1) {
            return 'IOS';
        } else {
            return 'PC';
        }
    }

    function reqUrl(reqUri, params, callbackName) {
        reqUri = "/akaxin" + reqUri;
        var type = getOsType();
        if (type == 'Android') {
            Android.requestPost(reqUri, params, callbackName);
        } else if (type == 'IOS') {
            ios_requestPost(reqUri, params, callbackName);
        } else {
            $.toast('暂时不支持该设备');
        }
    }

    function reqHtml(reqUri, params) {
        reqUri = "/akaxin" + reqUri;
        var type = getOsType();
        if (type == 'Android') {
            Android.requestPage(reqUri, params)
        } else if (type == 'IOS') {
            ios_requestPage(reqUri, params);
        } else {
            $.toast('暂时不支持该设备');
        }
    }

    function reqImageUpload(callback) {
        var type = getOsType();
        if (type == 'Android') {
            Android.imageUpload(callback);
        } else if (type == 'IOS') {
            ios_imageUpload(callback);
        } else {
            $.toast('暂时不支持该设备');
        }
    }

    function reqImageDownload(imageid, callback) {
        var type = getOsType();
        if (type == 'Android') {
            Android.imageDownload(imageid, callback);
        } else if (type == 'IOS') {
            ios_imageDownload(imageid, callback);
        } else {
            $.toast('暂时不支持该设备');
        }
    }

    function toast(msg) {
        var type = getOsType();
        if (type == 'Android') {
            Android.showToast(msg);
        } else if (type == 'IOS') {
            $.toast(msg);
        } else {
            $.toast('暂时不支持该设备');
        }
    }

    $(document).on("click", ".update-group-info-html", function () {
        var groupId = $(this).attr('group-id');
        var reqUri = $(this).attr('url-data');
        var params = {
            "group_id": groupId,
        };
        reqHtml(reqUri, JSON.stringify(params));
    });


    $(document).on("click", ".manage-group-member-html", function () {
        var groupId = $(this).attr('group-id');
        var reqUri = $(this).attr('url-data');
        var params = {
            "group_id": groupId
        };
        reqHtml(reqUri, JSON.stringify(params));

    });

    $(document).on("click", ".disband-group", function () {
        var groupId = $(this).attr('group-id');
        var reqUri = $(this).attr('url-data');
        $.confirm({
            title: '解散群',
            text: '确定要解散该群？',
            onOK: function () {
                var params = {
                    "group_id": groupId,
                };
                reqUrl(reqUri, JSON.stringify(params), "disbandGroup");
                $.closeModal();
            },
            onCancel: function () {
                console.log('cancle');
                toast('取消操作');
                $.closeModal();
            }
        });
    });

    $(document).on("click", ".group-add-member", function () {
        var groupId = $(this).attr('group-id');
        var reqUri = $(this).attr('url-data');
        var params = {
            "group_id": groupId,
        };
        reqHtml(reqUri, JSON.stringify(params));
    });

    function disbandGroup(result) {
        if (result == 'success') {
            $.toast("解散群成功");
        } else {
            $.toast("解散群失败", "forbidden");
        }
    }

    $(document).on("click", ".group_default", function () {
        var groupId = $(this).attr('group-id');
        var reqUri = $(this).attr('url-data');
        var params = {
            "group_id": groupId,
        };
        reqUrl(reqUri, JSON.stringify(params), 'groupDefault');
    });

    function groupDefault(results) {
        if (results == 'success') {
            $.toast("操作成功");
            var attr = $('.group_default').attr('defaultState');
            if (attr == '0') {
                $('.group_default').attr('defaultState', '1');
                $('.group_default').attr('url-data', '/group/deleteUserDefaultGroup');
                $('.group_default').html('取消默认添加群');
            } else {
                $('.group_default').attr('defaultState', '0');
                $('.group_default').attr('url-data', '/group/setUserDefaultGroup');
                $('.group_default').html('设为默认添加群');
            }
        } else {
            $.toast("操作失败", "forbidden");
        }
    }
</script>
</body>

</html>