headerSerch.vue 12 KB

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