<template>
	<!-- 设备概览 -->
	<view class="overview">
		<u-loading-page loading-text="loading..." :loading="loading"></u-loading-page>
		<u-sticky zIndex="3">
			<view class="head">
				<u-search placeholder="请输入盘点对象" v-model="keyword" @search="getList" @custom="getList"></u-search>
			</view>
		</u-sticky>
		<view class="main" v-for="(item, index) in deviceList" :key="index" >
				
				<u--image :src="item.picUrl" radius="5" :lazy-load="true" width="80" height="80" @click="imgPreview(item.picUrl)"></u--image>
				<view class="content" @click="toDetails(item)">
					<view class="c-name">
						<u-text :text="'任务：'+item.taskName"></u-text> 
					</view>
					<view class="c-addtime">
						<u-text :text="'截止：'+item.enableTime"></u-text>  
					</view>
					<view class="c-addtime">
						<u-text :text="'部门：'+item.deptName"></u-text>  
					</view>
					<view class="c-status">
						<u-text :text="'对象：'+item.nickName"></u-text>  
						<u-tag text="未完成" plain size="mini" v-if="item.status==0"></u-tag>
						<u-tag text="已完成" plain size="mini" type="warning" v-if="item.status==1"></u-tag>
						<u-tag text="已审核" plain size="mini" type="warning" v-if="item.status==2"></u-tag>
					</view>
				</view>
				<u-icon name="arrow-right" @click="toDetails(item)"></u-icon>
			</view>
		<u-divider text="没有更多数据了"></u-divider>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 1.2搜索内容
				search: '',
				loading: false,
				// 3.设备列表
				deviceList: [
				],
				
				// 配置项
				actionStyle: {
					background: 'hsl(200, 88%, 55%)',
					color: '#fafaff',
					'border-radius': '1vw',
					'line-height': '26px'
				},
				keyword:''
			}
		},
		
		onShow: function() {
			this.getList()
		},
		onPullDownRefresh(){
			this.getList()
		},
		mounted() {
		},
		methods: {
			async getList() {
				const { data:res } = await this.$http('/taskDetailsList',{'keyword':this.keyword})
				console.log(res)
				if(res.code) return
				// this.deviceList = res.data
				this.deviceList = [];
				for (var i = 0; i < res.data.length; i++) {
					res.data[i].picUrl = this.API_URL+res.data[i].picUrl;
					if(res.data[i].taskStatus < 3){
						this.deviceList.push(res.data[i])
					}
				}
			},
			
			
			// 1.2搜索
			async searchDevice() {
				const { data:res } = await this.$http('app/assetBaseList', {
					name: this.search
				})
				if(res.code) return
				this.deviceList = res.data
			},
			
			imgPreview(url){
				uni.previewImage({
					indicator:"number",
					loop:true,
					urls: [url]
				})
			},
			// 跳转详情页
			toDetails(item) {
				wx.navigateTo({
						url:'detail?task='+JSON.stringify(item),    
				    })
			}
		}
	}
</script>

<style lang="scss">
	.overview {
		background: #f6f6f6;
		// padding: 2.667vw 0;
		height: 100vh;
		.head {
			background: #fff;
			padding: 2.667vw;
			
			display: flex;
			justify-content: space-evenly;
			align-items: center;
			input {
				padding: 1vw;
				border-radius: 1vw;
			}
		}
		// 展示信息
		.main {
			background: #ffffff;
			margin: 2.667vw 0;
			display: flex;
			justify-content: space-around;
			padding: 2vh 0;
			.u-image{
				float: left;
			}
			.content{
				flex-direction: column;
				align-items: flex-start;
				justify-content: space-around;
				display: flex;
				width: 55vw;
				.c-status{
					display: flex;
				}
			}
			.u-tag{
				margin-left: 3vw;
			}
			
		}
	}
</style>
