<template>
	<view class="content">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption">
			<view class="phone-list">
				<u-swipe-action>
					<view class="form-swipe mb20" v-for="(item,index) in dataList" :key="index">
						<u-swipe-action-item :options="options" @click="cancel(item,index)" :name="index"
							:ref="'swipeAction' + index">
							<view class="item" @click.stop="showDetail(item)">
								<view class="phone-name">
									<view class="name">体检报告</view>
									<view class="time">{{item.examDate}}</view>
								</view>
								<image src="/static/images/health/right_arrow_right_icon24.png" class="w48 h48"></image>
							</view>
						</u-swipe-action-item>
					</view>

				</u-swipe-action>
			</view>
			<view class="h150"></view>
		</mescroll-body>
		<view class="btn-box2">
			<view class="sub-btn2" @click="navgetTo('/pages_user/user/dataAnalysis',1)">
				<text>数据分析</text>
			</view>
			<view class="sub-btn" @click="navgetTo('/pages_user/user/information',2)">
				<image src="/static/images/health/nav_add_icon24.png" class="w48 h48"></image>
				<text>新增</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getReportList,
		deleteReport
	} from '@/api/companyUser.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				orderStatus: [{
						name: "电话记录",
						val: 1
					},
					{
						name: "短信记录",
						val: 2
					},
				],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#FF5030'
					}
				}],
				showType: 1,
				mescroll: null,
				// 上拉加载的配置
				upOption: {
					onScroll: true,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon: 'https://user.test.ylrztop.com/images/empty_icon.png',
						tip: '暂无数据'
					}
				},
				// 列表数据
				dataList: [
					// {orderId:1, name:'今日 11:22',time:'4分16秒'},
					// {orderId:2, name:'昨天 09:16',time:'4分16秒'},
					// {orderId:3, name:'1月12 13:06',time:'4分16秒'}
				],

			}
		},
		onLoad(options) {
			this.userId=options.userId;
			this.companyUserId = options.companyUserId||'';
			uni.$on('refreshReportList', () => {
				this.mescroll.resetUpScroll()
			})
		},
		methods: {
			navgetTo(url, index) {
				uni.navigateTo({
					url: url + '?type=add&userId=' + this.userId + "&companyUserId="+this.companyUserId
				})
			},
			cancel(item, index) {
				var that = this;
				let test = 'swipeAction' + index
				uni.showModal({
					title: '提示',
					content: '确定删除体检报告吗',
					success: function(res) {
						if (res.confirm) {
							// var data = {
							// 	orderId:item.orderId
							// };
							deleteReport(item.reportId).then(res => {
								if (res.code == 200) {
									uni.showToast({
										icon: 'success',
										title: '删除成功',
									});
									that.$refs[test][0].closeHandler()
									that.mescroll.resetUpScroll()
								} else {
									uni.showToast({
										icon: 'none',
										title: res.msg,
									});
								}
							});
						} else if (res.cancel) {
							that.$refs[test][0].closeHandler()
						}
					}
				});
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					userId: this.userId,
					companyUserId: this.companyUserId,
					reportStatus: 1,
					pageNum: page.num,
					pageSize: page.size
				};
				getReportList(data).then(res => {
					if (res.code == 200) {
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list;

						} else {
							that.dataList = that.dataList.concat(res.data.list);

						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);

					} else {
						uni.showToast({
							icon: 'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			showDetail(item) {
				uni.navigateTo({
					url: '/pages_user/user/information?type=edit&id=' + item.reportId + '&userId=' + this.userId + "&companyUserId=" + this.companyUserId
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 20upx;

		.top-fixed {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 10;
		}

		.pub-tab-box {
			box-sizing: border-box;
			width: 100%;
			padding: 0 40upx;
			background-color: #FFFFFF;

			.tab-inner {
				height: 88upx;
				line-height: 88upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				overflow-x: auto;
			}

			.item {
				flex: 1;
				font-size: 28upx;
				white-space: nowrap;
				line-height: 1;
				font-family: PingFang SC;
				font-weight: 500;
				color: #626468;
				// margin-right: 60upx;
				display: flex;
				align-items: center;
				justify-content: center;

				&:last-child {
					margin-right: 0;
				}

				&.active {
					font-weight: bold;
					color: #008FD3;

					&::after {
						content: "";
						width: 48rpx;
						height: 8rpx;
						background: linear-gradient(120deg, #31A1FE 0%, #008FD3 100%);
						position: absolute;
						bottom: 0;
						border-radius: 6upx 6upx 0upx 0;
					}
				}

				.text {
					position: relative;
					z-index: 1;
				}

				.tab-bg {
					width: 72upx;
					height: 28upx;
					position: absolute;
					top: 17upx;
					left: 50%;
					transform: translateX(-36upx);
					z-index: -1;
				}
			}
		}

		.btn-box2 {
			z-index: 9999;
			width: 100%;
			padding: 30upx;
			position: fixed;
			bottom: 0;
			left: 0;
			box-sizing: border-box;
			background: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 40rpx;

			.sub-btn {
				flex: 1;
				// width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 32upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #008FD3;
				border-radius: 44upx;
				display: flex;
				align-items: center;
				border: 2rpx solid #008FD3;
				justify-content: center;

				image {
					margin-right: 16rpx;
				}
			}

			.sub-btn2 {
				flex: 1;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 32rpx;
				color: #008FD3;
				font-family: PingFang SC;
				font-weight: bold;
				background: #FFFFFF;
				border-radius: 44rpx 44rpx 44rpx 44rpx;
				border: 2rpx solid #008FD3;
				margin-right: 20rpx;
			}
		}

		.phone-list {

			// padding: 30rpx;
			.form-swipe {
				overflow: hidden;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
			}

			.item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				// border-bottom: 1rpx solid #ECECEC;
				padding: 20rpx;
				margin-bottom: 20rpx;

				&:last-child {
					margin-bottom: 0;

				}

				.phone-name {
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					// justify-content: flex-start;
					// padding-left: 24rpx;
					flex: 1;

					.name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #222426;
						text-align: left;
					}

					.type {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #626468;
						text-align: right;
					}

					.time {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #898E91;
						text-align: left;
						margin-top: 14rpx;
					}
				}

			}
		}

		.sms-list {
			.item {
				padding: 30rpx;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin-bottom: 20rpx;

				.title {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #222426;
					text-align: left;
				}

				.box {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-top: 22rpx;

					.time {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #898E91;
						text-align: left;
					}

					.state {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #2CAE5C;
						text-align: right;
					}
				}
			}
		}

	}
</style>