<template>
	<view class="container">
		<view>
			<text class="phoneText global-font">Hello,{{userInfo.nickName}}</text>
		</view>

		<view class="bannerBox">
			<swiper class="swiper-box" :interval="interval" autoplay indicator-dots indicator-color="#C7C7C7"
				indicator-active-color="#1aad19">
				<swiper-item v-for="(item, index) in bannerList" :key="index">
					<image src="../../static/images/banner2.png" class="imgItem" @click="bannerItemClick(item)"></image>
				</swiper-item>
			</swiper>
		</view>

		<view class="btnBox" v-if="userType !== '07'">
			<image v-if="isShow" class="btnImg" src="../../static/images/lrzc.png" @click="btnClick(0)" />
			<image v-if="userType !== '07'" class="btnImg img2" src="../../static/images/jsjz.png" @click="btnClick(1)" />
		</view>

		<view>
			<uni-card v-if="userType !== '07'" class="daiban">
				<uni-section type="line" title="待办事项">
					<template v-slot:right>
						<text @click="toList">更多 ></text>
					</template>

					<uni-list>
						<template v-for="(item,index) in dataList">
							<!-- (item.lzzt == '1' || item.lzzt == '2' || item.lzzt == '5'|| item.lzzt == '7') && -->
							<uni-list-item v-if=" item.state != '99'" :key="index" :title="item.lrXm" :note="item.sqyy"
								thumbSize="lg" :showArrow="false">
								<template v-slot:header>
									<image :src="item.lrTx?config.baseUrl+item.lrTx:config.baseUrl + config.head"
										style="width: 10vw;height: 5vh;margin-right: 2vw;border-radius: 50%;"></image>
								</template>
								<template v-slot:footer>
									<view class="item-right">
										<text>{{item.sqsj.substring(0,8) }}</text>
										<image class="item-img" src="@/static/images/daishenhe.png" mode=""></image>
										<!-- <text>{{item.lrSpyj || '无'}}</text> -->
									</view>
								</template>
							</uni-list-item>
						</template>

					</uni-list>
				</uni-section>
			</uni-card>
		</view>

	</view>
</template>

<script>
	import {
		getToken,
		getUser
	} from '@/common/auth.js'
	import {
		decryptRowData_ECB,
		decryptData_ECB
	} from '@/common/sm4.js'
	import {
		updateKhjbxx,
		infoKhjbxx,
		ListKhjbxx,
		ListKhShxx
	} from '@/api/kh.js'

	export default {
		data() {
			return {
				interval: 3000,
				isShow:true,
				bannerList: [{
					image: '../../static/image/banner2.png'
				}],
				lrInfo: {},
				// 人员信息
				userInfo: {},
				userType: '',
				form: {
					pageNum: 1,
					pageSize: 4,
					state:'0',
					// createUserId: ''
				},
				dataList: [],
				total: 0,
			}
		},
		onLoad() {
			// 老人07、员工04、监管00
			this.userInfo = getUser()
			this.userType = this.userInfo.userType
			if(['04'].includes(this.userInfo.userType)&&this.userInfo.lrzptype)
			{
					  if(this.userInfo.lrzptype=='2')
					  {
						  this.isShow=false;
					  }
			}
		},
		onShow() {
			// if (this.userType == '07') {
			//   this.info(this.userInfo.userId)
			// } else {
			//   this.form.createUserId = this.userInfo.userId
			// }
			if (this.userInfo.userType !== '00') {
				this.form.createUserId = this.userInfo.userId
			}
			this.dataList = []
			this.getDaiBanList()
		},
		methods: {
			getDaiBanList() {
				ListKhShxx(this.form).then(res => {
					if (res.code == 200) {
						this.total = res.total
						// let list = decryptRowData_ECB(res.rows, ["lrZjhm", "lrXm", "lrHjbcxx", "lrXjdzBcxx",
						// 	"lrCydh", "lrPoxm", "lrPoZjmh", "jhrXm", "jhrSjhm", "zlrXm", "zlrDh", "cjzh",
						// 	"yhzh", "khmc"
						// ], [2, 1, 4, 4, 3, 1, 2, 1, 2, 1, 3, 5, 5, 5])
						let list = res.rows
						this.dataList.push(...list)
					}
				})
			},
			toList() {
				// 待办事项（他给老人注册、他给老人维护）  会员维护  结算记账（食堂）
				// 登录不获取openid
				uni.navigateTo({
					url: '/pages/lr/shxxList'
				})
			},
			info(id) {
				infoKhjbxx(id).then(res => {
					if (res.code == 200) {
						this.lrInfo = decryptData_ECB(res.data, ["lrZjhm", "lrXm", "lrHjbcxx", "lrXjdzBcxx",
							"lrCydh", "lrPoxm", "lrPoZjmh", "jhrXm", "jhrSjhm", "zlrXm", "zlrDh", "cjzh",
							"yhzh", "khmc"
						], [2, 1, 4, 4, 3, 1, 2, 1, 2, 1, 3, 5, 5, 5]);
					}
				})
			},
			btnClick(index) {
				if (index == 1) {
					// uni.showToast({
					//   icon: 'none',
					//   title: '该功能暂未开放'
					// })
				} else {
					let baseUrl = '/pages/info/add-files'
					uni.navigateTo({
						url: baseUrl
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item-right {
		width: 60px;
		display: flex;
		flex-direction: column;
		background-position: left;
		background-size: 58px 58px;
		background-repeat: no-repeat;
		position: relative;
		font-size: 14px;

		.item-img {
			position: absolute;
			right: -5px;
			bottom: -10px;
			height: 40px;
			width: 40px;
		}
	}

	.container {
		// display: flex;
		// flex-direction: column;
		// height: 100vh;
    padding: 1px 0 50px;
		width: 100vw;
		background: linear-gradient(to bottom, #07bf61 0%, #fff 30%, #F8FCFF 100%);
	}

	/* 轮播图 */
	.bannerBox {
		width: 100vw;
	}

	.swiper-box {
		height: 19vh;
		margin: 7vh 2vh 20px;
	}


	.imgItem {
		width: 100%;
		height: 100%;
	}

	.swiper-box swiper-item {
		border-radius: 15px;
		overflow: hidden;
	}

	.phoneText {
		position: absolute;
		margin-top: 2vh;
		margin-left: 5vw;
		width: 80vw;
		height: 2vh;
		font-size: 14px;
		color: white;
		font-weight: 700;
		line-height: 2vh;
		text-align: left;
		vertical-align: top;
	}



	/* 按钮 */
	.btnBox {
		/* width: 90%; */
		display: flex;
		margin: 1vh 19px;
	}

	.btnImg {
		width: 49%;
		height: 16vh;
	}

	.img2 {
		margin-left: 2%;
		opacity: 0.36;
	}

	.daiban {
		// position: fixed;
		// left: 4px;
		// right: 4px;
    margin: 20px !important;
    padding: 0 !important;
	}
</style>