group_manager.js 44.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
//创建群菜单点击事件

function createGroupMenuClick() {
    //重置表单
    $('#cg_form')[0].reset();

    var sessList = document.getElementsByClassName("sesslist-group")[0];
    var num = 1;
    if (sessList && sessList.childNodes) {
        num = sessList.childNodes.length + 1;
    }
    $("#cg_name").val('群' + num);

    $('#create_group_dialog').modal('show');
}
//搜索群(按ID)菜单单击事件

function searchGroupMenuClick() {

    $("#sg_form")[0].reset();
    initSearchGroupTable([]);
    $('#search_group_table').bootstrapTable('load', []);
    $('#search_group_dialog').modal('show');
}
//搜索群(按名称)菜单单击事件

function searchGroupByNameMenuClick() {

    $("#sgbn_form")[0].reset();
    initSearchGroupByNameTable([]);
    $('#search_group_by_name_table').bootstrapTable('load', []);
    $('#search_group_by_name_dialog').modal('show');
}
//定义搜索群(按ID)结果表格每行的操作按钮

function sgOperateFormatter(value, row, index) {
    return [
        '<a class="plus" href="javascript:void(0)" title="申请加入">',
        '<i class="glyphicon glyphicon-plus"></i>',
        '</a>'

    ].join('');
}
//搜索群(按ID)结果表格按钮事件
window.sgOperateEvents = {
    'click .plus': function(e, value, row, index) {

        $("#ajg_group_id").val(row.GId);
        $("#ajg_group_type").val(row.Type);
        $("#ajg_group_name").val(row.Name);

        if (row.Type == 'ChatRoom') { //聊天室直接申请加入
            applyJoinGroup();
        } else {
            $("#ajg_apply_msg").val('你好,我想加入贵群~');
            $('#apply_join_group_dialog').modal('show');
        }
    }
};
//初始化搜索群(按ID)结果表格

function initSearchGroupTable(data) {
    $('#search_group_table').bootstrapTable({
        method: 'get',
        cache: false,
        height: 500,
        striped: true,
        pagination: true,
        pageSize: pageSize,
        pageNumber: 1,
        pageList: [10, 20, 50, 100],
        search: true,
        showColumns: true,
        clickToSelect: true,
        columns: [{
            field: "GroupId",
            title: "ID",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "TypeZh",
            title: "类型",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "Type",
            title: "类型(英文)",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "Name",
            title: "名称",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "Owner_Account",
            title: "群主",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "CreateTime",
            title: "创建时间",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "MemberNum",
            title: "群成员数",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "sgOperate",
            title: "操作",
            align: "center",
            valign: "middle",
            formatter: "sgOperateFormatter",
            events: "sgOperateEvents"
        }],
        data: data,
        formatNoMatches: function() {
            return '无符合条件的记录';
        }
    });
}


//定义搜索群(按名称)结果表格每行的操作按钮

function sgbnOperateFormatter(value, row, index) {
    return [
        '<a class="plus" href="javascript:void(0)" title="申请加入">',
        '<i class="glyphicon glyphicon-plus"></i>',
        '</a>'

    ].join('');
}
//搜索群(按名称)结果表格按钮事件
window.sgbnOperateEvents = {
    'click .plus': function(e, value, row, index) {

        $("#ajg_group_id").val(row.GId);
        $("#ajg_group_type").val(row.Type);
        $("#ajg_group_name").val(row.Name);

        if (row.Type == 'ChatRoom') { //聊天室直接申请加入
            applyJoinGroup();
        } else {
            $("#ajg_apply_msg").val('你好,我想加入贵群~');
            $('#apply_join_group_dialog').modal('show');
        }
    }
};
//初始化搜索群(按名称)结果表格

function initSearchGroupByNameTable(data) {
    $('#search_group_by_name_table').bootstrapTable({
        method: 'get',
        cache: false,
        height: 500,
        striped: true,
        pagination: true,
        pageSize: pageSize,
        pageNumber: 1,
        pageList: [10, 20, 50, 100],
        search: true,
        showColumns: true,
        clickToSelect: true,
        columns: [{
            field: "GroupId",
            title: "ID",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "TypeZh",
            title: "类型",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "Type",
            title: "类型(英文)",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "Name",
            title: "名称",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "FaceUrl",
            title: "群头像",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "Owner_Account",
            title: "群主",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "CreateTime",
            title: "创建时间",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "MemberNum",
            title: "群成员数",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "sgbnOperate",
            title: "操作",
            align: "center",
            valign: "middle",
            formatter: "sgbnOperateFormatter",
            events: "sgbnOperateEvents"
        }],
        data: data,
        formatNoMatches: function() {
            return '无符合条件的记录';
        }
    });
}


//定义我的群组表格每行的操作按钮

