<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-li">通知</view>
			<ul v-if="informList.length===0?false:true">
				<li  v-for="item in informList" :key="item.noticeId" class="notice-li" @click="toNotice(item.noticeId)"> 
					<i class="iconfont icon-yuandian"></i>
					{{item.noticeTitle}}
				</li>
			</ul>
			<view class="notice-li" v-else>暂无通知</view>
		</view>
		<view class="borrow-area" >
			<view class="notice-li">
				最新借用设备
			</view>
			<ul v-if="borList.length===0?false:true">
				<li  v-for="item in borList" :key="item.id" class="notice-li"> 
					<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 { borrowList } 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,
					})
				}
			},
			init(){
				// getNewInform(4).then(res=>{
				// 	this.informList = res
				// })
				// borrowList({
				// 	pageNum:1,
				// 	pageSize:1,
				// 	status:0
				// }).then(res=>{
				// 	// console.log(res.data.rows)
				// 	this.borList = res.data.rows
				// })
			},
			toMine(){
				uni.navigateTo({
					url:'/pages/menus/menu/menu',
				})
			},
			toScan(){
				uni.scanCode({
					scanType:['barCode'],
					success (res) {
						uni.navigateTo({
							url:'/pages/fault/fault-report/fault-report?id='+res.result
						})
					}
				})
			},
			toNotice(id){
				// console.log(id)
				uni.navigateTo({
					url:'/pages/notice/notice?id='+id,
				})
			},
			handleDate(val){
				let date = new Date(val)
				let year = date.getFullYear()
				let month = date.getMonth()+1
				let day = date.getDate()
				return year+"-"+month+"-"+day;
			}
		},
		onLoad:function(){
			this.keyword = "",
			getInfo().then(res=>{
				if(res.data.code===200){
					cache.session.setJSON('role',res.data.roles[0])
					cache.session.setJSON('phone',res.data.user.phonenumber)
					cache.session.setJSON('email',res.data.user.email)
					cache.session.setJSON('nickName',res.data.user.nickName)
					cache.session.setJSON('userName',res.data.user.userName)
				}
			})
			if(uni.getStorageSync('Admin-Token')){
				this.init()
			}
		}
	}
</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{
	margin-bottom: 20rpx ;
	flex-shrink: 0;
	// height: 270rpx;
	// border: 2rpx solid #000;
	.notice-li{
		display: flex;
		flex-direction: row;
		line-height: 200%;
	}
}
.borrow-area{
	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: #000;
		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>
