制作有提示的搜索框

本文介绍如何使用高德地图API进行停车场搜索,包括实时输入监测、搜索建议展示及搜索结果处理。通过监听输入事件,实现上海市内停车场的模糊搜索,并利用搜索结果进行导航。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

<header class="mui-bar mui-bar-nav" style="margin: 0px;height: 34px;margin-top:6px;">
						<div style="width:100%;height:100%;background-color: #fff;position: relative;box-shadow: 0px 2px 1px #c8c6c2;border-radius: 3px;">
							<!-- <a class="mui-action-back mui-icon mui-icon-arrowleft mui-pull-left cfgx-head-back"></a> -->

							<h1 class="mui-title" style="left: 20px;">
								<input type="search" class="cfgx-head-ipt" id="tipinput" @input="inputLength()"  @blur="limtNone()" @focus="limtBlock()"
								 @keypress="searchGoods" placeholder="请输入目的地搜索" style="">

							</h1>
							<a href="javascript:void(0)" class=" mui-pull-right cfgx-head-xx" v-if="isVlaueShow" @tap="cleanVlaue()"></a>
							<a href="javascript:void(0)" id="searchInput" class="cfgx-head-search  mui-pull-right" @tap="pageCheKu()">
								搜索
							</a>
						</div>

					</header>

在这里插入图片描述

				// 监听input输入事件
					inputLength() {
						var val = $("#tipinput").val();

						if (val.trim().length > 0 && val != '') {
							_this.isVlaueShow = true;
							_this.limtSecarch(val)
						} else {
							_this.limtDataList = [];
							_this.isVlaueShow = false;
						}
					},
					cleanVlaue() {
						$("#tipinput").val("");
						_this.limtDataList = [];
						_this.isVlaueShow = false;
					},
					limtBlock() {
						_this.inputLength()
					},
					limtNone() {
						_this.limtDataList = [];
					},
					limtSecarch(val){
								searchValue(val,(status,result)=>{
									_this.limtDataList = [];
									result.tips.forEach(val=>{
										if(val.name!=''&&val.district.indexOf('上海市')>-1){
											if(val.address==''){
												val.address = val.name;												
											}
											//名字跟坐标
											_this.cheKuValue = val.name;
											_this.cheKuLat = val.location.lat;
											_this.cheKuLng = val.location.lng;
											// return false
											_this.limtDataList.push(val);
											// this.limtDataList.push(val);
											}
									})
								})
							},

在这里插入图片描述

/**
 * 根据搜索值列出列表
 * @param {Object} value
 */
function searchValue(value, callback) {
	AMap.plugin('AMap.Autocomplete', function() {
		// 实例化Autocomplete
		var autoOptions = {
			//city: '全国',
			city: '上海'
		}
		var autoComplete = new AMap.Autocomplete(autoOptions);
		autoComplete.search(value, function(status, result) {
			var arr = [];
			// console.log(result.tips)
			if(result.tips != undefined){
					result.tips.map((val, index) => {
				if (val.name != '' && val.district.indexOf('上海市') > -1&&val.location!="" && val.location!=undefined) {
					arr.push(val)
				}
			})
			}
		
			result.tips = arr;
			callback(status, result)
			// 搜索成功时,result即是对应的匹配数据
			// var node = new PrettyJSON.view.Node({
			// 	el: document.querySelector("#input-info"),
			// 	data: result
			// });
		})
	})
}

在这里插入图片描述

					pageCheKu(){
						var _searchVal = $("#tipinput").val();
						if (!_searchVal || _searchVal.trim().length === 0) {
							mui.toast("请输入停车场名称!")
							return false;
						}
						var val = _this.cheKuValue;
						var lat = _this.cheKuLat;
						var lng = _this.cheKuLng;
						$("#tipinput").val();
						var url = `CheKuNavigation/parkingCar.html?_searchVal=${val}&lat=${lat}&lng=${lng}`;
						url = encodeURI(encodeURI(url)); //用了2次encodeURI 编码
						mui.openWindow({
							swipeBack: true, //启用右滑关闭功能
							url:url,
							waiting: {
								autoShow: true, //自动显示等待框,默认为true
								title: '正在加载数据...', //等待对话框上显示的提示内容
							},
						})
					},
					searchGoods(event) {
						if (event.keyCode == 13) {
							event.preventDefault(); //禁止默认事件(默认是换行)
							var _searchVal = $("#tipinput").val();
							app.limtDataList = [];
							if (!_searchVal || _searchVal.trim().length === 0) {
								mui.toast("请输入停车场名称!")
								return false;
							}
							var val = _this.cheKuValue;
							var lat = _this.cheKuLat;
							var lng = _this.cheKuLng;
							$("#tipinput").val();
							var url = `CheKuNavigation/parkingCar.html?_searchVal=${val}&lat=${lat}&lng=${lng}`;
							url = encodeURI(encodeURI(url)); //用了2次encodeURI 
							mui.openWindow({
								swipeBack: true, //启用右滑关闭功能
								url:url,
								waiting: {
									autoShow: true, //自动显示等待框,默认为true
									title: '正在加载数据...', //等待对话框上显示的提示内容
								},
							})
						}
					},

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值