MemberBase.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="div member-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. } from 'vuex'
  57. import {
  58. cartQuantity
  59. } from '../../api/homecart'
  60. export default {
  61. name: 'MemberBase',
  62. data() {
  63. return {
  64. page: '',
  65. cartNumber: 0,
  66. }
  67. },
  68. props: {
  69. show: {
  70. type: Boolean,
  71. default: true
  72. }
  73. },
  74. computed: {
  75. ...mapState({
  76. user: state => state.member.info,
  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.user) {
  95. uni.navigateTo({
  96. url: '/pages/home/memberlogin/Login?clear=1'
  97. })
  98. }
  99. this.getCartCount()
  100. },
  101. methods: {
  102. getCartCount() {
  103. if (this.isOnline) {
  104. cartQuantity().then(res => {
  105. if (res) {
  106. this.cartNumber = res.result.cart_count
  107. }
  108. })
  109. }
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .status-holder {
  116. background-color: #fff;
  117. }
  118. .member-base {
  119. /* #ifndef APP-PLUS-NVUE */
  120. display: flex;
  121. /* #endif */
  122. flex-direction: column;
  123. }
  124. .content {
  125. flex: 1
  126. }
  127. .item-wrap {
  128. position: relative
  129. }
  130. .image {
  131. width: 1rem;
  132. height: 1rem;
  133. /* #ifndef APP-PLUS-NVUE */
  134. display: block;
  135. margin-left: auto;
  136. margin-right: auto;
  137. /* #endif */
  138. margin-top: .2rem;
  139. margin-bottom: .2rem;
  140. }
  141. .icon {
  142. position: absolute;
  143. right: 0.8rem;
  144. top: 0.2rem;
  145. font-size: $h6;
  146. line-height: 0.7rem;
  147. width: 0.9rem;
  148. height: 0.7rem;
  149. background: #ef3338;
  150. border-radius: 1rem;
  151. text-align: center;
  152. color: #ffffff;
  153. }
  154. </style>