<template>
	<view class="warpper">
		<scroll-list ref="list" :option="option" @load="upCallback" @refresh="downCallback" style="background-color: #FFFFFF;">
			<view class="card-box" v-for="(item, index) in list" :key="index">
				<view class="header">
					<view class="title">{{item.name}}</view>
					<view class="desc">近30天</view>
				</view>
				<view class="content">
					<view class="info">
						<view class="">
							<view class="value">{{item.totalCapacity}}件</view>
							<view class="title">
								<image class="icon" src="/static/imgs/client-detail/address-icon.png"></image>
								设备产能
							</view>
						</view>
						<view class="">
							<view class="value">{{item.totalTime}}h</view>
							<view class="title">
								<image class="icon" src="/static/imgs/client-detail/address-icon.png"></image>
								工作时长
							</view>
						</view>
						<view class="">
							<view class="value">{{item.totalAvgStartingUp}}%</view>
							<view class="title">
								<image class="icon" src="/static/imgs/client-detail/address-icon.png"></image>
								开机率
							</view>
						</view>
					</view>
					<view class="shrink-box" v-if="seemoreFlag == index">
						<view class="row">
							<view class="left">
								<view class="title">设备图片：</view>
								<view class="look-over" @tap="previewImg(item.img, [item.img])">点击查看</view>
							</view>
							<view class="right">
								<view class="title">购买年份：</view>
								<view class="value">{{item.purchasingDate}}年</view>
							</view>
						</view>
						<view class="row">
							<view class="left">
								<view class="title">购买金额：</view>
								<view class="value">{{item.purchaseAmount}}万</view>
							</view>
							<view class="right">
								<view class="title">设备产能：</view>
								<view class="value">{{item.capacity}}</view>
							</view>
						</view>
						<view class="row">
							<view class="left">
								<view class="title">成色：</view>
								<view class="value">{{item.newnessDegree}}</view>
							</view>
							<view class="right">
								<view class="title">设备类型：</view>
								<view class="value">{{item.machineTypeName}}</view>
							</view>
						</view>
						<view class="row">
							<view class="left">
								<view class="title">最大输纸 长度：</view>
								<view class="value">{{item.inputMaxSizeLength}}mm</view>
							</view>
							<view class="right">
								<view class="title">最大输纸 宽度：</view>
								<view class="value">{{item.inputMaxSizeWidth}}mm</view>
							</view>
						</view>
						<view class="row">
							<view class="left">
								<view class="title">最大输纸 厚度：</view>
								<view class="value">{{item.inputMaxThickness}}mm</view>
							</view>
							<view class="right">
								<view class="title">咬口：</view>
								<view class="value">{{item.lockSeam}}mm</view>
							</view>
						</view>
					</view>
				</view>
				<view class="see-more">
					<view class="" @tap="seemoreTap(index)">
						<text>设备详情</text>
						<image class="icon" :src="!seemoreFlag ? '/static/imgs/client-detail/arrow-up-icon.png' : '/static/imgs/client-detail/arrow-down-icon.png'"></image>
					</view>
				</view>
				<uGap></uGap>
			</view>
		</scroll-list>
	</view>
</template>

<script>
import lvSelect from './lv-select.vue'
import uGap from '@/components/u-gap/u-gap.vue'
import { getDeviceInfo } from '@/apis/clientDetailApi.js'
export default {
	components: { lvSelect, uGap },
	data() {
		return {
			option: {
				size: 10,
				auto: true,
				emptyText: '暂无数据~',
				background: '#F7F8FA',
				disabled: false
			},
			seemoreFlag: 0,
			params: {
				asc: '',
				desc: '',
				duration: '3',
				enterpriseIds: [],
			},
			pagination: {
				pageNum: 0, // 初始会执行一次下拉加载
				pageSize: 10
			},
			list: []
		}
	},
	onLoad() {
		// this.getList()
	},
	methods: {
		previewImg(img, list) {
			uni.previewImage({
				urls: list,
				current: img
			});
		},
		getList() {
			return new Promise((resolve, reject) => {
				getDeviceInfo({ ...this.params, ...this.pagination })
					.then(res => {
						console.log('设备信息', res)
						if (res) {
							if (this.pagination.pageNum == 1) {
								this.list = res.records
							} else {
								this.list = this.list.concat(res.records)
							}
							// this.list = []
							// this.list = [...this.list, ...[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]
							resolve({ list: this.list, total: res.total })
						}
					})
					.catch(err => {
						reject(err)
					})
			})
		},
		seemoreTap(index) {
			this.seemoreFlag = index
		},
		downCallback() {
			this.pagination.pageNum = 1
			this.getList()
				.then(({ list, total }) => {
					this.$refs.list.refreshSuccess({ list, total })
				})
				.catch(() => {
					this.$refs.list.refreshFail()
				})
		},
		upCallback() {
			this.pagination.pageNum++
			this.getList()
				.then(({ list, total }) => {
					this.$refs.list.loadSuccess({ list, total })
				})
				.catch(() => {
					this.$refs.list.loadFail()
				})
		}
	}
}
</script>

<style lang="scss">
.warpper {
	.card-box {
		.header {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			height: 88rpx;
			background: #ffffff;
			padding: 0rpx 36rpx 0rpx 32rpx;
			.title {
				font-size: 30rpx;
				color: #000000;
				letter-spacing: 0;
				font-weight: 600;
			}
			.desc {
				font-size: 28rpx;
				color: #888888;
				letter-spacing: 0;
				text-align: right;
				font-weight: 400;
			}
		}
		.content {
			border-bottom: 2rpx solid #dddddd;
			border-top: 2rpx solid #dddddd;
			.info {
				display: flex;
				flex-direction: row;
				justify-content: space-around;
				align-items: center;
				text-align: center;
				height: 148rpx;
				background: #ffffff;
				.value {
					font-size: 28rpx;
					color: #333333;
					letter-spacing: 0;
					text-align: center;
					font-weight: 500;
				}
				.title {
					margin-top: 16rpx;
					font-size: 24rpx;
					color: #888888;
					letter-spacing: 0;
					text-align: center;
					font-weight: 400;
					display: flex;
					flex-direction: row;
					align-items: center;
				}
				.icon {
					width: 32rpx;
					height: 32rpx;
					padding-right: 6rpx;
				}
			}
			.shrink-box {
				background: #f7f8fa;
				padding: 8rpx 36rpx 16rpx 32rpx;
				.row {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					margin-top: 16rpx;
					.left {
						display: flex;
						flex-direction: row;
						width: 60%;
					}
					.right {
						display: flex;
						flex-direction: row;
						width: 40%;
					}
					.title {
						flex: 0 0 140rpx;
						font-size: 28rpx;
						color: #888888;
						letter-spacing: 0;
						font-weight: 400;
					}
					.value {
						font-size: 28rpx;
						color: #333333;
						letter-spacing: 0;
						font-weight: 400;
					}
					.look-over {
						font-size: 28rpx;
						color: #007aff;
						letter-spacing: 0;
						font-weight: 400;
					}
				}
			}
		}
		.see-more {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			height: 80rpx;
			line-height: 80rpx;
			background: #ffffff;
			padding: 0rpx 32rpx;
			font-size: 28rpx;
			color: #007aff;
			letter-spacing: 0;
			text-align: center;
			font-weight: 400;
			.icon {
				width: 24rpx;
				height: 24rpx;
			}
		}
	}
}
</style>
