HomeBase.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="div home-base">
  3. <view class="status-holder"></view>
  4. <view class="content">
  5. <slot></slot>
  6. </view>
  7. <view v-if="show" class='div common-footer-wrap'>
  8. <view class="common-footer">
  9. <view class='item-wrap' :class="{'active':page.route=='pages/home/index/Index'}">
  10. <navigator url="/pages/home/index/Index" open-type="reLaunch" class='item'>
  11. <image mode="aspectFit" src="@/static/image/tab/icon_home_pre.png" class="img image"
  12. v-if="page.route=='pages/home/index/Index'">
  13. <image mode="aspectFit" v-else src="@/static/image/tab/icon_home_nor.png" class="img image" /><text
  14. class='span text'>首页</text>
  15. </navigator>
  16. </view>
  17. <view class='item-wrap' :class="{'active':page.route=='pages/home/goodsclass/Goodsclass'}">
  18. <navigator url="/pages/home/goodsclass/Goodsclass" class='item'>
  19. <image mode="aspectFit" src="@/static/image/tab/icon_classify_pre.png" class="img image"
  20. v-if="page.route=='pages/home/goodsclass/Goodsclass'">
  21. <image mode="aspectFit" v-else src="@/static/image/tab/icon_classify_nor.png" class="img image" /><text
  22. class='span text'>分类</text>
  23. </navigator>
  24. </view>
  25. <view class='item-wrap' :class="{'active':page.route=='pages/home/search/Search'}">
  26. <navigator url="/pages/home/search/Search" class='item'>
  27. <image mode="aspectFit" src="@/static/image/tab/icon_seek_pre.png" class="img image"
  28. v-if="page.route=='pages/home/search/Search'">
  29. <image mode="aspectFit" v-else src="@/static/image/tab/icon_seek_nor.png" class="img image" /><text
  30. class='span text'>搜索</text>
  31. </navigator>
  32. </view>
  33. <view class='item-wrap' :class="{'active':page.route=='pages/member/cart/Cart'}">
  34. <navigator url="/pages/member/cart/Cart" class='item'>
  35. <image mode="aspectFit" src="@/static/image/tab/icon_shopping_pre.png" class="img image"
  36. v-if="page.route=='pages/member/cart/Cart'">
  37. <image mode="aspectFit" v-else src="@/static/image/tab/icon_shopping_nor.png" class="img image" /><text
  38. class='span text'>购物车</text><text class="span icon" v-if="cartNumber > 0">{{ getCarCount }}</text>
  39. </navigator>
  40. </view>
  41. <view class='item-wrap' :class="{'active':page.route=='pages/member/index/Index'}">
  42. <navigator url="/pages/member/index/Index" open-type="reLaunch" class='item'>
  43. <image mode="aspectFit" src="@/static/image/tab/icon_mine_pre.png" class="img image"
  44. v-if="page.route=='pages/member/index/Index'">
  45. <image mode="aspectFit" v-else src="@/static/image/tab/icon_mine_nor.png" class="img image" /><text
  46. class='span text'>我的</text>
  47. </navigator>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. mapState,
  56. mapMutations
  57. } from 'vuex'
  58. import {
  59. cartQuantity
  60. } from '../../api/homecart'
  61. export default {
  62. name: 'HomeBase',
  63. data() {
  64. return {
  65. page: '',
  66. cartNumber: 0,
  67. }
  68. },
  69. props: {
  70. show: {
  71. type: Boolean,
  72. default: true
  73. }
  74. },
  75. computed: {
  76. ...mapState({
  77. isOnline: state => state.member.isOnline,
  78. }),
  79. getCarCount() {
  80. if (this.cartNumber > 0 && this.cartNumber < 100) {
  81. return this.cartNumber
  82. } else if (this.cartNumber >= 100) {
  83. return '99+'
  84. }
  85. }
  86. },
  87. mounted: function() {
  88. var pages = getCurrentPages()
  89. var page = pages[pages.length - 1]
  90. this.page = {
  91. route: page.route,
  92. options: page.options
  93. }
  94. if (this.page.options && this.page.options.inviter_id) {
  95. this.memberInviterId({
  96. inviterId: this.page.options.inviter_id
  97. })
  98. }
  99. this.getCartCount()
  100. },
  101. methods: {
  102. ...mapMutations({
  103. memberInviterId: 'memberInviterId'
  104. }),
  105. getCartCount() {
  106. if (this.isOnline) {
  107. cartQuantity().then(res => {
  108. if (res) {
  109. this.cartNumber = res.result.cart_count
  110. }
  111. })
  112. }
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. .status-holder {
  119. background-color: #fff;
  120. }
  121. .home-base {
  122. display: flex;
  123. flex-direction: column;
  124. }
  125. .content {
  126. flex: 1
  127. }
  128. .item-wrap {
  129. position: relative
  130. }
  131. .image {
  132. width: 1rem;
  133. height: 1rem;
  134. display: block;
  135. margin-left: auto;
  136. margin-right: auto;
  137. margin-top: .2rem;
  138. margin-bottom: .2rem;
  139. }
  140. .icon {
  141. position: absolute;
  142. right: 0.8rem;
  143. top: 0.2rem;
  144. font-size: $h6;
  145. line-height: 0.7rem;
  146. width: 0.9rem;
  147. height: 0.7rem;
  148. background: #ef3338;
  149. border-radius: 1rem;
  150. text-align: center;
  151. color: #ffffff;
  152. }
  153. </style>