<template>
	<view class="container">
		<u-navbar bgColor="#2C6FF3" :autoBack="true" :placeholder="true" leftIconColor="#fff">
			<view slot="center" class="nav-center">
				<u-search :animation="true" bgColor="#fff" height="56rpx" placeholder="输入设备名称搜索" v-model="keyword"
					:showAction="false" @search="search"></u-search>
			</view>
		</u-navbar>
		<FilterDrop menuTop="148" @confirm="confirm" />
		<view class="tab-list">
			<!-- <u-subsection bgColor="#fff" activeColor="#2C6FF3" :list="tabList" :current="current" @change="tabChange"></u-subsection> -->
			<u-tabs :list="tabList" @click="tabChange" :current="current" :scrollable="false" bgColor="#fff"
				lineColor="#2C6FF3" ></u-tabs>
		</view>

		<view class="content">
			<view class="xy-card" v-for="(item,index) in list" :key="item.id" @click="$tab.navigateTo(`/pages/equipment/detail?id=${item.deviceId}`)">
				<view class="title">
					{{item.deviceName}}
					<view>
						<u-tag text="运营中" type="success" plain v-if="item.busyState==1"> </u-tag>
						<u-tag text="已停运" type="info" plain v-else> </u-tag>
					</view>
				</view>
				<view class="total">
					<view class="t-left">
						<view>
							<view>{{item.daySalesPrice}}</view>
							<text>今日销售(元)</text>
						</view>
						<view>
							<view>{{item.dayOrderNum}}</view>
							<text>今日订单</text>
						</view>
						<view>
							<view><text>{{item.deviceStatus.stock}}</text>/{{item.deviceStatus.afterFillStock}}</view>
							<text>库存/补后</text>
						</view>
					</view>
<!-- 					<view class="t-right">
						机器详情
					</view> -->
				</view>
				<view class="t-content">
					<view class="c-item-t">
						<view class="c-item">
							<view>编号：</view>
							<view>{{item.mercDeviceCode}}</view>
						</view>
						<view class="c-item">
							<view>商户：</view>
							<view>{{item.mercName}}</view>
						</view>
					</view>
					<view class="c-item-t">
						<view class="c-item">
							<view>温度：</view>
							<view>{{item.deviceStatus.tempValue}}</view>
						</view>
						<view class="c-item">
							<view>信号强度：</view>
							<view>{{item.deviceStatus.netDbm}}</view>
						</view>
					</view>
					
					<view class="c-item">
						<view>软件版本：</view>
						<view>{{item.deviceSysinfo.appUpmVersion}}</view>
					</view>
					<view class="c-item">
						<view>最后更新时间：</view>
						<view>{{item.updateTime}}</view>
					</view>
					<!-- <view class="c-item" v-if="current==3">
						<view>故障原因：</view>
						<view style="color: red;">锁不能正常开启</view>
					</view> -->
				</view>
				<view class="btn">
					<button class="cu-btn" style="width:180rpx;">故障日志</button>
					<button class="cu-btn" style="width: 180rpx;margin: 0 12rpx;">流量卡</button>
					<button class="cu-btn" style="width: 180rpx;">温度曲线</button>
				</view>
			</view>

			<u-loadmore :status="status" v-if="list.length>=1" />
		</view>
		<view class="empty" v-if="list.length==0">
			<u-empty text="没有设备!"></u-empty>
		</view>
	</view>
</template>

<script>
	import FilterDrop from './components/xy-filtedrop/index.vue'
	import {
		searchPage
	} from "@/api/device/device.js"
	import {
		areaTree
	} from "@/api/point/area"

	export default {
		components: {
			FilterDrop
		},
		data() {
			return {
				keyword: '',
				tabList: [{
						name: '在线'
					},
					{
						name: '离线'
					},
					{
						name: '停运'
					},
					{
						name: '故障'
					}
				],
				current: 0,

				status: 'loadmore',

				list: [],

				page: 1,
				size: 10,
				
				searchParams:{},//筛选条件
			}
		},

		onLoad() {
			this.getList()
		},

		methods: {
			search(){
				this.reset()
				this.getList()
			},
			//接收菜单结果
			confirm(e) {
				this.searchParams=e;
				this.reset()
				this.getList()
			},

			tabChange(e) {
				this.current = e.index
				this.reset()
				this.getList()
			},

			reset() {
				this.status == 'loadmore'
				this.page = 1;
				this.list = [];
			},

			getList() {
				searchPage({
					page: {
						current: this.page,
						size: this.size
					},
					keywords: this.keyword,
					fault: this.current==3?true:'',
					netState:this.current==0?1:this.current==1?2:'',
					busyState: this.current==2?2:'',
					deviceType:this.searchParams[0],
					stockStatus:this.searchParams[1],
					districtId:this.searchParams[2],
					placeLineId:this.searchParams[3],
				}).then(res => {
					let data = res.data.records;
					if (data.length < 10) {
						this.status = "nomore"
					} else {
						this.status = "loadmore"
					}
					this.list = this.list.concat(data)
				})
			},

			scrolltolower() {
				if (this.status == 'nomore') return
				this.page++
				this.getList()
			},
			
			detail(id){
				this.$tab.navigateTo(`/pages/equipment/detail?id=${id}`)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		position: relative;

		.nav-center {
			width: 450rpx;
			margin-left: -120rpx;
		}

		.tab-list {
			position: fixed;
			top: 230rpx;
			left: 0;
			width: 100%;
			background-color: #fff;
			z-index: 999;

			/deep/ .u-subsection--button__bar {
				background-color: #f3f3f3;
			}
		}

		.content {
			margin-top: 180rpx;
			padding: 12rpx 24rpx 24rpx;

			.xy-card+.xy-card {
				margin-top: 18rpx;
			}

			.title {
				font-size: 28rpx;
				font-weight: bold;
				color: #333;
				position: relative;

				>view{
					position: absolute;
					right:0;
					top:-12rpx;
				}
			}

			.total {
				margin-top: 28rpx;

				.t-left {
					font-size: 26rpx;
					display: flex;
					flex-flow: row nowrap;
					justify-content: space-between;
					text-align: center;

					>view {
						>view {
							color: red;
							font-weight: bold;
							font-size: 28rpx;

							>text {
								color: #333;
							}
						}

						>text {
							margin-top: 12rpx;
						}
					}
				}

				.t-right {
					display: inline-block;
					line-height: 34rpx;
					font-size: 26rpx;
					background-color: #2C6FF3;
					color: #fff;
					border-radius: 8rpx;
					padding: 0rpx 12rpx;
					position: absolute;
					right: 0;
					bottom: 0;
				}
			}

			.t-content {
				border-radius: 8rpx;
				background-color: rgb(245, 248, 251);
				box-sizing: border-box;
				padding: 24rpx 12rpx;
				margin-top: 24rpx;
				font-size: 26rpx;

				.c-item {
					display: flex;
					flex-direction: row;
					margin-bottom: 12rpx;
					align-items: center;

					>view:nth-child(1) {
						color: #666;
						width: 200rpx;
					}

					>view:nth-child(2) {
						color: #333;
					}
				}

				.c-item-t {
					display: flex;
					flex-flow: row nowrap;

					.c-item {
						width: 50%;
					}
				}

			}

			.btn {
				display: flex;
				flex-flow: row nowrap;
				justify-content: flex-end;
				margin-top: 24rpx;

				.cu-btn {
					background-color: #2C6FF3;
					color: #fff;
				}
			}
		}

		.empty {
			position: fixed;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
		}
	}
</style>
