indexRouter.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.orderStatistics = {}
  51. this.$cache.removeToken()
  52. this.$cache.removeCache('userInfo')
  53. uni.showToast({
  54. title: '当前用户不存在',
  55. icon: 'none'
  56. });
  57. }
  58. })
  59. },
  60. // 获取运单统计
  61. getHomeList() {
  62. this.$api.get('/api/waybill/home').then(res => {
  63. if (res.code == 200) {
  64. this.orderStatistics = res.data
  65. }
  66. })
  67. },
  68. // tab
  69. botomchos(e) {
  70. const that = this
  71. if (e == 2) {
  72. that.$nextTick(() => {
  73. setTimeout(function() {
  74. that.$refs.mine.refreshTokenil()
  75. }, 100);
  76. })
  77. }
  78. uni.setStorageSync('nowchos', e);
  79. that.nowchos = e
  80. },
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .bottomboxs {
  86. position: relative;
  87. bottom: 0;
  88. z-index: 2023;
  89. height: 100rpx;
  90. }
  91. </style>