<template>
	<view class="container">
		<uni-nav-bar title="门店信息" backgroundColor='#03803B' color="#fff" left-icon="left" fixed statusBar
			@clickLeft='goBack()' @clickRight="addDetails" rightWidth="140rpx">
			<block slot="right">
				<view style="font-size: 26rpx;">
					<!-- <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"
				cancelButton="none" @clear="searchChange">
			</uni-search-bar>
		</view>
		<z-paging ref="paging" v-model="dataList" @query="getList" :fixed="false" :auto-show-back-to-top="true"
			:empty-view-text="searchValue ? '未找到相关结果' : '暂无数据'" :hide-empty-view="false"
			:auto-show-system-loading="true">
			<view class="list">
				<view style="margin-top: 30rpx;" v-for="(item, index) in dataList" :key="index" @click="inEdit(item)">
					<uni-swipe-action>
						<uni-swipe-action-item>
							<view class="tab-bar-item">
								<image class="icon" :src="item.url" />
								<view class="text">
									<view class="text_title">
										<text style="color: #03803B;">店铺名称:</text>
										<text style="color: #6A6A6A" class='uni-lastmsg'>{{item.cname||'-'}}</text>
									</view>
									<view class="text_content">
										<text style="color: #03803B;">前置仓:</text>
										<text style="color: #6A6A6A"
											class='uni-lastmsg2'>{{item.deliveryWarehouseName||'暂无仓库'}}</text>
										<text style="color: #03803B;margin-left: 10rpx;">价格:</text>
										<text style="color: #6A6A6A"
											class='uni-lastmsg2'>￥{{item.priceSystem||0}}</text>
									</view>
									<view class="text_foot">
										<text style="color: #03803B;">电话:</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>
							<template v-slot:right>
								<view @click.stop="onClick(item)"
									style="width: 120rpx;background-color:#e43d33;display: flex;justify-content: center;align-items: center;color: #fff;">
									<text>删除</text>
								</view>
							</template>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
			</view>
		</z-paging>
		<uni-popup ref="popup">
			<image style="width: 400rpx;height: 400rpx;background-color: #fff;" :src="imgPopup" />
		</uni-popup>
	</view>
</template>

<script>
	import {
		getList,
		remove,
		generateQrCode
	} from '@/api/home/store.js'
	export default {
		data() {
			return {
				searchValue: null,
				dataList: [],
				imgPopup: null,
			}
		},
		onLoad() {
	
		},
		onShow() {
			if (uni.getStorageSync('isUpdate')) {
				this.$nextTick(() => {
					if (this.$refs.paging) {
						this.$refs.paging.reload();
					}
				});
				uni.removeStorageSync('isUpdate')
			}
		},
		methods: {
			onClick(row) {
				let _this = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除？',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中',
								mask: true
							});
							remove(row.id).then(res => {
									uni.showToast({
										title: '操作成功',
										icon: 'none',
										duration: 2000
									});
									_this.searchChange()
								})
								.finally(() => {
									uni.hideLoading()
								});
						}
					}
				});
			},
			addDetails() {
				uni.navigateTo({
					url: '/pages/home/store/details'
				});
			},
			inEdit(row) {
				uni.navigateTo({
					url: '/pages/home/store/details?id=' + row.id,
				});
			},
			inQR(row) {
				this.imgPopup = null
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				generateQrCode({
						corpId: row.id
					}).then(res => {
						// uni.previewImage({
						// 	urls: [res.data.filePath],
						// });
						this.$refs.popup.open()
						this.imgPopup = res.data.filePath
					})
					.finally(() => {
						uni.hideLoading()
					});
				// uni.showToast({
				// 	title: '暂无二维码',
				// 	icon: 'none'
				// });
			},
			searchChange() {
				this.$refs.paging.reload()
			},
			async getList(pageNo, pageSize) {
				try {
					const obj = {
						retrieve: this.searchValue,
						current: pageNo,
						size: pageSize
					}
					const res = await getList(obj)
					this.$refs.paging.complete(res.data.records)
				} catch (e) {
					this.$refs.paging.complete(false)
					uni.showToast({
						title: '加载失败',
						icon: 'none'
					})
				}
			},
			goBack() {
				uni.navigateBack({
					delta: 1,
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scroll-view {
		flex: 1;
		height: 100%;
		/* 关键样式：防止内容被裁剪 */
		overflow-anchor: none;
	}

	.container {
		height: 100vh;
		display: flex;
		flex-direction: column;
	}

	.loading,
	.no-more {
		text-align: center;
		padding: 20px;
		color: #999;
	}

	.uni-lastmsg {
		width: 260rpx;
		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;
			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 {
					display: flex;
					height: 44rpx;
					font-weight: 500;
					font-size: 28rpx;
					color: #6A6A6A;
				}

				.text_content {
					display: flex;
					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>