cat-search.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template name="headerNavbar">
  2. <!-- 自定义导航栏 -->
  3. <view class='navbar-wrap' :style="{height:navbarHeight+'px',paddingTop:statusBarHeight+'px'}"> 
  4. <view class="navbar-text" :style="{top:navbarBtn.top + statusBarHeight+'px;',height:navbarBtn.height+'px;',fontSize:fontSizeSetting+'px;'}">
  5.     <view class="gosearch-btn" :style="{paddingLeft:navbarBtn.height+'px;',left:navbarBtn.height/2+'px;',borderRadius:(navbarBtn.height/2)+'px;',width:(375-navbarBtn.width)-20+'px;',lineHeight:navbarBtn.height+'px;'}">
  6. <text class="iconfont icon-sousuo" :style="{width:navbarBtn.height+'px;',height:navbarBtn.height+'px;',lineHeight:navbarBtn.height+'px;'}"></text>
  7. <view class="input" @click="this.$api.navigateTo(clickPath)">搜索商品/供应商/项目仪器</view>
  8. </view>
  9.   </view>
  10. <view class="category-tab">
  11. <view class="category-tab-item" :class="categoryTabIndex ==1 ? 'active' : ''" @click="categoryTabClick(1)">产品</view>
  12. <view class="category-tab-item" :class="categoryTabIndex ==2 ? 'active' : ''" @click="categoryTabClick(2)">仪器</view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. var self;
  18. export default{
  19. name:'headerNavbar',
  20. props:{
  21. navbarData: { // 由父页面传递的数据
  22. type: Object
  23. },
  24. systeminfo:{
  25. type:Object
  26. },
  27. headerBtnPosi:{
  28. type:Object
  29. },
  30. page:{
  31. type:Number
  32. },
  33. headerTitle:{
  34. type:String
  35. },
  36. type:{
  37. type:String
  38. },
  39. },
  40. data() {
  41. return{
  42. headerType:'',
  43. clickPath:'/search/pages/search/search',
  44. haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  45.     statusBarHeight: 0, // 状态栏高度
  46.     navbarHeight: 0, // 顶部导航栏高度,
  47.     navbarBtn: { // 胶囊位置信息
  48.       height: 0,
  49.       width: 0,
  50.       top: 0,
  51.       bottom: 0,
  52.       right: 0
  53. },
  54. platform:'',
  55. fontSizeSetting:0,
  56. categoryTabIndex:1
  57. }
  58. },
  59. created() {
  60. this.headerType = this.type
  61. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  62. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  63. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  64.     /**
  65.      * wx.getMenuButtonBoundingClientRect() 坐标信息以屏幕左上角为原点
  66.      * 菜单按键宽度: 87
  67.      * 菜单按键高度: 32
  68.      * 菜单按键左边界坐标: 278
  69.      * 菜单按键上边界坐标: 26
  70.      * 菜单按键右边界坐标: 365
  71.      * 菜单按键下边界坐标: 58
  72.      */
  73. let btnPosi = { // 胶囊实际位置,坐标信息不是左上角原点
  74.       height: headerPosi.height,
  75.       width: headerPosi.width,
  76.       // 胶囊top - 状态栏高度
  77.       top: headerPosi.top - statusBarHeight,
  78.       // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  79.       bottom: headerPosi.bottom - headerPosi.height - statusBarHeight,
  80.       // 屏幕宽度 - 胶囊right
  81.       right: this.systeminfo.screenWidth - headerPosi.right
  82. }
  83. console.log(btnPosi)
  84. let haveBack;
  85. if (getCurrentPages().length === 1) { // 当只有一个页面时
  86.      haveBack = false;
  87. } else {
  88.      haveBack = true;
  89. }
  90.     this.haveBack=haveBack, // 获取是否是通过分享进入的小程序
  91.     this.statusBarHeight=statusBarHeight,
  92.     this.navbarHeight= headerPosi.bottom + btnPosi.bottom, // 原胶囊bottom + 现胶囊bottom
  93. this.$parent.navbarHeight = this.navbarHeight
  94. this.$parent.statusBarHeight = this.statusBarHeight
  95. // console.log(this.navbarHeight);
  96.     this.navbarBtn=btnPosi
  97. },
  98. onLoad(){
  99. },
  100. methods:{
  101. _goBack: function () {
  102.       uni.navigateBack({
  103.         delta: this.page
  104.       });
  105.     },
  106.     _goHome: function () {
  107.       uni.switchTab({
  108.         url: '/pages/tabBar/home/index'
  109.       })
  110.     },
  111. categoryTabClick(index){
  112. this.categoryTabIndex = index
  113. this.$emit('click',this.categoryTabIndex)
  114. },
  115. },
  116. onShow(){
  117. }
  118. }
  119. </script>
  120. <style lang="scss">
  121. .navbar-wrap {
  122. position: fixed;
  123. width: 100%;
  124. top: 0;
  125. z-index: 100000;
  126. background-color: #FFFFFF;
  127. box-sizing: border-box;
  128. &.bg-color{
  129. animation: showColor 0.3s ease-in-out both;
  130. }
  131. &.no-color{
  132. animation: hideColor 0.3s ease-in-out both;
  133. }
  134. }
  135. .navbar-text {
  136. width: 100%;
  137. color: #000000;
  138. font-weight: 500;
  139. position: fixed;
  140. }
  141. .gosearch-btn{
  142. height: 100%;
  143. background: rgba(255, 255, 255, 0.6);
  144. font-size: 28rpx;
  145. color: #999999;
  146. position: relative;
  147. box-sizing: border-box;
  148. position:absolute ;
  149. top: 0;
  150. border: 0.5px solid rgba(0, 0, 0, 0.1);
  151. .icon-sousuo{
  152. height: 100%;
  153. text-align: center;
  154. display: block;
  155. position: absolute;
  156. left: 0;
  157. top: 0;
  158. font-size: 34rpx;
  159. color: #999999;
  160. z-index: 10;
  161. }
  162. .input{
  163. height: 100%;
  164. float: left;
  165. font-size: $font-size-24;
  166. text-align: left;
  167. }
  168. }
  169. .category-tab{
  170. width: 100%;
  171. height: 76rpx;
  172. display: flex;
  173. border-bottom: 1px solid #EEE;
  174. position: absolute;
  175. bottom: -76rpx;
  176. background-color: #FFFFFF;
  177. .category-tab-item{
  178. flex: 1;
  179. font-size: $font-size-30;
  180. line-height: 76rpx;
  181. text-align: center;
  182. color: #93979f;
  183. position: relative;
  184. &::before{
  185. content: '';
  186. width:57rpx;
  187. height: 4rpx;
  188. background-color: #FFF;
  189. position: absolute;
  190. bottom: 0;
  191. left: 50%;
  192. margin-left: -28rpx;
  193. }
  194. &.active{
  195. color: #E15616;
  196. &::before{
  197. background-color: #E15616;
  198. }
  199. }
  200. }
  201. }
  202. </style>