//#import $owl_mall_u:services/modelService.jsx
//#import $owl_org_admin_groups:services/modelService.jsx

function main(){
    var params = JSON.parse($body);
    var data = params.data;
    var id = params.id;
    var mobile = data.mobile;
    var admin = owl_mall_uService.getUniqueObj('mobile',mobile);
    if(!admin){
        admin = owl_mall_uService.getUniqueObj('loginId',mobile);
    }
    if(!admin){
        var ret = {
            state:"err",
            msg:"手机号不存在"
        }
        out.print(JSON.stringify(ret));
        return;
    }
    var group = owl_org_admin_groupsService.get(id);
    if(!group){
        var ret = {
            state:"err",
            msg:"管理员组不存在"
        }
        out.print(JSON.stringify(ret));
        return;
    }
    var staff = group.staff;
    if(!staff){
        staff = [];
        group.staff = staff;
    }
    for(var i=0; i<staff.length; i++){
        var member = staff[i];
        if(member.id===admin.id){
            var ret = {
                state:"err",
                msg:"管理员已经存在,请勿重复添加"
            }
            out.print(JSON.stringify(ret));
            return;
        }
    }

    staff.push({
        id:admin.id,
        nickName:admin.nickName,
        realName:admin.realName,
        mobile:admin.mobile,
        loginId:admin.loginId
    });

    owl_org_admin_groupsService.update(group);
    var ret = {
        state:"ok",
        msg:"操作成功,请过几秒后刷新。"
    }
    out.print(JSON.stringify(ret));



}
main();