<template>
	<view class="home">
		
		<view class="search-area">
			<u-search 
			placeholder="搜索设备" 
			v-model="keyword" 
			shape="square" 
			:clearabled="true"
			:show-action="true" 
			action-text="搜索" 
			:animation="true"
			search-icon-color="#000"
			color="#000"
			placeholder-color="#5c5b5b"
			@search="search"
			bgColor="#fff"
			height="40"
			@custom="search"></u-search>
		</view>
		<view class="box">
			<view class="rule-area">
				<view class="notice">
					<view >
						<!-- <i class="iconfont icon-a-shezhi2"></i> -->
						<text>通知</text>
					</view>
					<text @click="toMoreNotice">更多>></text>
				</view>
				<ul v-if="informList.length===0?false:true">
					<li  v-for="item in informList" :key="item.noticeId" @click="toNotice(item.noticeId)"> 
						<i class="iconfont icon-tongzhi"></i>
						{{item.noticeTitle}}
					</li>
				</ul>
				<view class="notice-li" v-else>暂无通知</view>
			</view>
			<view class="rule-area" >
				<view class="notice">
					<view >
						<!-- <i class="iconfont icon-a-shezhi2"></i> -->
						<span>最新借用设备</span>	
					</view>
								
				</view>
				<ul v-if="borList.length===0?false:true">
					<li  v-for="item in borList" :key="item.id" class="notice-li" @click="toDetail(item.assetBarCode)"> 
						<view style="display: flex;align-items: center;">
							<i class="iconfont icon-shebei"></i>
							<text>设备编码：{{item.assetBarCode}}</text>
						</view>
						<text>{{handleDate(item.borrowDate)}}</text>
					</li>
				</ul>
				<view v-else>
					暂无最新借用设备
				</view>
			</view>
		</view>
		<view class="scan-area">
			<view class="scan-code" @click="toScan">
				<i class="iconfont icon-saoyisao"></i>
				<text>扫码设备</text>
			</view>
		</view>
	</view>
</template>

<script>
	// import { getInfo } from '@/api/user.js'
	// import cache from '@/utils/storage.js'
	import { getNewInform } from '@/api/notice.js'
	import { getBorrowList } from '@/api/asset.js'
	export default {
		data() {
			return {
				keyword:"",
				informList:[],
				borList:[]
			}
		},
		methods: {
			toMoreNotice(){
				uni.navigateTo({
					url:'/pages/notice-list/notice-list'
				})
			},
			search(){
				if(this.keyword===""){
					uni.showToast({
						title:"请输入查询字段",
						icon:'error'
					})
				}else{
					uni.navigateTo({
						url:'/pages/search/search?keyword='+this.keyword,
					})
				}
			},
			initInfo(){
				const that = this
				uni.showLoading({
					title:"正在加载中",
					icon:'none',
					mask:true
				})
				try{
					getNewInform(1,4).then(res=>{
						// console.log(res)
						if(res.data.msg ==="查询成功"){
							that.informList = res.data.rows
							getBorrowList({
								pageNum:1,
								pageSize:1,
								status:0
							}).then(res=>{
								if(res.data.rows){
									that.borList = res.data.rows
								}
								uni.hideLoading()
							})
						}else{
							uni.hideLoading()
						}
						// if(res instanceof Array){
						// 	that.informList = res
							
						// }else{
						// 	uni.hideLoading()
						// }
					})
				}catch(err){
					uni.hideLoading()
				}
				
			},
			toMine(){
				uni.switchTab({
					url:'/pages/menus/menu/menu',
				})
			},
			toScan(){
				uni.scanCode({
					scanType:['barCode'],
					success (res) {
						uni.navigateTo({
							url:'/pages/borrow/borrow?number='+res.result
						})
					}
				})
			},
			toNotice(id){
				uni.navigateTo({
					url:'/pages/notice/notice?id='+id,
				})
			},
			toDetail(bar){
				uni.navigateTo({
					url:'/pages/borrow/borrow?number='+bar,
				})
			},
			handleDate(val){
				let date = new Date(val)
				let year = date.getFullYear()
				let month = date.getMonth()+1
				let day = date.getDate()
				return year+"-"+month+"-"+day;
			}
		},
		onShow() {
			// uni.hideHomeButton()
			this.initInfo()
			this.keyword = ""
		}
	}
