all.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. //logs.js
  2. const util = require('../../../utils/util.js')
  3. var _request = require('../../../utils/request.js')
  4. var version = getApp().globalData.version
  5. var channel // 渠道二维码信息
  6. var scene // 渠道二维码id
  7. var url = '' // 分享或模板落地页
  8. var invite = 0 //邀请id
  9. var poster = []
  10. var project = []
  11. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0';
  12. Page({
  13. data: {
  14. userInfo: {},
  15. balance: 0,
  16. integral:0,
  17. silver:0,
  18. bindTel: false,
  19. checkData: {},
  20. merchant: {},
  21. info: {},
  22. show: 0,
  23. checkhead:true,
  24. wxlogincode:'',
  25. bindTelfirst:0,
  26. cashbalance:0,
  27. kfqr:'',//客服二维码
  28. showqr:false,
  29. avatarUrl: defaultAvatarUrl,
  30. nickname:''
  31. },
  32. onLoad: function () {
  33. //// console.log(options)
  34. // url = 0
  35. // if (options.scene) {
  36. // scene = decodeURIComponent(options.scene)
  37. // if (scene.indexOf('invite_wx_') > -1) {
  38. // invite = scene.slice(10)
  39. // } else if (scene.indexOf('poster') > -1) {
  40. // this.getPoster(scene)
  41. // } else if (scene.indexOf('project') > -1) {
  42. // this.getPosterProject(scene)
  43. // } else {
  44. // this.getScene(scene)
  45. // }
  46. // } else if (options.url) {
  47. // this.urlHandle(options)
  48. // }
  49. // if (options.invite) {
  50. // invite = options.invite
  51. // }
  52. // var that = this
  53. this.checkLogin();
  54. this.info();
  55. },
  56. onShow: function () {
  57. var that = this;
  58. // that.checkLogin();
  59. this.info();
  60. that.getBalanceInfo()
  61. that.getCashBalanceInfo()
  62. this.getqcode()
  63. // that.getIntegralInfo()
  64. // if (this.data.bindTel) {
  65. // this.getBalanceInfo()
  66. // this.getIntegralInfo()
  67. // if (that.data.checkData.merchant_id > 0) {
  68. // that.getmerchant()
  69. // }
  70. // } else {
  71. // // this.check()
  72. // // this.info()
  73. // }
  74. //原登陆检测
  75. },
  76. checkLogin:function(){
  77. var that = this;
  78. //2020登陆检测
  79. wx.login({
  80. success: res => {
  81. getApp().globalData.try_login = true;
  82. console.log('checkLogin',res.code)
  83. var url = 'xcx/login';
  84. invite = wx.getStorageSync('invite');
  85. var params = {
  86. code: res.code,
  87. invite_id: invite//新token模式
  88. }
  89. that.setData({
  90. wxlogincode: res.code
  91. })
  92. var success = function (res) {
  93. console.log('pageLogin',res);
  94. wx.setStorageSync('lbt_session_key', res.data.session_key)
  95. wx.setStorageSync('lbt_session_time', Date.now())
  96. wx.setStorageSync('lbt_token_key', res.data.token)
  97. console.log('nowtoken',res.data.token);
  98. if(res.data.wx_user && res.data.wx_user.head != ''){
  99. var userInfo = res.data.wx_user;
  100. that.setData({
  101. userInfo: userInfo
  102. })
  103. that.info()
  104. that.getBalanceInfo()
  105. that.getCashBalanceInfo()
  106. // that.getIntegralInfo()
  107. // if (that.data.checkData.merchant_id > 0) {
  108. // that.getmerchant()
  109. // }
  110. //checkwxhead---start
  111. // console.log('that.data.checkhead',that.data.checkhead);
  112. if(res.data.wx_user.head == '' ){
  113. that.setData({
  114. checkhead: false
  115. })
  116. that.setData({
  117. userInfo: 'nologin'
  118. })
  119. /*
  120. wx.getSetting({
  121. success: res => {
  122. var auth = res.authSetting
  123. if (auth['scope.userInfo']) {
  124. console.log('wxhead none')
  125. // wx.getUserInfo({
  126. // success: function(res3) {
  127. // console.log('userinfo',res3)
  128. // var url = 'xcx/save_wx_user/info'
  129. // var params = {
  130. // userinfo: JSON.stringify(res3)
  131. // }
  132. // var success = function (res4) {
  133. // console.log('authorize',res4)
  134. // that.onShow()
  135. // }
  136. // _request.$post(url, params, success)
  137. // }
  138. // })
  139. //新授权
  140. wx.getUserProfile({
  141. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  142. success: function(res3) {
  143. console.log('userinfo',res3)
  144. var url = 'xcx/save_wx_user/info'
  145. var params = {
  146. userinfo: JSON.stringify(res3.userInfo)
  147. }
  148. var success = function (res4) {
  149. console.log('authorize',res4);
  150. that.onLoad()
  151. }
  152. _request.$post(url, params, success)
  153. }
  154. })
  155. }else{
  156. that.setData({
  157. userInfo: 'nologin'
  158. })
  159. }
  160. }
  161. })
  162. */
  163. }
  164. //checkwxhead---end
  165. }else{
  166. that.setData({
  167. userInfo: 'nologin'
  168. })
  169. }
  170. }
  171. _request.$get(url, params, success)
  172. }
  173. })
  174. },
  175. getPoster: function (val) {
  176. poster = val.split('$')
  177. if (poster.length > 0) {
  178. invite = poster[2]
  179. }
  180. },
  181. getPosterProject: function (val) {
  182. project = val.split('$')
  183. if (project.length > 0) {
  184. invite = project[2]
  185. }
  186. },
  187. urlHandle: function (val) {
  188. if (val.url) {
  189. url = val.url + '?'
  190. for (var i in val) {
  191. if (i !== 'url') {
  192. url += i + '=' + val[i] + '&'
  193. }
  194. }
  195. }
  196. },
  197. getScene: function () {
  198. var that = this
  199. var url = 'v1/xcx/channel/info/' + scene
  200. var params = {}
  201. var success = function (res) {
  202. channel = res.data
  203. }
  204. _request.$get(url, params, success)
  205. },
  206. getUserInfo: function (val) {
  207. var channel_id = 0;
  208. invite = wx.getStorageSync('invite');
  209. if (channel && Number(channel.parent_id) > 0) {
  210. channel_id = Number(channel.parent_id)
  211. }
  212. var that = this
  213. if (val.detail.errMsg === 'getUserInfo:ok') {
  214. wx.showLoading({
  215. title: '加载中'
  216. })
  217. console.log('val',val)
  218. // _request.sendInfo(val, channel_id, invite, that)
  219. that.onLoad();
  220. // wx.showToast({
  221. // title: '请绑定手机号~',
  222. // icon: 'none',
  223. // duration: 2000
  224. // })
  225. // wx.navigateTo({
  226. // url: '/packageUser/pages/user/bind/bind'
  227. // })
  228. }
  229. },
  230. getUserProfile:function(){
  231. console.log('tap')
  232. var that = this
  233. console.log('getUserProfile')
  234. const app = this
  235. //增加判断昵称和头像是否设置
  236. if(app.data.avatarUrl == defaultAvatarUrl){
  237. wx.showToast({
  238. title: '请设置头像',
  239. icon: 'none',
  240. duration: 2000
  241. });
  242. return;
  243. }
  244. if(app.data.nickname == ''){
  245. wx.showToast({
  246. title: '请设置昵称',
  247. icon: 'none',
  248. duration: 2000
  249. });
  250. return;
  251. }
  252. console.log('用户同意了授权');
  253. // wx.getUserProfile({
  254. // desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  255. // success: (res) => {
  256. // this.setData({
  257. // userInfo: res.userInfo,
  258. // hasUserInfo: true
  259. // })
  260. // var channel_id = 0;
  261. // invite = wx.getStorageSync('invite');
  262. // if (channel && Number(channel.parent_id) > 0) {
  263. // channel_id = Number(channel.parent_id)
  264. // }
  265. // var that = this
  266. // console.log('res',res);
  267. // if (res.errMsg === "getUserProfile:ok") {
  268. // wx.showLoading({
  269. // title: '加载中'
  270. // })
  271. // res['wxlogincode'] = that.data.wxlogincode;
  272. // _request.sendInfo(res, channel_id, invite, that)
  273. // that.onShow();
  274. // }
  275. // }
  276. // })
  277. wx.getUserProfile({
  278. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  279. success: function(res3) {
  280. res3.userInfo.avatarUrl = that.data.avatarUrl;
  281. res3.userInfo.nickName = that.data.nickname;
  282. console.log('userinfo',res3)
  283. var url = 'xcx/save_wx_user/info'
  284. var params = {
  285. userinfo: JSON.stringify(res3.userInfo)
  286. }
  287. var success = function (res4) {
  288. console.log('authorize',res4)
  289. that.onLoad()
  290. }
  291. _request.$post(url, params, success)
  292. }
  293. })
  294. },
  295. getVersion: function (val) {
  296. // this.check()
  297. },
  298. info(){
  299. console.log('oninfo');
  300. var that = this
  301. var url = 'v1/user/info'
  302. var params = {}
  303. var success = function (res) {
  304. console.log(res)
  305. that.setData({
  306. info: res.data,
  307. show: res.data.wx_user?res.data.wx_user.show_invite_mode:'',
  308. bindTel: res.data.user.tel ? true : false
  309. })
  310. console.log('untel',res.data.user.tel)
  311. console.log('res.data.wx_user',res.data.wx_user)
  312. if(res.data.wx_user.head == ''){
  313. console.log('indddddddddddddddddddddddd')
  314. that.setData({
  315. userInfo: 'nologin'
  316. })
  317. }
  318. if(that.data.userInfo != 'nologin' && res.data.user.tel == '' && that.data.bindTelfirst == 0){
  319. that.setData({
  320. bindTelfirst:1
  321. })
  322. wx.navigateTo({
  323. url: '/packageUser/pages/user/bind/bind'
  324. })
  325. wx.showToast({
  326. title: '请先绑定手机号~',
  327. icon: 'none',
  328. duration: 2000
  329. })
  330. }
  331. }
  332. _request.$get(url, params, success)
  333. },
  334. check () {
  335. var that = this
  336. var url = 'v1/user/check'
  337. var params = {
  338. cache: false
  339. }
  340. var success = function (res) {
  341. if (res.data.wx_user_id <= 0) {
  342. wx.login({
  343. success: res => {
  344. _request.login(res)
  345. }
  346. })
  347. } else {
  348. that.setData({
  349. checkData: res.data
  350. })
  351. if (that.data.checkData.merchant_id > 0) {
  352. that.getmerchant()
  353. }
  354. if (res.data.user_id > 0 && !that.data.bindTel) {
  355. // that.setData({
  356. // bindTel: true
  357. // })
  358. that.getBalanceInfo()
  359. that.getCashBalanceInfo()
  360. // that.getIntegralInfo()
  361. that.info()
  362. }
  363. }
  364. }
  365. _request.$get(url, params, success)
  366. },
  367. buyVoucher(){
  368. if(this.data.info.user.tel == ''){//未绑定手机号
  369. wx.navigateTo({
  370. url: '/packageUser/pages/user/bind/bind'
  371. })
  372. wx.showToast({
  373. title: '请先绑定手机号~',
  374. icon: 'none',
  375. duration: 2000
  376. })
  377. //2020
  378. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/buy/buy'); //存入手机绑定后跳转页面
  379. }else{
  380. wx.navigateTo({
  381. url: '/packageUser/pages/user/buy/buy'
  382. })
  383. }
  384. },
  385. getmerchant () {
  386. var that = this
  387. var url = 'v1/merchant/orders/count'
  388. var params = {
  389. merchant_id: that.data.checkData.merchant_id
  390. }
  391. var success = function (res) {
  392. var result = res.data
  393. that.setData({
  394. merchant: result
  395. })
  396. console.log(that.data.merchant)
  397. }
  398. _request.$get(url, params, success)
  399. },
  400. getBalanceInfo () {
  401. var that = this
  402. var url = 'v1/user/balance/info'
  403. var params = {
  404. }
  405. var success = function (res) {
  406. var result = res.data.total
  407. that.setData({
  408. balance: result,
  409. silver: res.data.silver_total
  410. })
  411. }
  412. _request.$get(url, params, success)
  413. },
  414. getCashBalanceInfo () {
  415. var that = this
  416. var url = 'v1/user/cash/balance/info'
  417. var params = {
  418. }
  419. var success = function (res) {
  420. var result = res.data.total
  421. that.setData({
  422. cashbalance: result
  423. })
  424. }
  425. _request.$get(url, params, success)
  426. },
  427. getSilverInfo () {
  428. var that = this
  429. var url = 'v1/user/cent/info'
  430. var params = {
  431. }
  432. var success = function (res) {
  433. var result = res.data.total
  434. that.setData({
  435. integral: result
  436. })
  437. }
  438. _request.$get(url, params, success)
  439. },
  440. toInviteList () {
  441. var that = this;
  442. if(that.data.info.user.tel == ''){
  443. wx.navigateTo({
  444. url: '/packageUser/pages/user/bind/bind'
  445. })
  446. wx.showToast({
  447. title: '请先绑定手机号~',
  448. icon: 'none',
  449. duration: 2000
  450. })
  451. }else{
  452. wx.navigateTo({
  453. url: '/packageUser/pages/user/invite/invite'
  454. })
  455. }
  456. },
  457. // checkbindtel(){
  458. // var that = this;
  459. // if(that.data.info.user.tel == ''){
  460. // setTimeout(function(){
  461. // wx.navigateTo({
  462. // url: '/packageUser/pages/user/bind/bind'
  463. // })
  464. // wx.showToast({
  465. // title: '请先绑定手机号~',
  466. // icon: 'none',
  467. // duration: 2000
  468. // })
  469. // },500)
  470. // }
  471. // },
  472. toCashList () {
  473. if(this.data.info.user.tel == ''){//未绑定手机号
  474. wx.navigateTo({
  475. url: '/packageUser/pages/user/bind/bind'
  476. })
  477. wx.showToast({
  478. title: '请先绑定手机号~',
  479. icon: 'none',
  480. duration: 2000
  481. })
  482. //2020
  483. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/fund/fund'); //存入手机绑定后跳转页面
  484. }else{
  485. wx.navigateTo({
  486. url: '/packageUser/pages/user/fund/fund'
  487. })
  488. }
  489. },
  490. toUserInfo() {
  491. wx.navigateTo({
  492. url: '/packageUser/pages/user/userInfo/userInfo'
  493. })
  494. },
  495. toBindOldSys () {
  496. let that = this;
  497. wx.navigateTo({
  498. url: '/packageUser/pages/user/bindoldsys/bindoldsys?id='+that.data.userInfo.id
  499. })
  500. },
  501. toPromotion () {
  502. wx.navigateTo({
  503. url: '/packageUser/pages/user/promotion/promotion'
  504. })
  505. },
  506. toIdentity () {
  507. wx.navigateTo({
  508. url: '/packageUser/pages/user/identity/identity'
  509. })
  510. },
  511. toBankInfo () {
  512. wx.navigateTo({
  513. url: '/packageUser/pages/user/bankinfo/bankinfo'
  514. })
  515. },
  516. toAddressList () {
  517. wx.navigateTo({
  518. url: '/packageUser/pages/user/address/address'
  519. })
  520. },
  521. toRadish () {
  522. wx.navigateTo({
  523. url: '/packageUser/pages/user/radish/radish'
  524. })
  525. },
  526. toCash () {
  527. wx.navigateTo({
  528. url: '/packageUser/pages/user/cash/cash'
  529. })
  530. },
  531. toCommission () {
  532. wx.navigateTo({
  533. url: '/packageUser/pages/user/commission/commission'
  534. })
  535. },
  536. toIntegral () {
  537. wx.navigateTo({
  538. url: '/packageUser/pages/user/integral/integral'
  539. })
  540. },
  541. toSilver () {
  542. wx.navigateTo({
  543. url: '/packageUser/pages/user/silver/silver'
  544. })
  545. },
  546. toSafe () {
  547. wx.navigateTo({
  548. url: '/packageUser/pages/user/safe/safe'
  549. })
  550. },
  551. toCustom () {
  552. wx.reLaunch({
  553. url: '/pages/customservice/customservice'
  554. })
  555. },
  556. toProxy () {
  557. wx.navigateTo({
  558. url: '/packageUser/pages/user/proxyList/proxyList'
  559. })
  560. },
  561. toApplyLeader () {
  562. wx.navigateTo({
  563. url: '/packageUser/pages/user/applyLeader/applyLeader'
  564. })
  565. },
  566. toAreaCart () {
  567. wx.navigateTo({
  568. url: '/pages/areacart/areacart'
  569. })
  570. },
  571. toBindTel () {
  572. wx.navigateTo({
  573. url: '/packageUser/pages/user/bind/bind'
  574. })
  575. },
  576. toAbout () {
  577. var host = getApp().globalData.d5c
  578. if (host === 'tm.d5ct.com') {
  579. wx.navigateTo({
  580. url: '/pages/parse/parse?id=2'
  581. })
  582. } else if (host === 'm.d5ct.com') {
  583. wx.navigateTo({
  584. url: '/pages/parse/parse?id=1'
  585. })
  586. }
  587. },
  588. toMerchant () {
  589. wx.navigateTo({
  590. url: '/packageMerchant/pages/merchant/orders/orders?id=' + this.data.checkData.merchant_id + '&is_super_admin=' + this.data.checkData.is_super_admin
  591. })
  592. },
  593. toMerchant1 () {
  594. wx.navigateTo({
  595. url: '/packageMerchant/pages/merchant/accounts/accounts?id=' + this.data.checkData.merchant_id
  596. })
  597. },
  598. onShareAppMessage: function (val) {
  599. return _request.share({
  600. sc: 'xcx_user'
  601. })
  602. },
  603. getqcode: function () {
  604. var that = this
  605. var url = 'v1/customer_service/qrcode'
  606. var params = {}
  607. var success = function (res) {
  608. that.setData({
  609. kfqr: res.data
  610. })
  611. }
  612. _request.$get(url, params, success)
  613. },
  614. tiggerQR:function(){
  615. this.setData({
  616. showqr: !this.data.showqr
  617. })
  618. },
  619. catchtapQR:function(){
  620. console.log('catchtapQR');
  621. },
  622. /**
  623. * 用户头像设置
  624. */
  625. onChooseAvatar(e) {
  626. const { avatarUrl } = e.detail
  627. this.setData({
  628. avatarUrl,
  629. })
  630. },
  631. /**
  632. * 用户昵称设置
  633. */
  634. changeNickName(e) {
  635. console.log(e.detail);
  636. this.setData({
  637. nickname: e.detail.value
  638. })
  639. },
  640. savebtn(){
  641. var that = this;
  642. //增加判断昵称和头像是否设置
  643. if(that.data.avatarUrl == defaultAvatarUrl){
  644. wx.showToast({
  645. title: '请设置头像',
  646. icon: 'none',
  647. duration: 2000
  648. });
  649. return;
  650. }
  651. if(that.data.nickname == ''){
  652. wx.showToast({
  653. title: '请设置昵称',
  654. icon: 'none',
  655. duration: 2000
  656. });
  657. return;
  658. }
  659. var url = 'v1/user/update/info'
  660. var params = {
  661. nickname:that.data.nickname,
  662. birthday:'',
  663. sex:0,
  664. }
  665. var success = function (res) {
  666. console.log(res);
  667. wx.showToast({
  668. title: '更新成功',
  669. icon: 'none',
  670. duration: 2000
  671. })
  672. }
  673. var fail = function (res) {
  674. console.log(res);
  675. }
  676. _request.$uploadFile(url,'head',that.data.avatarUrl, params, success,fail)
  677. that.onLoad()
  678. },
  679. })