all.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. Page({
  12. data: {
  13. userInfo: {},
  14. balance: 0,
  15. integral:0,
  16. bindTel: false,
  17. checkData: {},
  18. merchant: {},
  19. info: {},
  20. show: 0,
  21. checkhead:true,
  22. wxlogincode:'',
  23. bindTelfirst:0
  24. },
  25. onLoad: function () {
  26. //// console.log(options)
  27. // url = 0
  28. // if (options.scene) {
  29. // scene = decodeURIComponent(options.scene)
  30. // if (scene.indexOf('invite_wx_') > -1) {
  31. // invite = scene.slice(10)
  32. // } else if (scene.indexOf('poster') > -1) {
  33. // this.getPoster(scene)
  34. // } else if (scene.indexOf('project') > -1) {
  35. // this.getPosterProject(scene)
  36. // } else {
  37. // this.getScene(scene)
  38. // }
  39. // } else if (options.url) {
  40. // this.urlHandle(options)
  41. // }
  42. // if (options.invite) {
  43. // invite = options.invite
  44. // }
  45. // var that = this
  46. this.checkLogin();
  47. this.info();
  48. },
  49. onShow: function () {
  50. var that = this;
  51. // that.checkLogin();
  52. this.info();
  53. // if (this.data.bindTel) {
  54. // this.getBalanceInfo()
  55. // this.getIntegralInfo()
  56. // if (that.data.checkData.merchant_id > 0) {
  57. // that.getmerchant()
  58. // }
  59. // } else {
  60. // // this.check()
  61. // // this.info()
  62. // }
  63. //原登陆检测
  64. },
  65. checkLogin:function(){
  66. var that = this;
  67. //2020登陆检测
  68. wx.login({
  69. success: res => {
  70. getApp().globalData.try_login = true;
  71. console.log('checkLogin',res.code)
  72. var url = 'xcx/login';
  73. invite = wx.getStorageSync('invite');
  74. var params = {
  75. code: res.code,
  76. invite_id: invite//新token模式
  77. }
  78. that.setData({
  79. wxlogincode: res.code
  80. })
  81. var success = function (res) {
  82. console.log('pageLogin',res);
  83. wx.setStorageSync('lbt_session_key', res.data.session_key)
  84. wx.setStorageSync('lbt_session_time', Date.now())
  85. wx.setStorageSync('lbt_token_key', res.data.token)
  86. console.log('nowtoken',res.data.token);
  87. if(res.data.wx_user && res.data.wx_user.head != ''){
  88. var userInfo = res.data.wx_user;
  89. that.setData({
  90. userInfo: userInfo
  91. })
  92. that.info()
  93. that.getBalanceInfo()
  94. that.getIntegralInfo()
  95. // if (that.data.checkData.merchant_id > 0) {
  96. // that.getmerchant()
  97. // }
  98. //checkwxhead---start
  99. // console.log('that.data.checkhead',that.data.checkhead);
  100. if(res.data.wx_user.head == '' ){
  101. that.setData({
  102. checkhead: false
  103. })
  104. wx.getSetting({
  105. success: res => {
  106. var auth = res.authSetting
  107. if (auth['scope.userInfo']) {
  108. console.log('wxhead none')
  109. // wx.getUserInfo({
  110. // success: function(res3) {
  111. // console.log('userinfo',res3)
  112. // var url = 'xcx/save_wx_user/info'
  113. // var params = {
  114. // userinfo: JSON.stringify(res3)
  115. // }
  116. // var success = function (res4) {
  117. // console.log('authorize',res4)
  118. // that.onShow()
  119. // }
  120. // _request.$post(url, params, success)
  121. // }
  122. // })
  123. //新授权
  124. wx.getUserProfile({
  125. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  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.userInfo)
  131. }
  132. var success = function (res4) {
  133. console.log('authorize',res4);
  134. that.onLoad()
  135. }
  136. _request.$post(url, params, success)
  137. }
  138. })
  139. }else{
  140. that.setData({
  141. userInfo: 'nologin'
  142. })
  143. }
  144. }
  145. })
  146. }
  147. //checkwxhead---end
  148. }else{
  149. that.setData({
  150. userInfo: 'nologin'
  151. })
  152. }
  153. }
  154. _request.$get(url, params, success)
  155. }
  156. })
  157. },
  158. getPoster: function (val) {
  159. poster = val.split('$')
  160. if (poster.length > 0) {
  161. invite = poster[2]
  162. }
  163. },
  164. getPosterProject: function (val) {
  165. project = val.split('$')
  166. if (project.length > 0) {
  167. invite = project[2]
  168. }
  169. },
  170. urlHandle: function (val) {
  171. if (val.url) {
  172. url = val.url + '?'
  173. for (var i in val) {
  174. if (i !== 'url') {
  175. url += i + '=' + val[i] + '&'
  176. }
  177. }
  178. }
  179. },
  180. getScene: function () {
  181. var that = this
  182. var url = 'v1/xcx/channel/info/' + scene
  183. var params = {}
  184. var success = function (res) {
  185. channel = res.data
  186. }
  187. _request.$get(url, params, success)
  188. },
  189. getUserInfo: function (val) {
  190. var channel_id = 0;
  191. invite = wx.getStorageSync('invite');
  192. if (channel && Number(channel.parent_id) > 0) {
  193. channel_id = Number(channel.parent_id)
  194. }
  195. var that = this
  196. if (val.detail.errMsg === 'getUserInfo:ok') {
  197. wx.showLoading({
  198. title: '加载中'
  199. })
  200. console.log('val',val)
  201. // _request.sendInfo(val, channel_id, invite, that)
  202. that.onLoad();
  203. // wx.showToast({
  204. // title: '请绑定手机号~',
  205. // icon: 'none',
  206. // duration: 2000
  207. // })
  208. // wx.navigateTo({
  209. // url: '/packageUser/pages/user/bind/bind'
  210. // })
  211. }
  212. },
  213. getUserProfile:function(){
  214. console.log('tap')
  215. var that = this
  216. // wx.getUserProfile({
  217. // desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  218. // success: (res) => {
  219. // this.setData({
  220. // userInfo: res.userInfo,
  221. // hasUserInfo: true
  222. // })
  223. // var channel_id = 0;
  224. // invite = wx.getStorageSync('invite');
  225. // if (channel && Number(channel.parent_id) > 0) {
  226. // channel_id = Number(channel.parent_id)
  227. // }
  228. // var that = this
  229. // console.log('res',res);
  230. // if (res.errMsg === "getUserProfile:ok") {
  231. // wx.showLoading({
  232. // title: '加载中'
  233. // })
  234. // res['wxlogincode'] = that.data.wxlogincode;
  235. // _request.sendInfo(res, channel_id, invite, that)
  236. // that.onShow();
  237. // }
  238. // }
  239. // })
  240. wx.getUserProfile({
  241. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  242. success: function(res3) {
  243. console.log('userinfo',res3)
  244. var url = 'xcx/save_wx_user/info'
  245. var params = {
  246. userinfo: JSON.stringify(res3.userInfo)
  247. }
  248. var success = function (res4) {
  249. console.log('authorize',res4)
  250. that.onLoad()
  251. }
  252. _request.$post(url, params, success)
  253. }
  254. })
  255. },
  256. getVersion: function (val) {
  257. // this.check()
  258. },
  259. info(){
  260. console.log('oninfo');
  261. var that = this
  262. var url = 'v1/user/info'
  263. var params = {}
  264. var success = function (res) {
  265. console.log(res)
  266. that.setData({
  267. info: res.data,
  268. show: res.data.wx_user?res.data.wx_user.show_invite_mode:'',
  269. bindTel: res.data.user.tel ? true : false
  270. })
  271. console.log('untel',res.data.user.tel)
  272. console.log('res.data.wx_user',res.data.wx_user)
  273. if(res.data.wx_user.head == ''){
  274. console.log('indddddddddddddddddddddddd')
  275. that.setData({
  276. userInfo: 'nologin'
  277. })
  278. }
  279. if(that.data.userInfo != 'nologin' && res.data.user.tel == '' && that.data.bindTelfirst == 0){
  280. that.setData({
  281. bindTelfirst:1
  282. })
  283. wx.navigateTo({
  284. url: '/packageUser/pages/user/bind/bind'
  285. })
  286. wx.showToast({
  287. title: '请先绑定手机号~',
  288. icon: 'none',
  289. duration: 2000
  290. })
  291. }
  292. }
  293. _request.$get(url, params, success)
  294. },
  295. check () {
  296. var that = this
  297. var url = 'v1/user/check'
  298. var params = {
  299. cache: false
  300. }
  301. var success = function (res) {
  302. if (res.data.wx_user_id <= 0) {
  303. wx.login({
  304. success: res => {
  305. _request.login(res)
  306. }
  307. })
  308. } else {
  309. that.setData({
  310. checkData: res.data
  311. })
  312. if (that.data.checkData.merchant_id > 0) {
  313. that.getmerchant()
  314. }
  315. if (res.data.user_id > 0 && !that.data.bindTel) {
  316. // that.setData({
  317. // bindTel: true
  318. // })
  319. that.getBalanceInfo()
  320. that.getIntegralInfo()
  321. that.info()
  322. }
  323. }
  324. }
  325. _request.$get(url, params, success)
  326. },
  327. buyVoucher(){
  328. if(this.data.info.user.tel == ''){//未绑定手机号
  329. wx.navigateTo({
  330. url: '/packageUser/pages/user/bind/bind'
  331. })
  332. wx.showToast({
  333. title: '请先绑定手机号~',
  334. icon: 'none',
  335. duration: 2000
  336. })
  337. //2020
  338. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/buy/buy'); //存入手机绑定后跳转页面
  339. }else{
  340. wx.navigateTo({
  341. url: '/packageUser/pages/user/buy/buy'
  342. })
  343. }
  344. },
  345. getmerchant () {
  346. var that = this
  347. var url = 'v1/merchant/orders/count'
  348. var params = {
  349. merchant_id: that.data.checkData.merchant_id
  350. }
  351. var success = function (res) {
  352. var result = res.data
  353. that.setData({
  354. merchant: result
  355. })
  356. console.log(that.data.merchant)
  357. }
  358. _request.$get(url, params, success)
  359. },
  360. getBalanceInfo () {
  361. var that = this
  362. var url = 'v1/user/balance/info'
  363. var params = {
  364. }
  365. var success = function (res) {
  366. var result = res.data.total
  367. that.setData({
  368. balance: result
  369. })
  370. }
  371. _request.$get(url, params, success)
  372. },
  373. getIntegralInfo () {
  374. var that = this
  375. var url = 'v1/user/cent/info'
  376. var params = {
  377. }
  378. var success = function (res) {
  379. var result = res.data.total
  380. that.setData({
  381. integral: result
  382. })
  383. }
  384. _request.$get(url, params, success)
  385. },
  386. toInviteList () {
  387. var that = this;
  388. if(that.data.info.user.tel == ''){
  389. wx.navigateTo({
  390. url: '/packageUser/pages/user/bind/bind'
  391. })
  392. wx.showToast({
  393. title: '请先绑定手机号~',
  394. icon: 'none',
  395. duration: 2000
  396. })
  397. }else{
  398. wx.navigateTo({
  399. url: '/packageUser/pages/user/invite/invite'
  400. })
  401. }
  402. },
  403. // checkbindtel(){
  404. // var that = this;
  405. // if(that.data.info.user.tel == ''){
  406. // setTimeout(function(){
  407. // wx.navigateTo({
  408. // url: '/packageUser/pages/user/bind/bind'
  409. // })
  410. // wx.showToast({
  411. // title: '请先绑定手机号~',
  412. // icon: 'none',
  413. // duration: 2000
  414. // })
  415. // },500)
  416. // }
  417. // },
  418. toCashList () {
  419. if(this.data.info.user.tel == ''){//未绑定手机号
  420. wx.navigateTo({
  421. url: '/packageUser/pages/user/bind/bind'
  422. })
  423. wx.showToast({
  424. title: '请先绑定手机号~',
  425. icon: 'none',
  426. duration: 2000
  427. })
  428. //2020
  429. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/fund/fund'); //存入手机绑定后跳转页面
  430. }else{
  431. wx.navigateTo({
  432. url: '/packageUser/pages/user/fund/fund'
  433. })
  434. }
  435. },
  436. toUserInfo() {
  437. wx.navigateTo({
  438. url: '/packageUser/pages/user/userInfo/userInfo'
  439. })
  440. },
  441. toBindOldSys () {
  442. let that = this;
  443. wx.navigateTo({
  444. url: '/packageUser/pages/user/bindoldsys/bindoldsys?id='+that.data.userInfo.id
  445. })
  446. },
  447. toPromotion () {
  448. wx.navigateTo({
  449. url: '/packageUser/pages/user/promotion/promotion'
  450. })
  451. },
  452. toIdentity () {
  453. wx.navigateTo({
  454. url: '/packageUser/pages/user/identity/identity'
  455. })
  456. },
  457. toBankInfo () {
  458. wx.navigateTo({
  459. url: '/packageUser/pages/user/bankinfo/bankinfo'
  460. })
  461. },
  462. toAddressList () {
  463. wx.navigateTo({
  464. url: '/packageUser/pages/user/address/address'
  465. })
  466. },
  467. toRadish () {
  468. wx.navigateTo({
  469. url: '/packageUser/pages/user/radish/radish'
  470. })
  471. },
  472. toIntegral () {
  473. wx.navigateTo({
  474. url: '/packageUser/pages/user/integral/integral'
  475. })
  476. },
  477. toSafe () {
  478. wx.navigateTo({
  479. url: '/packageUser/pages/user/safe/safe'
  480. })
  481. },
  482. toCustom () {
  483. wx.reLaunch({
  484. url: '/pages/customservice/customservice'
  485. })
  486. },
  487. toProxy () {
  488. wx.navigateTo({
  489. url: '/packageUser/pages/user/proxyList/proxyList'
  490. })
  491. },
  492. toApplyLeader () {
  493. wx.navigateTo({
  494. url: '/packageUser/pages/user/applyLeader/applyLeader'
  495. })
  496. },
  497. toAreaCart () {
  498. wx.navigateTo({
  499. url: '/pages/areacart/areacart'
  500. })
  501. },
  502. toBindTel () {
  503. wx.navigateTo({
  504. url: '/packageUser/pages/user/bind/bind'
  505. })
  506. },
  507. toAbout () {
  508. var host = getApp().globalData.d5c
  509. if (host === 'tm.d5ct.com') {
  510. wx.navigateTo({
  511. url: '/pages/parse/parse?id=2'
  512. })
  513. } else if (host === 'm.d5ct.com') {
  514. wx.navigateTo({
  515. url: '/pages/parse/parse?id=1'
  516. })
  517. }
  518. },
  519. toMerchant () {
  520. wx.navigateTo({
  521. url: '/packageMerchant/pages/merchant/orders/orders?id=' + this.data.checkData.merchant_id + '&is_super_admin=' + this.data.checkData.is_super_admin
  522. })
  523. },
  524. toMerchant1 () {
  525. wx.navigateTo({
  526. url: '/packageMerchant/pages/merchant/accounts/accounts?id=' + this.data.checkData.merchant_id
  527. })
  528. },
  529. onShareAppMessage: function (val) {
  530. return _request.share({
  531. sc: 'xcx_user'
  532. })
  533. }
  534. })