headerSerch.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <!-- 搜索框 -->
  3. <!-- #ifdef H5 -->
  4. <view class="header"
  5. :style="'background: linear-gradient(90deg, '+ bgColor[0].item +' 50%, '+ bgColor[1].item +' 100%);margin-top:'+ mbConfig*2 +'rpx;'">
  6. <view class="serch-wrapper acea-row row-middle"
  7. :class="(tabVal===0 || tabVal===1) && txtStyle===1?'center':(tabVal===0 || tabVal===1) && txtStyle===2?'right':''"
  8. :style="'padding-left:'+ prConfig*2 +'rpx;padding-right:'+ (tabVal===0 || tabVal===1?prConfig*2:20) +'rpx;'">
  9. <view class="logo skeleton-rect" v-if="logoConfig && tabVal===2 && radioVal===2">
  10. <image :src="logoConfig" mode="heightFix"></image>
  11. </view>
  12. <view class="title"
  13. :style="{color:`${textColor}`,fontStyle:`${textStyle!='bold'?textStyle:''}`,fontWeight:`${textStyle=='bold'?textStyle:''}`}"
  14. v-if="tabVal===0 || (tabVal===2 && radioVal === 0)" @click="goLink">{{titleConfig}}</view>
  15. <view class="map acea-row row-middle" @click="chooseLocation"
  16. :style="{color:`${textColor}`,fontStyle:`${textStyle!='bold'?textStyle:''}`,fontWeight:`${textStyle=='bold'?textStyle:''}`}"
  17. v-if="tabVal===1 || (tabVal===2 && radioVal === 1)">
  18. <text class="iconfont icon-dingwei4"></text>
  19. <view class="info line1" :class="tabVal===1?'on':'on1'">{{addressInfo}}</view>
  20. <text class="iconfont icon-xiangxia"></text>
  21. </view>
  22. <navigator v-if="tabVal===2" url="/pages/goods/goods_search/index"
  23. class="input acea-row row-middle skeleton-rect"
  24. :class="[boxStyle?'':'fillet',logoConfig?'':'on',txtStyle===1?'row-center':txtStyle===2?'row-right':'']"
  25. hover-class="none"><text class="iconfont icon-sousuo"></text>
  26. 搜索商品</navigator>
  27. </view>
  28. </view>
  29. <!-- #endif -->
  30. <!-- #ifdef MP || APP-PLUS -->
  31. <view v-if="special" class="header"
  32. :style="'background: linear-gradient(90deg, '+ bgColor[0].item +' 50%, '+ bgColor[1].item +' 100%);margin-top:'+ mbConfig*2 +'rpx;'">
  33. <view class="serch-wrapper acea-row row-middle"
  34. :class="(tabVal===0 || tabVal===1) && txtStyle===1?'center':(tabVal===0 || tabVal===1) && txtStyle===2?'right':''"
  35. :style="'padding-left:'+ prConfig*2 +'rpx;padding-right:'+ (tabVal===0 || tabVal===1?prConfig*2:20) +'rpx;'">
  36. <view class="logo skeleton-rect" v-if="logoConfig && tabVal===2 && radioVal===2">
  37. <image :src="logoConfig" mode="heightFix"></image>
  38. </view>
  39. <view class="title"
  40. :style="{color:`${textColor}`,fontStyle:`${textStyle!='bold'?textStyle:''}`,fontWeight:`${textStyle=='bold'?textStyle:''}`}"
  41. v-if="tabVal===0 || (tabVal===2 && radioVal === 0)" @click="goLink">{{titleConfig}}</view>
  42. <view class="map acea-row row-middle" @click="chooseLocation"
  43. :style="{color:`${textColor}`,fontStyle:`${textStyle!='bold'?textStyle:''}`,fontWeight:`${textStyle=='bold'?textStyle:''}`}"
  44. v-if="tabVal===1 || (tabVal===2 && radioVal === 1)">
  45. <text class="iconfont icon-dingwei4"></text>
  46. <view class="info line1" :class="tabVal===1?'on':'on1'">{{addressInfo}}</view>
  47. <text class="iconfont icon-xiangxia"></text>
  48. </view>
  49. <navigator v-if="tabVal===2" url="/pages/goods/goods_search/index"
  50. class="input acea-row row-middle skeleton-rect"
  51. :class="[boxStyle?'':'fillet',logoConfig?'':'on',txtStyle===1?'row-center':txtStyle===2?'row-right':'']"
  52. hover-class="none"><text class="iconfont icon-sousuo"></text>
  53. 搜索商品</navigator>
  54. </view>
  55. </view>
  56. <view v-else>
  57. <view class="mp-header"
  58. :style="'background: linear-gradient(90deg, '+ bgColor[0].item +' 50%, '+ bgColor[1].item +' 100%);margin-top:'+ mbConfig*2 +'rpx;'">
  59. <view class="sys-head" :style="{ height: statusBarHeight }"></view>
  60. <view class="serch-box" style="height: 43px;">
  61. <view class="serch-wrapper acea-row row-middle"
  62. :class="(tabVal===0 || tabVal===1) && txtStyle===1?'center':(tabVal===0 || tabVal===1) && txtStyle===2?'right':''"
  63. :style="'padding-left:'+ prConfig*2 +'rpx;padding-right:'+ (tabVal===0 || tabVal===1?prConfig*2:20) +'rpx;'">
  64. <view class="logo skeleton-rect" v-if="logoConfig && tabVal===2 && radioVal===2">
  65. <image :src="logoConfig" mode="heightFix"></image>
  66. </view>
  67. <view class="title"
  68. :style="{color:`${textColor}`,fontStyle:`${textStyle!='bold'?textStyle:''}`,fontWeight:`${textStyle=='bold'?textStyle:''}`}"
  69. v-if="tabVal===0 || (tabVal===2 && radioVal === 0)" @click="goLink">{{titleConfig}}</view>
  70. <view class="map acea-row row-middle" @click="chooseLocation"
  71. :style="{color:`${textColor}`,fontStyle:`${textStyle!='bold'?textStyle:''}`,fontWeight:`${textStyle=='bold'?textStyle:''}`}"
  72. v-if="tabVal===1 || (tabVal===2 && radioVal === 1)">
  73. <text class="iconfont icon-dingwei4"></text>
  74. <view class="info line1" :class="tabVal===1?'on':'on1'">{{addressInfo}}</view>
  75. <text class="iconfont icon-xiangxia"></text>
  76. </view>
  77. <navigator v-if="tabVal===2" url="/pages/goods/goods_search/index"
  78. class="input acea-row row-middle skeleton-rect"
  79. :class="[boxStyle?'':'fillet',logoConfig?'':'on',txtStyle===1?'row-center':txtStyle===2?'row-right':'']"
  80. hover-class="none">
  81. <text class="iconfont icon-sousuo"></text>
  82. 搜索商品
  83. </navigator>
  84. </view>
  85. </view>
  86. </view>
  87. <view :style="'height:'+marTop+'px;'"></view>
  88. </view>
  89. <!-- #endif -->
  90. </template>
  91. <script>
  92. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  93. export default {
  94. name: 'headerSerch',
  95. props: {
  96. dataConfig: {
  97. type: Object,
  98. default: () => {}
  99. },
  100. special: {
  101. type: Number,
  102. default: 0
  103. },
  104. addressInfo: {
  105. type: String,
  106. default: '选择地址'
  107. }
  108. },
  109. data() {
  110. return {
  111. statusBarHeight: statusBarHeight,
  112. marTop: 0,
  113. bgColor: this.dataConfig.bgColor.color,
  114. boxStyle: this.dataConfig.boxStyle.type,
  115. logoConfig: this.dataConfig.logoConfig.url,
  116. mbConfig: this.dataConfig.mbConfig.val,
  117. txtStyle: this.dataConfig.txtStyle.type,
  118. hotWords: this.dataConfig.hotWords.list,
  119. prConfig: this.dataConfig.prConfig.val,
  120. tabVal: this.dataConfig.tabConfig.tabVal,
  121. radioVal: this.dataConfig.radioConfig.tabVal,
  122. textColor: this.dataConfig.textColor.color[0].item,
  123. textStyle: this.dataConfig.textStyle.list[this.dataConfig.textStyle.type].style,
  124. titleConfig: this.dataConfig.titleConfig.value
  125. };
  126. },
  127. mounted() {
  128. let that = this;
  129. uni.setStorageSync('hotList', that.hotWords);
  130. that.$store.commit('hotWords/setHotWord', that.hotWords);
  131. // #ifdef MP || APP-PLUS
  132. setTimeout(() => {
  133. // 获取小程序头部高度
  134. let info = uni.createSelectorQuery().in(this).select(".mp-header");
  135. info.boundingClientRect(function(data) {
  136. that.marTop = data.height
  137. }).exec()
  138. }, 100)
  139. // #endif
  140. },
  141. methods: {
  142. goLink(){
  143. let url = this.dataConfig.linkConfig.value;
  144. if (url.indexOf("http") != -1) {
  145. // #ifdef H5
  146. location.href = url
  147. // #endif
  148. // #ifdef MP || APP-PLUS
  149. uni.navigateTo({
  150. url: `/pages/annex/web_view/index?url=${url}`
  151. });
  152. // #endif
  153. } else {
  154. if (['/pages/goods_cate/goods_cate', '/pages/order_addcart/order_addcart', '/pages/user/index']
  155. .indexOf(url) == -1) {
  156. uni.navigateTo({
  157. url: url
  158. })
  159. } else {
  160. uni.reLaunch({
  161. url: url
  162. })
  163. }
  164. }
  165. },
  166. chooseLocation: function() {
  167. let that = this;
  168. uni.chooseLocation({
  169. success: (res) => {
  170. that.$emit('getAddress',res)
  171. },
  172. fail: (err)=>{
  173. console.log(err)
  174. }
  175. })
  176. },
  177. }
  178. }
  179. </script>
  180. <style lang="scss">
  181. .serch-wrapper {
  182. &.center {
  183. justify-content: center;
  184. }
  185. &.right {
  186. justify-content: flex-end;
  187. /* #ifdef MP */
  188. padding-right: 185rpx !important;
  189. /* #endif */
  190. }
  191. }
  192. .title {
  193. font-size: 30rpx;
  194. }
  195. .map {
  196. color: #fff;
  197. font-size: 30rpx;
  198. margin-right: 20rpx;
  199. .info {
  200. &.on {
  201. width: 260rpx;
  202. }
  203. &.on1 {
  204. max-width: 156rpx;
  205. }
  206. }
  207. .iconfont {
  208. font-size: 32rpx;
  209. margin-right: 6rpx;
  210. }
  211. .icon-xiangxia {
  212. font-size: 28rpx;
  213. margin-left: 10rpx;
  214. }
  215. }
  216. .header {
  217. width: 100%;
  218. height: 100rpx;
  219. background: linear-gradient(90deg, $bg-star 50%, $bg-end 100%);
  220. .serch-wrapper {
  221. padding: 20rpx 20rpx 0 0;
  222. .logo {
  223. height: 60rpx;
  224. image {
  225. width: 100%;
  226. height: 100%;
  227. }
  228. }
  229. .input {
  230. flex: 1;
  231. height: 58rpx;
  232. padding: 0 20rpx 0 30rpx;
  233. background: rgba(247, 247, 247, 1);
  234. border: 1px solid rgba(241, 241, 241, 1);
  235. color: #BBBBBB;
  236. font-size: 28rpx;
  237. margin-left: 20rpx;
  238. .iconfont {
  239. margin-right: 20rpx;
  240. }
  241. // 没有logo,直接搜索框
  242. &.on {
  243. width: 100%;
  244. }
  245. // 设置圆角
  246. &.fillet {
  247. border-radius: 29rpx;
  248. }
  249. // 文本框文字居中
  250. &.row-center {
  251. padding: 0;
  252. }
  253. }
  254. }
  255. }
  256. /* #ifdef MP || APP-PLUS */
  257. .mp-header {
  258. z-index: 30;
  259. position: fixed;
  260. left: 0;
  261. top: 0;
  262. width: 100%;
  263. background: linear-gradient(90deg, $bg-star 50%, $bg-end 100%);
  264. .serch-wrapper {
  265. height: 100%;
  266. /* #ifdef MP */
  267. padding: 0 220rpx 0 53rpx !important;
  268. /* #endif */
  269. /* #ifdef APP-PLUS */
  270. padding: 0 50rpx 0 40rpx;
  271. /* #endif */
  272. .logo {
  273. height: 60rpx;
  274. margin-right: 30rpx;
  275. image {
  276. width: 100%;
  277. height: 100%;
  278. }
  279. }
  280. .input {
  281. flex: 1;
  282. height: 50rpx;
  283. padding: 0 0 0 30rpx;
  284. background: rgba(247, 247, 247, 1);
  285. border: 1px solid rgba(241, 241, 241, 1);
  286. color: #BBBBBB;
  287. font-size: 28rpx;
  288. .iconfont {
  289. margin-right: 20rpx;
  290. }
  291. // 没有logo,直接搜索框
  292. &.on {
  293. /* #ifdef MP */
  294. width: 70%;
  295. /* #endif */
  296. /* #ifdef APP-PLUS */
  297. width: 100%;
  298. /* #endif */
  299. }
  300. // 设置圆角
  301. &.fillet {
  302. border-radius: 29rpx;
  303. }
  304. // 文本框文字居中
  305. &.row-center {
  306. padding: 0;
  307. }
  308. }
  309. }
  310. }
  311. /* #endif */
  312. </style>