all.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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){
  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 == '' && that.data.checkhead){
  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. },
  239. getVersion: function (val) {
  240. // this.check()
  241. },
  242. info(){
  243. console.log('oninfo');
  244. var that = this
  245. var url = 'v1/user/info'
  246. var params = {}
  247. var success = function (res) {
  248. console.log(res)
  249. that.setData({
  250. info: res.data,
  251. show: res.data.wx_user?res.data.wx_user.show_invite_mode:'',
  252. bindTel: res.data.user.tel ? true : false
  253. })
  254. console.log('untel',res.data.user.tel)
  255. if(that.data.userInfo != 'nologin' && res.data.user.tel == '' && that.data.bindTelfirst == 0){
  256. that.setData({
  257. bindTelfirst:1
  258. })
  259. wx.navigateTo({
  260. url: '/packageUser/pages/user/bind/bind'
  261. })
  262. wx.showToast({
  263. title: '请先绑定手机号~',
  264. icon: 'none',
  265. duration: 2000
  266. })
  267. }
  268. }
  269. _request.$get(url, params, success)
  270. },
  271. check () {
  272. var that = this
  273. var url = 'v1/user/check'
  274. var params = {
  275. cache: false
  276. }
  277. var success = function (res) {
  278. if (res.data.wx_user_id <= 0) {
  279. wx.login({
  280. success: res => {
  281. _request.login(res)
  282. }
  283. })
  284. } else {
  285. that.setData({
  286. checkData: res.data
  287. })
  288. if (that.data.checkData.merchant_id > 0) {
  289. that.getmerchant()
  290. }
  291. if (res.data.user_id > 0 && !that.data.bindTel) {
  292. // that.setData({
  293. // bindTel: true
  294. // })
  295. that.getBalanceInfo()
  296. that.getIntegralInfo()
  297. that.info()
  298. }
  299. }
  300. }
  301. _request.$get(url, params, success)
  302. },
  303. buyVoucher(){
  304. if(this.data.info.user.tel == ''){//未绑定手机号
  305. wx.navigateTo({
  306. url: '/packageUser/pages/user/bind/bind'
  307. })
  308. wx.showToast({
  309. title: '请先绑定手机号~',
  310. icon: 'none',
  311. duration: 2000
  312. })
  313. //2020
  314. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/buy/buy'); //存入手机绑定后跳转页面
  315. }else{
  316. wx.navigateTo({
  317. url: '/packageUser/pages/user/buy/buy'
  318. })
  319. }
  320. },
  321. getmerchant () {
  322. var that = this
  323. var url = 'v1/merchant/orders/count'
  324. var params = {
  325. merchant_id: that.data.checkData.merchant_id
  326. }
  327. var success = function (res) {
  328. var result = res.data
  329. that.setData({
  330. merchant: result
  331. })
  332. console.log(that.data.merchant)
  333. }
  334. _request.$get(url, params, success)
  335. },
  336. getBalanceInfo () {
  337. var that = this
  338. var url = 'v1/user/balance/info'
  339. var params = {
  340. }
  341. var success = function (res) {
  342. var result = res.data.total
  343. that.setData({
  344. balance: result
  345. })
  346. }
  347. _request.$get(url, params, success)
  348. },
  349. getIntegralInfo () {
  350. var that = this
  351. var url = 'v1/user/cent/info'
  352. var params = {
  353. }
  354. var success = function (res) {
  355. var result = res.data.total
  356. that.setData({
  357. integral: result
  358. })
  359. }
  360. _request.$get(url, params, success)
  361. },
  362. toInviteList () {
  363. var that = this;
  364. if(that.data.info.user.tel == ''){
  365. wx.navigateTo({
  366. url: '/packageUser/pages/user/bind/bind'
  367. })
  368. wx.showToast({
  369. title: '请先绑定手机号~',
  370. icon: 'none',
  371. duration: 2000
  372. })
  373. }else{
  374. wx.navigateTo({
  375. url: '/packageUser/pages/user/invite/invite'
  376. })
  377. }
  378. },
  379. // checkbindtel(){
  380. // var that = this;
  381. // if(that.data.info.user.tel == ''){
  382. // setTimeout(function(){
  383. // wx.navigateTo({
  384. // url: '/packageUser/pages/user/bind/bind'
  385. // })
  386. // wx.showToast({
  387. // title: '请先绑定手机号~',
  388. // icon: 'none',
  389. // duration: 2000
  390. // })
  391. // },500)
  392. // }
  393. // },
  394. toCashList () {
  395. if(this.data.info.user.tel == ''){//未绑定手机号
  396. wx.navigateTo({
  397. url: '/packageUser/pages/user/bind/bind'
  398. })
  399. wx.showToast({
  400. title: '请先绑定手机号~',
  401. icon: 'none',
  402. duration: 2000
  403. })
  404. //2020
  405. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/fund/fund'); //存入手机绑定后跳转页面
  406. }else{
  407. wx.navigateTo({
  408. url: '/packageUser/pages/user/fund/fund'
  409. })
  410. }
  411. },
  412. toUserInfo() {
  413. wx.navigateTo({
  414. url: '/packageUser/pages/user/userInfo/userInfo'
  415. })
  416. },
  417. toBindOldSys () {
  418. let that = this;
  419. wx.navigateTo({
  420. url: '/packageUser/pages/user/bindoldsys/bindoldsys?id='+that.data.userInfo.id
  421. })
  422. },
  423. toPromotion () {
  424. wx.navigateTo({
  425. url: '/packageUser/pages/user/promotion/promotion'
  426. })
  427. },
  428. toIdentity () {
  429. wx.navigateTo({
  430. url: '/packageUser/pages/user/identity/identity'
  431. })
  432. },
  433. toBankInfo () {
  434. wx.navigateTo({
  435. url: '/packageUser/pages/user/bankinfo/bankinfo'
  436. })
  437. },
  438. toAddressList () {
  439. wx.navigateTo({
  440. url: '/packageUser/pages/user/address/address'
  441. })
  442. },
  443. toRadish () {
  444. wx.navigateTo({
  445. url: '/packageUser/pages/user/radish/radish'
  446. })
  447. },
  448. toIntegral () {
  449. wx.navigateTo({
  450. url: '/packageUser/pages/user/integral/integral'
  451. })
  452. },
  453. toSafe () {
  454. wx.navigateTo({
  455. url: '/packageUser/pages/user/safe/safe'
  456. })
  457. },
  458. toCustom () {
  459. wx.reLaunch({
  460. url: '/pages/customservice/customservice'
  461. })
  462. },
  463. toProxy () {
  464. wx.navigateTo({
  465. url: '/packageUser/pages/user/proxyList/proxyList'
  466. })
  467. },
  468. toApplyLeader () {
  469. wx.navigateTo({
  470. url: '/packageUser/pages/user/applyLeader/applyLeader'
  471. })
  472. },
  473. toAreaCart () {
  474. wx.navigateTo({
  475. url: '/pages/areacart/areacart'
  476. })
  477. },
  478. toBindTel () {
  479. wx.navigateTo({
  480. url: '/packageUser/pages/user/bind/bind'
  481. })
  482. },
  483. toAbout () {
  484. var host = getApp().globalData.d5c
  485. if (host === 'tm.d5ct.com') {
  486. wx.navigateTo({
  487. url: '/pages/parse/parse?id=2'
  488. })
  489. } else if (host === 'm.d5ct.com') {
  490. wx.navigateTo({
  491. url: '/pages/parse/parse?id=1'
  492. })
  493. }
  494. },
  495. toMerchant () {
  496. wx.navigateTo({
  497. url: '/packageMerchant/pages/merchant/orders/orders?id=' + this.data.checkData.merchant_id + '&is_super_admin=' + this.data.checkData.is_super_admin
  498. })
  499. },
  500. toMerchant1 () {
  501. wx.navigateTo({
  502. url: '/packageMerchant/pages/merchant/accounts/accounts?id=' + this.data.checkData.merchant_id
  503. })
  504. },
  505. onShareAppMessage: function (val) {
  506. return _request.share({
  507. sc: 'xcx_user'
  508. })
  509. }
  510. })