function gmgOperateFormatter(value, row, index) {
    return [
        '<a class="plus ml10" href="javascript:void(0)" title="邀请成员">',
        '<i class="glyphicon glyphicon-plus"></i>',
        '</a>',
        '<a class="user ml10" href="javascript:void(0)" title="查看群成员">',
        '<i class="glyphicon glyphicon-user"></i>',
        '</a>',
        '<a class="bell ml10" href="javascript:void(0)" title="设置群消息提示">',
        '<i class="glyphicon glyphicon-bell"></i>',
        '</a>',
        '<a class="logout ml10" href="javascript:void(0)" title="退出该群">',
        '<i class="glyphicon glyphicon-log-out"></i>',
        '</a>',
        '<a class="pencil ml10" href="javascript:void(0)" title="修改群资料">',
        '<i class="glyphicon glyphicon-pencil"></i>',
        '</a>',
        '<a class="share ml10" href="javascript:void(0)" title="转让该群">',
        '<i class="glyphicon glyphicon-share"></i>',
        '</a>',
        '<a class="trash ml10" href="javascript:void(0)" title="解散该群">',
        '<i class="glyphicon glyphicon-trash"></i>',
        '</a>',
        '<a class="envelope ml10" href="javascript:void(0)" title="发消息">',
        '<i class="glyphicon glyphicon-envelope"></i>',
        '</a>'

    ].join('');
}
//我的群组表格每行的操作按钮点击事件
window.gmgOperateEvents = {
    'click .plus': function(e, value, row, index) {
        // if (row.TypeEn != 'Private') {
        //    alert('公开群或聊天室不支持直接拉人操作');
        //     return;
        // }
        $('#gmfg_group_id').val(row.GId);
        getMyFriendGroup();
    },
    'click .user': function(e, value, row, index) {
        $('#ggm_group_id').val(row.GId);
        $('#ggm_my_role').val(row.Role);
        $('#ggm_group_type').val(row.TypeEn);

        getGroupMemberInfo(row.GId);
    },
    'click .bell': function(e, value, row, index) {
        $('#mgmf_sel_row_index').val(index);
        $('#mgmf_group_id').val(row.GId);
        //设置群消息提示类型
        //var msg_flag = webim.Tool.groupRoleCh2En(row.Role);
        var msg_flag = row.MsgFlagEn;
        //$("input[type=radio][name='mgmf_msg_flag_radio'][value=" + msg_flag + "]").attr("checked", 'checked');//此方法存在问题,当修改单选按钮值,并且关闭对话框,再打开对话时,无法选中真正的值
        var mgmf_msg_flag_radio = document.mgmf_form.mgmf_msg_flag_radio;
        for (var i = 0; i < mgmf_msg_flag_radio.length; i++) {
            if (mgmf_msg_flag_radio[i].value == msg_flag) {
                mgmf_msg_flag_radio[i].checked = true;
                break;
            }
        }
        $('#modify_group_msg_flag_dialog').modal('show');

    },
    'click .logout': function(e, value, row, index) {
        if (row.Role == '群主' && row.TypeEn != 'Private') {
            alert('您是群主,不能从公开群或聊天室退出');
            return;
        }
        if (confirm("确定退出该群吗?")) {
            quitGroup(row.GId);
        }
    },
    'click .pencil': function(e, value, row, index) {

        //成员可以修改私有群的基本资料
        if (row.Role == '成员' && row.Type != 'Private') {
            alert('你不是群主或管理员,无法进行此操作');
            return;
        }
        $('#mg_sel_row_index').val(index);
        $('#mg_group_id').val(row.GId);
        $('#mg_faceurl').val(row.FaceUrl);
        $('#mg_name').val(webim.Tool.formatHtml2Text(row.Name));
        $('#mg_introduction').val(webim.Tool.formatHtml2Text(row.Introduction));
        $('#mg_notification').val(webim.Tool.formatHtml2Text(row.Notification));
        $('#modify_group_dialog').modal('show');
        var shut_up_all = document.mg_form.mgm_up_all_radio;
        for (var i = 0; i < shut_up_all.length; i++) {
            if (shut_up_all[i].value == row.ShutUpAllMember) {
                shut_up_all[i].checked = true;
                break;
            }
        }
        //  $('#shut_up_all_member').val(row.ShutUpAllMember);
    },
    'click .share': function(e, value, row, index) {
        if (row.Role != '群主') {
            alert('你不是群主,无法进行此操作');
        } else {
            if (row.TypeEn == 'AVChatRoom') {
                alert('直播聊天室不能进行转让');
                return;
            }
            $("#cgo_form")[0].reset(); //清空原来表单的值
            $('#cgo_sel_row_index').val(index);
            $('#cgo_group_id').val(row.GId);
            $('#change_group_owner_dialog').modal('show');
        }
    },
    'click .trash': function(e, value, row, index) {
        if (row.Role != '群主') {
            alert('你不是群主,无法进行此操作');
        } else {
            if (row.TypeEn == 'Private') {
                alert('您是群主,不能解散私有群');
                return;
            }
            if (confirm("确定解散该群组吗?")) {
                destroyGroup(row.GId);
            }
        }
    },
    'click .envelope': function(e, value, row, index) {
        $('#sgm_to_groupid').val(row.GId);
        $('#sgm_to_group_name').val(row.Name);

        $('#send_group_msg_dialog').modal('show');
    }
};
//初始化我的群组表格

