index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. console.log(this.newData)
  114. if (this.isLogin) {
  115. this.getCartNum()
  116. }
  117. },
  118. data() {
  119. return {
  120. newData: {},
  121. activeRouter: '/',
  122. footHeight: 0
  123. }
  124. },
  125. methods: {
  126. goRouter(item) {
  127. var pages = getCurrentPages();
  128. if (pages.length) {
  129. var page = (pages[pages.length - 1]).$page.fullPath;
  130. } else {
  131. page = ''
  132. }
  133. if (item.link == page) return
  134. uni.switchTab({
  135. url: item.link,
  136. fail(err) {
  137. uni.redirectTo({
  138. url: item.link
  139. })
  140. }
  141. })
  142. },
  143. getCartNum: function() {
  144. let that = this;
  145. getCartCounts().then(res => {
  146. that.cartCount = res.data.count;
  147. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '...' : res.data.count)
  148. });
  149. },
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .page-footer {
  155. position: fixed;
  156. bottom: 0;
  157. z-index: 30;
  158. display: flex;
  159. align-items: center;
  160. justify-content: space-around;
  161. width: 100%;
  162. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  163. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  164. box-sizing: border-box;
  165. border-top: solid 1rpx #F3F3F3;
  166. background-color: #fff;
  167. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  168. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  169. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  170. .foot-item {
  171. display: flex;
  172. width: max-content;
  173. align-items: center;
  174. justify-content: center;
  175. flex-direction: column;
  176. position: relative;
  177. .count-num {
  178. position: absolute;
  179. display: flex;
  180. justify-content: center;
  181. align-items: center;
  182. width: 40rpx;
  183. height: 40rpx;
  184. top: 0rpx;
  185. right: -15rpx;
  186. color: #fff;
  187. font-size: 20rpx;
  188. background-color: #FD502F;
  189. border-radius: 50%;
  190. padding: 4rpx;
  191. }
  192. }
  193. .foot-item image {
  194. height: 50rpx;
  195. width: 50rpx;
  196. text-align: center;
  197. margin: 0 auto;
  198. }
  199. .foot-item .txt {
  200. font-size: 24rpx;
  201. &.active {}
  202. }
  203. }
  204. </style>