headerSerch.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view>
  3. <!-- 搜索框 -->
  4. <!-- #ifdef H5 -->
  5. <view class="header" :style="[headerStyle]">
  6. <view class="serch-wrapper acea-row row-middle" :style="[serchWrapperStyle,txtPosition]">
  7. <view class="logo skeleton-rect" v-if="styleConfig == 0 && styleTypeConfig == 1 && logoConfig">
  8. <image :src="logoConfig" mode="heightFix"></image>
  9. </view>
  10. <view class="title" :style="[txtStyle]" v-if="titleConfig && (styleConfig==1 || (styleConfig==0 && styleTypeConfig == 0))" @click="goLink">{{ titleConfig }}</view>
  11. <navigator v-if="styleConfig===0" url="/pages/goods/goods_search/index" class="input acea-row row-middle skeleton-rect" hover-class="none">
  12. <view class="search acea-row row-middle" :style="[searchStyle]">
  13. <text class="iconfont icon-ic_search"></text>
  14. <swiper v-if="hotWords.length" :autoplay="true" :interval="3000" :duration="1000" :vertical="true" :circular="true" class="swiper"
  15. :style="{ color: dataConfig.hotWordsColor.color[0].item }">
  16. <swiper-item v-for="(item, index) in hotWords" :key="index">
  17. {{ item.val }}
  18. </swiper-item>
  19. </swiper>
  20. <text v-else>{{ dataConfig.tipConfig.value }}</text>
  21. </view>
  22. </navigator>
  23. </view>
  24. </view>
  25. <!-- #endif -->
  26. <!-- #ifdef MP || APP-PLUS -->
  27. <view>
  28. <view class="mp-header" :class="special?'on':''" :style="[headerStyle]">
  29. <view class="sys-head" :style="{ height: statusBarHeight + 'px'}" v-if="!special"></view>
  30. <view class="serch-box" :style="[serchWrapperStyle, { height: serchHeight + 'px' }, { paddingRight: (!special?serchRight:0) + 'px' }]">
  31. <view class="serch-wrapper acea-row row-middle" :style="[txtPosition]">
  32. <view class="logo skeleton-rect" v-if="styleConfig == 0 && styleTypeConfig == 1 && logoConfig">
  33. <image :src="logoConfig" mode="heightFix"></image>
  34. </view>
  35. <view class="title" :style="[txtStyle]" v-if="titleConfig && (styleConfig==1 || (styleConfig==0 && styleTypeConfig == 0))" @click="goLink">{{ titleConfig }}</view>
  36. <navigator v-if="styleConfig===0" url="/pages/goods/goods_search/index" class="input acea-row row-middle skeleton-rect" hover-class="none">
  37. <view class="search acea-row row-middle line1" :style="[searchStyle]">
  38. <text class="iconfont icon-ic_search"></text>
  39. <swiper v-if="hotWords.length" :autoplay="true" :interval="3000" :duration="1000" :vertical="true" :circular="true" class="swiper"
  40. :style="{ color: dataConfig.hotWordsColor.color[0].item }">
  41. <swiper-item v-for="(item, index) in hotWords" :key="index">
  42. {{ item.val }}
  43. </swiper-item>
  44. </swiper>
  45. <text class="line1 flex-1" v-else>{{ dataConfig.tipConfig.value }}</text>
  46. </view>
  47. </navigator>
  48. </view>
  49. </view>
  50. </view>
  51. <view :style="'height:'+(statusBarHeight+serchHeight)+'px;'" v-if="!special"></view>
  52. </view>
  53. <!-- #endif -->
  54. </view>
  55. </template>
  56. <script>
  57. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  58. export default {
  59. name: 'headerSerch',
  60. props: {
  61. dataConfig: {
  62. type: Object,
  63. default: () => {}
  64. },
  65. special: {
  66. type: Number,
  67. default: 0
  68. },
  69. belongIndex: {
  70. type: Number,
  71. default: 0
  72. }
  73. },
  74. data() {
  75. return {
  76. statusBarHeight: statusBarHeight,
  77. marTop: 63,
  78. styleConfig: this.dataConfig.styleConfig.tabVal,
  79. styleTypeConfig:this.dataConfig.styleTypeConfig.tabVal,
  80. bgColor: this.dataConfig.moduleColor.color,
  81. titleConfig: this.dataConfig.titleConfig.value,
  82. txtColor: this.dataConfig.txtColor.color[0].item,
  83. txtStyleConfig: this.dataConfig.txtStyleConfig.tabList[this.dataConfig.txtStyleConfig.tabVal].style,
  84. txtSize: this.dataConfig.txtSize.val,
  85. // fixConfig: this.dataConfig.fixConfig.tabVal,
  86. logoConfig: this.dataConfig.logoConfig.url,
  87. txtFixConfig: this.dataConfig.txtFixConfig.tabVal,
  88. boxStyle: '',
  89. mbConfig: '',
  90. hotWords: [],
  91. prConfig: '',
  92. tabVal: '',
  93. radioVal: '',
  94. textColor: '',
  95. textStyle: '',
  96. serchHeight: 43,
  97. serchRight: ''
  98. };
  99. },
  100. computed: {
  101. txtStyle() {
  102. let num = 0
  103. if(this.styleConfig==0 && this.styleTypeConfig != 2){
  104. num = 30
  105. }
  106. return {
  107. color:`${this.txtColor}`,
  108. fontStyle:`${this.txtStyleConfig!='bold'?this.txtStyleConfig:''}`,
  109. fontWeight:`${this.txtStyleConfig=='bold'?this.txtStyleConfig:''}`,
  110. fontSize:`${this.txtSize*2}rpx`,
  111. marginRight:`${num}rpx`
  112. };
  113. },
  114. headerStyle() {
  115. return {
  116. padding: `${this.dataConfig.topConfig.val*2}rpx ${this.dataConfig.prConfig.val*2}rpx ${this.dataConfig.bottomConfig.val*2}rpx`,
  117. background: this.dataConfig.bottomBgColor.color[0].item,
  118. };
  119. },
  120. serchWrapperStyle() {
  121. let borderRadius = `${this.dataConfig.fillet.val * 2}rpx`;
  122. if(this.dataConfig.fillet.type){
  123. borderRadius = `${this.dataConfig.fillet.valList[0].val * 2}rpx ${this.dataConfig.fillet.valList[1].val * 2}rpx ${this.dataConfig.fillet.valList[3].val * 2}rpx ${this.dataConfig.fillet.valList[2].val * 2}rpx`;
  124. }
  125. return {
  126. borderRadius: borderRadius,
  127. background: `linear-gradient(90deg, ${this.dataConfig.moduleColor.color[0].item} 0%, ${this.dataConfig.moduleColor.color[1].item} 100%)`,
  128. };
  129. },
  130. txtPosition(){
  131. return {
  132. justifyContent:this.styleConfig !=0 && this.txtFixConfig===1?'center':this.styleConfig !=0 && this.txtFixConfig===2?'flex-end':'flex-start',
  133. paddingLeft:this.styleConfig !=0 && this.txtFixConfig===1?this.serchRight+'px !important':0
  134. }
  135. },
  136. searchStyle() {
  137. return {
  138. background: this.dataConfig.searchBoxColor.color[0].item,
  139. color: this.dataConfig.tipColor.color[0].item,
  140. justifyContent:this.txtFixConfig==0?'flex-start':this.txtFixConfig==2?'flex-end':'center'
  141. };
  142. },
  143. },
  144. mounted() {
  145. let that = this;
  146. that.hotWords = that.dataConfig.hotWords.list.filter(item => {
  147. if (item.val) {
  148. return item;
  149. }
  150. });
  151. uni.setStorageSync('hotList', that.hotWords);
  152. that.$store.commit('hotWords/setHotWord', that.hotWords);
  153. // #ifdef MP || APP-PLUS
  154. setTimeout(() => {
  155. // 获取小程序头部高度
  156. let info = uni.createSelectorQuery().in(this).select(".mp-header");
  157. info.boundingClientRect(function(data) {
  158. that.marTop = data.height
  159. }).exec()
  160. }, 100)
  161. // #endif
  162. // #ifdef MP
  163. const {
  164. windowWidth,
  165. statusBarHeight,
  166. } = uni.getSystemInfoSync();
  167. const {
  168. top,
  169. left,
  170. width,
  171. height,
  172. } = uni.getMenuButtonBoundingClientRect();
  173. that.serchHeight = (top - statusBarHeight) * 2 + height;
  174. that.serchRight = windowWidth - left;
  175. // #endif
  176. },
  177. methods: {
  178. goLink() {
  179. let url = this.dataConfig.linkConfig.value;
  180. this.$util.JumpPath(url);
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .serch-wrapper {
  187. &.center {
  188. justify-content: center;
  189. }
  190. &.right {
  191. justify-content: flex-end;
  192. /* #ifdef MP */
  193. padding-right: 185rpx !important;
  194. /* #endif */
  195. }
  196. }
  197. .title {
  198. margin-right: 30rpx;
  199. font-weight: 400;
  200. font-size: 30rpx;
  201. color: #333333;
  202. }
  203. .map {
  204. color: #fff;
  205. font-size: 28rpx;
  206. margin-right: 20rpx;
  207. max-width: 100%;
  208. .info {
  209. &.on {
  210. max-width: 260rpx;
  211. }
  212. &.on1 {
  213. max-width: 156rpx;
  214. }
  215. }
  216. .iconfont {
  217. font-size: 28rpx;
  218. }
  219. .icon-ic_downarrow {
  220. opacity: 0.8;
  221. }
  222. .icon-ic_location51{
  223. margin-right: 6rpx;
  224. }
  225. }
  226. .header {
  227. width: 100%;
  228. // height: 100rpx;
  229. // background: linear-gradient(90deg, $bg-star 50%, $bg-end 100%);
  230. .serch-wrapper {
  231. height: 96rpx;
  232. padding: 18rpx 30rpx !important;
  233. .logo {
  234. height: 60rpx;
  235. margin-right: 20rpx;
  236. image {
  237. width: 100%;
  238. height: 100%;
  239. }
  240. }
  241. .input {
  242. position: relative;
  243. flex: 1;
  244. .search {
  245. flex: 1;
  246. height: 60rpx;
  247. padding: 0 32rpx;
  248. border-radius: 30rpx;
  249. background: #F5F5F5;
  250. font-size: 28rpx;
  251. line-height: 32rpx;
  252. }
  253. .iconfont {
  254. margin-right: 16rpx;
  255. font-size: 32rpx;
  256. }
  257. .swiper {
  258. flex: 1;
  259. height: 32rpx;
  260. }
  261. }
  262. }
  263. }
  264. /* #ifdef MP || APP-PLUS */
  265. .mp-header {
  266. z-index: 30;
  267. position: fixed;
  268. left: 0;
  269. top: 0;
  270. width: 100%;
  271. background: linear-gradient(90deg, $bg-star 50%, $bg-end 100%);
  272. &.on{
  273. position: unset;
  274. }
  275. .serch-wrapper {
  276. height: 100%;
  277. /* #ifdef MP */
  278. padding: 0 30rpx !important;
  279. /* #endif */
  280. /* #ifdef APP-PLUS */
  281. padding: 0 30rpx !important;
  282. /* #endif */
  283. .logo {
  284. height: 60rpx;
  285. margin-right: 20rpx;
  286. image {
  287. width: 100%;
  288. height: 100%;
  289. }
  290. }
  291. .input {
  292. position: relative;
  293. flex: 1;
  294. .search {
  295. flex: 1;
  296. height: 60rpx;
  297. padding: 0 32rpx;
  298. border-radius: 30rpx;
  299. background: #F5F5F5;
  300. font-size: 28rpx;
  301. line-height: 32rpx;
  302. }
  303. .iconfont {
  304. font-size: 32rpx;
  305. margin-right: 18rpx;
  306. }
  307. .swiper {
  308. flex: 1;
  309. height: 32rpx;
  310. }
  311. .button {
  312. position: absolute;
  313. top: 4rpx;
  314. right: 4rpx;
  315. height: 52rpx;
  316. padding: 0 24rpx;
  317. border-radius: 26rpx;
  318. background: var(--view-theme);
  319. font-weight: 500;
  320. line-height: 52rpx;
  321. font-size: 22rpx;
  322. color: #FFFFFF;
  323. }
  324. .button2 {
  325. margin-left: 20rpx;
  326. font-size: 30rpx;
  327. color: var(--view-theme);
  328. }
  329. // 没有logo,直接搜索框
  330. &.on {
  331. /* #ifdef MP */
  332. width: 70%;
  333. /* #endif */
  334. /* #ifdef APP-PLUS */
  335. width: 100%;
  336. /* #endif */
  337. }
  338. // 设置圆角
  339. &.fillet {
  340. border-radius: 29rpx;
  341. }
  342. // 文本框文字居中
  343. &.row-center {
  344. padding: 0;
  345. }
  346. }
  347. }
  348. }
  349. /* #endif */
  350. .row-center uni-swiper-item, .row-center swiper-item{
  351. text-align: center;
  352. }
  353. </style>