<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>审批</title>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link href="../../css/OA-style.css" rel="stylesheet" />
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			
			.mui-card .mui-control-content {
				padding: 10px;
			}
			
			.mui-control-content {
				height: 800px;
			}
			
			.mui-segmented-control .mui-control-item.mui-active {
				background-color: #00c4cb;
			}
			
			.mui-segmented-control {
				border: 1px solid #00c4cb;
			}
			
			.mui-segmented-control .mui-control-item {
				border-left: 1px solid #00c4cb;
				color: #00C4CB;
			}
			
			.mui-bar~.mui-content .mui-fullscreen {
				top: 44px;
				height: auto;
			}
			
			.mui-pull-top-tips {
				position: absolute;
				top: -20px;
				left: 50%;
				margin-left: -25px;
				width: 40px;
				height: 40px;
				border-radius: 100%;
				z-index: 1;
			}
			
			.mui-bar~.mui-pull-top-tips {
				top: 24px;
			}
			
			.mui-pull-top-wrapper {
				width: 42px;
				height: 42px;
				display: block;
				text-align: center;
				background-color: #efeff4;
				border: 1px solid #ddd;
				border-radius: 25px;
				background-clip: padding-box;
				box-shadow: 0 4px 10px #bbb;
				overflow: hidden;
			}
			
			.mui-pull-top-tips.mui-transitioning {
				-webkit-transition-duration: 200ms;
				transition-duration: 200ms;
			}
			
			.mui-pull-top-tips .mui-pull-loading {
				/*-webkit-backface-visibility: hidden;
                -webkit-transition-duration: 400ms;
                transition-duration: 400ms;*/
				margin: 0;
			}
			
			.mui-pull-top-wrapper .mui-icon,
			.mui-pull-top-wrapper .mui-spinner {
				margin-top: 7px;
			}
			
			.mui-pull-top-wrapper .mui-icon.mui-reverse {
				/*-webkit-transform: rotate(180deg) translateZ(0);*/
			}
			
			.mui-pull-bottom-tips {
				text-align: center;
				background-color: #efeff4;
				font-size: 15px;
				line-height: 40px;
				color: #777;
			}
			/*我的图书界面样式*/
			
			.mybk_shucolor {
				color: #3b688a;
			}
			
			.img {
				margin-top: 10px;
				width: 30%;
				float: left;
			}
			
			.mybk_div {
				float: left;
				width: 40%;
				margin-left: 15px;
				margin-top: 10px;
				font-size: 12px;
				color: #a5a5a5
			}
			
			.mybk_div1 {
				float: left;
				width: 30%;
				margin-top: 10px;
				font-size: 12px;
				color: #a5a5a5
			}
			
			.mui-pull-top-canvas {
				overflow: hidden;
				background-color: #fafafa;
				border-radius: 40px;
				box-shadow: 0 4px 10px #bbb;
				width: 40px;
				height: 40px;
				margin: 0 auto;
			}
			
			.mui-pull-top-canvas canvas {
				width: 40px;
			}
			
			.mui-slider-indicator.mui-segmented-control {
				background-color: #efeff4;
			}
			
			.mui-slider .mui-slider-group .mui-slider-item img {
				height: auto;
				width: 50px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav ">
			<a class="mui-action-back back mui-pull-left"><img src="../../images/back.png"></a>
			<h1 id="title" class="mui-title">我的图书</h1>
		</header>

		<div class="mui-content">
			<div id="slider" class="mui-slider mui-fullscreen">
				<div style="padding: 5px;">
					<div class="mui-segmented-control" id="segmentedControl">
						<a id="allBook" class="mui-control-item mui-active" href="#allBookPage">
							全部
						</a>
						<a id="borrowBook" class="mui-control-item" href="#borrowBookPage">
							已借
						</a>
						<a id="returnBook" class="mui-control-item" href="#returnBookPage">
							归还
						</a>

					</div>
				</div>
				<div class="mui-slider-group">
					<div id="allBookPage" class="mui-slider-item mui-control-content mui-active">
						<div id="scroll1" class="mui-scroll-wrapper">
							<div class="mui-scroll" id="allBookList">
								<ul class="mui-table-view" id="all">
									<li class="mui-table-view-cell"  v-for="itemA in itemAs" @tap="open_detailA(itemA)" >
										<div class="mybk_shucolor" ><b>{{itemA.appliance_bookname}}</b></div>
										<img src="../../images/borrybook.png" class="mybk_img">
										<div class="mybk_div" style="margin-left: 10%;">											
											<p>借阅时间:{{itemA.appliance_info_borrowtime.substring(0,10)}}</p>
											<p>归还时间:{{itemA.appliance_info_returntime.substring(0,10)}}</p>
											<template  >	
												<p  v-if="itemA.borrowDay>0">借阅剩余天数:{{itemA.borrowDay}}天</p>
												<p v-else-if="itemA.day >= 0">归还状态:正常</p> 
												<p v-else  style="color: red;">归还状态:超时</p> 											
											</template>	
										</div>
										
									</li>
								</ul>
							</div>
						</div>
					</div>
					<div id="borrowBookPage" class="mui-slider-item mui-control-content ">
						<div class="mui-scroll-wrapper">
							<div class="mui-scroll" id="borrowBookList">
								<ul class="mui-table-view" id="borrow">
									<li class="mui-table-view-cell" v-for="itemB in itemBs" @tap="open_detailA(itemB)">
										<div class="mybk_shucolor"><b>{{itemB.appliance_bookname}}</b></div>
										<img src="../../images/borrybook.png" class="mybk_img">
										<div class="mybk_div" style="margin-left: 10%;">											
											<p>借阅时间:{{itemB.appliance_info_borrowtime.substring(0,10)}}</p>
											<p>归还时间:{{itemB.appliance_info_returntime.substring(0,10)}}</p>
											<template  >
												<p  v-if="itemB.borrowDay>0" >借阅剩余天数:{{itemB.borrowDay}}天</p>
												<p v-else-if="itemB.day >= 0" >归还状态:正常</p> 
												<p v-else  style="color: red;" >归还状态:超时</p> 											
											</template>	
										</div>
										
									</li>
								</ul>

							</div>
						</div>
					</div>
					<div id="returnBookPage" class="mui-slider-item mui-control-content ">
						<div class="mui-scroll-wrapper">
							<div class="mui-scroll" id="returnBookList">
								<ul class="mui-table-view" id="return">
									<li class="mui-table-view-cell" v-for="itemC in itemCs" @tap="open_detailA(itemC)">
										<div class="mybk_shucolor"><b>{{itemC.appliance_bookname}}</b></div>
										<img src="../../images/borrybook.png" class="mybk_img">
										<div class="mybk_div" style="margin-left: 10%;">											
											<p>借阅时间:{{itemC.appliance_info_borrowtime.substring(0,10)}}</p>
											<p>归还时间:{{itemC.appliance_info_returntime.substring(0,10)}}</p>
											<template  >	
												<p  v-if="itemC.borrowDay>0">借阅剩余天数:{{itemC.borrowDay}}天</p>
												<p v-else-if="itemC.day >= 0">归还状态:正常</p> 
												<p v-else  style="color: red;">归还状态:超时</p> 											
											</template>	
										</div>
										
									</li>
								</ul>

							</div>
						</div>
					</div>

				</div>
			</div>
		</div>
		<script type="text/javascript" src="../../js/jquery-1.11.2.min.js"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/config.js"></script>
		<script src="../../js/app.js"></script>
		<script src="../../js/mui.pullToRefresh.js"></script>
		<script src="../../js/mui.pullToRefresh.material.js"></script>
		<script src="../../js/vue.min.js"></script>
		<script>
			mui.init();
			//初始化单页的区域滚动
			mui('.mui-scroll-wrapper').scroll();
			var pageNo = 1;
			var pageNo2 = 1;
			var pageNo3 = 1;

			(function($) {
				var segmentedControl = document.getElementById('segmentedControl22');
				$('.mui-input-group').on('change', 'input', function() {
					if(this.checked) {
						var styleEl = document.querySelector('input[name="style"]:checked');
						console.log(styleEl);
						var colorEl = document.querySelector('input[name="color"]:checked');
						if(styleEl && colorEl) {
							var style = styleEl.value;
							var color = colorEl.value;
							segmentedControl.className = 'mui-segmented-control' + (style ? (' mui-segmented-control-' + style) : '') + ' mui-segmented-control-' + color;
						}
					}
				});

				//阻尼系数
				var deceleration = mui.os.ios ? 0.003 : 0.0009;
				$('.mui-scroll-wrapper').scroll({
					bounce: false,
					indicators: true, //是否显示滚动条
					deceleration: deceleration
				});
				var allBook;
				var returnBook;
				var borrowBook;

				mui.plusReady(function() {
					var self1 = plus.webview.currentWebview();
					var zx = self1.zxid;
					var ph = self1.phid;
					var at = self1.atid;
					var zxfirst = true;
					var phfirst = true;
					var borrowBook = true;

					allBook = document.getElementById("allBook");
					returnBook = document.getElementById("returnBook");
					borrowBook = document.getElementById("borrowBook");

					//循环初始化所有下拉刷新，上拉加载。
					$.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) {
						$(pullRefreshEl).pullToRefresh({
							down: {
								callback: function() {
									var self = this;
									setTimeout(function() {
										var ul = self.element.querySelector('.mui-table-view');
										createFragmentB(ul, self);
										self.endPullDownToRefresh();
									}, 1000);
								}
							},
							up: {
								contentrefresh: '正在加载...',
								auto: true, //可选,默认false.自动上拉加载一次
								callback: function() {
									var self = this;
									setTimeout(function() {
										var ul = self.element.querySelector('.mui-table-view');
										createFragment(ul, self);
										self.endPullUpToRefresh();
									}, 1000);
								}
							}
						});
					});
					var createFragment = function(ul, self) {
						var dataType = self.element.id;
						if("allBookList" == dataType) {
							allBookList(ul, self);
						} else if("borrowBookList" == dataType) {
							borrowBookList(ul, self);
						} else if("returnBookList" == dataType) {
							returnBookList(ul, self);
						}
					}

					//下拉菜单

					var createFragmentB = function(ul, self) {
						var dataType = self.element.id;

						if("allBookList" == dataType) {
							pageNo = 1;
							vmA.itemAs = [];
							allBookList(ul, self);
						} else if("borrowBookList" == dataType) {
							pageNo2 = 1;
							vmB.itemBs = [];
							borrowBookList(ul, self);
						} else if("returnBookList" == dataType) {
							pageNo3 = 1;
							vmC.itemCs = [];
							returnBookList(ul, self);
						}
					}

					//全部图书
					function allBookList(ul, self) {
						var url = API.API_URL();
						var state = app.getState(); //获取登陆信息
						var staffId = state.user.useId;
						var obj = {
							'serviceId': 'oa_PHONE_myBooksList',
							'params': '{currentUser:' + staffId + ',p:"' + pageNo + '",pSize:"' + APP.PageSize + '",type:"' + self.element.id + '"}'
						};
						mui.ajax(url, {
							dataType: 'json', //服务器返回json格式数据
							type: 'post', //HTTP请求类型
							data: obj,
							timeout: 10000, //超时时间设置为10秒；
							headers: {
								'Accept': 'application/json'
							},
							success: function(data) {
								if(data.returnCode == "0") {
									var totalRow = data.returnParams.total;
									var totalPage = Math.ceil(totalRow / APP.PageSize);
									if(totalPage == 0) {
										totalPage = 1;
									}
									console.log("全部********totalPage***" + JSON.stringify(data));
									var result = data.returnParams.list;
									if(result.length > 0) {
										vmA.itemAs = vmA.itemAs.concat(result);
									}
									self.endPullUpToRefresh(totalPage == pageNo); //参数为true代表没有更多数据了。
									if(pageNo == 1 && totalPage > 1)
										self.refresh(true); //调用.refresh(true)方法，可重置上拉加载控件,注意：refresh()中需传入true
									pageNo = pageNo + 1;
								}
							},
							error: function(xhr, type, errorThrown) {}
						});
					}

					//已借图书
					function borrowBookList(ul, self) {
						var url = API.API_URL();
						var state = app.getState(); //获取登陆信息
						var staffId = state.user.useId;
						var obj = {
							'serviceId': 'oa_PHONE_myBooksList',
							'params': '{currentUser:' + staffId + ',p:"' + pageNo2 + '",pSize:"' + APP.PageSize + '",type:"' + self.element.id + '"}'
						};
						mui.ajax(url, {
							dataType: 'json', //服务器返回json格式数据
							type: 'post', //HTTP请求类型
							data: obj,
							timeout: 10000, //超时时间设置为10秒；
							headers: {
								'Accept': 'application/json'
							},
							success: function(data) {
								if(data.returnCode == "0") {
									var totalRow = data.returnParams.total;
									var totalPage = Math.ceil(totalRow / APP.PageSize);
									if(totalPage == 0) {
										totalPage = 1;
									}
									console.log("已借********totalPage***" + totalPage);
									var result = data.returnParams.list;
									
									if(result.length > 0) {
										vmB.itemBs = vmB.itemBs.concat(result);
										
									}
									self.endPullUpToRefresh(totalPage == pageNo2); //参数为true代表没有更多数据了。
									if(pageNo2 == 1 && totalPage > 1)
										self.refresh(true); //调用.refresh(true)方法，可重置上拉加载控件,注意：refresh()中需传入true
									pageNo2 = pageNo2 + 1;
								}
							},
							error: function(xhr, type, errorThrown) {}
						});
					}

					//归还图书
					function returnBookList(ul, self) {
						var url = API.API_URL();
						var state = app.getState(); //获取登陆信息
						var staffId = state.user.useId;
						var obj = {
							'serviceId': 'oa_PHONE_myBooksList',
							'params': '{currentUser:' + staffId + ',p:"' + pageNo3 + '",pSize:"' + APP.PageSize + '",type:"' + self.element.id + '"}'
						};
						mui.ajax(url, {
							dataType: 'json', //服务器返回json格式数据
							type: 'post', //HTTP请求类型
							data: obj,
							timeout: 10000, //超时时间设置为10秒；
							headers: {
								'Accept': 'application/json'
							},
							success: function(data) {
								if(data.returnCode == "0") {
									var totalRow = data.returnParams.total;
									var totalPage = Math.ceil(totalRow / APP.PageSize);
									if(totalPage == 0) {
										totalPage = 1;
									}
									console.log("归还********totalPage***" + totalPage);
									var result = data.returnParams.list;
									if(result.length > 0) {
										vmC.itemCs = vmC.itemCs.concat(result);
									}
									self.endPullUpToRefresh(totalPage == pageNo3); //参数为true代表没有更多数据了。
									console.log("归还********pageNo3***" + pageNo3);
									if(pageNo3 == 1 && totalPage > 1)
										self.refresh(true); //调用.refresh(true)方法，可重置上拉加载控件,注意：refresh()中需传入true
									pageNo3 = pageNo3 + 1;
								}
							},
							error: function(xhr, type, errorThrown) {}
						});
					}
				});

			})(mui);
			//全部
			var vmA = new Vue({
				el: '#allBookList',
				data: {
					itemAs: [], //列表信息流数据,
					
				}
			});
			//已借
			var vmB = new Vue({
				el: '#borrow',
				data: {
					itemBs: [], //列表信息流数据
					
				}
			});
			//归还
			var vmC = new Vue({
				el: '#return',
				data: {
					itemCs: [] //列表信息流数据
				}
			});
			
			/**
			 * 打开图书详情
			 * 
			 * @param {Object} item 当前点击的新闻对象
			 */
			function open_detailA(itemA) {

				//触发子窗口变更新闻详情	
				var appliance_info_id = itemA.appliance_info_id;
				var appliance_info_type = itemA.appliance_info_type;
				console.log(appliance_info_type);
				var page = "booksView.html";
				mui.openWindow({
					createNew: true,
					url: page,
					extras: {
						appliance_info_type: appliance_info_type,
						appliance_info_id: appliance_info_id
					}
				});

			}

			/**
			 * 打开续借页面
			 * 
			 * @param {Object} item 当前点击的新闻对象
			 */
			function open_detailB(itemB) {

				//触发子窗口变更新闻详情	
				var appliance_info_id = itemB.appliance_info_id;
				var page = "booksBorrowView.html";
				mui.openWindow({
					createNew: true,
					url: page,
					extras: {
						appliance_info_id: appliance_info_id
					}
				});

			}
		</script>
	</body>

</html>