index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (C) 2018-2019
  3. * All rights reserved, Designed By www.joolun.com
  4. * 注意:
  5. * 本软件为www.joolun.com开发研制,项目使用请保留此说明
  6. */
  7. const app = getApp()
  8. Page({
  9. data: {
  10. config: app.globalData.config,
  11. wxUser: null,
  12. userInfo: null,
  13. orderCountAll: []
  14. },
  15. onShow(){
  16. //更新tabbar购物车数量
  17. wx.setTabBarBadge({
  18. index: 2,
  19. text: app.globalData.shoppingCartCount + ''
  20. })
  21. let wxUser = app.globalData.wxUser
  22. this.setData({
  23. wxUser: wxUser
  24. })
  25. this.wxUserGet()
  26. this.orderCountAll()
  27. if(this.data.config.adEnable){
  28. // 在页面中定义插屏广告
  29. let interstitialAd = null
  30. // 在页面onLoad回调事件中创建插屏广告实例
  31. if (wx.createInterstitialAd) {
  32. interstitialAd = wx.createInterstitialAd({
  33. adUnitId: this.data.config.adInsertScreenID
  34. })
  35. interstitialAd.onLoad(() => { })
  36. interstitialAd.onError((err) => { })
  37. interstitialAd.onClose(() => { })
  38. }
  39. // 在适合的场景显示插屏广告
  40. if (interstitialAd) {
  41. interstitialAd.show().catch((err) => {
  42. console.error(err)
  43. })
  44. }
  45. }
  46. },
  47. onLoad(){
  48. },
  49. /**
  50. * 小程序设置
  51. */
  52. settings: function () {
  53. wx.openSetting({
  54. success: function (res) {
  55. console.log(res.authSetting)
  56. }
  57. })
  58. },
  59. getUserProfile(e) {
  60. wx.getUserProfile({
  61. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  62. success: (detail) => {
  63. app.api.wxUserSave(detail)
  64. .then(res => {
  65. let wxUser = res.data
  66. this.setData({
  67. wxUser: wxUser
  68. })
  69. app.globalData.wxUser = wxUser
  70. this.wxUserGet()
  71. })
  72. }
  73. })
  74. },
  75. //获取商城用户信息
  76. wxUserGet(){
  77. app.api.wxUserGet()
  78. .then(res => {
  79. this.setData({
  80. userInfo: res.data
  81. })
  82. })
  83. },
  84. orderCountAll(){
  85. app.api.orderCountAll()
  86. .then(res => {
  87. this.setData({
  88. orderCountAll: res.data
  89. })
  90. })
  91. }
  92. })