<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">
			<image class="btnImg" src="../../static/images/hywh.png" @click="btnClick(0)" />
			<image class="btnImg img2" src="../../static/images/jsjz.png" @click="btnClick(1)" />
		</view>

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

					<uni-list>
						<uni-list-item v-for="(item,index) in dataList" :key="index" :title="item.lrXm"
							:thumb="item.lrTx?config.baseUrl+item.lrTx:config.baseUrl + config.head" :note="item.lrCydh"
							thumbSize="lg" :showArrow="false">
							<template v-slot:footer>
								<view v-if="item.lzzt == '0'"
									style="width: 60px;display: flex;flex-direction: column;background-image: url('../../static/images/caogao.png');background-position: left;background-size:58px 58px;background-repeat: no-repeat;">
									<text v-if="item.updateTime">{{item.updateTime.substring(0,8) }}</text>
									<text v-else>{{item.createTime.substring(0,8) }}</text>
									<text>{{item.lrSpyj || '无'}}</text>
								</view>
								<view v-else-if="item.lzzt == '1' || item.lzzt == '2'"
									style="width: 60px;display: flex;flex-direction: column;background-image: url('../../static/images/daishenhe.png');background-position: left;background-size:58px 58px;background-repeat: no-repeat;">
									<text v-if="item.updateTime">{{item.updateTime.substring(0,8) }}</text>
									<text v-else>{{item.createTime.substring(0,8) }}</text>
									<text>{{item.lrSpyj || '无'}}</text>
								</view>
								<view v-else-if="item.lzzt == '3'"
									style="width: 60px;display: flex;flex-direction: column;background-image: url('../../static/images/tongguo.png');background-position: left;background-size:58px 58px;background-repeat: no-repeat;">
									<text v-if="item.updateTime">{{item.updateTime.substring(0,8) }}</text>
									<text v-else>{{item.createTime.substring(0,8) }}</text>
									<text>{{item.lrSpyj || '无'}}</text>
								</view>
								<view v-else-if="item.lzzt == '4'"
									style="width: 60px;display: flex;flex-direction: column;background-image: url('../../static/images/jujue.png');background-position: left;background-size:58px 58px;background-repeat: no-repeat;">
									<text v-if="item.updateTime">{{item.updateTime.substring(0,8) }}</text>
									<text v-else>{{item.createTime.substring(0,8) }}</text>
									<text>{{item.lrSpyj || '无'}}</text>
								</view>

							</template>
						</uni-list-item>
					</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
	} from '@/api/kh.js'
	export default {
		data() {
			return {
				interval: 3000,
				bannerList: [{
					image: '../../static/image/banner2.png'
				}],
				lrInfo: {},
				// 人员信息
				userInfo: {},
				userType: '',
				form: {
					pageNum: 1,
					pageSize: 4,
					createUserId: ''
				},
				dataList: [],
				total: 0,
			}
		},
		onShow() {
			// 老人07、员工04、监管06
			this.userInfo = getUser()
			this.userType = this.userInfo.userType
			if (this.userType == '07') {
				this.info(this.userInfo.userId)
			} else {
				this.form.createUserId = this.userInfo.userId
			}
			this.dataList = []
			this.getDaiBanList()
		},
		methods: {
			getDaiBanList() {
				ListKhjbxx(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])
						if (list) this.dataList.push(...list)
					}
				})
			},
			toList() {
				// 待办事项（他给老人注册、他给老人维护）  会员维护  结算记账（食堂）
				// 登录不获取openid
				uni.navigateTo({
					url: '/pages/lr/list'
				})
			},
			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 && this.userType != '04') {
					uni.showToast({
						icon: 'none',
						title: '该功能暂未开放'
					})
				} else {
					let baseUrl = '/pages/lr/base?info=' + JSON.stringify(this.lrInfo)
					let url = index == 0 ? baseUrl : '/pages/lr/eat'
					uni.navigateTo({
						url: url
					})
				}

			}
		}
	}
</script>

<style scoped>
	.container {
		display: flex;
		flex-direction: column;
		height: 100vh;
		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%;
	}

	.daiban {
		position: fixed;
		left: 4px;
		right: 4px;
	}
</style>