all.js 13 KB

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