my_personal.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. $(function() {
  2. var needToLogin = urlParse('need_to_login')
  3. if (needToLogin == 1) {
  4. HuoUtils.switchTemplate('login')
  5. }
  6. window.redirectUrl = decodeURIComponent(urlParse('redirect_url'))
  7. //弹窗
  8. var $login_icon = $('.login_icon');
  9. var $register = $('.register');
  10. var $toLogin = $('.toLogin');
  11. var $toAccountRegister = $('.toAccountRegister')
  12. var $toPhoneRegister = $('.toPhoneRegister')
  13. var $gameLogin = $('.gameLogin')
  14. var $accountRegister = $('.accountRegister')
  15. $login_icon.on('click', function(){
  16. initPop();
  17. $register.show()
  18. });
  19. $toLogin.on('click', function(){
  20. initPop();
  21. $gameLogin.show()
  22. })
  23. $toPhoneRegister.on('click', function(){
  24. initPop()
  25. $register.show()
  26. })
  27. $toAccountRegister.on('click', function(){
  28. initPop()
  29. $accountRegister.show()
  30. })
  31. var $forgetPassword = $('.forgetPassword')
  32. var $findPassword1 = $('.findPassword1')
  33. var $findPassword2 = $('.findPassword2')
  34. var $nextFindPassword = $('.nextFindPassword')
  35. $forgetPassword.on('click', function(){
  36. initPop()
  37. $findPassword1.show()
  38. })
  39. $nextFindPassword.on('click',function(){
  40. initPop()
  41. $findPassword2.show()
  42. })
  43. //初始化弹窗
  44. function initPop(){
  45. $accountRegister.hide()
  46. $gameLogin.hide()
  47. $register.hide()
  48. $findPassword1.hide()
  49. $findPassword2.hide()
  50. }
  51. // 积分tab切换
  52. $('.jifenjilu_tab__p').click(function () {
  53. $(this).addClass('tabSelect').siblings().removeClass('tabSelect')
  54. $('.jiluList').eq($(this).index()).removeClass('hidden').siblings('.jiluList').addClass('hidden')
  55. huoScrollMore()
  56. })
  57. // 首页新开服,开服提醒tab切换
  58. $('.xinfuTab_item__list').on('click', function () {
  59. $(this).addClass('activitySelected').siblings().removeClass('activitySelected')
  60. $('.runCoolKid').eq($(this).index()).show().siblings('.runCoolKid').hide()
  61. huoScrollMore()
  62. })
  63. // 首页:热门,新上架,活动,新开服Tab切换
  64. $('.hotTabBox_item').on('click', function () {
  65. $('.shadowScroll').scrollTop(0)
  66. $(this).addClass('tabBox_selected').siblings().removeClass('tabBox_selected')
  67. $('.game_content').eq($(this).index()).show().siblings('.game_content').hide()
  68. localStorage.setItem('tabIndex', $(this).index())
  69. huoScrollMore()
  70. })
  71. // 首页-活动:活动,有奖,公告Tab切换
  72. $('.activityTab_item__list').on('click', function () {
  73. // $(this).addClass('activitySelected').siblings().removeClass('activitySelected')
  74. $('.noMore2').hide()
  75. $('.activity_content').eq($(this).index()).show().siblings('.activity_content').hide()
  76. huoScrollMore()
  77. })
  78. // 礼包
  79. $(document).on('click', '.getMore', function(e){
  80. var $target = $(e.currentTarget).parent().find('.giftList_others')
  81. var high = $target.find('li').length * 96;
  82. if($target.css("height") == high + "px"){
  83. $target.animate({"height": "0px"})
  84. }else{
  85. $target.animate({"height": high + "px"})
  86. }
  87. var $sq = $(e.currentTarget).find('.shouqi')
  88. if ($sq.text() === '收起') {
  89. $sq.text('查看更多礼包')
  90. $(this).find('img').attr({src : $('#staticSite').val() + "/h5wap/images/icon_denglu_xialaanniu.png"})
  91. } else {
  92. $sq.text('收起')
  93. $(this).find('img').attr({src : $('#staticSite').val() + "/h5wap/images/icon_xiangshang.png"})
  94. }
  95. })
  96. // 礼包查看
  97. $(document).on('click', '[giftcode]', function () {
  98. var code = $(this).attr('giftcode')
  99. $('.getSucess_p2__code').html(code)
  100. $('.getSucess').show().css('z-index', 2001)
  101. })
  102. // 复制
  103. $(document).on('click', '.getSucessBox_p4:not(.noCopy)', function () {
  104. //复制礼包码
  105. var $text = $('.getSucess_p2__code').html()
  106. var input = document.createElement('input')
  107. input.setAttribute('readonly', 'readonly');
  108. input.setAttribute('value', $text );
  109. document.body.appendChild(input)
  110. input.select()
  111. input.setSelectionRange(0, 9999)
  112. if (document.execCommand('copy')) {
  113. document.execCommand('copy')
  114. }
  115. document.body.removeChild(input)
  116. $('.fuzhiSucess').css({'display': 'block', 'z-index': 2001}).html('复制成功')
  117. $('.getSucess').hide()
  118. setTimeout(function(){
  119. $(".fuzhiSucess").hide()
  120. },1000)
  121. })
  122. //积分商城:虚拟产品与实物产品tab切换
  123. var $product_real = $(".product_real")
  124. var $product_virtual = $(".product_virtual")
  125. var $realProductList = $(".realProductList")
  126. var $virtualProductList =$(".virtualProductList")
  127. function initProduct(){
  128. $product_real.removeClass("product_selected")
  129. $product_virtual.removeClass("product_selected")
  130. $realProductList.hide()
  131. $virtualProductList.hide()
  132. }
  133. $product_real.on('click', function(e){
  134. initProduct()
  135. $(e.currentTarget).addClass("product_selected")
  136. $realProductList.show()
  137. })
  138. $product_virtual.on('click', function(e){
  139. initProduct()
  140. $(e.currentTarget).addClass("product_selected")
  141. $virtualProductList.show()
  142. })
  143. //游戏详情页
  144. $('.detailsContainer_content').scroll( function() {
  145. var scrollLength = $('.detailsContainer_content').scrollTop()
  146. if (scrollLength >= 17) {
  147. $('.detailsContainer .overScroll').css({"padding-top":"0"})
  148. } else if (scrollLength === 0) {
  149. $('.detailsContainer .overScroll').css({"padding-top":"16px"})
  150. }
  151. });
  152. // 绑定游戏详情悬浮窗关闭事件
  153. $(document).on('click', '.gameShare_close', function () {
  154. $('.detailsContainer').animate({'height': '0px'}, 500)
  155. $('.shadow').animate({'height': '100%'}, 500, function(){
  156. $('#gameDetail').hide().html('').removeAttr('open')
  157. })
  158. })
  159. $(document).on('click', '.ui-checked', function () {
  160. $(this).attr('select', +$(this).attr('select') == '1' ? '2' : '1')
  161. })
  162. $(document).on('click', '[stopPropagation]', function (e) {
  163. e.stopPropagation()
  164. })
  165. // 积分商城签到
  166. var $jifenqiandao = $('.jifenqiandao')
  167. var $jifenqiandao_btn = $('.jifenqiandao_btn')
  168. $jifenqiandao_btn.on('click', function () {
  169. $jifenqiandao.hide()
  170. location.reload()
  171. })
  172. //轮播图
  173. //轮播图样式随窗口变化而变化
  174. var $width
  175. function change(){
  176. $width = $(window).width()
  177. if($width<750){
  178. $(".banner").css({"width": $width+"px","margin":"0","padding":"0","overflow":"hidden","position":"relative"})
  179. $(".bannerBox").css({"width": $('.bannerBox_list').length*$width+"px","margin":"0","padding":"0","overflow":"hidden","position":"relative"})
  180. $(".bannerBox_list").css({"width": $width+"px"})
  181. }else{
  182. var width = parseInt($('.wrap').css("width"))
  183. $(".banner").css({"width": width+"px","margin":"0","padding":"0","overflow":"hidden","position":"relative"})
  184. $(".bannerBox").css({"width": $('.bannerBox_list').length*width+"px","margin":"0","padding":"0","overflow":"hidden","position":"relative"})
  185. $(".bannerBox_list").css({"width": width+"px","margin":"0","padding":"0"})
  186. }
  187. }
  188. function banner(time){
  189. if($width<750){
  190. var distance = $width
  191. }else{
  192. var distance = parseInt($('.wrap').css("width"))
  193. }
  194. num++
  195. if(num >= $('.bannerBox_list').length){
  196. num=0;
  197. }
  198. $(".bannerBox").css({"transform":"translate(-"+ distance*num +"px,0)","transition-duration": time ||"200ms"})
  199. }
  200. var num = 0;
  201. var timer
  202. if ($('.bannerBox_list').length > 1) {
  203. timer = setInterval(banner, 3000)
  204. }
  205. change();
  206. $(window).resize(function() {
  207. change();
  208. banner("0ms")
  209. });
  210. /**
  211. * 首页吸顶
  212. */
  213. var homeTop = $('.homeContent').offset() && $('.homeContent').offset().top
  214. var hotTop = $('.hotTab').offset() && $('.hotTab').offset().top
  215. $('#homeCeil').scroll(function () {
  216. if ($(this).scrollTop() >= hotTop - homeTop) {
  217. $('.hotTab').addClass('hotTab__ceil')
  218. $(this).css('padding-top', 44)
  219. } else {
  220. $('.hotTab').removeClass('hotTab__ceil')
  221. $(this).css('padding-top', 0)
  222. }
  223. })
  224. $('.banner img').load(function () {
  225. // hotTop = $('.hotTab').offset().top
  226. })
  227. //修改昵称
  228. if($('.personalAccount_detail').length > 0){
  229. var $xiugai = $('.personalAccount_detail').find('.xiugai')
  230. $('.personalAccount').on('click',function(e){
  231. if($(e.target).hasClass('xiugai')){
  232. var $niCheng = $('.niCheng').html()
  233. $('.personalAccount_detail__p1').replaceWith("<p class='personalAccount_detail__p1'><input type='text' class='newNiCheng' value=" + $niCheng + "/><button class='newNiChengBtn'>修改</button></p>")
  234. $('.newNiChengBtn').on('click',function(){
  235. var $newNiCheng = $('.newNiCheng').val()
  236. $('.personalAccount_detail__p1').replaceWith("<p class='personalAccount_detail__p1'><span class='niCheng'>" + $newNiCheng +"</span><img class='xiugai' src='../images/mine_xiugaimingcheng.png' /></p>")
  237. })
  238. }
  239. })
  240. }
  241. /**
  242. * 返回列表
  243. * 可指定返回的 url
  244. */
  245. $(document).on('click', '[returntolist]', function () {
  246. var url = $(this).attr('returntolist')
  247. if (url) {
  248. window.location.href = url
  249. } else {
  250. location.replace(document.referrer)
  251. }
  252. })
  253. $('.returnBtn').click(function(){
  254. location.replace('/wap/user/index')
  255. })
  256. /**
  257. * 积分商城虚拟产品和实物产品分类
  258. */
  259. $('.sort_container').on('click', 'a', function () {
  260. $(this).addClass('active').siblings().removeClass('active')
  261. var $parent = $(this).parents('.sort').siblings('.productList')
  262. var type = $(this).attr('type')
  263. if (type) {
  264. type = type.toUpperCase()
  265. if (type === 'ALL') {
  266. $('.productList_item', $parent).show()
  267. } else {
  268. $('.productList_item', $parent).each(function (i, item) {
  269. var _type = $(this).attr('type').toUpperCase()
  270. if (type.indexOf(_type) > -1) {
  271. $(this).show()
  272. } else {
  273. $(this).hide()
  274. }
  275. })
  276. }
  277. }
  278. })
  279. /**
  280. * 地址级联
  281. */
  282. $('.address_select').change(function () {
  283. addressList($(this).val(), $(this).attr('level'))
  284. })
  285. /**
  286. * 弹出游戏详情框
  287. */
  288. $(document).on('click', '[gameid]', function () {
  289. if ($('#gameDetail').attr('open')) return false
  290. $('#gameDetail').attr('open', true)
  291. fetchGameDetail($(this).attr('gameid'))
  292. })
  293. /**
  294. * 跳转到礼包详情页
  295. */
  296. $(document).on('click', '[giftid]', function (e) {
  297. if (!$(e.target).hasClass('lingqu') && !$(e.target).hasClass('jiaqun')) {
  298. window.location.href = '/wap/gift/detail?gift_id=' + $(this).attr('giftid')
  299. }
  300. })
  301. /**
  302. * 跳转到资讯详情页
  303. */
  304. $(document).on('click', '[newsid]', function () {
  305. window.location.href = '/wap/news/detail?news_id=' + $(this).attr('newsid')
  306. })
  307. /**
  308. * 跳转到抽奖
  309. */
  310. $(document).on('click', '[awardid]', function (e) {
  311. var _this = $(this)
  312. $.get('/wap/news/list', {type: 5,format: 'json'}, function (res) {
  313. if (res.code === 200) {
  314. if(res.data.list[_this.index()].url == ''){
  315. window.location.href = '/wap/lottery/index?act_id=' + _this.attr('awardid')
  316. }else{
  317. window.location.href = res.data.list[_this.index()].url
  318. }
  319. }
  320. })
  321. // window.location.href = '/wap/lottery/index?act_id=' + $(this).attr('awardid')
  322. })
  323. /**
  324. * 中奖消息列表滚动
  325. */
  326. $('.getPrizeList').myScroll({
  327. speed: 40, //数值越大,速度越慢
  328. rowHeight: 32 //li的高度
  329. })
  330. /**
  331. * 我的奖品伸缩
  332. */
  333. $('.myPrizeOtherList').slideToggle()
  334. $('.myPrize_box').on('click', '.checkMore', function () {
  335. $('.myPrizeOtherList').slideToggle(function () {
  336. if ($('.checkMore').text() === '查看更多') {
  337. $('.checkMore').text('收起')
  338. } else {
  339. $('.checkMore').text('查看更多')
  340. }
  341. })
  342. })
  343. /**
  344. * 分享
  345. */
  346. $('#shareBtn').click(function () {
  347. if (/micromessenger/i.test(navigator.userAgent)) {
  348. $('.zhiyin').show()
  349. } else {
  350. $('.popShareBox').show()
  351. $('.popShare').animate({'bottom': 0})
  352. }
  353. })
  354. $('.cancelShare').on('click', function () {
  355. $('.popShare').animate({'bottom': -170}, function () {
  356. $('.popShareBox').hide()
  357. })
  358. })
  359. /**
  360. * Mac 去除滚动条的占位空间
  361. */
  362. var ua = navigator.userAgent
  363. if (/mac os x/i.test(ua)) {
  364. $('.shadowScroll').css({
  365. width: '100%',
  366. overflowY: 'auto'
  367. })
  368. }
  369. /**
  370. * 微信环境操作
  371. */
  372. if (/micromessenger/i.test(navigator.userAgent)) {
  373. // 移除个人中心的登录/退出按钮
  374. // $('.wx-remove').remove()
  375. $('#shareBtn').show()
  376. $('.zhuanjifenList_item[name="wx_share"]').css('display', 'flex')
  377. }
  378. /**
  379. * app 环境
  380. */
  381. if (window.huo && window.huo.getEnvironment) {
  382. var app = huo.getEnvironment()
  383. switch (app) {
  384. case 'and_app':
  385. case 'ios_app':
  386. case 'and_sdk':
  387. case 'ios_sdk':
  388. case 'and_h5_app':
  389. case 'ios_h5_app':
  390. $('.app-remove').remove()
  391. break
  392. }
  393. }
  394. })
  395. // 最近在玩 PC鼠标移动事件
  396. function recentInit () {
  397. var $li_num = $('.recentGame').find('li').length
  398. $('.recentGame').css({width: 100 * $li_num + 16})
  399. $('.recentGame').on({
  400. mousemove: _opacity,
  401. touchmove: _opacity
  402. })
  403. function _opacity () {
  404. var x = parseInt($(this).parent().css('margin-left'))
  405. if (x === 0) {
  406. $('.recentGame_tip').css('opacity', 1)
  407. } else {
  408. $('.recentGame_tip').css('opacity', 0.3)
  409. }
  410. }
  411. $('.recentGame').find('li').click(function (e) {
  412. var t = new Date().getTime() - $(this).parents('.recentPlay_main').attr('t')
  413. if (t > 200) {
  414. e.stopPropagation()
  415. }
  416. })
  417. }
  418. // 打开实名认证页面
  419. function openIdentifyPage () {
  420. $('.wrap').append('<iframe id="huoFrame" name="huoFrame" src="' + $('#h5iSite').val() + '/api/wap/identify/index" style="height: 100%; width: 100%; position: absolute; left: 0; top: 0; z-index: 1002; background-color: transparent; border: 0 none;"></iframe>')
  421. }
  422. // 分享任务
  423. function handleShareTask (flag) {
  424. if (/micromessenger/i.test(navigator.userAgent)) {
  425. $('.wxShare').show()
  426. if (!flag) {
  427. $.get('/user/share/notify', function (res) {
  428. })
  429. }
  430. } else {
  431. alert('去微信内分享')
  432. }
  433. }
  434. // $('.awardBox_p1__guanbi').on('click',function(){
  435. // $('.award').hide()
  436. // })
  437. // $('.awardBox_confirm').on('click',function(){
  438. // $('.award').hide()
  439. // // $('.getAwardInformation').show();
  440. // })
  441. // $('.getAwardInformationBox_p1__img').on('click',function(){
  442. // $('.getAwardInformation').hide();
  443. // })
  444. // $('.getAwardInformationBox_confirm__btn').on('click',function(){
  445. // $('.getAwardInformation').hide()
  446. // $('.getAwardSucess').show();
  447. // })
  448. // $('.getAwardSucess').on('click',function(){
  449. // $('.getAwardSucess').hide();
  450. // })
  451. //无缝滚动
  452. $.fn.myScroll = function(options){
  453. //默认配置
  454. var defaults = {
  455. speed: 40, //滚动速度,值越大速度越慢
  456. rowHeight: 24 //每行的高度
  457. };
  458. var opts = $.extend({}, defaults, options),intId = [];
  459. function marquee(obj, step){
  460. obj.find("ul").animate({
  461. marginTop: '-=1'
  462. },0,function(){
  463. var s = Math.abs(parseInt($(this).css("margin-top")));
  464. if(s >= step){
  465. $(this).find("li").slice(0, 1).appendTo($(this));
  466. $(this).css("margin-top", 0);
  467. }
  468. });
  469. }
  470. this.each(function(i){
  471. var sh = opts["rowHeight"],speed = opts["speed"],_this = $(this);
  472. intId[i] = setInterval(function(){
  473. if(_this.find("ul").height()<=_this.height()){
  474. clearInterval(intId[i]);
  475. }else{
  476. marquee(_this, sh);
  477. }
  478. }, speed);
  479. _this.hover(function(){
  480. clearInterval(intId[i]);
  481. },function(){
  482. intId[i] = setInterval(function(){
  483. if(_this.find("ul").height()<=_this.height()){
  484. clearInterval(intId[i]);
  485. }else{
  486. marquee(_this, sh);
  487. }
  488. }, speed);
  489. });
  490. });
  491. }
  492. function showAll (e) {
  493. e = e || window.event
  494. $(e.target).parent().find('.gameDescript').css({'display':'block','height':'auto'});
  495. $(e.target).hide();
  496. }
  497. function showQQGroup () {
  498. var type = qqGroupDeviceType()
  499. switch (type) {
  500. case 'idkey':
  501. $('[qqgrouptype="and_key"], [qqgrouptype="ios_key"]').remove()
  502. break
  503. case 'and_key':
  504. $('[qqgrouptype="idkey"], [qqgrouptype="ios_key"]').remove()
  505. break
  506. case 'ios_key':
  507. $('[qqgrouptype="idkey"], [qqgrouptype="and_key"]').remove()
  508. break
  509. }
  510. $('[qqgrouptype]').show()
  511. }
  512. // QQ加群
  513. function qqGroupDeviceType () {
  514. var ua = navigator.userAgent
  515. var type = 'idkey'
  516. var ios = /i(pad|phone|pod)/i.test(ua)
  517. var and = /android/i.test(ua)
  518. var wx = /micromessenger/i.test(ua)
  519. if (wx) {
  520. type = 'idkey'
  521. } else if (ios) {
  522. type = 'ios_key'
  523. } else if (and) {
  524. type = 'and_key'
  525. }
  526. return type
  527. }
  528. // 抽取 url 中的参数
  529. function urlParse (key) {
  530. var value = ''
  531. var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)')
  532. var r = window.location.search.substr(1).match(reg)
  533. if (r != null) {
  534. value = r[2]
  535. }
  536. return value
  537. }
  538. /***
  539. * 关闭我的账号内所有弹框
  540. * */
  541. $('.mask_close').click(function(){
  542. $('.mask').fadeOut()
  543. $('.mask_content').html('')
  544. })
  545. /***
  546. * 修改昵称弹框
  547. * */
  548. $('#editUsernameId').click(function(){
  549. $('.mask').fadeIn()
  550. $('.mask_content').html('')
  551. $('.mask_content').append(`<p class="editTitle">修改昵称</p>
  552. <input class="editInput" id="editInput" type="text" placeholder="请输入">
  553. <div class="confirmBtn">
  554. <button class="confirmBtn_button" type="button" onclick="editUsernameApi()">保存</button>
  555. </div>`)
  556. })
  557. /***
  558. * 修改密码
  559. * */
  560. $('#userStatus').click(function(){
  561. let status = Number($(this).attr('data-status'))
  562. // HuoFloat.showAddress('editPassWord', status)
  563. $('.mask').fadeIn()
  564. $('.mask_content').html('')
  565. if(status == 1){
  566. $('.mask_content').append(`<div class="resetWrap">
  567. <p class="editTitle">设置密码</p>
  568. <input class="editInput" id="editPassNew" name="editPassWord" style="margin-bottom: 14px" type="text" placeholder="请输入新密码">
  569. <input class="editInput" id="editPassNewRepeat" name="editPassWord" type="text" placeholder="请重复输入新密码">
  570. <div class="confirmBtn">
  571. <button class="confirmBtn_button" type="button" onclick="savePassWord(${status})">确认</button>
  572. </div>
  573. </div>`)
  574. }else{
  575. $('.mask_content').append(`<div class="resetWrap">
  576. <p class="editTitle">修改密码</p>
  577. <input class="editInput" style="margin-bottom: 16px" id="editPass" name="editPassWord" type="text" placeholder="请输入旧密码">
  578. <input class="editInput" id="editPassNew" name="editPassWord" style="margin-bottom: 14px" type="text" placeholder="请输入新密码">
  579. <input class="editInput" id="editPassNewRepeat" name="editPassWord" type="text" placeholder="请重复输入新密码">
  580. <div class="confirmBtn">
  581. <button class="confirmBtn_button" type="button" onclick="savePassWord(${status})">确认</button>
  582. </div>
  583. </div>`)
  584. }
  585. })
  586. /***
  587. * 保存修改昵称
  588. * */
  589. function editUsernameApi(){
  590. $.ajax({
  591. url: '/cfloat/user/nickname/update',
  592. data: {
  593. "nickname": $('#editInput').val(),
  594. "format": 'json'
  595. },
  596. dataType: 'json',
  597. success: res => {
  598. console.log('res===', res)
  599. if(res.code == 200){
  600. $('.mask').fadeOut()
  601. $('.mask_content').html('')
  602. window.location.reload()
  603. }else{
  604. HuoUtils.tips(res.msg)
  605. }
  606. }
  607. })
  608. }
  609. /**
  610. * 保存修改密码
  611. * */
  612. function savePassWord(id){
  613. console.log('id===', id)
  614. let oldPwd = $('.resetWrap #editPass').val();
  615. let newPwd = $('.resetWrap #editPassNew').val();
  616. let repPwd = $('.resetWrap #editPassNewRepeat').val();
  617. let data
  618. if(repPwd != newPwd){
  619. HuoUtils.tips('两次输入的密码不一致')
  620. return false
  621. }
  622. if(id == 1){
  623. data={
  624. "status": 1,
  625. "newpwd": newPwd,
  626. "format": 'json'
  627. }
  628. }else{
  629. data={
  630. "oldpwd": oldPwd,
  631. "newpwd": newPwd,
  632. "format": 'json'
  633. }
  634. }
  635. $.ajax({
  636. url: '/cfloat/user/passwd/update',
  637. data: data,
  638. dataType: 'json',
  639. success: res => {
  640. if(res.code == 200){
  641. $('.mask').fadeOut()
  642. $('.mask_content').html('')
  643. HuoApi.userLogout()
  644. }else{
  645. HuoUtils.tips(res.msg)
  646. }
  647. }
  648. })
  649. }
  650. /**
  651. * 修改头像
  652. * */
  653. $('#modifying').click(function(){
  654. let img = $(this).attr('data-img')
  655. $('.mask').fadeIn()
  656. $('.mask_content').html('')
  657. $('.mask_content').append(`<p class="editTitle">修改头像</p>
  658. <input type="file" id="uploadUserHead" style="display: none" name="file" onchange="uoloadImg(event, this)" accept="image/*">
  659. <div style="text-align: center;">
  660. <label for="uploadUserHead">
  661. <img id="showUserImg" crossorigin="anonymous" style="width: 66px;max-height: 66px" src="${img}" alt="">
  662. </label>
  663. </div>
  664. <div class="confirmBtn">
  665. <button class="confirmBtn_button" id="saveImg" type="button" disabled onclick="EditAgentInfo(this)">保存修改</button>
  666. </div>`)
  667. })
  668. /**
  669. * 修改头像
  670. * */
  671. function uoloadImg(e, item){
  672. let file = $(item)[0].files[0]; //获取文件信息
  673. console.log('files===', file)
  674. let fd = new FormData();
  675. fd.append("enctype", 'multipart/form-data');
  676. fd.append("filetype", "image");
  677. fd.append("app", "agent");
  678. fd.append("file", file);
  679. fd.append("id", "UPLOAD_FILE_LOGO");
  680. fd.append("name", file.name);
  681. fd.append("type", file.type);
  682. fd.append("lastModifiedDate", file.lastModifiedDate);
  683. fd.append("size", file.size);
  684. fd.append("format", 'json');
  685. fd.append('method', 'POST')
  686. let xhr = new XMLHttpRequest();
  687. xhr.open("POST", "/user/asset/upload");
  688. xhr.upload.onprogress = function(ev) {
  689. let percent = ((ev.loaded / ev.total) * 100).toFixed(0) + "%";
  690. console.log(percent);
  691. };
  692. xhr.send(fd);
  693. xhr.onreadystatechange = function() {
  694. if (xhr.readyState === 4 && xhr.status === 200) {
  695. let res = JSON.parse(xhr.response);
  696. console.log(res)
  697. if (res.code === 200) {
  698. $('#showUserImg').attr('src', res.data.url)
  699. $('#saveImg').attr('data-url', res.data.url)
  700. $('#saveImg').attr('disabled', false)
  701. } else {
  702. HuoUtils.tips(res.msg)
  703. }
  704. }
  705. };
  706. }
  707. /**
  708. * 保存修改后的头像
  709. * */
  710. function EditAgentInfo(item) {
  711. let url = $(item).attr('data-url');
  712. $.ajax({
  713. url: '/user/avatar/update',
  714. data: {
  715. "avatar": url,
  716. "format": 'json'
  717. },
  718. dataType: 'json',
  719. success: res =>{
  720. console.log(res)
  721. if(res.code == 200){
  722. $('.mask').fadeOut()
  723. $('.mask_content').html('')
  724. window.location.reload()
  725. }else{
  726. HuoUtils.tips(res.msg)
  727. }
  728. }
  729. })
  730. }