<template>
	<view class="app">
		<view class="body">
			<view class="left">
				<u-collapse :accordion='false'>
					<u-collapse-item :title="item.year" v-for="(item, index) in itemlistleft" :key="index"
						:class="item.check?'headcollapse':''" @change='tapcollapseleft(item)' :open="item.open">
						<view class="itemtext" v-for="aitem in item.list" @tap="dataies(aitem)">
							<view :style="recordCode == aitem.recordCode ? 'color:#26A888' : ''">
								{{aitem.recordDate}}
							</view>
						</view>
					</u-collapse-item>
				</u-collapse>
			</view>
			<view class="right">
				<u-collapse :item-style="itemStyle" :arrow="false" :accordion='false'>
					<u-collapse-item :title="item.tempName" v-for="(item, index) in itemList" :open="item.open"
						:key="index" @change='tapcollapse(item)' :class="item.check?'headcollapse':''">
						<view class="" v-if="item.onelist">
							<view class="uitemtitle">健康生活方式</view>
							<view class="itemtext" v-for="(uitem,uindex) in item.onelist" :key="uindex">
								<view class="collapse_top">
									<view class="itemsdata">
										<view class="itemword">
											<u-checkbox active-color="#26A888" v-model="uitem.val" disabled>
												<view class="checkboxtitle">
													{{ uitem.content }}
												</view>
												<view v-if="uitem.ptValList">
													<view class="checkboxtext" v-for="bitem in uitem.ptValList"
														:key="bitem.id">
														{{ bitem.content }}
													</view>
												</view>
											</u-checkbox>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="" v-if="item.twolist">
							<view class="uitemtitle">治疗与康复</view>
							<view class="itemtext" v-for="(uitem,uindex) in item.twolist" :key="uindex">
								<view class="collapse_top">
									<view class="itemsdata">
										<view class="itemword">
											<u-checkbox active-color="#26A888" v-model="uitem.val" disabled>
												<view class="checkboxtitle">
													{{ uitem.content }}
												</view>
												<view v-if="uitem.ptValList">
													<view class="checkboxtext" v-for="bitem in uitem.ptValList"
														:key="bitem.id">
														{{ bitem.content }}
													</view>
												</view>
											</u-checkbox>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="" v-if="item.threelist">
							<view class="uitemtitle">急症处理</view>
							<view class="itemtext" v-for="(uitem,uindex) in item.threelist" :key="uindex">
								<view class="collapse_top">
									<view class="itemsdata">
										<view class="itemword">
											<u-checkbox active-color="#26A888" v-model="uitem.val" disabled>
												<view class="checkboxtitle">
													{{ uitem.content }}
												</view>
											</u-checkbox>
											<view v-if="uitem.ptValList">
												<view class="checkboxtext" v-for="bitem in uitem.ptValList"
													:key="bitem.id">
													{{ bitem.content }}
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</u-collapse-item>
				</u-collapse>
			</view>
		</view>
		<u-loading :show="show" mode="flower" size="40"></u-loading>
	</view>
</template>

<script>
	import {
		dayList,
		detail
	} from "@/api/pagesB/threeHundredAndSixty/threeHundredAndSixty.js"
	export default {
		data() {
			return {
				show: true,
				lastrecodedata: null,
				cardNo: '',
				itemlistleft: [],
				itemList: [],
				recordCode: '',
			}
		},
		mounted() {
			this.lastrecodelist()
		},
		methods: {
			lastrecodelist() {
				if (uni.getStorageSync("userinfo")) {
					this.cardNo = uni.getStorageSync("userinfo").cardNo
					dayList(this.cardNo).then(res => {
						if (res.data && res.data.length > 0) {
							res.data.forEach(e => {
								if (e.list && e.list.length > 0) {
									e.list.forEach(el => {
										el.recordDate = el.recordDate.substr(5, 9);
									})
								}
							})
						}
						this.itemlistleft = res.data
						this.itemlistleft && this.itemlistleft.length > 0 ? this.itemlistleft[0].open = true : ''
						if (res.data && res.data[0].list.length > 0) {
							this.recordCode = res.data[0].list[0].recordCode
							this.dataies({
								recordCode: this.recordCode
							});
						} else {
							this.show = false
						}
					})
				}
			},
			tapcollapse(item) {
				item.check = !item.check
			},
			dataies(aitem) {
				this.recordCode = aitem.recordCode
				detail(this.recordCode).then(res => {
					res.data && res.data.ptList && res.data.ptList.length > 0 ? res.data.ptList[0]
						.open = true : ''
					res.data.ptList.forEach(e => {
						e.ptValList.forEach(el => {
							el.val == "true" ? el.val = true : el.val = false
						})
						e.onelist = e.ptValList.filter(el => el.itemType == '1')
						e.twolist = e.ptValList.filter(el => el.itemType == '2')
						e.threelist = e.ptValList.filter(el => el.itemType == '3')
					})
					this.itemList = res.data.ptList
					this.show = false
				})
			},
			tapcollapseleft(item) {
				item.check = !item.check
			}
		}
	}
