all.js 13 KB

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