headerSerch.vue 11 KB

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