</script>

<style lang="scss">
page{
	background-color: #f5f6fa;
}
.home{
	padding: 20rpx 24rpx;
	display: flex;
	flex-direction: column;
	height: 100vh;
	box-sizing: border-box;
}
.search-area{
	margin-bottom: 20rpx ;
	flex-shrink: 0;
	position: relative;
	input{
		height: 80rpx;
		// border: 2rpx solid #252525;
		line-height: 80rpx;
		// padding-left:80rpx ;
	}
	.iconfont{
		position: absolute;
		font-size: 40rpx;
		top: 20rpx;
		left: 16rpx;
	}
}
.box {
	border-radius: 18rpx;
	.rule-area{
		background-color: rgba(255, 255, 255, 0.6);
		z-index: 2;
		flex-shrink: 0;
		border-radius: 18rpx;
		// box-shadow:  0 1rpx 8rpx 0 rgba(0, 0, 0, 0.2);
		box-shadow: 0px 0px 21px 0px #ececec;
		padding: 30rpx;
		.notice{
			display: flex;
			flex-direction: row;
			font-size: 36rpx;
			font-weight: bolder;
			color: #252525;
			padding-bottom: 10rpx;
			align-items: center;
			justify-content: space-between;
			// border-bottom: 1px solid rgba(0, 0, 0, 0.1);
			border-bottom: 1px solid rgba(134, 134, 134, 0.1);
			i {
				margin-right: 10rpx;
				font-size: 36rpx;
				color: orange;
				display: inline-block;
			}
		}
		
		ul {
			animation-name: ruleArea;
			animation-duration: 0.5s;
		}
		
		li {
			padding: 10rpx 0;
			width: 100%;
			overflow: hidden;  /*超出部分隐藏*/
			white-space: nowrap;  /*禁止换行*/
			text-overflow: ellipsis; /*省略号*/
			display: flex;
			align-items: center;
			color: #252525;
			i {
				padding-right: 10rpx;
				color: #2979ff;
			}
		}
	}
	.rule-area:nth-child(2) {
		margin-top: 24rpx;
		i {
			color: #19be6b;
		}
		li {
			display: flex;
			justify-content: space-between;
		}
		li:first-child {
			padding-top: 10rpx;
		}
	}
	
	@keyframes ruleArea {
		from {
			max-height: 0;
		}
		to {
			max-height: 400rpx;
		}
	}
}

.borrow-area_bck{
	flex-shrink: 0;
	margin-bottom: 20rpx ;
	height: 120rpx;
	.notice-li{
		line-height: 200%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
	// border: 2rpx solid #000;
}
.scan-area{
	flex-shrink: 1;
	height: 100%;
	// max-height: 750rpx;
	position: relative;
	.scan-code{
		width: 280rpx;
		height: 280rpx;
		background-color: rgba(21, 184, 88, 0.9);
		box-shadow:  0 2rpx 8rpx 2rpx rgba(0, 0, 0, 0.4);
		color: $uni-text-color-inverse;
		border-radius: 50%;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%,-50%);
		display: flex;    
		align-items: center;
		justify-content: center;
		text-align: center;
		flex-direction: column;
		font-size: 36rpx;
		.iconfont{
			font-size: 80rpx;
			margin: 20rpx 0;
			
		}
		-webkit-box-reflect: below 10rpx -webkit-linear-gradient(transparent, transparent 75%, rgba(255, 255, 255, .3));
	}
	.scan-mine{
		width: 80rpx;
		height: 80rpx;
		color: rgba(80, 80, 80, 1);
		border-radius: 21px;
		// font-size: 14px;
		line-height: 150%;
		box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.5);
		display: flex;
		align-items: center;
		justify-content: center;
		text-align: center;
		flex-direction: column;
		font-size: 36rpx;
		position: absolute;
		bottom: 20rpx;
		left: 20rpx;
	}
}
</style>
