indexRouter.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view>
  3. <Home :token="token" :userInfo="userInfo" :orderStatistics="orderStatistics" v-if="nowchos === 0"
  4. :key="Math.random()"></Home>
  5. <Mine ref="mine" :token="token" :userInfo="userInfo" v-else-if="nowchos === 1"></Mine>
  6. <view class="bottomboxs">
  7. <x-navbottom :nowchos='nowchos' @botomchos='botomchos'></x-navbottom>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import Home from './home/index.vue' // 引入首页
  13. import Mine from './mine/index.vue' // 我的
  14. export default {
  15. components: { //在这里注册相应的组件
  16. Home,
  17. Mine,
  18. },
  19. data() {
  20. return {
  21. nowchos: 0, //当前选择了那个底部菜单
  22. isorders: 0,
  23. userType: 3,
  24. token: '',
  25. userInfo: {},
  26. orderStatistics: {},
  27. }
  28. },
  29. onShow() {
  30. var token = this.$cache.getToken()
  31. this.token = token
  32. var userInfo = this.$cache.getCache('userInfo')
  33. if (userInfo) {
  34. this.userInfo = userInfo
  35. } else {
  36. this.userInfo = {}
  37. }
  38. this.getUserInfo()
  39. },
  40. methods: {
  41. getUserInfo() {
  42. this.$api.get('/api/user/profile').then(res => {
  43. if (res.code == 200) {
  44. this.userInfo = res.data.user
  45. this.$cache.setCache('userInfo', this.userInfo)
  46. if (this.nowchos == 0) {
  47. this.getHomeList()
  48. }
  49. } else {
  50. this.$cache.removeToken()
  51. this.$cache.removeCache('userInfo')
  52. uni.showToast({
  53. title: '当前用户不存在',
  54. icon: 'none'
  55. });
  56. }
  57. })
  58. },
  59. // 获取订单统计
  60. getHomeList() {
  61. this.$api.get('/api/waybill/home').then(res => {
  62. if (res.code == 200) {
  63. this.orderStatistics = res.data
  64. }
  65. })
  66. },
  67. // tab
  68. botomchos(e) {
  69. const that = this
  70. if (e == 2) {
  71. that.$nextTick(() => {
  72. setTimeout(function() {
  73. that.$refs.mine.refreshTokenil()
  74. }, 100);
  75. })
  76. }
  77. uni.setStorageSync('nowchos', e);
  78. that.nowchos = e
  79. },
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .bottomboxs {
  85. position: relative;
  86. bottom: 0;
  87. z-index: 2023;
  88. height: 100rpx;
  89. }
  90. </style>