headerSerch.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <view class="header"
  4. :style="'background: linear-gradient(90deg, '+ bgColor[0].item +' 50%, '+ bgColor[1].item +' 100%);margin-top:'+ mbConfig*2 +'rpx;'">
  5. <view class="serch-wrapper acea-row row-middle" :style="'padding-left:'+ prConfig*2 +'rpx;'">
  6. <!-- <view class="logo skeleton-rect" v-if="logoConfig">
  7. <image :src="logoConfig" mode="heightFix"></image>
  8. </view> -->
  9. <navigator url="/pages/goods/goods_search/index" class="input acea-row row-middle skeleton-rect"
  10. :class="[boxStyle?'':'fillet',logoConfig?'':'on',txtStyle?'row-center':'']" hover-class="none"><text
  11. class="iconfont icon-sousuo"></text>
  12. {{$t(`搜索商品`)}}</navigator>
  13. <view class="right" v-if="array.length">
  14. <picker @change="bindPickerChange" range-key="name" :value="setIndex" :range="array">
  15. <view class="right-text">{{array[setIndex].name}}<text class="iconfont icon-xiangxia" style="padding-left: 10rpx;"></text></view>
  16. </picker>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- #endif -->
  21. <!-- #ifdef MP || APP-PLUS -->
  22. <view v-if="special" class="header"
  23. :style="'background: linear-gradient(90deg, '+ bgColor[0].item +' 50%, '+ bgColor[1].item +' 100%);margin-top:'+ mbConfig*2 +'rpx;'">
  24. <view class="serch-wrapper acea-row row-middle" :style="'padding-left:'+ prConfig*2 +'rpx;'">
  25. <view class="logo skeleton-rect" v-if="logoConfig">
  26. <image :src="logoConfig" mode="heightFix"></image>
  27. </view>
  28. <navigator url="/pages/goods/goods_search/index" class="input acea-row row-middle skeleton-rect"
  29. :class="[boxStyle?'':'fillet',logoConfig?'':'on',txtStyle?'row-center':'']" hover-class="none"><text
  30. class="iconfont icon-sousuo"></text>
  31. {{$t(`搜索商品名称`)}}</navigator>
  32. </view>
  33. </view>
  34. <view v-else>
  35. <view class="mp-header"
  36. :style="'background: linear-gradient(90deg, '+ bgColor[0].item +' 50%, '+ bgColor[1].item +' 100%);margin-top:'+ mbConfig*2 +'rpx;'">
  37. <view class="sys-head" :style="{ height: statusBarHeight }"></view>
  38. <view class="serch-box" style="height: 43px;">
  39. <view class="serch-wrapper acea-row row-middle" :style="'padding-left:'+ prConfig*2 +'rpx;'">
  40. <view class="logo skeleton-rect" v-if="logoConfig">
  41. <image :src="logoConfig" mode="heightFix"></image>
  42. </view>
  43. <navigator url="/pages/goods/goods_search/index" class="input acea-row row-middle skeleton-rect"
  44. :class="[boxStyle?'':'fillet',logoConfig?'':'on',txtStyle?'row-center':'']" hover-class="none">
  45. <text class="iconfont icon-sousuo"></text>
  46. {{$t(`搜索商品名称`)}}
  47. </navigator>
  48. </view>
  49. </view>
  50. </view>
  51. <view :style="'height:'+marTop+'px;'"></view>
  52. </view>
  53. <!-- #endif -->
  54. </template>
  55. <script>
  56. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  57. import {
  58. getLangJson,
  59. getLangList,
  60. } from '@/api/user.js';
  61. import Cache from '@/utils/cache';
  62. export default {
  63. name: 'headerSerch',
  64. props: {
  65. dataConfig: {
  66. type: Object,
  67. default: () => {}
  68. },
  69. special: {
  70. type: Number,
  71. default: 0
  72. }
  73. },
  74. data() {
  75. return {
  76. statusBarHeight: statusBarHeight,
  77. marTop: 0,
  78. bgColor: this.dataConfig.bgColor.color,
  79. boxStyle: this.dataConfig.boxStyle.type,
  80. logoConfig: this.dataConfig.logoConfig.url,
  81. mbConfig: this.dataConfig.mbConfig.val,
  82. txtStyle: this.dataConfig.txtStyle.type,
  83. hotWords: this.dataConfig.hotWords.list,
  84. prConfig: this.dataConfig.prConfig.val,
  85. array: [],
  86. setIndex: 0,
  87. };
  88. },
  89. mounted() {
  90. let that = this;
  91. uni.setStorageSync('hotList', that.hotWords);
  92. that.$store.commit('hotWords/setHotWord', that.hotWords);
  93. // #ifdef MP || APP-PLUS
  94. setTimeout(() => {
  95. // 获取小程序头部高度
  96. let info = uni.createSelectorQuery().in(this).select(".mp-header");
  97. info.boundingClientRect(function(data) {
  98. that.marTop = data.height
  99. }).exec()
  100. }, 100)
  101. // #endif
  102. this.getLangList()
  103. },
  104. methods: {
  105. bindPickerChange(e, item) {
  106. this.setIndex = e.detail.value
  107. Cache.set('locale', this.array[this.setIndex].value)
  108. getLangJson().then(res => {
  109. uni.setStorageSync('localeJson', res.data);
  110. this.$i18n.setLocaleMessage(this.array[this.setIndex].value, res.data[this.array[
  111. this.setIndex].value]);
  112. this.$nextTick(e => {
  113. this.$i18n.locale = this.array[this.setIndex].value;
  114. })
  115. })
  116. },
  117. getLangList() {
  118. getLangList().then(res => {
  119. this.array = res.data
  120. this.setLang();
  121. })
  122. },
  123. setLang() {
  124. this.array.map((item, i) => {
  125. if (this.$i18n.locale == item.value) {
  126. this.setIndex = i
  127. }
  128. })
  129. },
  130. }
  131. }
  132. </script>
  133. <style lang="scss">
  134. .right-text{
  135. color:#FFF;
  136. padding: 0 10rpx;
  137. padding-left: 30rpx;
  138. }
  139. .header {
  140. width: 100%;
  141. height: 100rpx;
  142. background: linear-gradient(90deg, $bg-star 50%, $bg-end 100%);
  143. .serch-wrapper {
  144. padding: 20rpx 20rpx 0 0;
  145. .logo {
  146. height: 60rpx;
  147. margin-right: 20rpx;
  148. width: 154rpx;
  149. flex-shrink: 0;
  150. text-align: center;
  151. image {
  152. width: 100%;
  153. height: 100%;
  154. }
  155. }
  156. .input {
  157. flex: 1;
  158. height: 58rpx;
  159. padding: 0 0 0 30rpx;
  160. background: rgba(247, 247, 247, 1);
  161. border: 1px solid rgba(241, 241, 241, 1);
  162. color: #BBBBBB;
  163. font-size: 28rpx;
  164. .iconfont {
  165. margin-right: 20rpx;
  166. }
  167. // 没有logo,直接搜索框
  168. &.on {
  169. width: 100%;
  170. }
  171. // 设置圆角
  172. &.fillet {
  173. border-radius: 29rpx;
  174. }
  175. // 文本框文字居中
  176. &.row-center {
  177. padding: 0;
  178. }
  179. }
  180. }
  181. }
  182. /* #ifdef MP || APP-PLUS */
  183. .mp-header {
  184. z-index: 30;
  185. position: fixed;
  186. left: 0;
  187. top: 0;
  188. width: 100%;
  189. background: linear-gradient(90deg, $bg-star 50%, $bg-end 100%);
  190. .serch-wrapper {
  191. height: 100%;
  192. /* #ifdef MP */
  193. padding: 0 220rpx 0 53rpx;
  194. /* #endif */
  195. /* #ifdef APP-PLUS */
  196. padding: 0 50rpx 0 40rpx;
  197. /* #endif */
  198. .logo {
  199. height: 60rpx;
  200. margin-right: 30rpx;
  201. image {
  202. width: 100%;
  203. height: 100%;
  204. }
  205. }
  206. .input {
  207. flex: 1;
  208. height: 50rpx;
  209. padding: 0 0 0 30rpx;
  210. background: rgba(247, 247, 247, 1);
  211. border: 1px solid rgba(241, 241, 241, 1);
  212. color: #BBBBBB;
  213. font-size: 28rpx;
  214. .iconfont {
  215. margin-right: 20rpx;
  216. }
  217. // 没有logo,直接搜索框
  218. &.on {
  219. /* #ifdef MP */
  220. width: 70%;
  221. /* #endif */
  222. /* #ifdef APP-PLUS */
  223. width: 100%;
  224. /* #endif */
  225. }
  226. // 设置圆角
  227. &.fillet {
  228. border-radius: 29rpx;
  229. }
  230. // 文本框文字居中
  231. &.row-center {
  232. padding: 0;
  233. }
  234. }
  235. }
  236. }
  237. /* #endif */
  238. </style>