</script>

<style lang="scss">
	::v-deep .u-checkbox__icon-wrap--disabled--checked {
		background-color: #2979ff !important;
		border-color: #2979ff !important;
	}

	page {
		background-color: #fff;
	}

	.checkboxtitle {
		font-size: 24rpx;
		margin-bottom: 10rpx;
		font-weight: 600;
	}

	.checkboxtext {
		color: #606266;
		font-weight: 550;
		font-size: 22rpx;
		padding-left: 40rpx;
	}

	.app {
		// height: 100vh;
		padding: 32rpx 10rpx;
		text-align: center;
		font-size: 36rpx;

		.body {
			width: 100%;
			// height: 100vh;
			display: flex;

			.left {
				// height: 100vh;
				width: 30%;

				::v-deep .u-collapse-title {
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #000;
					padding-left: 10rpx;
					font-weight: 600;
				}

				::v-deep .u-collapse-head {
					width: 96%;
					margin: 0 auto;

				}

				.itemtext {
					font-size: 28rpx;
					background: #FFFFFF;
					font-weight: 500;
					color: #333333;
					height: 100rpx;
					padding-left: 10rpx;
					line-height: 100rpx;
					border-bottom: 2rpx solid #E6E6E6;
					margin: 0 auto;
					display: flex;
					justify-content: space-between;
				}

				.headcollapse {
					::v-deep .u-collapse-head {
						border-bottom: 2rpx solid #E6E6E6;
					}

					::v-deep .u-collapse-item {
						padding-bottom: 4rpx;
					}
				}


				::v-deep .u-collapse-head {
					width: 96%;
					margin: 0 auto;
					// background: #169BD5 !important;
					text-align: center;
					color: #fff;
				}

				::v-deep .u-collapse-item {
					// background-color: #4271B9;
					margin-bottom: 2rpx;
				}
			}

			.right {
				// height: 100vh;
				width: 70%;

				::v-deep .u-collapse-title {
					font-size: 30rpx;
					font-weight: 600;
					padding-left: 10rpx;
				}

				::v-deep .u-icon--right {
					color: #26A888 !important;
				}

				.headcollapse {
					::v-deep .u-collapse-head {
						border-bottom: 2rpx solid #E6E6E6;
						text-align: center !important;
					}

					::v-deep .u-collapse-title {
						color: #26A888;
					}
				}

				::v-deep .u-collapse-head {
					width: 96%;
					margin: 0 auto;
					background: #26A888 !important;
					text-align: center;
					color: #fff;
				}

				.uitemtitle {
					font-weight: 600;
					font-size: 28rpx;
					color: #000;
					margin-top: 15rpx;
					padding-left: 30rpx;
				}

				// background-color: red;
				.itemtext {
					.collapse_top {
						font-size: 22rpx;
						font-weight: 500;
						color: #000;
						width: 100%;
						line-height: 40rpx;
						margin: 0 auto;
						padding: 10rpx;

						.itemsdata {
							width: 100%;

							.itemword {
								margin: 15rpx;
							}
						}
					}
				}
			}
		}
	}
</style>