all.js 14 KB

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