会员手机运营商统计

AngularJs 对应controller中写:

$scope.moblie_test=function (telphone) {
        var isChinaMobile = /^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])\d{8}$/;
        var isChinaUnion  = /^(?:13[0-2]|145|15[56]|176|18[56])\d{8}$/;
        var isChinaTelcom = /^(?:133|153|177|18[019])\d{8}$/;
        var isOtherTelphone   = /^170([059])\d{7}$/;

        var telphone = telphone;
        if(telphone.length !== 11){
            return this.setReturnJson(false, '手机号码不正确');
        }
        else{
            if(isChinaMobile.test(telphone)){
                return this.setReturnJson(true, '移动', {name: 'ChinaMobile'});
            }
            else if(isChinaUnion.test(telphone)){
                return this.setReturnJson(true, '联通', {name: 'ChinaUnion'});
            }
            else if(isChinaTelcom.test(telphone)){
                return this.setReturnJson(true, '电信', {name: 'ChinaTelcom'});
            }
            else if(isOtherTelphone.test(telphone)){
                var num = isOtherTelphone.exec(telphone);
                return this.setReturnJson(true, '', {name: ''});
            }
            else{
                return this.setReturnJson(false, '未检测到正确的手机号码');
            }
        }
    };
    $scope.setReturnJson= function(status, name, data){
        if(typeof status !== 'boolean' && typeof status !== 'number'){
            status = false;
        }
        if(typeof name !== 'string'){
            name = '';
        }
        return {
            'status': status,
            'name': name,
            'data': data
        };
    };
    function mobile_change (item){
        $scope.mobile =[];
        $scope.ChinaMobile =[];
        $scope.ChinaUnion =[];
        $scope.ChinaTelcom =[];
        $scope.otherMobile = [];
        angular.forEach(item,function (value,name) {
            var string_name=$scope.moblie_test(name).name;
             // $scope.mobile.push({value:parseInt(value),name:string_name,number:name});
            if(string_name=="移动")
            {
                $scope.ChinaMobile.push({value:parseInt(value),name:string_name,number:name});
            }
            if(string_name=="联通")
            {
                $scope.ChinaUnion.push({value:parseInt(value),name:string_name,number:name});
            }
             if(string_name=="电信")
             {
                 $scope.ChinaTelcom.push({value:parseInt(value),name:string_name,number:name});
             }
              else {
                 if (string_name == "手机号码不正确" || string_name == "未检测到正确的手机号码")
                 {
                     $scope.otherMobile.push({value: parseInt(value), name: string_name, number: name});
                 }
             }
        })

    };
前端写:
   <tr>
                        <th>移动</th>
                        <th>联通</th>
                        <th>电信</th>
                        <tbody>
                        <tr>
                           <td>人数:{{ChinaMobile.length}}</td>
                            <td>人数:{{ChinaUnion.length}}</td>
                            <td>人数:{{ChinaTelcom.length}}</td>
                        </tr>
                        <tr>
                            <td>比重:{{ChinaMobile.length/data.total*100|number:0}}%</td>
                            <td>比重:{{ChinaUnion.length/data.total*100|number:0}}%</td>
                            <td>比重:{{ChinaTelcom.length/data.total*100|number:0}}%</td>
                        </tr>

 

posted @ 2017-05-01 21:50  soyosuyang  阅读(198)  评论(0编辑  收藏  举报