all.js 12 KB

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