headerSerch.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <common-wrapper :config="configData">
  3. <view>
  4. <!-- 搜索框 -->
  5. <!-- #ifdef H5 -->
  6. <view class="header">
  7. <view
  8. class="serch-wrapper acea-row row-middle"
  9. :style="[serchWrapperStyle, txtPosition]"
  10. >
  11. <view
  12. class="logo skeleton-rect"
  13. v-if="styleConfig == 0 && styleTypeConfig == 1 && logoConfig"
  14. >
  15. <image :src="logoConfig" mode="heightFix"></image>
  16. </view>
  17. <view
  18. class="title"
  19. :style="[txtStyle]"
  20. v-if="
  21. titleConfig &&
  22. (styleConfig == 1 || (styleConfig == 0 && styleTypeConfig == 0))
  23. "
  24. @click="goLink"
  25. >{{ titleConfig }}</view
  26. >
  27. <navigator
  28. v-if="styleConfig === 0"
  29. url="/pages/goods/goods_search/index"
  30. class="input acea-row row-middle skeleton-rect"
  31. hover-class="none"
  32. >
  33. <view class="search acea-row row-middle" :style="[searchStyle]">
  34. <text class="iconfont icon-ic_search"></text>
  35. <swiper
  36. v-if="hotWords.length"
  37. :autoplay="true"
  38. :interval="3000"
  39. :duration="1000"
  40. :vertical="true"
  41. :circular="true"
  42. class="swiper"
  43. :style="{ color: dataConfig.hotWordsColor.color[0].item }"
  44. >
  45. <swiper-item v-for="(item, index) in hotWords" :key="index">
  46. {{ item.val }}
  47. </swiper-item>
  48. </swiper>
  49. <text v-else>{{ dataConfig.tipConfig.value }}</text>
  50. </view>
  51. </navigator>
  52. </view>
  53. </view>
  54. <!-- #endif -->
  55. <!-- #ifdef MP || APP-PLUS -->
  56. <view>
  57. <view class="mp-header" :class="special ? 'on' : ''">
  58. <view
  59. class="sys-head"
  60. :style="{ height: statusBarHeight + 'px' }"
  61. v-if="!special"
  62. ></view>
  63. <view
  64. class="serch-box"
  65. :style="[
  66. serchWrapperStyle,
  67. { height: serchHeight + 'px' },
  68. { paddingRight: (!special ? serchRight : 0) + 'px' },
  69. ]"
  70. >
  71. <view
  72. class="serch-wrapper acea-row row-middle"
  73. :style="[txtPosition]"
  74. >
  75. <view
  76. class="logo skeleton-rect"
  77. v-if="styleConfig == 0 && styleTypeConfig == 1 && logoConfig"
  78. >
  79. <image :src="logoConfig" mode="heightFix"></image>
  80. </view>
  81. <view
  82. class="title"
  83. :style="[txtStyle]"
  84. v-if="
  85. titleConfig &&
  86. (styleConfig == 1 ||
  87. (styleConfig == 0 && styleTypeConfig == 0))
  88. "
  89. @click="goLink"
  90. >{{ titleConfig }}</view
  91. >
  92. <navigator
  93. v-if="styleConfig === 0"
  94. url="/pages/goods/goods_search/index"
  95. class="input acea-row row-middle skeleton-rect"
  96. hover-class="none"
  97. >
  98. <view
  99. class="search acea-row row-middle line1"
  100. :style="[searchStyle]"
  101. >
  102. <text class="iconfont icon-ic_search"></text>
  103. <swiper
  104. v-if="hotWords.length"
  105. :autoplay="true"
  106. :interval="3000"
  107. :duration="1000"
  108. :vertical="true"
  109. :circular="true"
  110. class="swiper"
  111. :style="{ color: dataConfig.hotWordsColor.color[0].item }"
  112. >
  113. <swiper-item v-for="(item, index) in hotWords" :key="index">
  114. {{ item.val }}
  115. </swiper-item>
  116. </swiper>
  117. <text class="line1 flex-1" v-else>{{
  118. dataConfig.tipConfig.value
  119. }}</text>
  120. </view>
  121. </navigator>
  122. </view>
  123. </view>
  124. </view>
  125. <view
  126. :style="'height:' + (statusBarHeight + serchHeight) + 'px;'"
  127. v-if="!special"
  128. ></view>
  129. </view>
  130. <!-- #endif -->
  131. </view>
  132. </common-wrapper>
  133. </template>
  134. <script>
  135. import commonWrapper from "./commonWrapper.vue";
  136. let statusBarHeight = uni.getWindowInfo().statusBarHeight;
  137. export default {
  138. name: "headerSerch",
  139. components: {
  140. commonWrapper,
  141. },
  142. props: {
  143. dataConfig: {
  144. type: Object,
  145. default: () => {},
  146. },
  147. special: {
  148. type: Number,
  149. default: 0,
  150. },
  151. belongIndex: {
  152. type: Number,
  153. default: 0,
  154. },
  155. },
  156. data() {
  157. return {
  158. statusBarHeight: statusBarHeight,
  159. marTop: 63,
  160. styleConfig: this.dataConfig.styleConfig.tabVal,
  161. styleTypeConfig: this.dataConfig.styleTypeConfig.tabVal,
  162. bgColor: this.dataConfig.moduleColor.color,
  163. titleConfig: this.dataConfig.titleConfig.value,
  164. txtColor: this.dataConfig.txtColor.color[0].item,
  165. txtStyleConfig:
  166. this.dataConfig.txtStyleConfig.tabList[
  167. this.dataConfig.txtStyleConfig.tabVal
  168. ].style,
  169. txtSize: this.dataConfig.txtSize.val,
  170. // fixConfig: this.dataConfig.fixConfig.tabVal,
  171. logoConfig: this.dataConfig.logoConfig.url,
  172. txtFixConfig: this.dataConfig.txtFixConfig.tabVal,
  173. boxStyle: "",
  174. mbConfig: "",
  175. hotWords: [],
  176. prConfig: "",
  177. tabVal: "",
  178. radioVal: "",
  179. textColor: "",
  180. textStyle: "",
  181. serchHeight: 43,
  182. serchRight: "",
  183. };
  184. },
  185. computed: {
  186. configData() {
  187. return {
  188. ...this.dataConfig,
  189. zIndexConfig: 1000,
  190. paddingConfig: this.dataConfig.paddingConfig || {
  191. isAll: false,
  192. valList: [
  193. {
  194. val: this.dataConfig.topConfig
  195. ? this.dataConfig.topConfig.val
  196. : 0,
  197. },
  198. {
  199. val: this.dataConfig.prConfig ? this.dataConfig.prConfig.val : 0,
  200. },
  201. {
  202. val: this.dataConfig.bottomConfig
  203. ? this.dataConfig.bottomConfig.val
  204. : 0,
  205. },
  206. {
  207. val: this.dataConfig.prConfig ? this.dataConfig.prConfig.val : 0,
  208. },
  209. ],
  210. },
  211. marginConfig: this.dataConfig.marginConfig || {
  212. isAll: false,
  213. valList: [
  214. {
  215. val: this.dataConfig.mbConfig ? this.dataConfig.mbConfig.val : 0,
  216. },
  217. {
  218. val: 0,
  219. },
  220. {
  221. val: 0,
  222. },
  223. {
  224. val: 0,
  225. },
  226. ],
  227. },
  228. backgroundConfig: this.dataConfig.bottomBgColor,
  229. };
  230. },
  231. txtStyle() {
  232. let num = 0;
  233. if (this.styleConfig == 0 && this.styleTypeConfig != 2) {
  234. num = 30;
  235. }
  236. return {
  237. color: `${this.txtColor}`,
  238. fontStyle: `${
  239. this.txtStyleConfig != "bold" ? this.txtStyleConfig : ""
  240. }`,
  241. fontWeight: `${
  242. this.txtStyleConfig == "bold" ? this.txtStyleConfig : ""
  243. }`,
  244. fontSize: `${this.txtSize * 2}rpx`,
  245. marginRight: `${num}rpx`,
  246. };
  247. },
  248. serchWrapperStyle() {
  249. let borderRadius = `${this.dataConfig.fillet.val * 2}rpx`;
  250. if (this.dataConfig.fillet.type) {
  251. borderRadius = `${this.dataConfig.fillet.valList[0].val * 2}rpx ${
  252. this.dataConfig.fillet.valList[1].val * 2
  253. }rpx ${this.dataConfig.fillet.valList[3].val * 2}rpx ${
  254. this.dataConfig.fillet.valList[2].val * 2
  255. }rpx`;
  256. }
  257. return {
  258. background: `linear-gradient(90deg, ${this.dataConfig.moduleColor.color[0].item} 0%, ${this.dataConfig.moduleColor.color[1].item} 100%)`,
  259. };
  260. },
  261. txtPosition() {
  262. return {
  263. justifyContent:
  264. this.styleConfig != 0 && this.txtFixConfig === 1
  265. ? "center"
  266. : this.styleConfig != 0 && this.txtFixConfig === 2
  267. ? "flex-end"
  268. : "flex-start",
  269. paddingLeft:
  270. this.styleConfig != 0 && this.txtFixConfig === 1
  271. ? this.serchRight + "px !important"
  272. : 0,
  273. };
  274. },
  275. searchStyle() {
  276. return {
  277. background: this.dataConfig.searchBoxColor.color[0].item,
  278. color: this.dataConfig.tipColor.color[0].item,
  279. justifyContent:
  280. this.txtFixConfig == 0
  281. ? "flex-start"
  282. : this.txtFixConfig == 2
  283. ? "flex-end"
  284. : "center",
  285. };
  286. },
  287. },
  288. mounted() {
  289. let that = this;
  290. that.hotWords = that.dataConfig.hotWords.list.filter((item) => {
  291. if (item.val) {
  292. return item;
  293. }
  294. });
  295. uni.setStorageSync("hotList", that.hotWords);
  296. that.$store.commit("hotWords/setHotWord", that.hotWords);
  297. // #ifdef MP || APP-PLUS
  298. setTimeout(() => {
  299. // 获取小程序头部高度
  300. let info = uni.createSelectorQuery().in(this).select(".mp-header");
  301. info
  302. .boundingClientRect(function (data) {
  303. that.marTop = data.height;
  304. })
  305. .exec();
  306. }, 100);
  307. // #endif
  308. // #ifdef MP
  309. const { windowWidth, statusBarHeight } = uni.getWindowInfo();
  310. const { top, left, width, height } = uni.getMenuButtonBoundingClientRect();
  311. that.serchHeight = (top - statusBarHeight) * 2 + height;
  312. that.serchRight = windowWidth - left;
  313. // #endif
  314. },
  315. methods: {
  316. goLink() {
  317. let url = this.dataConfig.linkConfig.value;
  318. this.$util.JumpPath(url);
  319. },
  320. },
  321. };
  322. </script>
  323. <style lang="scss" scoped>
  324. .serch-wrapper {
  325. &.center {
  326. justify-content: center;
  327. }
  328. &.right {
  329. justify-content: flex-end;
  330. /* #ifdef MP */
  331. padding-right: 185rpx !important;
  332. /* #endif */
  333. }
  334. }
  335. .title {
  336. margin-right: 30rpx;
  337. font-weight: 400;
  338. font-size: 30rpx;
  339. color: #333333;
  340. }
  341. .map {
  342. color: #fff;
  343. font-size: 28rpx;
  344. margin-right: 20rpx;
  345. max-width: 100%;
  346. .info {
  347. &.on {
  348. max-width: 260rpx;
  349. }
  350. &.on1 {
  351. max-width: 156rpx;
  352. }
  353. }
  354. .iconfont {
  355. font-size: 28rpx;
  356. }
  357. .icon-ic_downarrow {
  358. opacity: 0.8;
  359. }
  360. .icon-ic_location51 {
  361. margin-right: 6rpx;
  362. }
  363. }
  364. .header {
  365. width: 100%;
  366. // height: 100rpx;
  367. // background: linear-gradient(90deg, $bg-star 50%, $bg-end 100%);
  368. .serch-wrapper {
  369. height: 96rpx;
  370. padding: 18rpx 30rpx !important;
  371. .logo {
  372. height: 60rpx;
  373. margin-right: 20rpx;
  374. image {
  375. width: 100%;
  376. height: 100%;
  377. }
  378. }
  379. .input {
  380. position: relative;
  381. flex: 1;
  382. .search {
  383. flex: 1;
  384. height: 60rpx;
  385. padding: 0 32rpx;
  386. border-radius: 30rpx;
  387. background: #f5f5f5;
  388. font-size: 28rpx;
  389. line-height: 32rpx;
  390. }
  391. .iconfont {
  392. margin-right: 16rpx;
  393. font-size: 32rpx;
  394. }
  395. .swiper {
  396. flex: 1;
  397. height: 32rpx;
  398. }
  399. }
  400. }
  401. }
  402. /* #ifdef MP || APP-PLUS */
  403. .mp-header {
  404. z-index: 300;
  405. position: fixed;
  406. left: 0;
  407. top: 0;
  408. width: 100%;
  409. &.on {
  410. position: unset;
  411. }
  412. .serch-wrapper {
  413. height: 100%;
  414. /* #ifdef MP */
  415. padding: 0 30rpx !important;
  416. /* #endif */
  417. /* #ifdef APP-PLUS */
  418. padding: 0 30rpx !important;
  419. /* #endif */
  420. .logo {
  421. height: 60rpx;
  422. margin-right: 20rpx;
  423. image {
  424. width: 100%;
  425. height: 100%;
  426. }
  427. }
  428. .input {
  429. position: relative;
  430. flex: 1;
  431. .search {
  432. flex: 1;
  433. height: 60rpx;
  434. padding: 0 32rpx;
  435. border-radius: 30rpx;
  436. background: #f5f5f5;
  437. font-size: 28rpx;
  438. line-height: 32rpx;
  439. }
  440. .iconfont {
  441. font-size: 32rpx;
  442. margin-right: 18rpx;
  443. }
  444. .swiper {
  445. flex: 1;
  446. height: 32rpx;
  447. }
  448. .button {
  449. position: absolute;
  450. top: 4rpx;
  451. right: 4rpx;
  452. height: 52rpx;
  453. padding: 0 24rpx;
  454. border-radius: 26rpx;
  455. background: var(--view-theme);
  456. font-weight: 500;
  457. line-height: 52rpx;
  458. font-size: 22rpx;
  459. color: #ffffff;
  460. }
  461. .button2 {
  462. margin-left: 20rpx;
  463. font-size: 30rpx;
  464. color: var(--view-theme);
  465. }
  466. // 没有logo,直接搜索框
  467. &.on {
  468. /* #ifdef MP */
  469. width: 70%;
  470. /* #endif */
  471. /* #ifdef APP-PLUS */
  472. width: 100%;
  473. /* #endif */
  474. }
  475. // 设置圆角
  476. &.fillet {
  477. border-radius: 29rpx;
  478. }
  479. // 文本框文字居中
  480. &.row-center {
  481. padding: 0;
  482. }
  483. }
  484. }
  485. }
  486. /* #endif */
  487. .row-center uni-swiper-item,
  488. .row-center swiper-item {
  489. text-align: center;
  490. }
  491. </style>