headerSearch.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <!-- 搜索框 -->
  3. <view>
  4. <view class="mp-header">
  5. <!-- #ifdef MP || APP-PLUS -->
  6. <view class="sys-head tui-skeleton" :style="{ height: `${isSmallPage?0:statusBarHeight}px` }"></view>
  7. <!-- #endif -->
  8. <!-- #ifdef APP -->
  9. <view class="serch-box tui-skeleton" :style="[boxStyle]" style="height: 43px;">
  10. <!-- #endif -->
  11. <!-- #ifndef APP -->
  12. <view class="serch-box tui-skeleton" :style="[boxStyle]">
  13. <!-- #endif -->
  14. <view class="serch-wrapper flex">
  15. <view class="leftNav-box" v-if="merId">
  16. <view class="select_nav flex justify-center align-center" id="home">
  17. <text class="iconfont icon-fanhui2 px-20" @tap="returns" ></text>
  18. <navigator url="/pages/index/index" open-type="switchTab"
  19. class="iconfont icon-shouye7 px-20"></navigator>
  20. <text class="nav_line"></text>
  21. </view>
  22. </view>
  23. <view v-if="logoConfig&&!merId" class="logo skeleton-rect">
  24. <image :src="logoUrl" mode=""></image>
  25. </view>
  26. <navigator :style="[contentStyle]" v-if="hotWords.length > 0"
  27. :url="merId?'/pages/goods/goods_list/index?merId='+merId:'/pages/goods/goods_search/index?searchVal='+searchVal"
  28. :class="logoConfig&&!isSmallPage ? 'input' : logoConfig&&isSmallPage?'uninput':!logoConfig&&!isSmallPage?'uninput':'maxInput'" hover-class="none" class="input skeleton-rect">
  29. <view class='swiperTxt' :style="[swiperTxtStyle]">
  30. <swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
  31. :duration="duration" vertical="true" circular="true" @change="textChange">
  32. <block v-for="(item,index) in hotWords" :key='index'>
  33. <swiper-item catchtouchmove='catchTouchMove'>
  34. <view class='acea-row row-between-wrapper'>
  35. <view class='text'>
  36. <view class='newsTitle line1'><text class="iconfont icon-ic_search"></text><text class="ml-6">{{item.val}}</text></view>
  37. </view>
  38. </view>
  39. </swiper-item>
  40. </block>
  41. </swiper>
  42. </view>
  43. </navigator>
  44. <navigator hover-class="none" v-else
  45. :url="merId?'/pages/goods/goods_list/index?merId='+merId:'/pages/goods/goods_search/index'" :style="[contentStyle]"
  46. :class="logoConfig&&!isSmallPage ? 'input' : logoConfig&&isSmallPage?'uninput':!logoConfig&&!isSmallPage?'uninput':'maxInput'" class="skeleton-rect input">
  47. <view class='newsTitle swiperTxt' :style="[swiperTxtStyle]">
  48. <text class="iconfont icon-ic_search" ></text><text>{{placeWords}}</text>
  49. </view>
  50. </navigator>
  51. </view>
  52. </view>
  53. </view>
  54. <view :style="'height:'+marTop+'px;'"></view>
  55. </view>
  56. </template>
  57. <script>
  58. // +----------------------------------------------------------------------
  59. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  60. // +----------------------------------------------------------------------
  61. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  62. // +----------------------------------------------------------------------
  63. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  64. // +----------------------------------------------------------------------
  65. // | Author: CRMEB Team <admin@crmeb.com>
  66. // +----------------------------------------------------------------------
  67. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  68. let app = getApp();
  69. export default {
  70. name: 'headerSerch',
  71. props: {
  72. dataConfig: {
  73. type: Object,
  74. default: () => {}
  75. },
  76. merId: { // 商户id
  77. type: Number,
  78. default: 0
  79. },
  80. //是否为微页面
  81. isSmallPage: {
  82. type: Boolean,
  83. default: false
  84. },
  85. //是否开始滚动
  86. isScrolled: {
  87. type: Boolean,
  88. default: false
  89. },
  90. },
  91. data() {
  92. return {
  93. statusBarHeight: app.globalData.statusBarHeight,
  94. indicatorDots: false,
  95. autoplay: true,
  96. duration: 500,
  97. marTop: 0,
  98. searchH: 0,
  99. searchVal: '',
  100. searchTop:0,
  101. searchRight:0,
  102. searchHeight:0,
  103. statusWidth:0,
  104. searchBoxHeight:0
  105. };
  106. },
  107. computed: {
  108. //轮播切换时间
  109. interval() {
  110. return this.dataConfig.titleConfig.val * 1000
  111. },
  112. //判断logo图是否展示
  113. logoConfig() {
  114. if(!this.merId){
  115. return this.dataConfig.logoConfig && this.dataConfig.logoConfig.url && this.dataConfig.searConfig.tabVal === 1
  116. }else{
  117. return true
  118. }
  119. },
  120. //logo图
  121. logoUrl() {
  122. if(!this.merId){
  123. if(this.isScrolled&&this.dataConfig.logoFixConfig.url){
  124. return this.dataConfig.logoFixConfig.url
  125. }else{
  126. return this.dataConfig.logoConfig.url
  127. }
  128. }
  129. },
  130. //最外层盒子的样式
  131. boxStyle() {
  132. return {
  133. borderRadius: this.dataConfig.bgStyle.val * 2 + 'rpx',
  134. background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
  135. margin: 0 + ' ' + this.dataConfig.lrConfig.val * 2 + 'rpx' +
  136. ' ' + 0,
  137. // #ifdef MP
  138. height:this.searchBoxHeight + 'px',
  139. // #endif
  140. }
  141. },
  142. //搜索热词
  143. hotWords() {
  144. return this.dataConfig.hotWords.list
  145. },
  146. //内容圆角
  147. contentStyle() {
  148. return {
  149. borderRadius: this.dataConfig.contentStyle.val ? this.dataConfig.contentStyle.val + 'px' : '0',
  150. background: this.dataConfig.borderColor.color[0].item,
  151. color: this.dataConfig.textColor.color[0].item,
  152. textAlign: this.dataConfig.textPosition.list[this.dataConfig.textPosition.tabVal].style,
  153. // #ifdef MP
  154. height:this.searchHeight + 'px',
  155. flex:!this.isSmallPage?1:'',
  156. marginRight:!this.isSmallPage?(this.statusWidth + this.searchRight+'px'):'',
  157. // #endif
  158. }
  159. },
  160. swiperTxtStyle(){
  161. return {
  162. // #ifdef MP
  163. lineHeight:this.searchHeight + 'px',
  164. // #endif
  165. }
  166. },
  167. //搜索提示语
  168. placeWords() {
  169. return this.dataConfig.placeWords.val;
  170. }
  171. },
  172. mounted() {
  173. // 使用nextTick,确保页面更新结束后,再请求高度
  174. // #ifdef MP || APP-PLUS
  175. this.$nextTick(() => {
  176. setTimeout(() => {
  177. // 获取小程序头部高度
  178. let info = uni.createSelectorQuery().in(this).select(".serch-box");
  179. info.boundingClientRect((data)=> {
  180. this.marTop = this.isSmallPage ? data.height :data.height + this.statusBarHeight
  181. }).exec()
  182. }, 100)
  183. })
  184. // #endif
  185. // #ifdef MP
  186. const res = uni.getMenuButtonBoundingClientRect()
  187. const statusHeight = res.top //胶囊距离顶部
  188. const statusRight = res.right //胶囊右边界坐标
  189. const jnHeight = res.height //胶囊高度
  190. this.statusWidth= res.width
  191. this.searchTop=statusHeight-this.statusBarHeight
  192. this.searchHeight=jnHeight
  193. this.searchBoxHeight = this.searchTop*2 + jnHeight
  194. //搜索框宽度计算
  195. uni.getSystemInfo({
  196. success:res=>{
  197. this.searchRight=res.windowWidth-statusRight-this.dataConfig.lrConfig.val
  198. }
  199. })
  200. // #endif
  201. // #ifdef H5
  202. this.marTop = 43
  203. // #endif
  204. },
  205. methods: {
  206. // 后退
  207. returns: function() {
  208. uni.navigateBack();
  209. },
  210. textChange(e) {
  211. let {
  212. current,
  213. source
  214. } = e.detail;
  215. if (source === 'autoplay' || source === 'touch') {
  216. this.searchVal = this.hotWords[e.detail.current]['val'];
  217. }
  218. },
  219. toBack(){
  220. uni.navigateBack();
  221. },
  222. toHome(){
  223. this.$util.navigateTo('/pages/index/index');
  224. }
  225. }
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. .ml40 {
  230. margin-left: 40rpx;
  231. }
  232. .sys-head{
  233. background: #f5f5f5;
  234. }
  235. .header {
  236. width: 100%;
  237. background: #ffffff;
  238. .btn {
  239. position: relative;
  240. .iconfont {
  241. font-size: 45rpx;
  242. }
  243. }
  244. .iconnum {
  245. min-width: 6px;
  246. color: #fff;
  247. border-radius: 15rpx;
  248. position: absolute;
  249. right: -10rpx;
  250. top: -10rpx;
  251. font-size: 10px;
  252. padding: 0 4px;
  253. }
  254. .serch-wrapper {
  255. align-items: center;
  256. padding: 20rpx 24rpx 20rpx 24rpx;
  257. .logo {
  258. width: 152rpx;
  259. height: 60rpx;
  260. }
  261. }
  262. }
  263. .swiperTxt {
  264. width: 100%;
  265. height: 100%;
  266. /* #ifndef MP */
  267. line-height: 58rpx;
  268. /* #endif */
  269. overflow: hidden;
  270. }
  271. .swiperTxt .text {
  272. width: 100%;
  273. }
  274. .swiperTxt .text .label {
  275. font-size: 20rpx;
  276. color: #ff4c48;
  277. width: 64rpx;
  278. height: 30rpx;
  279. border-radius: 40rpx;
  280. text-align: center;
  281. line-height: 28rpx;
  282. border: 2rpx solid #ff4947;
  283. }
  284. .swiperTxt .text .newsTitle {
  285. // width: 300rpx;
  286. font-size: 24rpx;
  287. // text-align: center;
  288. /* #ifdef MP */
  289. // width: 260rpx !important;
  290. /* #endif */
  291. }
  292. .swiperTxt swiper {
  293. height: 100%;
  294. }
  295. .mp-header {
  296. z-index: 90;
  297. position: fixed;
  298. left: 0;
  299. top: 0;
  300. width: 100%;
  301. .logo {
  302. line-height: 0;
  303. }
  304. .serch-wrapper {
  305. height: 100%;
  306. align-items: center;
  307. padding: 0 20rpx;
  308. image {
  309. width: 152rpx;
  310. height: 60rpx;
  311. margin-right: 20rpx;
  312. }
  313. .input,
  314. .uninput {
  315. display: flex;
  316. align-items: center;
  317. /* #ifdef MP*/
  318. width: 48%;
  319. /* #endif */
  320. /* #ifdef H5 || APP*/
  321. width: 100%;
  322. flex: 1;
  323. /* #endif */
  324. height: 58rpx;
  325. line-height: 58rpx;
  326. padding: 0 20rpx 0 20rpx;
  327. background: rgba(0, 0, 0, 0.22);
  328. border-radius: 29rpx;
  329. color: #fff;
  330. font-size: 28rpx;
  331. position: relative;
  332. box-sizing: border-box;
  333. .iconfont {
  334. // position: absolute;
  335. left: 14rpx;
  336. font-size: 26rpx;
  337. //top: 10rpx;
  338. }
  339. .line1{
  340. display: inline-block;
  341. }
  342. }
  343. .uninput {
  344. /* #ifdef MP */
  345. width: 75% ;
  346. /* #endif */
  347. /* #ifndef MP */
  348. width: 100%;
  349. /* #endif */
  350. }
  351. }
  352. }
  353. .maxInput{
  354. width: 100% !important;
  355. }
  356. .leftNav{
  357. width: 144rpx !important;
  358. height: 60rpx !important;
  359. margin-right: 20rpx;
  360. margin-top: 10rpx;
  361. }
  362. .leftNav-box{
  363. position: relative;
  364. margin-right: 20rpx;
  365. }
  366. .left{
  367. position: absolute;
  368. width: 72rpx;
  369. height: 50rpx;
  370. top: 10rpx;
  371. }
  372. .right{
  373. position: absolute;
  374. width: 72rpx;
  375. height: 50rpx;
  376. top: 10rpx;
  377. left:72rpx;;
  378. }
  379. .select_nav {
  380. background: rgba(255,255,255,0.6);
  381. border: 1rpx solid rgba(0,0,0,0.1);
  382. color: #000;
  383. font-size: 18px;
  384. line-height: 58rpx;
  385. z-index: 1000;
  386. border-radius: 29rpx;
  387. }
  388. .nav_line {
  389. content: "";
  390. display: inline-block;
  391. width: 1rpx;
  392. height: 30rpx;
  393. background: #e8dfdf;
  394. position: absolute;
  395. left: 0;
  396. right: 0;
  397. margin: 19rpx auto;
  398. }
  399. .px-20 {
  400. padding: 0 20rpx 0;
  401. }
  402. </style>