<template>
	<view style="height: 100vh;">
		<uni-nav-bar title="门店信息" backgroundColor='#03803B' color="#fff" left-icon="left" fixed statusBar
			@clickLeft='goBack()' @clickRight="addDetails">
			<block slot="right">
				<view>
					<image class="nav-right" src="@/static/images/home/store/add.png" />
				</view>
			</block>
		</uni-nav-bar>
		<view style="background-color: #fff;">
			<uni-search-bar bgColor="#F6F6F6 " v-model="searchValue" placeholder="请输入店铺名称" @confirm="searchChange"
				@cancel="searchChange" @clear="searchChange">
			</uni-search-bar>
		</view>
		<scroll-view scroll-y="true" :refresher-enabled="true" :refresher-triggered="triggered"
			@refresherrefresh="onRefresh" class="scroll-view">
			<view class="list">
				<u-empty v-if='dataList.length==0' mode="list">
				</u-empty>
				<view class="tab-bar-item" v-for="(item, index) in dataList" :key="index" @click="inEdit(item)">
					<image class="icon" :src="item.url" />
					<view class="text">
						<view class="text_title">
							{{item.cname}}
						</view>
						<view class="text_content">
							<text style="color: #999999;">前置仓:</text>
							<text style="color: #6A6A6A"
								class='uni-lastmsg'>{{item.deliveryWarehouseName||'暂无仓库'}}</text>
							<text style="color: #999999;margin-left: 10rpx;">价格:</text>
							<text style="color: #6A6A6A" class='uni-lastmsg2'>￥{{item.priceSystem||0}}</text>
						</view>
						<view class="text_foot">
							<text style="color: #999999;">电话:</text>
							<text style="color: #6A6A6A">{{item.tel}}</text>
						</view>
					</view>
					<view class="menu">
						<view class="">
							<image class="edit" src="@/static/images/home/store/edit.png" />
						</view>
						<view class="">
							<image class="QR" src="@/static/images/home/store/QR.png"  @click.stop="inQR(item)"/>
						</view>
					</view>
				</view>
			</view>
			<view v-if="loading" class="loading">加载中...</view>
			<view v-if="noMore" class="no-more">没有更多数据了</view>
		</scroll-view>

	</view>
</template>

<script>
	import {
		getList
	} from '@/api/home/store.js'
	export default {
		data() {
			return {
				triggered: false,
				searchValue: null,
				page: {
					current: 1,
					size: 10,
					total: 0,
				},
				dataList: [],
				loading: false,
				noMore: false
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			if (!this.noMore) {
				this.page.current += 1
				this.getList()
			}
		},
		methods: {
			onRefresh() {
				if (this.triggered) return;
				this.triggered = true;
				this.noMore = false;
				// 模拟异步请求
				setTimeout(() => {
					this.page.current = 1
					this.dataList = []
					this.getList()
				}, 500);
			},
			addDetails() {
				uni.navigateTo({
					url: '/pages/home/store/details'
				});
			},
			inEdit(row) {
				uni.navigateTo({
					url: '/pages/home/store/details?id=' + row.id,
				});
			},
			inQR(row) {
				uni.showToast({
					title: '暂无二维码',
					icon: 'none'
				});
			},
			searchChange(res) {
				this.triggered = true;
				this.noMore = false;
				// 模拟异步请求
				setTimeout(() => {
					this.page.current = 1
					this.dataList = []
					this.getList()
				}, 500);
			},
			getList() {
				const obj = {
					retrieve: this.searchValue,
					current: this.page.current,
					size: this.page.size
				}
				this.loading = true
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				getList(obj).then(res => {
						this.dataList = [...this.dataList, ...res.data.records]
						console.log(this.dataList.length)
						if (res.data.total <= this.dataList.length) {
							this.noMore = true
						}
					})
					.finally(() => {
						uni.hideLoading()
						this.loading = false
						this.triggered = false
					});
			},
			goBack() {
				uni.navigateBack({
					delta: 1,
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scroll-view {
	  height: 100%;
	}
	.loading,
	.no-more {
		text-align: center;
		padding: 20px;
		color: #999;
	}

	.uni-lastmsg {
		width: 150rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		display: block;
		/* 需明确设置display */
	}

	.uni-lastmsg2 {
		width: 140rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		display: block;
		/* 需明确设置display */
	}

	.nav-right {
		width: 54rpx;
		height: 54rpx;
	}

	.list {
		width: 100%;

		.tab-bar-item {
			background-color: #fff;
			margin-top: 30rpx;
			padding: 30rpx 62rpx;
			display: flex;

			.icon {
				width: 140rpx;
				height: 140rpx;
				background: #909090;
				border-radius: 14rpx;
			}

			.text {
				padding: 0rpx 17rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				height: 140rpx;

				.text_title {
					height: 44rpx;
					font-weight: 500;
					font-size: 28rpx;
					color: #6A6A6A;
				}

				.text_content {
					display: flex;
					margin-top: 8rpx;
					font-size: 28rpx;
					font-weight: 500;
				}

				.text_foot {
					font-size: 28rpx;
					font-weight: 500;
				}
			}

			.menu {
				position: absolute;
				right: 62rpx;

				.edit {
					margin-top: 10rpx;
					width: 30rpx;
					height: 33rpx;
				}

				.QR {
					margin-top: 54rpx;
					width: 30rpx;
					height: 31rpx;
				}
			}
		}
	}
</style>