headerSerch.vue 14 KB

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