function initGetMyGroupTable(data) {
    $('#get_my_group_table').bootstrapTable({
        method: 'get',
        cache: false,
        height: 500,
        striped: true,
        pagination: true,
        pageSize: pageSize,
        pageNumber: 1,
        pageList: [10, 20, 50, 100],
        search: true,
        showColumns: true,
        clickToSelect: true,
        columns: [{
            field: "GroupId",
            title: "ID",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "Type",
            title: "类型",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "TypeEn",
            title: "类型(英文)",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "FaceUrl",
            title: "群头像",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "Name",
            title: "名称",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "RoleEn",
            title: "角色(英文)",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "Role",
            title: "角色",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "MsgFlagEn",
            title: "消息提示类型(英文)",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "MsgFlag",
            title: "消息提示类型",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "JoinTime",
            title: "加入时间",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "MemberNum",
            title: "成员数",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "Notification",
            title: "公告",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "Introduction",
            title: "简介",
            align: "center",
            valign: "middle",
            sortable: "true",
            visible: false
        }, {
            field: "ShutUpAllMember",
            title: "全局禁言",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "gmgOperate",
            title: "操作",
            align: "center",
            valign: "middle",
            formatter: "gmgOperateFormatter",
            events: "gmgOperateEvents"
        }],
        data: data,
        formatNoMatches: function() {
            return '无符合条件的记录';
        }
    });
}
//定义邀请好友加群表格每行的操作按钮

function gmfgOperateFormatter(value, row, index) {
    return [
        '<a class="plus" href="javascript:void(0)" title="邀请加入">',
        '<i class="glyphicon glyphicon-plus"></i>',
        '</a>'

    ].join('');
}
//邀请好友加群表格每行按钮单击事件
window.gmfgOperateEvents = {
    'click .plus': function(e, value, row, index) {
        $('#agm_group_id').val($('#gmfg_group_id').val());
        $('#agm_account').val(row.Info_Account);
        $('#add_group_member_dialog').modal('show');
    }
};
//初始化邀请好友加群表格

function initGetMyFriendGroupTable(data) {
    $('#get_my_friend_group_table').bootstrapTable({
        method: 'get',
        cache: false,
        height: 500,
        striped: true,
        pagination: true,
        pageSize: pageSize,
        pageNumber: 1,
        pageList: [10, 20, 50, 100],
        search: true,
        showColumns: true,
        clickToSelect: true,
        columns: [{
            field: "Info_Account",
            title: "账号",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "Nick",
            title: "昵称",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "gmfgOperate",
            title: "操作",
            align: "center",
            valign: "middle",
            formatter: "gmfgOperateFormatter",
            events: "gmfgOperateEvents"
        }],
        data: data,
        formatNoMatches: function() {
            return '无符合条件的记录';
        }
    });
}

