index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="content" :style="{ paddingBottom: isIphoneX ? '140rpx' : '98rpx' }">
  3. <!-- 采美采购商城 -->
  4. <view :style="{ display: show_index == 0 ? 'block' : 'none' }">
  5. <supplier-home ref="home" v-if="isHomeData"></supplier-home>
  6. </view>
  7. <!-- 商品分类 -->
  8. <view :style="{ display: show_index == 1 ? 'block' : 'none' }">
  9. <supplier-category ref="category" v-if="isCategory"></supplier-category>
  10. </view>
  11. <!-- 通知消息 -->
  12. <view :style="{ display: show_index == 2 ? 'block' : 'none' }">
  13. <supplier-notice ref="notice" v-if="isNotice"></supplier-notice>
  14. </view>
  15. <!-- 账户中心 -->
  16. <view :style="{ display: show_index == 3 ? 'flex' : 'none' }">
  17. <supplier-user ref="user" v-if="isUserData"></supplier-user>
  18. </view>
  19. <!-- isIphoneX判断是否为刘海屏在main.js里,好像uniapp有一个css变量获取刘海屏的安全区域 -->
  20. <view class="tabBar" :style="{ height: isIphoneX ? '140rpx' : '98rpx' }">
  21. <!-- 导航的中间圆圈 -->
  22. <view class="tabBar_list" :style="{ paddingBottom: isIphoneX ? '40rpx' : '' }">
  23. <view v-for="item in tab_nav_list" :key="item.id" class="tabBar_item" @tap="cut_index(item.id)">
  24. <image v-if="show_index == item.id" :src="item.iconAc"></image>
  25. <image v-else :src="item.icon"></image>
  26. <view
  27. v-if="item.id == 2 && upNum > 0"
  28. class="uni-badge uni-badge-error uni-small uni-badge--small icon-num "
  29. >
  30. {{ upNum | BadgeType }}
  31. </view>
  32. <view :class="{ tabBar_name: true, nav_active: show_index == item.id }">{{ item.name }}</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import supplierHome from '@/components/cm-module/supplier/home.vue'
  40. import supplierUser from '@/components/cm-module/supplier/user.vue'
  41. import supplierNotice from '@/components/cm-module/supplier/notice.vue'
  42. import supplierCategory from '@/components/cm-module/supplier/category.vue'
  43. export default {
  44. components: {
  45. supplierHome, //采美采购商城 0
  46. supplierUser, //账户中心 1
  47. supplierNotice, //通知消息 2
  48. supplierCategory //商品分类 3
  49. },
  50. data() {
  51. return {
  52. show_index: 3, //控制显示那个组件
  53. isUserData: false,
  54. isCategory: false,
  55. isNotice: false,
  56. isHomeData: false,
  57. isIphoneX: this.$store.state.isIphone,
  58. tab_nav_list: [
  59. //菜单列表
  60. {
  61. id: 0,
  62. name: '首页',
  63. icon: 'https://static.caimei365.com/app/img/icon/icon-home@3x.png',
  64. iconAc: 'https://static.caimei365.com/app/img/icon/icon-home-active@3x.png'
  65. },
  66. {
  67. id: 1,
  68. name: '分类',
  69. icon: 'https://static.caimei365.com/app/img/icon/icon-sort@3x.png',
  70. iconAc: 'https://static.caimei365.com/app/img/icon/icon-sort-active@3x.png'
  71. },
  72. {
  73. id: 2,
  74. name: '消息',
  75. icon: 'https://static.caimei365.com/app/img/icon/icon-news@3x.png',
  76. iconAc: 'https://static.caimei365.com/app/img/icon/icon-news-active@3x.png'
  77. },
  78. {
  79. id: 3,
  80. name: '我的',
  81. icon: 'https://static.caimei365.com/app/img/icon/icon-user@3x.png',
  82. iconAc: 'https://static.caimei365.com/app/img/icon/icon-user-active@3x.png'
  83. }
  84. ],
  85. nvabarData: {
  86. //顶部自定义导航
  87. showCapsule: 0, // 是否显示左上角图标 1表示显示 0表示不显示,
  88. showSearch: 0,
  89. title: '账户中心', // 导航栏 中间的标题
  90. textLeft: false
  91. },
  92. upNum:0,
  93. isIphoneX: this.$store.state.isIphoneX,
  94. CustomBar: this.CustomBar // 顶部导航栏高度
  95. }
  96. },
  97. filters: {
  98. BadgeType(value) {
  99. if(value){return value > 99 ? '99+' : value}
  100. }
  101. },
  102. onLoad() {
  103. this.$nextTick(() => {
  104. // 一定要等视图更新完再调用方法
  105. setTimeout(() => {
  106. this.isUserData = true
  107. this.initData();
  108. }, 100)
  109. })
  110. },
  111. methods: {
  112. async initData() {
  113. const userInfo = await this.$api.getStorage()
  114. this.upNum = userInfo.savedCount
  115. },
  116. // 切换组件
  117. cut_index(type) {
  118. this.show_index = type
  119. if (this.show_index == 0) {
  120. this.isHomeData = true
  121. this.isUserData = false
  122. this.isNotice = false
  123. this.isCategory = false
  124. } else if (this.show_index == 1) {
  125. this.isHomeData = false
  126. this.isUserData = false
  127. this.isNotice = false
  128. this.isCategory = true
  129. } else if(this.show_index == 2){
  130. this.isHomeData = false
  131. this.isUserData = false
  132. this.isNotice = true
  133. this.isCategory = false
  134. }else if (this.show_index == 3) {
  135. this.isHomeData = false
  136. this.isNotice = false
  137. this.isUserData = true
  138. this.isCategory = false
  139. }
  140. },
  141. onPullDownRefresh() {
  142. if (this.show_index == 0) {
  143. this.$refs.home.getHomeInformation()
  144. } else if(this.show_index == 2){
  145. this.$refs.notice.initGetList()
  146. }else if (this.show_index == 3) {
  147. this.$refs.user.initData()
  148. }
  149. uni.stopPullDownRefresh()
  150. }
  151. },
  152. onShareAppMessage(res) {
  153. //分享转发
  154. if (res.from === 'button') {
  155. // 来自页面内转发按钮
  156. }
  157. return {
  158. title: '生美医美正品采购服务平台',
  159. path: 'pages/tabBar/home/index',
  160. imageUrl: 'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss">
  166. .tabBar {
  167. width: 100%;
  168. height: 98rpx;
  169. background: #fff;
  170. border-top: 1px solid #e5e5e5;
  171. position: fixed;
  172. bottom: 0px;
  173. left: 0px;
  174. right: 0px;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. z-index: 999;
  179. .tabBar_list {
  180. width: 86%;
  181. display: flex;
  182. justify-content: space-between;
  183. image {
  184. width: 48rpx;
  185. height: 48rpx;
  186. margin-bottom: 2rpx;
  187. }
  188. .tabBar_item {
  189. width: 150rpx;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. flex-direction: column;
  194. font-size: 20rpx;
  195. color: #999999;
  196. position: relative;
  197. .icon-num {
  198. position: absolute;
  199. right: 10rpx;
  200. top: -9rpx;
  201. }
  202. }
  203. }
  204. }
  205. .nav_active {
  206. color: $color-system;
  207. }
  208. </style>