headerSerch.vue 13 KB

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