//读取群组公开资料-高级接口(可用于搜索群,按ID)
var getGroupPublicInfo = function() {
    if ($("#sg_group_id").val().length == 0) {
        alert('请输入群组ID');
        return;
    }
    if (webim.Tool.trimStr($("#sg_group_id").val()).length == 0) {
        alert('您输入的群组ID全是空格,请重新输入');
        return;
    }
    var options = {
        'GroupIdList': [
            $("#sg_group_id").val()
        ],
        'GroupBasePublicInfoFilter': [
            'Type',
            'Name',
            'Introduction',
            'Notification',
            'FaceUrl',
            'CreateTime',
            'Owner_Account',
            'LastInfoTime',
            'LastMsgTime',
            'NextMsgSeq',
            'MemberNum',
            'MaxMemberNum',
            'ApplyJoinOption'
        ]
    };
    webim.getGroupPublicInfo(
        options,
        function(resp) {
            var data = [];
            if (resp.GroupInfo && resp.GroupInfo.length > 0) {
                for (var i in resp.GroupInfo) {
                    if (resp.GroupInfo[i].ErrorCode > 0) {
                        alert(resp.GroupInfo[i].ErrorInfo);
                        return;
                    }
                    var group_id = resp.GroupInfo[i].GroupId;
                    var name = webim.Tool.formatText2Html(resp.GroupInfo[i].Name);
                    var type_zh = webim.Tool.groupTypeEn2Ch(resp.GroupInfo[i].Type);
                    var type = resp.GroupInfo[i].Type;
                    var owner_account = resp.GroupInfo[i].Owner_Account;
                    var create_time = webim.Tool.formatTimeStamp(resp.GroupInfo[i].CreateTime);
                    var member_num = resp.GroupInfo[i].MemberNum;
                    var notification = webim.Tool.formatText2Html(resp.GroupInfo[i].Notification);
                    var introduction = webim.Tool.formatText2Html(resp.GroupInfo[i].Introduction);
                    data.push({
                        'GId': group_id,
                        'GroupId': webim.Tool.formatText2Html(group_id),
                        'Name': name,
                        'TypeZh': type_zh,
                        'Type': type,
                        'Owner_Account': owner_account,
                        'MemberNum': member_num,
                        'Notification': notification,
                        'Introduction': introduction,
                        'CreateTime': create_time
                    });
                }
            }
            $('#search_group_table').bootstrapTable('load', data);
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};

//搜索群(按名称)
var searchGroupByName = function() {
    if ($("#sgbn_group_name").val().length == 0) {
        alert('请输入群名称');
        return;
    }
    if (webim.Tool.trimStr($("#sgbn_group_name").val()).length == 0) {
        alert('您输入的群名称都是空格,请重新输入');
        return;
    }
    var options = {
        'Content': $("#sgbn_group_name").val(), //群名称
        "PageNum": 0, //0表示从第1页开始拉取
        "GroupPerPage": 20, //每页拉取20条
        'ResponseFilter': {
            "GroupBasePublicInfoFilter": [ //基础信息过滤器,可以通过它设置需要拉取的公开的基础信息
                'Type', //群组类型
                'Name', //群名称
                "FaceUrl", //群头像
                "Introduction", //群简介
                'CreateTime', //群创建时间
                'Owner_Account', //群创建者
                'MemberNum', //成员个数
                'MaxMemberNum', //群成员最大个数
                'ApplyJoinOption' //申请加群选项
            ]
        }
    };
    webim.searchGroupByName(
        options,
        function(resp) {
            var data = [];
            if (resp.GroupInfo && resp.GroupInfo.length > 0) {
                for (var i in resp.GroupInfo) {
                    if (resp.GroupInfo[i].ErrorCode > 0) {
                        alert(resp.GroupInfo[i].ErrorInfo);
                        return;
                    }
                    var group_id = resp.GroupInfo[i].GroupId;
                    var name = webim.Tool.formatText2Html(resp.GroupInfo[i].Name);
                    var type_zh = webim.Tool.groupTypeEn2Ch(resp.GroupInfo[i].Type);
                    var type = resp.GroupInfo[i].Type;
                    var owner_account = resp.GroupInfo[i].Owner_Account;
                    var create_time = webim.Tool.formatTimeStamp(resp.GroupInfo[i].CreateTime);
                    var member_num = resp.GroupInfo[i].MemberNum;
                    var faceUrl = resp.GroupInfo[i].FaceUrl;
                    var introduction = webim.Tool.formatText2Html(resp.GroupInfo[i].Introduction);
                    //var maxMemberNum = resp.GroupInfo[i].MaxMemberNum;
                    //var applyJoinOption = resp.GroupInfo[i].ApplyJoinOption;
                    data.push({
                        'GId': group_id,
                        'GroupId': webim.Tool.formatText2Html(group_id),
                        'Name': name,
                        'TypeZh': type_zh,
                        'Type': type,
                        'Owner_Account': owner_account,
                        'MemberNum': member_num,
                        'FaceUrl': faceUrl,
                        'Introduction': introduction,
                        'CreateTime': create_time
                    });
                }
            }
            $('#search_group_by_name_table').bootstrapTable('load', data);
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};

//创建群组
var createGroup = function() {
    var sel_friends = $('#select_friends').val();

    var member_list = [];
    var members = sel_friends.split(";"); //字符分割
    for (var i = 0; i < members.length; i++) {
        if (members[i] && members[i].length > 0) {
            member_list.push(members[i]);
        }
    }
    var faceurl = $("#cg_faceurl").val();
    var cg_id = $("#cg_id").val().trim();
    if (cg_id && !/^[A-Za-z0-9_]+$/gi.test(cg_id)) {
        alert('群组ID只能是数字、字母或下划线');
        return
    }
    if ($("#cg_name").val().length == 0) {
        alert('请输入群组名称');
        return;
    }
    if ($("#cg_name").val().length == 0) {
        alert('请输入群组名称');
        return;
    }
    if (webim.Tool.trimStr($("#cg_name").val()).length == 0) {
        alert('您输入的群组名称全是空格,请重新输入');
        return;
    }
    if (webim.Tool.getStrBytes($("#cg_name").val()) > 30) {
        alert('您输入的群组名称超出限制(最长10个汉字)');
        return;
    }
    if (webim.Tool.getStrBytes($("#cg_notification").val()) > 150) {
        alert('您输入的群组公告超出限制(最长50个汉字)');
        return;
    }
    if (webim.Tool.getStrBytes($("#cg_introduction").val()) > 120) {
        alert('您输入的群组简介超出限制(最长40个汉字)');
        return;
    }
    var groupType = $('input[name="cg_type_radio"]:checked').val();
    var options = {
        'GroupId': cg_id,
        'Owner_Account': loginInfo.identifier,
        'Type': groupType, //Private/Public/ChatRoom/AVChatRoom
        'Name': $("#cg_name").val(),
        'Notification': $("#cg_notification").val(),
        'Introduction': $('#cg_introduction').val(),
        'MemberList': member_list
    };
    if (faceurl) {
        options.FaceUrl = faceurl;
    }
    if (groupType != 'Private') { //非私有群才支持ApplyJoinOption属性
        options.ApplyJoinOption = $('input[name="cg_ajp_type_radio"]:checked').val();
    }
    webim.createGroup(
        options,
        function(resp) {
            $('#create_group_dialog').modal('hide');
            alert('创建群成功');
            //读取我的群组列表
            //getJoinedGroupListHigh(getGroupsCallbackOK);
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};
//修改群资料
var modifyGroup = function() {
    var faceurl = $("#mg_faceurl").val();
    if ($("#mg_name").val().length == 0) {
        alert('请输入群组名称');
        return;
    }
    if (webim.Tool.trimStr($("#mg_name").val()).length == 0) {
        alert('您输入的群组名称全是空格,请重新输入');
        return;
    }
    if (webim.Tool.getStrBytes($("#fsm_name").val()) > 30) {
        alert('您输入的群组名称超出限制(最长10个汉字)');
        return;
    }
    if (webim.Tool.getStrBytes($("#fsm_notification").val()) > 150) {
        alert('您输入的群组公告超出限制(最长50个汉字)');
        return;
    }
    if (webim.Tool.getStrBytes($("#fsm_introduction").val()) > 120) {
        alert('您输入的群组简介超出限制(最长40个汉字)');
        return;
    }
    var up_all = $('input[name="mgm_up_all_radio"]:checked').val();
    var options = {
        'GroupId': $('#mg_group_id').val(),
        'Name': $('#mg_name').val(),
        'Notification': $('#mg_notification').val(),
        'Introduction': $('#mg_introduction').val(),
        'ShutUpAllMember': up_all
    };
    if (faceurl) {
        options.FaceUrl = faceurl;
    }
    webim.modifyGroupBaseInfo(
        options,
        function(resp) {
            //在表格中修改对应的行
            $('#get_my_group_table').bootstrapTable('updateRow', {
                index: $('#mg_sel_row_index').val(),
                row: {
                    Type: $('input[name="mg_type_radio"]:checked').val(),
                    Name: webim.Tool.formatText2Html($('#mg_name').val()),
                    Introduction: webim.Tool.formatText2Html($('#mg_introduction').val()),
                    Notification: webim.Tool.formatText2Html($('#mg_notification').val())
                }
            });
            $('#modify_group_dialog').modal('hide');
            alert('修改群资料成功');
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};

//转让群组
var changeGroupOwner = function() {
    var newOwer = $("#cgo_new_owner").val();
    if (newOwer.length == 0) {
        alert('请输入新的群主账号');
        return;
    }
    if (webim.Tool.trimStr(newOwer).length == 0) {
        alert('您输入的新群主账号全是空格,请重新输入');
        return;
    }
    if (newOwer == loginInfo.identifier) {
        alert('不能给自己转让群组');
        return;
    }

    var options = {
        'GroupId': $('#cgo_group_id').val(),
        'NewOwner_Account': newOwer
    };
    webim.changeGroupOwner(
        options,
        function(resp) {
            //在表格中修改对应的行
            $('#get_my_group_table').bootstrapTable('updateRow', {
                index: $('#cgo_sel_row_index').val(),
                row: {
                    RoleEn: "Member",
                    Role: "成员"
                }
            });
            $('#change_group_owner_dialog').modal('hide');
            alert('转让群组成功');
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};

//申请加群
var applyJoinGroup = function() {
    if (webim.Tool.getStrBytes($("#ajg_apply_msg").val()) > 300) {
        alert('您输入的附言超出限制(最长100个汉字)');
        return;
    }
    var options = {
        'GroupId': $("#ajg_group_id").val(),
        'ApplyMsg': $("#ajg_apply_msg").val(),
        'UserDefinedField': ''
    };
    webim.applyJoinGroup(
        options,
        function(resp) {
            $('#apply_join_group_dialog').modal('hide');
            var joinedStatus = resp.JoinedStatus; //JoinedSuccess--成功加入,WaitAdminApproval--等待管理员审核
            if (joinedStatus == "JoinedSuccess") {
                //刷新我的群组列表
                //getJoinedGroupListHigh(getGroupsCallbackOK);
                alert('成功加入该群');
            } else {
                alert('申请成功,请等待群主审核');
            }
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};
//获取我的群组
var getMyGroup = function() {
    initGetMyGroupTable([]);
    var options = {
        'Member_Account': loginInfo.identifier,
        'Limit': totalCount,
        'Offset': 0,
        //'GroupType':'',
        'GroupBaseInfoFilter': [
            'Type',
            'Name',
            'Introduction',
            'Notification',
            'FaceUrl',
            'CreateTime',
            'Owner_Account',
            'LastInfoTime',
            'LastMsgTime',
            'NextMsgSeq',
            'MemberNum',
            'MaxMemberNum',
            'ApplyJoinOption',
            'ShutUpAllMember'
        ],
        'SelfInfoFilter': [
            'Role',
            'JoinTime',
            'MsgFlag',
            'UnreadMsgNum'
        ]
    };
    webim.getJoinedGroupListHigh(
        options,
        function(resp) {
            if (!resp.GroupIdList || resp.GroupIdList.length == 0) {
                alert('你目前还没有加入任何群组');
                return;
            }
            var data = [];
            for (var i = 0; i < resp.GroupIdList.length; i++) {

                var group_id = resp.GroupIdList[i].GroupId;
                var name = webim.Tool.formatText2Html(resp.GroupIdList[i].Name);
                var faceUrl = resp.GroupIdList[i].FaceUrl;
                var type_en = resp.GroupIdList[i].Type;
                var type = webim.Tool.groupTypeEn2Ch(resp.GroupIdList[i].Type);
                var role_en = resp.GroupIdList[i].SelfInfo.Role;
                var role = webim.Tool.groupRoleEn2Ch(resp.GroupIdList[i].SelfInfo.Role);
                var msg_flag = webim.Tool.groupMsgFlagEn2Ch(resp.GroupIdList[i].SelfInfo.MsgFlag);
                var msg_flag_en = resp.GroupIdList[i].SelfInfo.MsgFlag;
                var join_time = webim.Tool.formatTimeStamp(resp.GroupIdList[i].SelfInfo.JoinTime);
                var member_num = resp.GroupIdList[i].MemberNum;
                var notification = webim.Tool.formatText2Html(resp.GroupIdList[i].Notification);
                var introduction = webim.Tool.formatText2Html(resp.GroupIdList[i].Introduction);
                var ShutUpAllMember = resp.GroupIdList[i].ShutUpAllMember; //== 'On' ? resp.GroupIdList[i].ShutUpAllMember = '开启' : resp.GroupIdList[i].ShutUpAllMember = '关闭';
                data.push({
                    'GId': group_id,
                    'GroupId': webim.Tool.formatText2Html(group_id),
                    'Name': name,
                    'FaceUrl': faceUrl,
                    'TypeEn': type_en,
                    'Type': type,
                    'RoleEn': role_en,
                    'Role': role,
                    'MsgFlagEn': msg_flag_en,
                    'MsgFlag': msg_flag,
                    'MemberNum': member_num,
                    'Notification': notification,
                    'Introduction': introduction,
                    'JoinTime': join_time,
                    'ShutUpAllMember': ShutUpAllMember
                });
            }
            //打开我的群组列表对话框
            $('#get_my_group_table').bootstrapTable('load', data);
            $('#get_my_group_dialog').modal('show');
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};
//退群
var quitGroup = function(group_id) {
    var options = null;
    if (group_id) {
        options = {
            'GroupId': group_id
        };
    }
    if (options == null) {
        alert('退群时,群组ID非法');
        return;
    }
    webim.quitGroup(
        options,
        function(resp) {
            //在表格中删除对应的行
            $('#get_my_group_table').bootstrapTable('remove', {
                field: 'GroupId',
                values: [group_id]
            });
            //刷新我的群组列表
            //getJoinedGroupListHigh(getGroupsCallbackOK);
            deleteSessDiv(webim.SESSION_TYPE.GROUP, group_id); //在最近的联系人列表删除可能存在的群会话
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};
//读取群组基本资料-高级接口
var getGroupInfo = function(group_id, cbOK, cbErr) {
    var options = {
        'GroupIdList': [
            group_id
        ],
        'GroupBaseInfoFilter': [
            'Type',
            'Name',
            'Introduction',
            'Notification',
            'FaceUrl',
            'CreateTime',
            'Owner_Account',
            'LastInfoTime',
            'LastMsgTime',
            'NextMsgSeq',
            'MemberNum',
            'MaxMemberNum',
            'ApplyJoinOption',
            'ShutUpAllMember'
        ],
        'MemberInfoFilter': [
            'Account',
            'Role',
            'JoinTime',
            'LastSendMsgTime',
            'ShutUpUntil'
        ]
    };
    webim.getGroupInfo(
        options,
        function(resp) {
            if (resp.GroupInfo[0].ShutUpAllMember == 'On') {
                alert('该群组已开启全局禁言');
            }
            if (cbOK) {
                cbOK(resp);
            }
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};

//解散群组
var destroyGroup = function(group_id) {
    var options = null;
    if (group_id) {
        options = {
            'GroupId': group_id
        };
    }
    if (options == null) {
        alert('解散群时,群组ID非法');
        return;
    }
    webim.destroyGroup(
        options,
        function(resp) {
            //在表格中删除对应的行
            $('#get_my_group_table').bootstrapTable('remove', {
                field: 'GroupId',
                values: [group_id]
            });
            //读取我的群组列表
            //getJoinedGroupListHigh(getGroupsCallbackOK);
            deleteSessDiv(webim.SESSION_TYPE.GROUP, group_id); //在最近的联系人列表删除可能存在的群会话
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};

//获取我的好友,然后邀请加群
var getMyFriendGroup = function() {

    initGetMyFriendGroupTable([]);
    var options = {
        'From_Account': loginInfo.identifier,
        'TimeStamp': 0,
        'StartIndex': 0,
        'GetCount': totalCount,
        'LastStandardSequence': 0,
        "TagList": [
            "Tag_Profile_IM_Nick",
            "Tag_SNS_IM_Remark"
        ]
    };

    webim.getAllFriend(
        options,
        function(resp) {

            if (resp.FriendNum > 0) {
                var table_friends_data = [];
                var friends = resp.InfoItem;
                if (!friends || friends.length == 0) {
                    alert('你目前还没有好友,无法邀请好友加入该群');
                    return;
                }
                var count = friends.length;

                for (var i = 0; i < count; i++) {
                    var friend_name = friends[i].Info_Account;
                    if (friends[i].SnsProfileItem && friends[i].SnsProfileItem[0] && friends[i].SnsProfileItem[0].Tag) {
                        friend_name = friends[i].SnsProfileItem[0].Value;
                    }

                    table_friends_data.push({
                        'Info_Account': webim.Tool.formatText2Html(friends[i].Info_Account),
                        'Nick': webim.Tool.formatText2Html(friend_name)
                    });
                }
                //打开我的好友列表对话框
                $('#get_my_friend_group_table').bootstrapTable('load', table_friends_data);
                $('#get_my_friend_group_dialog').modal('show');

            } else {
                alert('你目前还没有好友,无法邀请好友加入该群');
            }

        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};


//选择我的好友
var selectMyFriendGroup = function() {

    initSelectMyFriendGroupTable([]);
    var options = {
        'From_Account': loginInfo.identifier,
        'TimeStamp': 0,
        'StartIndex': 0,
        'GetCount': totalCount,
        'LastStandardSequence': 0,
        "TagList": [
            "Tag_Profile_IM_Nick",
            "Tag_SNS_IM_Remark"
        ]
    };

    webim.getAllFriend(
        options,
        function(resp) {

            if (resp.FriendNum > 0) {
                var table_friends_data = [];
                var friends = resp.InfoItem;
                if (!friends || friends.length == 0) {
                    alert('你目前还没有好友,无法建群');
                    return;
                }
                var count = friends.length;

                for (var i = 0; i < count; i++) {
                    var friend_name = friends[i].Info_Account;
                    if (friends[i].SnsProfileItem && friends[i].SnsProfileItem[0] && friends[i].SnsProfileItem[0].Tag) {
                        friend_name = friends[i].SnsProfileItem[0].Value;
                    }

                    table_friends_data.push({
                        'Info_Account': webim.Tool.formatText2Html(friends[i].Info_Account),
                        'Nick': webim.Tool.formatText2Html(friend_name)
                    });
                }
                //打开选择我的好友列表对话框
                $('#select_my_friend_group_table').bootstrapTable('load', table_friends_data);
                $('#select_my_friend_group_dialog').modal('show');

            } else {
                alert('你目前还没有好友,无法建群');
            }

        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};

//定义(创建群之前)选择好友表格每行按钮

function smfgOperateFormatter(value, row, index) {
    return [
        '<a class="plus" href="javascript:void(0)" title="选中">',
        '<i class="glyphicon glyphicon-plus"></i>',
        '</a>',
        '<a class="minus" href="javascript:void(0)" title="取消">',
        '<i class="glyphicon glyphicon-minus"></i>',
        '</a>',
    ].join('');
}
//(创建群之前)选择好友表格每行按钮单击事件
window.smfgOperateEvents = {
    'click .plus': function(e, value, row, index) {

        var sel_friends = $('#select_friends').val();
        var account = row.Info_Account;
        //先判断是否已选择
        if (sel_friends && sel_friends != '') {
            var pos = sel_friends.indexOf(";" + account + ";");
            if (pos >= 0) {
                alert('已选择该好友,请选择其他好友');
                return;
            }
        } else {
            sel_friends = ';';
        }
        sel_friends += row.Info_Account + ";";
        $('#select_friends').val(sel_friends);
        alert('选择成功');

    },
    'click .minus': function(e, value, row, index) {
        var sel_friends = $('#select_friends').val();
        var account = row.Info_Account;
        //先判断是否已选择
        if (!sel_friends || sel_friends == '') {

            alert('还未选择好友,不能进行此操作');
            return;


        } else {
            var pos = sel_friends.indexOf(";" + account + ";");
            var strlen = (account + ";").length;
            if (pos >= 0) {
                var begin = sel_friends.substr(0, pos);
                var end = sel_friends.substr(pos + strlen);
                var new_sel_friends = begin + end;
            } else {
                alert('未选择该好友,不能进行此操作');
                return;
            }

        }
        if (new_sel_friends == ';') {
            new_sel_friends = '';
        }
        $('#select_friends').val(new_sel_friends);
        alert('取消成功');
    }
};
//初始化(创建群之前)选择好友表格

function initSelectMyFriendGroupTable(data) {
    $('#select_my_friend_group_table').bootstrapTable({
        method: 'get',
        cache: false,
        height: 500,
        striped: true,
        pagination: true,
        pageSize: pageSize,
        pageNumber: 1,
        pageList: [10, 20, 50, 100],
        search: true,
        showColumns: true,
        clickToSelect: true,
        columns: [{
            field: "Info_Account",
            title: "账号",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "Nick",
            title: "昵称",
            align: "center",
            valign: "middle",
            sortable: "true"
        }, {
            field: "smfgOperate",
            title: "操作",
            align: "center",
            valign: "middle",
            formatter: "smfgOperateFormatter",
            events: "smfgOperateEvents"
        }],
        data: data,
        formatNoMatches: function() {
            return '无符合条件的记录';
        }
    });
}

//从我的群组列表中发群消息

function sendGroupMsg() {

    toAccount = $("#sgm_to_groupid").val();
    toName = $("#sgm_to_group_name").val();
    msgtosend = $("#sgm_content").val();

    var msgLen = webim.Tool.getStrBytes(msgtosend);

    var maxLen, errInfo;

    maxLen = webim.MSG_MAX_LENGTH.GROUP;
    errInfo = "消息长度超出限制(最多" + Math.round(maxLen / 3) + "汉字)";

    if (msgtosend.length < 1) {
        alert("发送的消息不能为空!");
        return;
    }

    if (msgLen > maxLen) {
        alert(errInfo);
        return;
    }

    var sess = webim.MsgStore.sessByTypeId(webim.SESSION_TYPE.GROUP, toAccount);
    if (!sess) {
        sess = new webim.Session(webim.SESSION_TYPE.GROUP, toAccount, toName, groupHeadUrl, Math.round(new Date().getTime() / 1000));
    }
    var isSend = true; //是否为自己发送
    var seq = -1; //消息序列,-1表示sdk自动生成,用于去重
    var random = Math.round(Math.random() * 4294967296); //消息随机数,用于去重
    var msgTime = Math.round(new Date().getTime() / 1000); //消息时间戳
    var subType; //消息子类型

    subType = webim.GROUP_MSG_SUB_TYPE.COMMON;

    var msg = new webim.Msg(sess, isSend, seq, random, msgTime, loginInfo.identifier, subType, loginInfo.identifierNick);

    var text_obj;

    text_obj = new webim.Msg.Elem.Text(msgtosend);
    msg.addText(text_obj);

    webim.sendMsg(msg, function(resp) {

        if (!selToID) { //没有聊天会话
            selType = webim.SESSION_TYPE.GROUP;
            selToID = toAccount;
            selSess = sess;
            addSess(selType, toAccount, toName, groupHeadUrl, 0, 'sesslist');
            setSelSessStyleOn(toAccount);
            //群聊时,长轮询接口会返回自己发的消息
            //addMsg(msg);
        } else { //有聊天会话
            if (selToID == toAccount) { //聊天对象不变
                //不做任何操作
            } else { //聊天对象发生改变
                var tempSessDiv = document.getElementById("sessDiv_" + toAccount);
                if (!tempSessDiv) { //不存在这个会话
                    addSess(webim.SESSION_TYPE.GROUP, toAccount, toName, groupHeadUrl, 0, 'sesslist'); //增加一个会话
                }
                onSelSess(webim.SESSION_TYPE.GROUP, toAccount); //再进行切换
            }
        }
        webim.Tool.setCookie("tmpmsg_" + toAccount, '', 0);
        $("#sgm_content").val('');
        $('#send_group_msg_dialog').modal('hide');
        $('#get_my_group_dialog').modal('hide');

    }, function(err) {
        alert(err.ErrorInfo);
        $("#sgm_content").val('');
    });
}

//将我的群组资料(群名称和群头像)保存在infoMap
var initInfoMapByMyGroups = function(cbOK) {

    var options = {
        'Member_Account': loginInfo.identifier,
        'Limit': totalCount,
        'Offset': 0,
        'GroupBaseInfoFilter': [
            'Name',
            'FaceUrl'
        ]
    };
    webim.getJoinedGroupListHigh(
        options,
        function(resp) {
            if (resp.GroupIdList && resp.GroupIdList.length) {
                for (var i = 0; i < resp.GroupIdList.length; i++) {
                    var group_name = resp.GroupIdList[i].Name;
                    var group_image = resp.GroupIdList[i].FaceUrl;
                    var key = webim.SESSION_TYPE.GROUP + "_" + resp.GroupIdList[i].GroupId;
                    infoMap[key] = {
                        'name': group_name,
                        'image': group_image
                    }
                }
            }
            if (cbOK) {
                cbOK();
            }
        },
        function(err) {
            alert(err.ErrorInfo);
        }
    );
};