index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view>
  3. <view v-if="newData" class="page-footer" id="target">
  4. <view class="foot-item" v-for="(item,index) in newData.menuList" :key="index" @click="goRouter(item)"
  5. :style="{'background-color':newData.bgColor.color[0].item}">
  6. <block v-if="item.link == activeRouter">
  7. <image :src="item.imgList[0]"></image>
  8. <view class="txt" :style="{color:newData.activeTxtColor.color[0].item}">{{item.name}}</view>
  9. </block>
  10. <block v-else>
  11. <image :src="item.imgList[1]"></image>
  12. <view class="txt" :style="{color:newData.txtColor.color[0].item}">{{item.name}}</view>
  13. </block>
  14. <div class="count-num" v-if="item.link === '/pages/order_addcart/order_addcart' && cartNum>0">
  15. {{cartNum > 99 ? '99+' : cartNum}}
  16. </div>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. mapState,
  24. mapGetters
  25. } from "vuex"
  26. import {
  27. getNavigation
  28. } from '@/api/public.js'
  29. import {
  30. getCartCounts,
  31. } from '@/api/order.js';
  32. export default {
  33. name: 'pageFooter',
  34. props: {
  35. status: {
  36. type: Number | String,
  37. default: 1
  38. },
  39. countNum: {
  40. type: Number | String,
  41. default: 0
  42. },
  43. },
  44. data() {
  45. return {
  46. newData: undefined
  47. }
  48. },
  49. computed: {
  50. ...mapState({
  51. configData: state => state.app.pageFooter
  52. })
  53. },
  54. computed: mapGetters(['isLogin', 'cartNum']),
  55. watch: {
  56. configData: {
  57. handler(nVal, oVal) {
  58. let self = this
  59. const query = uni.createSelectorQuery().in(this);
  60. this.newData = nVal
  61. this.$nextTick(() => {
  62. query.select('#target').boundingClientRect(data => {
  63. uni.$emit('footHeight', data.height)
  64. if (data) {
  65. self.footHeight = data.height + 50
  66. }
  67. }).exec();
  68. })
  69. },
  70. deep: true
  71. },
  72. },
  73. created() {
  74. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  75. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  76. this.activeRouter = '/' + curRoute
  77. },
  78. onShow() {
  79. },
  80. mounted() {
  81. getNavigation().then(res => {
  82. uni.setStorageSync('pageFoot', res.data)
  83. this.$store.commit('FOOT_UPLOAD', res.data)
  84. this.newData = res.data
  85. })
  86. let that = this
  87. uni.hideTabBar()
  88. console.log(this.cartNum, 'cartNum')
  89. this.newData = this.$store.state.app.pageFooter
  90. if (this.isLogin) {
  91. this.getCartNum()
  92. }
  93. },
  94. data() {
  95. return {
  96. newData: {},
  97. activeRouter: '/',
  98. footHeight: 0
  99. }
  100. },
  101. methods: {
  102. goRouter(item) {
  103. var pages = getCurrentPages();
  104. var page = (pages[pages.length - 1]).$page.fullPath;
  105. if (item.link == page) return
  106. uni.switchTab({
  107. url: item.link,
  108. fail(err) {
  109. uni.redirectTo({
  110. url: item.link
  111. })
  112. }
  113. })
  114. },
  115. getCartNum: function() {
  116. let that = this;
  117. getCartCounts().then(res => {
  118. that.cartCount = res.data.count;
  119. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '...' : res.data.count)
  120. });
  121. },
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .page-footer {
  127. position: fixed;
  128. bottom: 0;
  129. z-index: 30;
  130. display: flex;
  131. align-items: center;
  132. justify-content: space-around;
  133. width: 100%;
  134. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  135. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  136. box-sizing: border-box;
  137. border-top: solid 1rpx #F3F3F3;
  138. background-color: #fff;
  139. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  140. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  141. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  142. .foot-item {
  143. display: flex;
  144. width: max-content;
  145. align-items: center;
  146. justify-content: center;
  147. flex-direction: column;
  148. position: relative;
  149. width: 100%;
  150. height: 100%;
  151. .count-num {
  152. position: absolute;
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. width: 40rpx;
  157. height: 40rpx;
  158. top: 0rpx;
  159. right: calc(50% - 55rpx);
  160. color: #fff;
  161. font-size: 20rpx;
  162. background-color: #FD502F;
  163. border-radius: 50%;
  164. padding: 4rpx;
  165. }
  166. }
  167. .foot-item image {
  168. height: 50rpx;
  169. width: 50rpx;
  170. text-align: center;
  171. margin: 0 auto;
  172. }
  173. .foot-item .txt {
  174. font-size: 24rpx;
  175. &.active {}
  176. }
  177. }
  178. </style>