<template>
	<view class="content">
		<view class="container">
			<view class="haers">
				<view class="" @click="goback">
					<u-icon name="arrow-left" color="#fff" size="18"></u-icon>
				</view>
				<view class="input-box">
					<input type="text" placeholder-class="inputcolor" @input="getTerminalListBySN()"
						placeholder="请输入商户名称或SN查询" v-model="merchantNameOrSn" />
				</view>
				<view class=""></view>
			</view>
			<view class="box_" v-for="(item,index) in terminalList" :key="index" @click="goDetails(item.sn)">
				<view class="">
					<view class="">设备SN:{{item.sn}}</view>
					<view class="title_">商户名称:{{item.merchantName}}</view>
					<view class="" v-if="item.merchantName==0">
						<text>状态: </text>
						<text style="color: #eb473e;margin-left: 5px;"> 未绑定</text>
					</view>
					<view class="" v-if="item.merchantName!=0">
						<text>状态: </text>
						<text style="color: #eb473e;margin-left: 5px;"> 绑定</text>
					</view>
				</view>
				<u-icon name="arrow-right" color="#c2c2c2" size="20"></u-icon>
			</view>
			<u-loadmore :status="status" v-if="show == true" />
		</view>

	</view>
</template>

<script>
	import request from '../../utils/request.js'
	import headers from '../../components/header/headers.vue'

	export default {
		data() {
			return {
				merchantNameOrSn: '',
				page: 1,
				limit: 10,
				totalPage: 0,
				terminalList: [],
				titles: "机具管理",
				text: '请输入商户名称或SN查询',
				msg: "1",
				dataList: [],
				show: false,
				status: 'loading',
			}
		},
		onShow() {
			this.getTerminalList()
		},
		onPullDownRefresh() {
			this.limit = 10,
				this.page = 1,
				this.terminalList = [],
				this.getTerminalList()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.terminalList.length < totalPage) {
				this.page++
				this.getTerminalList()
			}
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		components: {
			headers

		},
		methods: {
			//机具列表
			getTerminalList() {
				request({
					url: '/app/uaAgent/terminalList',
					method: 'post',
					data: {
						limit: this.limit,
						page: this.page,
						merchantNameOrSn: this.merchantNameOrSn
					}
				}).then(res => {
					if (res.data) {
						if (this.page != 1) {
							this.terminalList = this.terminalList.concat(res.data)
						} else {
							this.terminalList = res.data
						}
						this.totalPage = res.total
						console.log("机具列表", this.terminalList);
					}
				})
			},
			//商户名称查询
			getTerminalListBySN() {
				this.page = 1
				this.getTerminalList()
			},
			goDetails(sn) {
				uni.navigateTo({
					url: '/homePages/EquipmentManagement/details?sn=' + sn
				})
			},
			goback() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	/deep/.inputcolor {
		color: #fff;
	}

	.content {
		background: #fff;
		height: 100vh;
	}

	.container {
		width: 100%;
		background: #fff;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.haers {
		width: 100%;
		background: #E4612E;
		height: 88px;
		box-sizing: border-box;
		padding: 0px 15px;
		padding-top: 40px;

		z-index: 99999;
		background: #E4612E;
		position: fixed;
		top: 0px;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.input-box {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 65%;
		height: 25px;
		border-radius: 50px;
		border: 1px solid #fff;
		color: white;
		padding: 0px 10px;
		text-align: center;

		input {
			width: 100%;
		}


	}

	.box_ {
		width: 100%;
		box-sizing: border-box;
		padding: 15px;
		border-bottom: 1px solid #efefef;
		display: flex;
		align-items: center;

		justify-content: space-between;
	}

	.title_ {
		font-size: 18px;
		margin: 10px 0px;
	}
</style>
