<template>
	<view class="page">
		<!-- <view class="top">
			<view class="position" @click="isShowSite = true">
				<u-icon name="map-fill"></u-icon>
				<text>{{ vuex_site.name || ' ' }}</text>
				<u-icon name="arrow-down" size="22"></u-icon>
			</view>
		</view> -->
		<image class="bkg" src="~@/package_sub/static/ServeHospital/bkg.png"></image>

		<view class="container">
			<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">

				<view v-if="list.length>0">
					<view class="list">
						<view class="list-item" v-for="(item,i) in list" :key="i" @click="toDetail(item)">
							<view class="left">
								<image  :src="item.cover?item.cover.url:''" alt=""></image>
							</view>
							<view class="center">
								<view class="title">{{ item.name }}</view>
								<view class="tag">
									<view class="tag__item" v-if="item.level">{{ item.level }}</view>
									<view class="tag__item" v-if="item.type">{{ item.type }}</view>
								</view>
								<view class="description"> 对接科室{{item.serve_hospital_department_count}}个 累计咨询量：{{item.serve_hospital_forms_count}} </view>
							</view>
							<view class="right">
								<u-icon size="40" color="#7f7f7f" name="arrow-right"></u-icon>
							</view>
						</view>
						<u-loadmore :margin-top="20" :status="loadStatus" bgColor="#f2f2f2"></u-loadmore>
					</view>
				</view>
				<view v-else style="height: 100%;" class="d-flex ai-center jc-center">
					<u-empty mode="list"></u-empty>
				</view>
			</scroll-view>

		</view>
		<!-- 选择站点 -->
		<u-select v-model="isShowSite" value-name="id" @confirm="confirmSite" label-name="name"
			:list="list_site"></u-select>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderBtnStyle: {
					'background-image': 'linear-gradient(-90deg, #e26165 0%, #c10d12 94%, #c10d12 100%)',
					'font-weight': '500',
					'font-size': '27rpx',
					'color': '#fff',
					'width': '130rpx',
					'height': '60rpx',
					'line-height': '60rpx'
				},
				last_page: 1,
				select: {
					page: 1,
					page_size: 5,
				},
				list: [],
				loadStatus: 'loadmore',
				isShowSite: false,
				list_site: [{
					id: '',
					name: '全部站点'
				}],


			};
		},
		mounted() {
			// if (this.$store.state.vuex_location !== 2) {
			// 	this.$store.dispatch('getLocation')
			// }
		},
		onLoad(options) {
			this.select.type = options.type ? options.type : ''
			this.getSiteList()
			this.getList()
		},
		methods: {
			async getSiteList() {
				const res = await this.$u.api.otherSite()
				this.list_site.push(...res)
			},
			async getList() {
				const res = await this.$u.api.serveHospital({
					...this.select,
					// site_id: this.vuex_site?.id
				})
				this.last_page = res.last_page
				this.loadStatus = this.select.page >= this.last_page ? 'nomore' : 'loadmore'
				this.list.push(...res.data)
				console.log(this.select.page, this.last_page)
			},
			reachBottom() {
				if (this.select.page > this.last_page) {
					this.loadStatus = 'nomore'
					return
				}
				this.loadStatus = 'loading'
				this.select.page++
				this.getList()
			},
			confirmSite(e) {
				this.$u.vuex("vuex_site", e[0])
				this.list = []
				this.select.page = 1
				this.getList()
			},
			toDetail(item) {
				if(item.serve_hospital_department_count<1){
					uni.showToast({
						title:'当前还未设置对接科室',
						icon:'none',
					})
					return
				}
				this.$u.route({
					url: '/package_sub/pages/ServeDetail/ServeDetail?id=' + item.id
				})
			}
		},
		computed: {
			token() {
				return this.vuex_token || uni.getStorageSync('lifeData')?.vuex_token
			}
		}
	}
</script>

<style lang="scss">
	.page {
		position: relative;
		background-color: #f5efee;
		height:100vh;
		padding-bottom:40rpx;
	}

	::v-deep .u-load-more-wrap {
		background-color: #fff !important;
		.u-line-1 {
			background-color: #fff !important;
		}
	}

	.top {
		width: 100vw;
		background: #fff;
		padding: 26rpx 28rpx;
		z-index: 4;
		position: sticky;
		top: 0;
		height: 94rpx;

		.position {
			color: #000;
			font-size: 30rpx;
			letter-spacing: 3rpx;
			font-weight: 500;

			&>text {
				padding: 0 13rpx;
			}
		}
	}

	.bkg {
		height: 316rpx;
		width: 100vw;
		position: absolute;
	}

	.container {
		z-index: 1;
		height: calc(100vh - 390rpx);
		position: relative;
		top:350rpx;
		    

		.list {
			position: relative;
			z-index: 3;
			padding-bottom: 40rpx;
			padding-top:20rpx;
			background-color: #fff;
			border-radius: 10rpx;
			margin: 0 25rpx;
			&-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 15rpx 30rpx;
				.left {
					&>image {
						height: 160rpx;
						width: 220rpx;
						border-radius: 6rpx;
					}
				}

				.center {
					width:calc(100% - 300rpx);
					
					.title {
						font-size: 28rpx;
						color: #000000;
						font-weight: bold;
					}

					.tag {
						margin-top: 16rpx;
						display: flex;
						flex-wrap: wrap;

						&__item {
							padding: 5rpx 16rpx;
							font-size: 22rpx;
							line-height: 31rpx;
							font-weight: 500;

							&:nth-child(1) {
								color: #ca2328;
								background-color: #faefef;
							}

							&:nth-child(2) {
								color: #f38628;
								background-color: #fcf3e9;
							}
						}

						.tag__item+.tag__item {
							margin-left: 12rpx;
						}
					}

					.description {
						// max-width: 350rpx;
						width:100%;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						font-size: 22rpx;
						color: #929196;
						font-weight: 500;
						margin-top: 16rpx;
					}
				}

				.right {
					width:40rpx;
				}

			}
		}
	}
</style>