<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"
			@custom="search"></u-search>
		</view>
		<view class="rule-area">
			<view class="notice">
				<i class="iconfont icon-a-shezhi2"></i>
				<span>通知</span>
			</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-yuandian"></i> -->
					{{item.noticeTitle}}&nbsp;&nbsp;文本溢出文本溢出文本溢出文本溢出文本溢出
				</li>
			</ul>
			<view class="notice-li" v-else>暂无通知</view>
		</view>
		<view class="rule-area" >
			<view class="notice">
				<i class="iconfont icon-a-shezhi2"></i>
				<span>最新借用设备</span>				
			</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)"> 
					<text>设备编码：{{item.assetBarCode}}</text>
					<text>{{handleDate(item.borrowDate)}}</text>
				</li>
			</ul>
			<view v-else>
				暂无最新借用设备
			</view>
		</view>
		<view class="scan-area">
			<view class="scan-code" @click="toScan">
				<i class="iconfont icon-saoyisao"></i>
				<text>扫码设备</text>
			</view>
			<!-- <view class="scan-mine" @click="toMine">
				<i class="iconfont icon-wode"></i>
			</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: {
			search(){
				if(this.keyword===""){
					uni.showToast({
						title:"请输入查询字段",
						icon:'none'
					})
				}else{
					uni.navigateTo({
						url:'/pages/search/search?keyword='+this.keyword,
					})
				}
			},
			initInfo(){
				const that = this
				uni.showLoading({
					title:"正在加载中",
					icon:'none',
					mask:true
				})
				try{
					getNewInform(4).then(res=>{
						if(res instanceof Array){
							that.informList = res
							getBorrowList({
								pageNum:1,
								pageSize:1,
								status:0
							}).then(res=>{
								if(res.data.rows){
									that.borList = res.data.rows
								}
								uni.hideLoading()
							})
						}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() {
			this.initInfo()
			this.keyword = ""
		}
	}
</script>

<style lang="scss" scoped>
.home{
	padding: 20rpx;
	display: flex;
	flex-direction: column;
	height: 100vh;
	box-sizing: border-box;
}
.search-area{
	margin-bottom: 20rpx ;
	flex-shrink: 0;
	position: relative;
	input{
		height: 76rpx;
		border: 2rpx solid #000;
		line-height: 76rpx;
		padding-left:80rpx ;
	}
	.iconfont{
		position: absolute;
		font-size: 40rpx;
		top: 20rpx;
		left: 16rpx;
	}
}
.rule-area{
	flex-shrink: 0;
	border-radius: 18rpx;
	box-shadow:  0 2rpx 8rpx 0 rgba(0, 0, 0, 0.2), 0 2rpx 6rpx 0 rgba(0, 0, 0, 0.19);
	padding: 16rpx;
	.notice{
		display: flex;
		flex-direction: row;
		font-size: 36rpx;
		font-weight: bolder;
		padding-bottom: 10rpx;
		align-items: center;
		border-bottom: 1px solid rgba(0, 0, 0, 0.3);
		i {
			margin-right: 10rpx;
			font-size: 36rpx;
			color: orange;
		}
	}
	
	li {
		padding: 10rpx 0;
		width: 100%;
		overflow: hidden;  /*超出部分隐藏*/
		white-space: nowrap;  /*禁止换行*/
		text-overflow: ellipsis; /*省略号*/
	}
}
.rule-area:nth-child(3) {
	margin-top: 32rpx;
	i {
		color: #19be6b;
	}
	li {
		display: flex;
		justify-content: space-between;
	}
}
.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;
		}
	}
	.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>
