<template>
	<view class="page">
		<u-navbar title="我的店铺" :border-bottom="false" :background="bgc" title-color='#fff' title-size='36'
			back-icon-color="#fff" height='50'></u-navbar>
		<view class="box">
			<view class="top">
				<u-search placeholder="搜索" input-align="center" v-model="keyword" @custom="searchs"></u-search>
				<view class="cjshop" @click="creadshop">创建店铺</view>
			</view>

			<view class="list" @scrolltolower="onReachBottom">
				<view class="listitem" v-for="(item,index) in wateringList" :key="index" @click="btnshopxq(item.storeId)">
					<view class="toptit">
						<image src="https://api.ccttiot.com/smartmeter/img/static/uIKex42Zr1fwfzYGgGKz" mode=""></image>
						<view class="tit">
							{{item.name}}
						</view>
						<view class="yuan">
							<text
								style="width: 9rpx;height: 9rpx;border-radius: 50%;margin-right: 5rpx;background-color: #000;display: inline-block;"></text>
							<text
								style="width: 9rpx;height: 9rpx;border-radius: 50%;margin-right: 5rpx;background-color: #000;display: inline-block;"></text>
							<text
								style="width: 9rpx;height: 9rpx;border-radius: 50%;margin-right: 5rpx;background-color: #000;display: inline-block;"></text>
						</view>
					</view>
					<view class="rishou">
						<view class="rishouwz">
							<text> 日收 </text><text> 月收 </text><text> 上月收</text><text> 在线 </text><text> 离线 </text>
						</view>
						<view class="rishouje">
							<text>{{item.todayIncome}}￥</text><text>{{item.monthIncome}}￥</text><text>{{item.lastMonthIncome}}￥</text><text>{{item.onlineCount}}台</text><text>{{item.offlineCount}}台</text>
						</view>
					</view>
					<view class="gzlist">
						<view class="jfgz" v-if="item.status == 2">
							<text>审核状态：</text> 审核中
						</view>
						<view class="jfgz" v-if="item.status == 1">
							<text>审核状态：</text> 正常
						</view>
						<view class="jfgz" style="margin-top: 16rpx;">
							<text>是否生效：</text> {{item.enabled == false ? '未生效' : '生效'}}
						</view>
						<view class="jfgz" style="margin-top: 16rpx;">
							<text>客服名称：</text>{{item.contactName}}
						</view>
						<view class="phone">
							<text>客服电话：</text>{{item.contactMobile}}
						</view>
					</view>
					<view class="yunxing">
						<text>已运营{{item.daysDifference + 1}}天</text> <text>{{item.createTime}}</text>
					</view>
				</view>
				<view class="" v-if="showflag" style="width: 100%;height: 200rpx;margin: auto;margin-top: 170rpx;text-align: center;">
					<image style="width: 200rpx;height: 200rpx;"
						src="https://api.ccttiot.com/smartmeter/img/static/uZFUpcz0YZZ4f4RjvGg2" mode=""></image>
					<view class="" style="font-size: 28rpx;color: #808080;margin-top: 30rpx;">暂无更多店铺...</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: " #8883F0",
				},
				pagenum: 1,
				wateringList: [],
				pagesize: 10, // 一页多少数据
				isLoading: false, // 是否正在加载数据  
				noMoreData: false, // 是否没有更多数据  
				total: 0,
				keyword: '',
				showflag: false
			}
		},
		onLoad() {
           
		},
		// 分享到好友（会话）
		  onShareAppMessage: function () {  
		    return {  
		      title: '创想物联',  
		      path: '/pages/shouye/index'  
		    }  
		  },  
		  
		  // 分享到朋友圈  
		  onShareTimeline: function () {  
		    return {  
		      title: '创想物联',  
		      query: '',  
		      path: '/pages/shouye/index'  
		    }  
		  },
		onShow() {
			this.pagenum = 1
			this.wateringList = []
			this.getlist()
		},
		methods: {
			// 请求店铺列表
			getlist() {
				// if (this.isLoading || this.noMoreData) {
				// 	return;
				// }
				this.isLoading = true;
				this.$u.get("/app/store/list?pageNum=" + this.pagenum + '&pageSize=' + this.pagesize + '&keyword=' + this.keyword).then(res => {
					if (res.code == 200) {
						this.total = res.total
						if (this.total > 0) {
							this.showflag = false
						} else {
							this.showflag = true
						}
						if (res.rows.length > 0) {
							// 有数据，追加到列表  
							this.wateringList = this.wateringList.concat(res.rows)
							this.pagenum++

							// 计算创建到现在运行了多少天
							this.wateringList.forEach((item, index) => {
								var dateTime = new Date(item.createTime)
								if (isNaN(dateTime.getTime())) {
									console.error(`无法解析日期时间字符串: ${item.createTime}`)
									return
								}
								var now = new Date().getTime()
								var differenceInMilliseconds = now - dateTime.getTime();
								var differenceInDays = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24))
								// 直接修改原数组中的对象，添加daysDifference属性  
								item.daysDifference = differenceInDays
							})
						} else {
							// 没有更多数据  
							this.noMoreData = true
						}
						this.isLoading = false
					}
				}).catch(error => {
					console.error('获取店铺失败:', error)
					this.isLoading = false // 加载失败也标记为完成  
				})
			},

			searchs() {
				this.wateringList = []
				this.getlist()
			},

			onReachBottom() {
				let sum = this.total / this.pagesize
				if (this.pagenum - 1 < sum) {
					this.getlist() // 上拉加载更多  
				} else {
					uni.showToast({
						title: '没有更多店铺了',
						icon: 'none',
						duration: 1000
					});
				}
			},

			creadshop() {
				uni.navigateTo({
					url: '/page_fenbao/statulist/myshop/shopxx/index'
				})
			},
			btnshopxq(id) {
				uni.navigateTo({
					url: '/page_fenbao/statulist/myshop/shopdetail/index?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	/deep/ .u-title {
		padding-bottom: 22rpx;
	}
	/deep/ .uicon-nav-back {
		padding-bottom: 22rpx;
	}
	.page {
		width: 750rpx;
		height: 100vh;
		.box {
			width: 750rpx;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			padding-top: 150rpx;
			.list {
				padding-bottom: 400rpx;
				margin-top: 26rpx;
				.listitem {
					margin-bottom: 28rpx !important;
					padding: 12rpx 38rpx;
					box-sizing: border-box;
					width: 680rpx;
					height: 540rpx;
					background: #FFFFFF;
					border-radius: 38rpx 38rpx 38rpx 38rpx;
					margin: auto;
					.yunxing {
						display: flex;
						justify-content: space-between;
						font-size: 26rpx;
						color: #808080;
						margin-top: 26rpx;
					}
					.phones {
						margin-top: 16rpx;
						font-size: 26rpx;
						color: #1DBE7B;
						border-bottom: 1px solid #ccc;
						padding-bottom: 26rpx;
						box-sizing: border-box;
						text {
							color: #808080;
						}
					}
					.phone {
						margin-top: 16rpx;
						font-size: 26rpx;
						color: #3D3D3D;
						text {
							color: #808080;
						}
					}
					.gzlist {
						margin-top: 30rpx;
						border-bottom: 1rpx solid #ccc;
						padding-bottom: 26rpx;
						.jfgz {
							font-size: 26rpx;
							color: #3D3D3D;
							text {
								color: #808080;
							}
						}
					}
					.rishou {
						margin-top: 26rpx;
						box-sizing: border-box;
						.rishouwz {
							display: flex;
							justify-content: space-between;
							text {
								font-size: 26rpx;
								color: #808080;
								width: 230rpx;
								text-align: center;
							}
						}
						.rishouje {
							display: flex;
							justify-content: space-between;
							margin-top: 10rpx;
							text {
								font-weight: 500;
								font-size: 32rpx;
								color: #3D3D3D;
								width: 230rpx;
								text-align: center;
							}
						}
					}
					.toptit {
						border-bottom: 1px solid #ccc;
						display: flex;
						justify-content: space-between;
						padding-bottom: 12rpx;
						box-sizing: border-box;
						image {
							width: 48rpx;
							height: 48rpx;
							margin-top: 10rpx;
						}
						.tit {
							width: 484rpx;
							height: 68rpx;
							line-height: 68rpx;
							padding-left: 20rpx;
							background: #F4F3FF;
							border-radius: 16rpx 16rpx 16rpx 16rpx;
							font-weight: 600;
							font-size: 30rpx;
							color: #3D3D3D;
							box-sizing: border-box;
						}
						.bd {
							margin-top: 28rpx;
							height: 100%;
							font-size: 20rpx;
							color: #FFFFFF;
							padding: 4rpx 12rpx;
							box-sizing: border-box;
							background: #1DBE7B;
							border-radius: 6rpx 6rpx 6rpx 6rpx;
						}
						.yuan {
							margin-top: 10rpx;
						}
					}
				}
			}
			.top {
				width: 750rpx;
				height: 150rpx;
				background: #FFFFFF;
				padding: 45rpx 36rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				position: fixed;
				top: 170rpx;
				.cjshop {
					width: 200rpx;
					height: 64rpx;
					background-color: #8883F0;
					border-radius: 50rpx;
					text-align: center;
					line-height: 64rpx;
					color: #fff;
					font-size: 32rpx;
					margin-left: 20rpx;
				}
				/deep/ .u-content {
					border: 1px solid #ccc;
					border-radius: 50rpx 0 0 50rpx !important;
				}
				/deep/ .u-action {
					border-radius: 0 50rpx 50rpx 0 !important;
					width: 112rpx;
					height: 65rpx;
					line-height: 65rpx;
					border: 2rpx solid #ccc;
					margin-left: 0;
					color: #3D3D3D;
					background-color: #f2f2f2;
				}
			}
		}
	}
</style>