Geen omschrijving

operatorSystm.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. var token = '';
  2. var isPageFlag = 1;//判断是搜索页面还是首页会员页面 1 首页 2 搜索页面
  3. var searchPage = 1;//搜索分页
  4. var maxPageSearchFlag = false;
  5. var searchFlag = false;
  6. var searchList = [];
  7. var page =1;
  8. var maxPageFlag = false;
  9. var loadingFlag = false;
  10. var userList = [];
  11. var upLevelCount = 0;//当前可升级的人数
  12. var isUpLevel = 0;//是否有升级限制 运营商中心没用升级限制 为-1
  13. $().ready(function () {
  14. getToken();//获取token
  15. $(window).scroll(function(){
  16. if($(window).scrollTop()>= $(document).height()-$(window).height()){
  17. //到达底部加载数据
  18. if(isPageFlag == 1){//首页
  19. if(loadingFlag){
  20. page ++ ;
  21. getAllUserForOperate(token,page)
  22. }
  23. return;
  24. }
  25. if(isPageFlag == 2){
  26. //搜索页面
  27. if(searchFlag) {
  28. searchPage ++ ;
  29. searchEvent()
  30. }
  31. }
  32. }
  33. });
  34. })
  35. //获取token
  36. function getToken () {
  37. var param = '{"js_callback" : "callBackMethodName"}';
  38. try{
  39. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  40. window.webkit.messageHandlers.app_h5_login.postMessage(param);
  41. }
  42. if(navigator.userAgent.match(/android/i)){
  43. obj4H5.app_h5_login(param);
  44. }
  45. }catch(e){
  46. //TODO handle the exception
  47. console.log("兼容")
  48. // getAllUserForOperate('',1);
  49. // token = ''
  50. }
  51. }
  52. function callBackMethodName (data) {//app token 回调
  53. var data = JSON.parse(data)
  54. token = data.token;
  55. getAllUserForOperate(data.token,1);//获取运营商底下所有的会员
  56. }
  57. //获取运营商底下所有的会员
  58. function getAllUserForOperate (token,page){
  59. loadingFlag = false;
  60. if(maxPageFlag){
  61. showMsg("没有更多了")
  62. return;
  63. }
  64. $(".loading").show();
  65. setTimeout(function () {
  66. $(".loading").hide();
  67. },10000)
  68. $.ajax({
  69. type:"post",
  70. url:"/api/v2/adzoneCreate/getAllUserForOperate?time=" + new Date().getTime(),
  71. dataType:'json',
  72. headers:{
  73. token:token,
  74. },
  75. data:{
  76. page:page
  77. },
  78. success:function (res) {
  79. $(".loading").hide()
  80. if(res && res.errno == 0){
  81. var conHtml = '',memberHtml = '',upLevelHtml = '';
  82. upLevelCount = res.rst.up_limit.upUserTotal - res.rst.up_limit.upUserUsed;//当前可升级的人数
  83. isUpLevel = res.rst.up_limit.upUserTotal;//升级总数 运营中心是为-1 升级无限制
  84. if(res.rst.data.length == 0 && res.rst.page == 1){
  85. //暂无数据
  86. conHtml = '<p style = "text-align:center">暂时没有好友需要升级为超级会员</p>'
  87. $(".content").html(conHtml)
  88. return;
  89. }
  90. if(res.rst.data.length > 0) {
  91. if(userList.length != 0){
  92. userList = userList.concat(res.rst.data);
  93. userList.forEach(function (item,index) {
  94. var userSuperior = '';
  95. if(item.up_headimgurl || item.up_name){
  96. userSuperior = '<div class="userSuperior"><span>Ta的上级: </span><img src="'+item.up_headimgurl+'"><span>'+item.up_name+'</span></div>'
  97. }
  98. 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>&ensp;&ensp;<span>'+item.regist_at+'</span></div></div></div><div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级</div></div>'+userSuperior
  99. })
  100. }else{
  101. userList = res.rst.data;
  102. userList.forEach(function (item,index) {
  103. var userSuperior = '';
  104. if(item.up_headimgurl || item.up_name){
  105. userSuperior = '<div class="userSuperior"><span>Ta的上级: </span><img src="'+item.up_headimgurl+'"><span>'+item.up_name+'</span></div>'
  106. }
  107. 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>&ensp;&ensp;<span>'+item.regist_at+'</span></div></div></div><div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级</div></div>'+userSuperior
  108. })
  109. }
  110. // if(isUpLevel != -1){
  111. // upLevelHtml = `<div class="memberTitleItem">
  112. // <p>当前可升级人数${(upLevelCount) <= 0 ? '0' : upLevelCount}人</p>
  113. // </div>`
  114. // }//-1的时候不展示----运营中心
  115. 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>';
  116. $(".content").html(conHtml);
  117. loadingFlag = true;
  118. if(userList.length == res.rst.count){
  119. maxPageFlag = true;//没有更多数据了,禁止调用接口
  120. }
  121. }else{
  122. maxPageFlag = true;//没有更多数据了,禁止调用接口
  123. showMsg('没有更多了')
  124. }
  125. }else if(res.errno == 400){
  126. $("#mask").css('display','block')
  127. }
  128. },
  129. fail: function () {
  130. $(".loading").hide();
  131. showMsg('请求失败,请稍后再试')
  132. }
  133. });
  134. }
  135. //全部升级
  136. function upLevelAllUser () {
  137. if(upLevelCount <= 0 && isUpLevel != -1){
  138. showMsg('您的升级名额已达到上限,请登录PC后台申请更多升级名额!')
  139. return;
  140. }
  141. if($(".loading").css('display') == 'block'){
  142. return;//禁止重复点击
  143. }
  144. $(".loading").show();
  145. setTimeout(function () {
  146. $(".loading").hide();
  147. },10000)
  148. $.ajax({
  149. type:"post",
  150. url:"/api/v2/adzoneCreate/upLevelAllUser",
  151. dataType:'json',
  152. headers:{
  153. token:token
  154. },
  155. success:function (res) {
  156. $(".loading").hide();
  157. if(res && res.errno == 0){
  158. if(res.rst.data[0].flag == 1){
  159. showMsg('升级成功')
  160. }else{
  161. showMsg('升级失败')
  162. }
  163. setTimeout(function () {
  164. init();//页面初始化
  165. },1000)
  166. }else{
  167. showMsg(res.rst.data[0].info)
  168. }
  169. },
  170. fail: function () {
  171. $(".loading").hide();
  172. showMsg('请求失败,请稍后再试')
  173. }
  174. });
  175. }
  176. //单个用户升级
  177. function userUpdateLevel (userId) {
  178. if(upLevelCount <= 0 && isUpLevel != -1){
  179. showMsg('您的升级名额已达到上限,请登录PC后台申请更多升级名额!')
  180. return;
  181. }
  182. $(".loading").show();
  183. setTimeout(function () {
  184. $(".loading").hide();
  185. },10000)
  186. $.ajax({
  187. type:"post",
  188. url:"/api/v2/adzoneCreate/UserUpdateLevel",
  189. dataType:'json',
  190. headers:{
  191. token:token,
  192. },
  193. data:{
  194. userId:userId
  195. },
  196. success:function (res) {
  197. $(".loading").hide();
  198. if(res && res.errno == 0){
  199. if(res.rst.data.flag == 1){
  200. showMsg(res.rst.data.info)
  201. setTimeout(function () {
  202. init();//页面初始化
  203. },1500)
  204. }else{
  205. showMsg(res.rst.data.info)
  206. }
  207. }else{
  208. showMsg(res.rst.data.info)
  209. }
  210. },
  211. fail: function () {
  212. $(".loading").hide();
  213. showMsg('请求失败,请稍后再试')
  214. }
  215. });
  216. }
  217. //搜索接口
  218. function searchEvent () {
  219. searchList = [];
  220. var phone = $("#phone").val();
  221. // var myreg = /^[0-9]{11}$/;
  222. if (phone == '') {
  223. //手机号码未填写及填写不正确
  224. showMsg('请正确输入注册猎豆的手机号')
  225. return;
  226. }
  227. searchFlag = false;
  228. if(maxPageSearchFlag){
  229. showMsg("没有更多了")
  230. return;
  231. }
  232. if($(".loading").css('display') == 'block'){
  233. return;//禁止重复点击
  234. }
  235. $(".loading").show();
  236. setTimeout(function () {
  237. $(".loading").hide();
  238. },10000)
  239. $.ajax({
  240. type:"post",
  241. url:"/api/v2/adzoneCreate/getSearchPhone",
  242. dataType:'json',
  243. headers:{
  244. token:token,
  245. },
  246. data:{
  247. phone:phone,
  248. page:searchPage
  249. },
  250. success:function (res) {
  251. upLevelCount = res.rst.up_limit.upUserTotal - res.rst.up_limit.upUserUsed;//当前可升级的人数
  252. isUpLevel = res.rst.up_limit.upUserTotal;//升级总数 运营中心是为-1 升级无限制
  253. $(".loading").hide()
  254. if(res && res.errno == 0) {
  255. isPageFlag = 2;
  256. var html = '';
  257. if(res.rst.data.length > 0) {
  258. if(searchList.length != 0){
  259. searchList = searchList.concat(res.rst.data);
  260. html = searchHtml(searchList)
  261. }else{
  262. searchList = res.rst.data;
  263. html = searchHtml(searchList)
  264. }
  265. $(".content").html(html);
  266. searchFlag = true;
  267. }else{
  268. maxPageSearchFlag = true;//没有更多数据了,禁止调用接口
  269. showMsg('没有更多了')
  270. }
  271. }else{
  272. showMsg(res.err)
  273. }
  274. // if(level == 1){
  275. // buttonHtml = `<div class="button" onclick="userUpdateLevel(${res.rst.data.user_id})">申请升级为超级会员</div>`
  276. // }else if(level == 2 && res.rst.data.fans_num >= 50 && res.rst.data.three_predict >= 2000){
  277. // buttonHtml = `<div class="button" onclick="userUpdateLevel(${res.rst.data.user_id})">申请升级为运营商</div>`
  278. // }else if(level == 2 && res.rst.data.fans_num < 50 || level == 2 && res.rst.data.three_predict < 2000){
  279. // buttonHtml = `<div class="button" style="background: #cccccc;">申请升级为运营商</div>
  280. // <p style="text-align: center;font-size: 0.14rem;color: #FB552B;">该用户暂不符合升级条件</p>`
  281. // }
  282. // html = `<div class="user" style="border-bottom:1px solid #f4f4f4">
  283. // <div class="left">
  284. // <img src="${res.rst.data.img}" />
  285. // <div class="info">
  286. // <div class="infoName">
  287. // <span>${res.rst.data.name}</span>
  288. // <span>${res.rst.data.level == 1 ? '会员' : (res.rst.data.level == 2 ? '超级会员' : '')}</span>
  289. // </div>
  290. // <div class="infoPhone">
  291. // <span>${res.rst.data.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')}</span>&ensp;&ensp;
  292. // <span>${res.rst.data.regist_at}</span>
  293. // </div>
  294. // </div>
  295. // </div>
  296. // </div>
  297. // <div class="directlyUser">
  298. // <span>直属好友数量</span>
  299. // <span>${res.rst.data.fans_num}</span>
  300. // </div>
  301. // <div class="directlyUser">
  302. // <span>最近连续三个月预估收入</span>
  303. // <span>¥${res.rst.data.three_predict}</span>
  304. // </div>
  305. // </div>${buttonHtml}
  306. // `
  307. },
  308. fail: function () {
  309. $(".loading").hide();
  310. showMsg('请求失败,请稍后再试')
  311. }
  312. });
  313. }
  314. //页面初始化
  315. function init () {
  316. page =1;
  317. searchPage = 1;
  318. isPageFlag = 1;
  319. maxPageFlag = false;
  320. loadingFlag = false;
  321. userList = [];
  322. searchList = [];
  323. isPageFlag = 1;//判断是搜索页面还是首页会员页面 1 首页 2 搜索页面
  324. maxPageSearchFlag = false;
  325. searchFlag = false;
  326. $("#phone").val('')
  327. getAllUserForOperate(token,1);//获取运营商底下所有的会员
  328. }
  329. //提示弹框
  330. function showMsg(msg) {
  331. var msgBox = $('.alert-info');
  332. msgBox.children('p').text(msg);
  333. msgBox.show();
  334. setTimeout(function() {
  335. msgBox.hide();
  336. }, 1500);
  337. }
  338. function searchHtml (searchList) {
  339. var buttonHtml = '',html = '';
  340. // if(isUpLevel != -1){
  341. // html = `<div class="upLevalSearch">
  342. // 当前可升级人数${(upLevelCount) <= 0 ? '0' : upLevelCount}人
  343. // </div>`
  344. // }//-1的时候不展示----运营中心
  345. searchList.forEach(function (item,index) {
  346. var level = item.level;
  347. var userSuperior = '';
  348. if(item.up_headimgurl || item.up_name){
  349. userSuperior = '<div class="userSuperior"><span>Ta的上级: </span><img src="'+item.up_headimgurl+'"><span>'+item.up_name+'</span></div>'
  350. }
  351. if(level == 1){
  352. //升级为超级会员
  353. 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>&ensp;&ensp;<span>'+item.regist_at+'</span></div></div></div><div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级</div></div>'+userSuperior
  354. }else if(level == 2){
  355. //升级为运营商
  356. if(level == 2 && item.fans_num >= 50 && item.three_predict >= 2000){
  357. // buttonHtml = '<div class="upgrade" onclick="userUpdateLevel('+item.user_id+')">升级为运营商</div>'
  358. }else if(level == 2 && item.fans_num < 50 || level == 2 && item.three_predict < 2000){
  359. // buttonHtml = '<div style="color:#878787;border:0.01rem solid #878787;" class="upgrade">升级为运营商</div>'
  360. }
  361. 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>&ensp;<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>'
  362. }
  363. })
  364. return html;
  365. }