index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view>
  3. <view class="Tabbar savepadding">
  4. <view v-for="(item, index) in list" :key="index" class="nav-tab-item" @tap="goUrl(item.click)">
  5. <image class="nav_icon11 image" :src="channel===item.channel ?item.selectedIconPath:item.iconPath">
  6. </image>
  7. <view :class="channel===item.channel?'active':''">{{item.text}}<text class="dots"
  8. v-if="count > 0&&item.channel==='cart'">{{count}}</text></view>
  9. </view>
  10. </view>
  11. <view class="savepadding" style="height:115rpx"></view>
  12. </view>
  13. </template>
  14. <script>
  15. const app = getApp();
  16. const req = require("../../utils/request.js");
  17. import foot from "./index";
  18. export default {
  19. data() {
  20. return {
  21. bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
  22. iconSrc: req.public.iconSrc,
  23. about: {},
  24. list: [],
  25. count: ""
  26. };
  27. },
  28. components: {
  29. foot
  30. },
  31. props: {
  32. channel: {
  33. type: String,
  34. default: 'home'
  35. },
  36. isUpdate: {
  37. type: Boolean,
  38. default: false
  39. },
  40. productType: {
  41. type: Number,
  42. default: 0
  43. }
  44. },
  45. watch: {
  46. "isUpdate": function(isUpdate) {
  47. // console.log('需要更新消息', isUpdate);
  48. if (!this.isReady) return;
  49. this.getCount();
  50. }
  51. },
  52. mounted() {
  53. // console.log('ready');
  54. this.isReady = true;
  55. this.getCount();
  56. this.getTab();
  57. },
  58. methods: {
  59. getCount() {
  60. // console.log(this.productType);
  61. let from = {};
  62. if (this.productType == 2) {
  63. from.purchaseType = 2;
  64. } else {
  65. from.purchaseType = 1;
  66. }
  67. // req.getRequest('/api/purchase/count', from, res => {
  68. // this.setData({
  69. // count: res
  70. // });
  71. // });
  72. },
  73. // 获取tab导航
  74. getTab() {
  75. // console.log(req.tab); // 过滤关闭的tab
  76. let data = req.tab.filter(it => it.show == true); // 排序更换位置
  77. // console.log(data.sort(this.compare('index')))
  78. this.setData({
  79. list: data.sort(this.compare('index'))
  80. }); // console.log(data.sort(this.compare('index')))
  81. },
  82. // 排序
  83. compare(property) {
  84. return function(a, b) {
  85. var value1 = a[property];
  86. var value2 = b[property];
  87. return value1 - value2;
  88. };
  89. },
  90. /**
  91. * 跳转
  92. */
  93. // goUrl: function(e) {
  94. // // console.log(e)
  95. // if (e == "goShop") {
  96. // this.goShop()
  97. // }
  98. // if (e == "goHome") {
  99. // this.goHome()
  100. // }
  101. // if (e == "goSort") {
  102. // this.goSort()
  103. // }
  104. // if (e == "goInteractive") {
  105. // this.goInteractive()
  106. // }
  107. // if (e == "goLive") {
  108. // this.goLive()
  109. // }
  110. // if (e == "goCart") {
  111. // this.goCart()
  112. // }
  113. // if (e == "goUser") {
  114. // this.goUser()
  115. // }
  116. // },
  117. goUrl: function(e) {
  118. console.log(e)
  119. for(var i=0; i<this.list.length; i++){
  120. let item = this.list[i]
  121. if (e == item.click) {
  122. if (this.channel === item.channel) return;
  123. uni.switchTab({
  124. url:'/'+item.pagePath
  125. })
  126. return false
  127. }
  128. }
  129. },
  130. goHome: function() {
  131. if (this.channel === "home") return;
  132. app.globalData.switchTab('pages/index/index');
  133. },
  134. goSort: function() {
  135. if (this.channel === "sort") return;
  136. app.globalData.switchTab('pages/sort/sort');
  137. },
  138. goInteractive: function() {
  139. if (this.channel === "interactive") return;
  140. app.globalData.switchTab('pages/interactive/index');
  141. },
  142. goLive: function() {
  143. if (this.channel === "live") return;
  144. app.globalData.switchTab('pages/live/live');
  145. },
  146. goCart: function() {
  147. if (this.channel === "cart") return;
  148. app.globalData.switchTab('pages/cart/cart');
  149. },
  150. goUser: function() {
  151. if (this.channel === "user") return;
  152. app.globalData.switchTab('pages/user/user');
  153. },
  154. goShop: function() {
  155. if (this.channel === "shop") return;
  156. app.globalData.switchTab('pages/timelyDelivery/index');
  157. }
  158. }
  159. };
  160. </script>
  161. <style>
  162. @import "./index.css";
  163. </style>