index.vue 4.9 KB

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