123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- var token = '';
- var isPageFlag = 1;//判断是搜索页面还是首页会员页面 1 首页 2 搜索页面
- var searchPage = 1;//搜索分页
- var maxPageSearchFlag = false;
- var searchFlag = false;
- var searchList = [];
- var page =1;
- var maxPageFlag = false;
- var loadingFlag = false;
- var userList = [];
- var upLevelCount = 0;//当前可升级的人数
- var isUpLevel = 0;//是否有升级限制 运营商中心没用升级限制 为-1
- $().ready(function () {
- getToken();//获取token
- $(window).scroll(function(){
- if($(window).scrollTop()>= $(document).height()-$(window).height()){
- //到达底部加载数据
- if(isPageFlag == 1){//首页
- if(loadingFlag){
- page ++ ;
- getAllUserForOperate(token,page)
- }
- return;
- }
- if(isPageFlag == 2){
- //搜索页面
- if(searchFlag) {
- searchPage ++ ;
- searchEvent()
- }
- }
-
- }
- });
- })
- //获取token
- function getToken () {
- var param = '{"js_callback" : "callBackMethodName"}';
- try{
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- window.webkit.messageHandlers.app_h5_login.postMessage(param);
- }
- if(navigator.userAgent.match(/android/i)){
- obj4H5.app_h5_login(param);
- }
- }catch(e){
- //TODO handle the exception
- console.log("兼容")
- // getAllUserForOperate('',1);
- // token = ''
- }
-
- }
- function callBackMethodName (data) {//app token 回调
- var data = JSON.parse(data)
- token = data.token;
- getAllUserForOperate(data.token,1);//获取运营商底下所有的会员
- }
- //获取运营商底下所有的会员
- function getAllUserForOperate (token,page){
- loadingFlag = false;
- if(maxPageFlag){
- showMsg("没有更多了")
- return;
- }
- $(".loading").show();
- setTimeout(function () {
- $(".loading").hide();
- },10000)
- $.ajax({
- type:"post",
- url:"/api/v2/adzoneCreate/getAllUserForOperate?time=" + new Date().getTime(),
- dataType:'json',
- headers:{
- token:token,
- },
- data:{
- page:page
- },
- success:function (res) {
- $(".loading").hide()
- if(res && res.errno == 0){
- var conHtml = '',memberHtml = '',upLevelHtml = '';
- upLevelCount = res.rst.up_limit.upUserTotal - res.rst.up_limit.upUserUsed;//当前可升级的人数
- isUpLevel = res.rst.up_limit.upUserTotal;//升级总数 运营中心是为-1 升级无限制
- if(res.rst.data.length == 0 && res.rst.page == 1){
- //暂无数据
- conHtml = '<p style = "text-align:center">暂时没有好友需要升级为超级会员</p>'
- $(".content").html(conHtml)
- return;
- }
- if(res.rst.data.length > 0) {
- if(userList.length != 0){
- userList = userList.concat(res.rst.data);
- userList.forEach(function (item,index) {
- var userSuperior = '';
- if(item.up_headimgurl || item.up_name){
- userSuperior = '<div class="userSuperior"><span>Ta的上级: </span><img src="'+item.up_headimgurl+'"><span>'+item.up_name+'</span></div>'
- }
- memberHtml += '<div class="user memberUser"><div class="left"><img src="'+item.img+'"><div class="info"><div class="infoName"><span>'+item.name+'</span><span>'+(item.level == 1 ? "会员" : "")+'</span></div><div class="infoPhone"><span>'+item.phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2")+'</span>  <span>'+item.regist_at+'</span></div></div></div><div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级</div></div>'+userSuperior
- })
- }else{
- userList = res.rst.data;
- userList.forEach(function (item,index) {
- var userSuperior = '';
- if(item.up_headimgurl || item.up_name){
- userSuperior = '<div class="userSuperior"><span>Ta的上级: </span><img src="'+item.up_headimgurl+'"><span>'+item.up_name+'</span></div>'
- }
- memberHtml += '<div class="user memberUser"><div class="left"><img src='+item.img+'><div class="info"><div class="infoName"><span>'+item.name+'</span><span>'+(item.level == 1 ? "会员" : "")+'</span></div><div class="infoPhone"><span>'+item.phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2")+'</span>  <span>'+item.regist_at+'</span></div></div></div><div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级</div></div>'+userSuperior
- })
- }
- // if(isUpLevel != -1){
- // upLevelHtml = `<div class="memberTitleItem">
- // <p>当前可升级人数${(upLevelCount) <= 0 ? '0' : upLevelCount}人</p>
- // </div>`
- // }//-1的时候不展示----运营中心
-
- conHtml = '<div class="memberTitle"><div class="memberTitleItem"><p>共有'+res.rst.count+'位好友可以升级到超级会员</p><div class = "upLevel" onclick="upLevelAllUser()">全部升级</div></div></div><div class="userList" style="padding-top:0.4rem ;">'+memberHtml+'</div>';
- $(".content").html(conHtml);
- loadingFlag = true;
- if(userList.length == res.rst.count){
- maxPageFlag = true;//没有更多数据了,禁止调用接口
- }
- }else{
- maxPageFlag = true;//没有更多数据了,禁止调用接口
- showMsg('没有更多了')
- }
- }else if(res.errno == 400){
- $("#mask").css('display','block')
- }
- },
- fail: function () {
- $(".loading").hide();
- showMsg('请求失败,请稍后再试')
- }
- });
- }
- //全部升级
- function upLevelAllUser () {
- if(upLevelCount <= 0 && isUpLevel != -1){
- showMsg('您的升级名额已达到上限,请登录PC后台申请更多升级名额!')
- return;
- }
- if($(".loading").css('display') == 'block'){
- return;//禁止重复点击
- }
- $(".loading").show();
- setTimeout(function () {
- $(".loading").hide();
- },10000)
- $.ajax({
- type:"post",
- url:"/api/v2/adzoneCreate/upLevelAllUser",
- dataType:'json',
- headers:{
- token:token
- },
- success:function (res) {
- $(".loading").hide();
- if(res && res.errno == 0){
- if(res.rst.data[0].flag == 1){
- showMsg('升级成功')
- }else{
- showMsg('升级失败')
- }
- setTimeout(function () {
- init();//页面初始化
- },1000)
- }else{
- showMsg(res.rst.data[0].info)
- }
- },
- fail: function () {
- $(".loading").hide();
- showMsg('请求失败,请稍后再试')
- }
- });
- }
- //单个用户升级
- function userUpdateLevel (userId) {
- if(upLevelCount <= 0 && isUpLevel != -1){
- showMsg('您的升级名额已达到上限,请登录PC后台申请更多升级名额!')
- return;
- }
- $(".loading").show();
- setTimeout(function () {
- $(".loading").hide();
- },10000)
- $.ajax({
- type:"post",
- url:"/api/v2/adzoneCreate/UserUpdateLevel",
- dataType:'json',
- headers:{
- token:token,
- },
- data:{
- userId:userId
- },
- success:function (res) {
- $(".loading").hide();
- if(res && res.errno == 0){
- if(res.rst.data.flag == 1){
- showMsg(res.rst.data.info)
- setTimeout(function () {
- init();//页面初始化
- },1500)
- }else{
- showMsg(res.rst.data.info)
- }
- }else{
- showMsg(res.rst.data.info)
- }
- },
- fail: function () {
- $(".loading").hide();
- showMsg('请求失败,请稍后再试')
- }
- });
- }
- //搜索接口
- function searchEvent () {
- searchList = [];
- var phone = $("#phone").val();
- // var myreg = /^[0-9]{11}$/;
- if (phone == '') {
- //手机号码未填写及填写不正确
- showMsg('请正确输入注册猎豆的手机号')
- return;
- }
- searchFlag = false;
- if(maxPageSearchFlag){
- showMsg("没有更多了")
- return;
- }
- if($(".loading").css('display') == 'block'){
- return;//禁止重复点击
- }
- $(".loading").show();
- setTimeout(function () {
- $(".loading").hide();
- },10000)
- $.ajax({
- type:"post",
- url:"/api/v2/adzoneCreate/getSearchPhone",
- dataType:'json',
- headers:{
- token:token,
- },
- data:{
- phone:phone,
- page:searchPage
- },
- success:function (res) {
- upLevelCount = res.rst.up_limit.upUserTotal - res.rst.up_limit.upUserUsed;//当前可升级的人数
- isUpLevel = res.rst.up_limit.upUserTotal;//升级总数 运营中心是为-1 升级无限制
- $(".loading").hide()
- if(res && res.errno == 0) {
- isPageFlag = 2;
- var html = '';
- if(res.rst.data.length > 0) {
- if(searchList.length != 0){
- searchList = searchList.concat(res.rst.data);
- html = searchHtml(searchList)
- }else{
- searchList = res.rst.data;
- html = searchHtml(searchList)
- }
- $(".content").html(html);
- searchFlag = true;
- }else{
- maxPageSearchFlag = true;//没有更多数据了,禁止调用接口
- showMsg('没有更多了')
- }
- }else{
- showMsg(res.err)
- }
-
- // if(level == 1){
- // buttonHtml = `<div class="button" onclick="userUpdateLevel(${res.rst.data.user_id})">申请升级为超级会员</div>`
- // }else if(level == 2 && res.rst.data.fans_num >= 50 && res.rst.data.three_predict >= 2000){
- // buttonHtml = `<div class="button" onclick="userUpdateLevel(${res.rst.data.user_id})">申请升级为运营商</div>`
- // }else if(level == 2 && res.rst.data.fans_num < 50 || level == 2 && res.rst.data.three_predict < 2000){
- // buttonHtml = `<div class="button" style="background: #cccccc;">申请升级为运营商</div>
- // <p style="text-align: center;font-size: 0.14rem;color: #FB552B;">该用户暂不符合升级条件</p>`
- // }
- // html = `<div class="user" style="border-bottom:1px solid #f4f4f4">
- // <div class="left">
- // <img src="${res.rst.data.img}" />
- // <div class="info">
- // <div class="infoName">
- // <span>${res.rst.data.name}</span>
- // <span>${res.rst.data.level == 1 ? '会员' : (res.rst.data.level == 2 ? '超级会员' : '')}</span>
- // </div>
- // <div class="infoPhone">
- // <span>${res.rst.data.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')}</span>  
- // <span>${res.rst.data.regist_at}</span>
- // </div>
- // </div>
- // </div>
- // </div>
- // <div class="directlyUser">
- // <span>直属好友数量</span>
- // <span>${res.rst.data.fans_num}</span>
- // </div>
- // <div class="directlyUser">
- // <span>最近连续三个月预估收入</span>
- // <span>¥${res.rst.data.three_predict}</span>
- // </div>
- // </div>${buttonHtml}
- // `
-
- },
- fail: function () {
- $(".loading").hide();
- showMsg('请求失败,请稍后再试')
- }
- });
- }
- //页面初始化
- function init () {
- page =1;
- searchPage = 1;
- isPageFlag = 1;
- maxPageFlag = false;
- loadingFlag = false;
- userList = [];
- searchList = [];
- isPageFlag = 1;//判断是搜索页面还是首页会员页面 1 首页 2 搜索页面
- maxPageSearchFlag = false;
- searchFlag = false;
- $("#phone").val('')
- getAllUserForOperate(token,1);//获取运营商底下所有的会员
- }
- //提示弹框
- function showMsg(msg) {
- var msgBox = $('.alert-info');
- msgBox.children('p').text(msg);
- msgBox.show();
- setTimeout(function() {
- msgBox.hide();
- }, 1500);
- }
- function searchHtml (searchList) {
- var buttonHtml = '',html = '';
- // if(isUpLevel != -1){
- // html = `<div class="upLevalSearch">
- // 当前可升级人数${(upLevelCount) <= 0 ? '0' : upLevelCount}人
- // </div>`
- // }//-1的时候不展示----运营中心
- searchList.forEach(function (item,index) {
- var level = item.level;
- var userSuperior = '';
- if(item.up_headimgurl || item.up_name){
- userSuperior = '<div class="userSuperior"><span>Ta的上级: </span><img src="'+item.up_headimgurl+'"><span>'+item.up_name+'</span></div>'
- }
- if(level == 1){
- //升级为超级会员
- html += '<div class="user memberUser"><div class="left"><img src="'+item.img+'"><div class="info"><div class="infoName"><span>'+item.name+'</span><span>'+(item.level == 1 ? "会员" : "超级会员")+'</span></div><div class="infoPhone"><span>'+item.phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2")+'</span>  <span>'+item.regist_at+'</span></div></div></div><div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级</div></div>'+userSuperior
- }else if(level == 2){
- //升级为运营商
- if(level == 2 && item.fans_num >= 50 && item.three_predict >= 2000){
- // buttonHtml = '<div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级为运营商</div>'
- }else if(level == 2 && item.fans_num < 50 || level == 2 && item.three_predict < 2000){
- // buttonHtml = '<div style="color:#878787;border:0.01rem solid #878787;" class="upgrade">升级为运营商</div>'
- }
- html += '<div class="user" style="border-bottom:none"><div class="left"><img src="'+item.img+'"><div class="info"><div class="infoName"><span>'+item.name+'</span><span>'+(item.level == 1 ? "会员" : "超级会员")+'</span></div><div class="infoPhone"><span>'+item.phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2")+'</span> <span>'+item.regist_at+'</span></div></div></div>'+buttonHtml+'</div>'+userSuperior+'<div class="directlyUser"><span>直属好友数量</span><span>'+item.fans_num+'</span></div><div class="directlyUser" style="border-bottom: 0.01rem solid #f4f4f4"><span>最近连续三个月预估收入</span><span>¥'+item.three_predict+'</span></div>'
- }
- })
- return html;
- }
|