<template>
	<view class="siteInspection-wrap">
		<!-- 搜索框 -->
		<view class="search-con">
			<u-search placeholder="查找全部门店" v-model="queryValue" @custom="searchHandle(1)" @search="searchHandle(1)" bg-color="#fff" :action-style="{background: '#2979ff',color: '#fff', borderRadius: '6upx',padding: '6upx 0', fontSize: '26upx'}"></u-search>
		</view>
		<!-- 定位 -->
		<view class="location-con" ref="location">
			<text class="location-tit">当前位置：</text>
			<view class="location-main" @click="getLocation">
				<text class="location-addr">{{location}}</text>
				<u-icon name="map" color="#2979ff" size="34" class="location-icon"></u-icon>
			</view>
		</view>
		<!-- 附近的门店 -->
		<view class="store-con">
			<text class="store-tit">附近的门店：</text>
			<scroll-view class="scroll-con" scroll-y :style="{'height': 'calc(100vh - ' + Height + 'px)'}">
				<!-- 列表数据 -->
				<view class="list-con">
					<view class="list-item" v-for="(item,index) in listdata" :key="index" @click="chooseStore(item)">
						<view class="item-main">
							<u-icon class="company-icon" name="mendian" custom-prefix="xd-icon" size="40" color="#888"></u-icon>
							<text>{{item.name}}</text>
						</view>
						<u-icon class="listData-item-r-icon" name="xianchangrenwu" custom-prefix="xd-icon" size="40" color="#2b85e4"></u-icon>
					</view>
				</view>
				<u-empty class="nodata" :text="noDataText" v-if="listdata.length==0 && status!='loading'" mode="list"></u-empty>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import { clzConfirm } from '@/libs/tools.js'
	import { findStoreList } from '@/api/store.js'
	export default{
		data(){
			return{
				queryValue: '',
				location: '陕西西安未央区北二环信息机大厦100号',
				noDataText: '未查找到附近门店',  //  列表请求状态提示语
				status: 'loadmore',  //  加载中状态
				listdata: [],  //  列表数据
				pageNo: 1,  //  当前页码
				pageSize: 10,  //  每页条数
				total: 0,  //  数据总条数
				Height: 200,  //  滚动区域  元素dom高度
			}
		},
		onReady() {
			this.init()
		},
		methods: {
			// 初始化
			init(){
				this.getLocation()
			},
			// 获取当前位置
			getLocation(){
				const _this = this
				uni.getLocation({
				    type: 'gcj02',
					geocode: true,
				    success: function (res) {
						console.log(res)
						// _this.location = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum +'靠近' + res.address.poiName
						setTimeout(()=>{
							_this.searchHandle(res)
						}, 500)
				    }
				})
			},
			//查询门店列表
			searchHandle(res){
				this.status = "loading"
				findStoreList({
					lng:res.longitude,
					lat:res.latitude,
					queryWord: this.queryValue
				}).then(res => {
					if (res.status == 200) {
						this.listdata = res.data.list || []
						this.total = this.listdata.length
						this.listdata.length == 0 && this.queryValue != '' ? this.noDataText = '没有搜索到相关结果' : this.noDataText = '暂无数据'
					} else {
						this.noDataText = res.message
						this.listdata = []
						this.total = 0
					}
					this.status = "loadmore"
				})
			},
			// 选择门店
			chooseStore(item){
				uni.navigateTo({
					url:"/pages/signIn/signIn?id="+item.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.siteInspection-wrap{
		background-color: #f8f8f8;
		.search-con{
			padding: 30upx 30upx;
		}
		// 定位
		.location-con{
			padding: 0 30upx;
			.location-main{
				margin-top: 14upx;
				padding: 20upx;
				border-radius: 12upx;
				background-color: #fff;
				.location-icon{
					padding-left: 10upx;
					vertical-align: bottom;
				}
			}
		}
		// 附近的门店
		.store-con{
			.store-tit{
				display: block;
				padding: 30upx 30upx 20upx;
			}
			//  列表  44 62  
			.scroll-con{
				height: calc(100vh - 215px);
				width: 100%;
				overflow: auto;
				.list-con{
					padding: 0 30upx;
					.list-item{
						background-color: #fff;
						padding: 20upx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						border-bottom: 1px solid #F8F8F8;
						.item-main{
							font-size: 15px;
							color: rgb(48, 49, 51);
							display: flex;
							align-items: center;
							.company-icon{
								margin-right: 6upx;
							}
						}
					}
				}
			}
		}
	}
</style>
