<template>
	<view class="content">
		<!-- 搜索 -->
		<view class="searchBoxBg">
			<!-- <view class="searchBox">
				<image src="../../static/img/icon_search.png" mode="" class="searchImg"></image>
				<input type="text" class="searchInput" placeholder="请输入门店名称、联系人、手机号" v-model="searchValue"
					@confirm="searchDone" />
			</view> -->
			<searchBox placeholder="请输入门店名称、联系人、手机号" @search='search($event)'></searchBox>

		</view>

		<!-- 门店列表 -->
		<view class="shopContent">
			<view v-for="(item,index) in shopData" :key="index">
				<view class="shopBox">
					<view class="shopTop">
						<view class="shopName">{{item.ShopName}}</view>

						<!-- 地址和电话 -->
						<image class="tubiao" src="../../static/img/icon_daohang_def@2x.png" mode=""
							@click="goAddress(item)">
						</image>
						<image class="tubiao" src="../../static/img/icon_phone_def@2x.png" mode=""
							@click="call(item.ContactorPhone)">
						</image>
					</view>

					<!-- 门店类型-开业时间-联系人 -->
					<view class="shopType"><text style='color: #B98B5D;'>{{item.levelName}}</text> ·
						<text v-if="item.OpeningTime != null">{{item.OpeningTime}}</text> 联系人：{{item.Contactor}}
					</view>
					<!-- 详细地址 -->
					<view class="addressView">
						<view class="address">{{item.Address}}</view>
						<view class="distance" v-if="item.distance != 0.00">{{item.distance}}km</view>
					</view>


				</view>
			</view>
		</view>

		<!-- 上拉 加载更多 -->
		<view class="noMore" v-if="noMoreShow">没有更多数据</view>
		<!-- 无数据空白页 -->
		<view class="nodataBox" v-if="shopData.length == 0">
			<image src="../../static/img/pic_empty_def.png" mode="widthFix" class="nodataImg"></image>
			<view class="noTxt">暂无数据</view>
		</view>

	</view>
</template>

<script>
	import searchBox from '@/components/searchBox/searchBox.vue'
	export default {
		components: {
			searchBox
		},
		data() {
			return {
				searchValue: '',
				managerID: '',
				lng: '',
				lat: '',
				shopData: [],
				page: 1,
				noMoreShow: false,
			}
		},
		onLoad: function(option) {
			this.managerID = option.managerID
			var that = this
			uni.getLocation({
				success(res) {
					that.lng = res.longitude
					that.lat = res.latitude

					that.page = 1
					that.getShopData()
				}
			})
		},
		methods: {
			search(val) {
				// console.log(val);
				this.searchValue = val
				this.page = 1
				this.getShopData()
			},
			getShopData() {
				uni.showLoading({
					title: '加载中'
				})
				let url = 'accompany/SuperAccounts/queryShopListByManagerID',
					params = {
						page: this.page,
						limit: 20,
						managerID: this.managerID,
						shopName: this.searchValue,
						lng: this.lng,
						lat: this.lat,
					}
				this.$http(url, params, 'GET').then(res => {
					var list = res.data.Items

					// 处理 undefined和null转为空白字符串
					list.forEach((item, index) => {
						for (const key in item) {
							item[key] = this.$praseStrEmpty(item[key])
						}
					})


					if (this.page == 1) {
						this.shopData = list
					} else {
						this.shopData = this.shopData.concat(list)
					}

					if (list.length < 10) {
						this.noMoreShow = false
					} else {
						this.noMoreShow = true
					}

				})
			},

			goAddress(v) {
				if (!v.lat) {
					uni.showToast({
							title: '该门店未设置定位',
							icon: 'none',
							duration: 2000,
						});
						return
				}
				uni.openLocation({
					latitude: Number(v.lat),
					longitude: Number(v.lng),
					name: v.ShopName,
					address: v.Address,
				});
			},
			call(e) {
				if (e.length != 0) {
					uni.makePhoneCall({
						phoneNumber: e
					})
				}
			}
		},
		// 下拉刷新 上拉加载更多
		onPullDownRefresh() {
			this.getShopData()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.page++
			this.getShopData()
		}
	}
</script>

<style>
	.content {
		background-color: #F4F5F7;
		min-height: 100vh;

	}

	.searchBoxBg {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		background-color: #FFFFFF;
		z-index: 99;
	}

	/* #ifdef H5 */
	.searchBoxBg {
		top: 44px;
	}

	/* #endif */
	.searchBox {
		display: flex;
		height: 72rpx;
		margin: 24rpx;
		background-color: #F4F5F7;
		border-radius: 36rpx;
	}

	.searchImg {
		margin-top: 20rpx;
		margin-left: 20rpx;
		width: 32rpx;
		height: 32rpx;
	}

	.searchInput {
		height: 72rpx;
		font-size: 28rpx;
		padding-left: 16rpx;
		width: 85%;
	}

	.shopContent {

		padding: 0rpx 24rpx;
		padding-top: 120rpx;
		background-color: #F4F5F7;

	}

	.shopBox {
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin: 20rpx 0rpx;
	}

	.shopTop {
		display: flex;
		padding: 30rpx 20rpx 10rpx 20rpx;
		justify-content: space-between;

	}

	.shopName {
		font-size: 30rpx;
		color: #3C3C3C;
		font-weight: bold;
		width: 500rpx;
	}

	.tubiao {
		width: 48rpx;
		height: 48rpx;
		margin-left: 40rpx;
	}

	.shopType {
		font-size: 26rpx;
		padding: 10rpx 20rpx;
		color: #3C3C3C;
	}

	.addressView {
		font-size: 26rpx;
		color: #999999;
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-top: 10rpx;
		padding-bottom: 30rpx;
		display: flex;
		justify-content: space-between;

	}

	.distance {
		margin-left: 20rpx;
		margin-right: 20rpx;
	}

	/* 空白页css */
	.nodataBox {
		text-align: center;
	}

	.nodataImg {
		width: 400rpx;
		padding-top: 300rpx;
	}

	.noTxt {
		font-size: 30rpx;
		color: #999999;
		padding-top: 50rpx;
	}

	.noMore {
		text-align: center;
		line-height: 50rpx;
		color: #999999;
		font-size: 28rpx;
	}
</style>
