<template>
	<!-- 冰排管理、 -->
	<view>
		<u-navbar autoBack placeholder @rightClick="rightClick">
			<view class="u-nav-slot" slot="right">
				<u-icon name="plus-circle" size="20"></u-icon>
				<span>添加</span>
			</view>
		</u-navbar>
		<u-sticky :customNavHeight="navbarHeight()">
			<view class="search_card">
				<u-search :showAction="false" v-model="keyword" @change="searchChange"
					placeholder="输入关键字快速查找"></u-search>
			</view>
		</u-sticky>
		<view class="card_incubator" v-if="orderList.length > 0">
			<view class="item_bator" v-for="(item,index) in orderList" :key="index">
				<view style="height: 100%;">
					<view style="display: flex;align-items: center;">
						<span class="iconfont imagebwx icon-bingpaiguanli"></span>
						<view>
							<view class="title_ice">{{item.code}}</view>
							<view class="title_ice">{{item.label}}</view>
						</view>
					</view>
					<view class="card_Cooling_release" style="display: flex;flex-direction: column;">
						<view style="display: flex;align-items: center;margin-top: 5rpx;">
							<view class="title_ice1">冷冻要求：{{getFreeze(item.freezeClaim)}}</view>
						</view>
						<view class="cooling_release_title" v-if="isIceInfo.isIceReleaseCold">释冷温度:
							<span>{{item.suitableForCold}}℃</span>
						</view>
						<view class="cooling_release_title" v-if="isIceInfo.isIceReleaseCold">释冷地点:
							{{item.iceColdAddress}}
						</view>
					</view>
				</view>
				<view class="right_up_down">
					<view :style="{color:geticeColor(item.status)}">{{geticeState(item.status)}}</view>
					<view class="card_btn_emit center_in" @click="selectIncubator(item)">
						编辑<u-icon name="edit-pen" size="26"></u-icon>
					</view>
				</view>
			</view>
			<view style="width: 100%;">
				<u-loadmore lineColor="#ffffff" :status="loadStatus" :key="Math.random()" />
			</view>
		</view>
		<view style="margin-top: 20%;" v-else>
			<u-empty mode="list" text="暂无冰排"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				currentPage: 1,
				pageSize: 10,
				loadingMore: true,
				loadStatus: 'loadmore', //loading 、nomore
				incubatorValue: '',
				orderList: [],
				detailsFlag: false,
				isIceInfo: {},
			}
		},
		onReachBottom() {
			if (!this.loadingMore) {
				this.getIncubator()
			}
		},
		onShow() {
			var userInfo = this.$cache.getCache('userInfo')
			this.isIceInfo = userInfo.dept
			this.searchChange()
		},
		mounted() {},
		methods: {
			rightClick() {
				uni.navigateTo({
					url: '/pages/order/addIceRaft'
				});
			},
			// 搜索
			searchChange(value) {
				this.currentPage = 1
				this.orderList = []
				this.loadingMore = true
				this.getIncubator()
			},
			// 获取冰排
			getIncubator() {
				this.loadStatus = 'loading'
				this.loadingMore = true
				this.$api.get('/api/ice-raft', {
					page: this.currentPage,
					pageSize: this.pageSize,
					code: this.keyword,
				}).then(res => {
					if (res.code == 200) {
						const data = res.data.list
						if (this.loadingMore == true && data) {
							this.orderList = this.orderList.concat(data);
						}
						if (data.length < this.pageSize) {
							this.loadingMore = true
							this.loading = '没有更多了'
							this.loadStatus = 'nomore'
						} else {
							this.loading = '加载中'
							this.loadStatus = 'loading'
							this.loadingMore = false
							this.currentPage++
						}
					}
				})
			},
			// 选择冰排
			selectIncubator(value) {
				let arr = {
					id: value.id,
					code: value.code,
					label: value.label,
					status: value.status,
					freezeClaim: value.freezeClaim,
					suitableForCold: value.suitableForCold,
					iceColdAddress: value.iceColdAddress,
				}
				uni.navigateTo({
					url: '/pages/order/addIceRaft?list=' + JSON.stringify(arr)
				});
				console.log(value, '详情')
			},
			// 冷冻要求
			getFreeze(event) {
			  let title = event
			  let arrList = []
			  title.forEach(item => {
			    let arr = '≥' + item + 'h'
			    arrList.push(arr)
			  })
			  return arrList.toString()
			},
			geticeState(event) {
				let title = ''
				if (event == '2') {
					title = '正常'
				} else {
					title = '停用'
				}
				return title
			},
			geticeColor(event) {
				let color = ''
				if (event == '2') {
					color = '#19be6b'
				} else {
					color = '#fa3534'
				}
				return color
			},
			navbarHeight() {
				let systemInfo = uni.getSystemInfoSync();
				/* (750 / systemInfo.windowWidth) */
				/* 在uview navBar组件中有一个默认高度，当这个默认高度加上状态栏高度后就是吸顶的位置，由于这两者相加是px，所以最后还需要转为rpx */
				let topHeight = 0
				// #ifdef APP-PLUS
				topHeight = 44 + systemInfo.statusBarHeight;
				// #endif
				// #ifdef MP
				let height = systemInfo.platform == 'ios' ? 44 : 48;
				topHeight = height + systemInfo.statusBarHeight
				// #endif
				/* 最后一步将px转为rpx */
				return topHeight * (750 / systemInfo.windowWidth) / 2
			},
		},
	}
</script>

<style lang="scss" scoped>
	.card_incubator {
		display: flex;
		flex-direction: column;
		margin-top: 10rpx;
	}

	.search_card {
		background-color: #fff;
		padding: 20rpx;
	}

	.item_bator {
		display: flex;
		justify-content: space-between;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 30rpx;
		margin: 10rpx 20rpx;
	}

	.item_bator_item {
		width: 100%;
		display: flex;
	}

	.card_Cooling_release {
		width: 100%;
		margin-top: 5rpx;
	}

	.right_up_down {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;
	}

	.cooling_release_title {
		font-size: 30rpx;
		margin-right: 20rpx;

		span {
			color: #19be6b;
		}
	}

	.imagebwx {
		color: #19be6b;
		font-size: 80rpx;
		margin-right: 20rpx;
	}

	.title_ice {
		font-size: 32rpx;
	}

	.title_ice1 {
		margin-right: 30rpx;
		font-size: 30rpx;
	}

	.space_between {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
	}

	.u-nav-slot {
		display: flex;
		align-items: center;

		span {
			font-size: 32rpx;
			margin-left: 5rpx;
		}
	}

	.card_btn_emit {
		margin-top: 4rpx;
		display: flex;
		justify-content: flex-end;
		color: #606266;
		font-size: 30rpx;
		border-radius: 40rpx;
	}
</style>