<!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" />

	</head>

	<body>
		<header class="mui-bar mui-bar-nav" id="login">
			<a href="" class="mui-action-back back mui-pull-left"><img src="../../../images/back.png"></a>
			<h1 class="mui-title" id="title">图书管理</h1>
			<a id="toAdd">
				<img src="../../../images/app_add.png" style="width: 44px;float: right;">
			</a>
			<a id="menu" class="mui-action-menu mui-icon mui-pull-right" href="#topPopover">
				<img src="../../../images/book.png" style="width: 20px;">
			</a>
			
		</header>
		<div class="mui-content">

			<div id="pullrefresh" class="mui-content mui-scroll-wrapper" style="">

				<!--<div class="zhgl_div1" style="padding-left: 35px;padding-top: 5px;" v-for="item in items">
					<div class="mybk_shucolor"><b>{{item.appliance_bookName}}</b></div>
					<img src="../../../images/borrybook.png" class="mybk_img">
					<div class="mybk_div">
						<span>作者:{{item.writer}}</span><br>
						<span>条码:<b id="barcode">{{item.barcode}}</b></span> <br>
						<span>借阅次数:<b id="barcode">{{item.borrowNumber}}</b></span> <br>
					</div>
					<div class="mybk_div1">
						<span>出版社:{{item.appliance_factory}}</span><br>
						<span>编码:{{item.appliance_number}}</span> <br>

					</div>
					<div class="zhgl_div">

						<button type="button" id="perorder" @tap="perorder(item)" class="mui-btn mui-btn-outlined">查看</button>
						<button type="button" id="edit" @tap="editBook(item)" class="mui-btn mui-btn-outlined">编辑</button>
						<button type="button" id="del" @tap="delbook(item)" class="mui-btn mui-btn-danger mui-btn-outlined">删除</button>
					</div>
				</div>-->
				<ul class="mui-table-view">
					<li class="mui-table-view-cell" v-for="item in items">
						<div>
							<div class="mybk_shucolor"><b>{{item.appliance_bookName}}</b></div>
							<img src="../../../images/borrybook.png" class="mybk_img">
							<div class="mybk_div">
								<span>作者:{{item.writer}}</span><br>
								<span>条码:<b id="barcode">{{item.barcode}}</b></span><br>

								<span>出版社:{{item.appliance_factory}}</span><br>
								<span>编码:{{item.appliance_number}}</span><br>
								<span>借阅次数:<b id="barcode">{{item.borrowNumber}}</b></span><br>
							</div>
							<div class="mybk_div2">
								<button type="button" id="perorder" @tap="perorder(item)" class="mui-btn mui-btn-outlined mybk_button">查看</button><br>
								<button type="button" id="edit" @tap="editBook(item)" class="mui-btn mui-btn-outlined mybk_button">编辑</button><br>
								<button type="button" id="del" @tap="delbook(item)" class="mui-btn mui-btn-danger mui-btn-outlined mybk_button">删除</button><br>
							</div>
						</div>
					</li>
				</ul>

				<!--右上角弹出菜单-->
				<div id="topPopover" class="mui-popover">
					<div class="mui-popover-arrow"></div>
					<div class="mui-scroll-wrapper">
						<div class="mui-scroll">
							<ul class="mui-table-view">
								<li class="mui-table-view-cell">
									
										<div class="mui-input-row mui-search" >
											<input type="search" id="searchname" class="mui-input-clear" placeholder="请输入书名">

										</div>
										<div cclass="mui-input-row mui-search" >
											<button type="button" id="searchBook" class="mui-btn mui-btn-outlined" style="margin-left:20px;">查询</button>
											<button type="button" id="searchAllBook" class="mui-btn mui-btn-outlined" style="margin-left: 40px;">查询全部</button>
										</div>
									
								</li>
							</ul>
						</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/vue.min.js"></script>

			<script>
				var pageDetail = null;
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
							color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
							height: '50px', //可选,默认50px.下拉刷新控件的高度,
							range: '100px', //可选 默认100px,控件可下拉拖拽的范围
							offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
							//						auto: true, //可选,默认false.首次加载自动上拉刷新一次
							callback: reloadNews //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
						},
						up: {
							contentrefresh: '正在加载...',
							auto: true, //可选,默认false.自动上拉加载一次
							callback: pullupRefresh
						}
					},
					statusBarBackground: '#D20000', //设置状态栏颜色,仅iOS可用
					//				preloadLimit:5,
				});

				var vmA = new Vue({
					el: '#pullrefresh',
					data: {
						items: [] //列表信息流数据
					}
				});

				/**
				 * 下拉刷新具体业务实现
				 */
				function reloadNews() {
					var self = plus.webview.currentWebview();
					var appliance_sort_id = self.appliance_sort_id;
					var appliance_sort_name = self.appliance_sort_name;
					pageNo = 1;
					vmA.items = [];
					addData(appliance_sort_id);
				}

				var pageNo = 1;
				var type = 0;
				/**
				 * 上拉加载具体业务实现
				 */
				function pullupRefresh() {
					//接受上个页面传递的appliance_info_type和appliance_info_id的值
					var self = plus.webview.currentWebview();
					var appliance_sort_id = self.appliance_sort_id;
					var appliance_sort_name = self.appliance_sort_name;
					
					vmA.items = [];
					addData(appliance_sort_id);
					
				}

				function addData(appliance_sort_id) {
					var url = API.API_URL();
					var serviceId = "oa_PHONE_20180524BooksList";
					var state = app.getState(); //获取登陆信息		
					var unitId = state.user.unitId;
					console.log("*********" + appliance_sort_id);
					var p = pageNo;
					var bookname = $("#searchname").val();
					if(bookname == "") {
						var p = 1;
					}
					var obj = {
						unitId: unitId,
						pSize: APP.PageSize,
						p: p,
						appliance_sort_id: appliance_sort_id,
						bookname: bookname
					};
					app.ajax(serviceId, obj, function(data) {
						//服务器返回响应
						console.log(JSON.stringify(data))
						var result = data.returnParams;
						var totalRow = data.total;
					
						var totalPage = Math.ceil(totalRow / APP.PageSize);
						if(totalPage == 0){
							totalPage =1;
						}		
						var list = data.list;
						if(list.length > 0) {
							vmA.items = vmA.items.concat(list);
						}
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(totalPage == pageNo); //参数为true代表没有更多数据了。

						if(pageNo == 1 && totalPage>1) {
							mui('#pullrefresh').pullRefresh().endPulldown();
							mui('#pullrefresh').pullRefresh().refresh(true);
						}
						if(totalPage == 1 ){
							mui('#pullrefresh').pullRefresh().endPulldown();
						}						
						pageNo = pageNo + 1;

					});
				}
				window.addEventListener('refresh', function(e) { //执行刷新
					location.reload();

				});

				//图书明细
				function perorder(item) {
					//前往页面
					mui.openWindow({
						//页面
						url: 'bookview.html',
						//传参
						extras: {
							'appliance_id': item.appliance_id,
							'bookname': item.appliance_bookname
						}
					})
				}
				document.getElementById("toAdd").addEventListener('click', function() {
					//接受上个页面传递的appliance_info_type和appliance_info_id的值
					var self = plus.webview.currentWebview();
					var appliance_sort_id = self.appliance_sort_id;
					var appliance_sort_name = self.appliance_sort_name;
					mui.openWindow({
						url: '../bookAdd.html',
						extras: {
							'appliance_sort_id': appliance_sort_id,
							'appliance_sort_name': appliance_sort_name

						}
					})
				})

				//图书编辑页面
				function editBook(item) {
					mui.openWindow({
						url: 'bookEdit.html',
						//传参
						extras: {
							'appliance_id': item.appliance_id,
							'bookname': item.appliance_bookname,
							'barcode': item.barcode,
							'appliance_number': item.appliance_number,
							'appliance_putaway_date': item.appliance_putaway_date
						}
					})
				}
				//删除
				function delbook(item) {
					var btnArray = ['取消', '确认'];
					mui.confirm('确定要删除吗', '警告', btnArray, function(e) {
						if(e.index == 1) {
							var url = API.API_URL();
							var serviceId = "oa_PHONE_20180524delBook";
							var state = app.getState(); //获取登陆信息
							var appliance_id = item.appliance_id;
							var obj = {
								appliance_id: appliance_id,
							};
							app.ajax(serviceId, obj, function(data) {
								//服务器返回响应
								console.log(JSON.stringify(data))
								if(data == '1') {
									alert('删除失败:该书借出未还!');
									location.reload();
								} else {
									if(data == '0') {
										alert('删除成功');
										location.reload();
									} else {
										alert('删除失败：' + data.msg);
									}
								}

							});
						} else {

						}
					})
				}
				
				
				//查询
				document.getElementById("searchBook").addEventListener('click', function() {
					var self = plus.webview.currentWebview();
					var appliance_sort_id = self.appliance_sort_id;
					var url = API.API_URL();
					var state = app.getState(); //获取登陆信息		
					var bookname = $("#searchname").val();
					var unitId = state.user.unitId;
					var serviceId = "oa_PHONE_20180524BooksList";
					var obj = {
						unitId: unitId,
						appliance_sort_id:appliance_sort_id,
						bookname: bookname,
						pSize: APP.PageSize,
						p: 1
					};
					app.ajax(serviceId, obj, function(data) {
						//服务器返回响应
						console.log(JSON.stringify(data))
						if(data.total == 0) {
							mui.toast("该书不存在");
						} else {
							mui.toast("查找成功");
							var result = data.returnParams;
							var list = data.list;
							console.log(list.length);
							if(list.length > 0) {
								vmA.items = [];
								vmA.items = vmA.items.concat(list);
							}
						}
                     mui(".mui-popover").popover("toggle");
					});
				});
				//查询全部
				document.getElementById("searchAllBook").addEventListener('click', function() {
					
					var url = API.API_URL();
					var self = plus.webview.currentWebview();
					var appliance_sort_id = self.appliance_sort_id;
					var bookname = "";
					var state = app.getState(); //获取登陆信息		
					var unitId = state.user.unitId;
					var serviceId = "oa_PHONE_20180524BooksList";
					var obj = {
						unitId: unitId,
						bookname: bookname,
						appliance_sort_id:appliance_sort_id,
						pSize: APP.PageSize,
						p: 1
					};
					app.ajax(serviceId, obj, function(data) {
						//服务器返回响应
						console.log(JSON.stringify(data))
						if(data.total == 0) {
							mui.toast("该书不存在");
						} else {
							mui.toast("查找成功");
							var result = data.returnParams;

							var list = data.list;
							console.log(list.length);
							if(list.length > 0) {
								vmA.items = [];
								vmA.items = vmA.items.concat(list);
							}
							mui(".mui-popover").popover("toggle");
						}
                    
					});
				});

			</script>
	</body>

</html>