<template>
	<page-meta :page-style="themeColor"></page-meta>
	<div class="view">
		<div class="card">
			<div class="box">
				<div class="title">正常使用</div>
				<ns-empty text="暂无数据"  :isIndex="false" v-if="!storeList1.length"></ns-empty>
				<div :class="active==item.id?'row_active':'row'" v-for="(item,index) in storeList1" :key="index"
					@click="changeActive(item)">
					<!-- <image class="avatar" :src="$util.img('/upload/weapp/user/wx.png')"></image> -->
					<div class="name">{{item.title}}</div>
					<div class="label" v-if="item.label">{{item.label}}</div>
					<div class="reduce" v-else>
						<image :src="$util.img('/upload/weapp/user/reduce.png')" @click.stop="changeStatus(item,'reduce')" mode="">
						</image>
					</div>
					<image class="gou" :src="$util.img('/upload/weapp/user/gou2.png')" mode=""></image>
				</div>
			</div>
		</div>

		<div class="card">
			<div class="box">
				<div class="title">待审核店铺</div>
				<ns-empty text="暂无数据"  :isIndex="false" v-if="!storeList0.length"></ns-empty>
				<div class="row" v-for="(item,index) in storeList0" :key="index">
					<!-- <image class="avatar"  :src="$util.img('/upload/weapp/user/wx.png')"></image> -->
					<div class="name">{{item.title}}</div>
					<div class="label" v-if="item.label">{{item.label}}</div>
					<div class="edit">
						<image @click.stop="editStore(item)" :src="$util.img('/upload/weapp/user/edit.png')" mode=""></image>
					</div>
					<div class="del">
						<image @click.stop="changeStatus(item,'del')" :src="$util.img('/upload/weapp/user/del.png')" mode=""></image>
					</div>
				</div>
			</div>
		</div>

		<div class="card">
			<div class="box">
				<div class="title">已驳回店铺</div>
				<ns-empty text="暂无数据"  :isIndex="false" v-if="!storeList2.length"></ns-empty>
				<div class="row" v-for="(item,index) in storeList2" :key="index">
					<!-- <image class="avatar" :src="$util.img('/upload/weapp/user/wx.png')"></image> -->
					<div class="name">{{item.title}}</div>
					<div class="edit">
						<image @click.stop="editStore(item)" :src="$util.img('/upload/weapp/user/edit.png')" mode=""></image>
					</div>
					<div class="del">
						<image @click.stop="changeStatus(item,'del')" :src="$util.img('/upload/weapp/user/del.png')" mode=""></image>
					</div>
					<image class="gou" :src="$util.img('/upload/weapp/user/gou2.png')" mode=""></image>
				</div>
			</div>
		</div>
		<div class="card">
			<div class="box">
				<div class="title">已停用店铺</div>
				<ns-empty text="暂无数据"  :isIndex="false" v-if="!storeList3.length"></ns-empty>
				<div class="row" v-for="(item,index) in storeList3" :key="index">
					<div class="name">{{item.title}}</div>
					<div class="edit">
						<image @click.stop="editStore(item)" :src="$util.img('/upload/weapp/user/edit.png')" mode=""></image>
					</div>
					<div style="flex: 1;display: flex;justify-content: flex-end;">
						<div class="del" style="flex: 0;">
							<image @click.stop="changeStatus(item,'del')" :src="$util.img('/upload/weapp/user/del.png')" mode=""></image>
						</div>
						<div class="reduce" style="flex: 0;">
							<image :src="$util.img('/upload/weapp/user/reduce.png')" @click.stop="firing(item)" mode="">
							</image>
						</div>
					</div>
					
					<image class="gou" :src="$util.img('/upload/weapp/user/gou2.png')" mode=""></image>
				</div>
			</div>
		</div>
		<div class="btnbox">
			<div class="btn" @click="toNewStore">新增店铺</div>
		</div>

		<u-overlay :show="showOverlay" class="overlay">
			<div class="modal_box">
				<div class="title">提示</div>
				<div class="desc">{{overlayType=='del'?'确认要删除该店铺吗？':'确认要停用该店铺吗？停用后，店铺不能再继续使用'}}</div>
				<div class="btn_box">
					<div class="cancel" @click="showOverlay=false">取消</div>
					<div class="submit" @click="confirm" :style="overlayType=='del'?'background: #F33B50;' : 'background: #21BBF3;'">确定
					</div>
				</div>
			</div>
		</u-overlay>
		
		<loading-cover ref="loadingCover"></loading-cover>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				showOverlay: false,
				overlayType: '',
				active: 0,
				storeList0: [],//待审核
				storeList1: [],//审核通过
				storeList2: [],//驳回
				storeList3: [],//停用
				editVla:{},
			}
		},
		onLoad() {
		},
		onShow() {
			for (let i = 0; i <= 3; i++) {
				this.getStoreList(i)
			}
		},
		methods: {
			//店铺列表
			getStoreList(status = 1) {
				this.loading = true
				this.$api.sendRequest({
					url: '/api/member/getStoreList',
					data: {
						status
					},
					success: ({
						data
					}) => {
						this[`storeList${status}`] = data
						if(data.length&&status==1){
							let myStore=uni.getStorageSync('myStore')
							myStore?this.active=myStore.id:this.active=data[0].id
						}
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					complete: res => {
						this.loading = false
					}
				})
			},
			toNewStore() {
				uni.navigateTo({
					url: '/pages_tool/member/store/add_store'
				})
			},
			//切换店铺
			changeActive(item) {
				uni.setStorageSync('myStore', item);
				this.active = item.id
			},
			changeStatus(val,type){
				this.editVla=val
				this.overlayType =type
				this.showOverlay = true
			},
			//删除 停用
			confirm(){
				let apiUrl = this.overlayType=='del'?'/api/member/delStore':'/api/member/stopStore'
				this.$api.sendRequest({
					url: apiUrl,
					data: {
						id:this.editVla.id
					},
					success: res => {
						this.$util.showToast({
							title: res.message
						});
						if(this.editVla.status==1){
							this.getStoreList(1)
							this.getStoreList(3)
						}else{
							this.getStoreList(this.editVla.status)
						}	
					},
					complete: res => {
						this.showOverlay = false
					}	
				})
			},
			//启用
			firing(val){
				this.$api.sendRequest({
					url: '/api/member/startStore',
					data: {
						id:val.id
					},
					success: res => {
						this.$util.showToast({
							title: '店铺启用成功，请等待管理员重新审核'
						});
						this.getStoreList(0)
						this.getStoreList(3)
					}	
				})
			},
			editStore(item){
				uni.navigateTo({
					url: '/pages_tool/member/store/add_store?id='+item.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card {
		line-height: 1;
		margin: 32rpx;
		padding: 32rpx;
		background-color: #fff;
		border-radius: 24rpx;
	}

	.box {
		.title {
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 600;
			color: #333333;
		}

		.row_active {
			margin-top: 24rpx;

			height: 92rpx;
			background: rgba(33, 187, 243, 0.08);
			border-radius: 16rpx;
			border: 2rpx solid $base-color;

			display: flex;
			align-items: center;

			position: relative;

			.avatar {
				width: 48rpx;
				height: 48rpx;
				margin-left: 24rpx;
			}

			.name {
				margin-left: 16rpx;
			}

			.label {
				margin-left: 20rpx;
				border-radius: 8rpx;
				border: 1rpx solid rgba(33, 187, 243, 0.2);
				padding: 8rpx;

				height: 32rpx;
				font-size: 22rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: $base-color;
				line-height: 32rpx;
			}

			.gou {
				width: 32rpx;
				height: 32rpx;
				position: absolute;
				right: 0rpx;
				bottom: -3rpx;
			}

			.reduce {
				display: none;
			}
		}

		.row {
			margin-top: 24rpx;
			border: 2rpx solid #fff;
			height: 92rpx;
			background: #F7F7F7;
			border-radius: 16rpx;

			display: flex;
			align-items: center;

			.avatar {
				width: 48rpx;
				height: 48rpx;
				margin-left: 24rpx;
			}

			.name {
				margin-left: 16rpx;
			}

			.edit {
				margin-left: 32rpx;

				image {
					width: 24rpx;
					height: 24rpx;
				}
			}

			.del {
				margin-right: 32rpx;
				flex: 1;
				text-align: right;

				image {
					width: 24rpx;
					height: 24rpx;
				}
			}

			.label {
				margin-left: 20rpx;
				padding: 8rpx;
				border-radius: 8rpx;
				border: 1rpx solid #E8E8E8;

				height: 32rpx;
				font-size: 22rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;

				font-weight: 400;
				color: $base-color;
				text-align: center;

			}

			.gou {
				width: 32rpx;
				height: 32rpx;
				display: none;
			}

			.reduce {
				flex-grow: 1;
				text-align: right;
				margin-right: 32rpx;

				image {
					width: 24rpx;
					height: 24rpx;
				}
			}

		}
	}

	.btnbox {
		position: fixed;
		bottom: 0;
		width: 100%;
		padding: 32rpx;
		box-sizing: border-box;
		background-color: #fff;

		.btn {
			width: 100%;
			height: 80rpx;
			background: #21BBF3;
			border-radius: 40rpx;

			display: flex;
			justify-content: center;
			align-items: center;

			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 600;
			color: #FFFFFF;
			line-height: 40rpx;
		}
	}

	.view {
		padding-bottom: 154rpx;
	}

	.modal_box {
		width: 100%;

		position: relative;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);

		width: 540rpx;
		background: #FFFFFF;
		border-radius: 24rpx;


		.title {
			padding-top: 24rpx;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 600;
			color: #222222;
		}

		.desc {
			text-align: center;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #585858;
			padding: 32rpx 32rpx 0;
			line-height: 1.2;
		}


		.btn_box {
			margin: 56rpx 0 32rpx 0;
			display: flex;
			justify-content: space-evenly;

			.cancel {
				width: 206rpx;
				height: 72rpx;
				border-radius: 40rpx;
				border: 2rpx solid #E8E8E8;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				color: #222222;
			}

			.submit {
				width: 206rpx;
				height: 72rpx;

				border-radius: 40rpx;

				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 40rpx;
				display: flex;
				justify-content: center;
				align-items: center;

			}
		}
	}
</style>
