<template>
	<!-- 我的钢瓶 -->
	<view>
		<view class="head_sticky">
			<view class="head_mine_title">我的钢瓶</view>
			<view style="width: 100%;">
				<u-tabs :list="bottleList" lineWidth="40" :scrollable="false" @click="bottleClick"></u-tabs>
			</view>
		</view>
		<!-- 在这里放置可滚动的内容 -->
		<view style="width: 100%;" v-if="list.length > 0">
			<view class="card_dinay" v-for="(item,index) in list" :key="index">
				<view style="display: flex;align-items: center;">
					<view class="item_current">{{index + 1}}</view>
					<view class="item_title1">{{item.inner_code}}</view>
				</view>
				<view class="iconfont icon-yehuaqiping icon_cylinder" :style="{color:getColor()}"></view>
			</view>
			<view style="width: 100%;height: 150rpx;"></view>
		</view>
		<view class="empty_information" v-else>
			<u-empty mode="list" text="暂无钢瓶"></u-empty>
		</view>
		<view class="card_button_bottom">
			<view class="bottom_btn_flex">
				<view class="but_allot center_in" @click="addCylinder">添加</view>
			</view>
			<view class="bottom_btn_flex">
				<view class="but_allot center_in" @click="transferCylinders">调拨</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				bottleList: [{
					name: '重瓶区',
				}, {
					name: '空瓶区',
				}, {
					name: '不合格瓶区'
				}],
				current: 1,
				Pagination: {
					PageIndex: 1,
					PageSize: 20,
					Total: 0,
				},
				loadingMore: true,
			}
		},
		mounted() {
			uni.$on('refresh', () => {
				this.list = []
				this.Pagination.PageIndex = 1
				this.getList()
			})
			this.getList()
		},
		methods: {
			// 触底事件
			bottomingEvent() {
				if (!this.loadingMore) {
					this.getList()
				}
			},
			bottleClick(value) {
				this.current = value.index + 1
				this.Pagination.PageIndex = 1
				this.list = []
				this.getList()
			},
			// 获取列表
			getList() {
				this.loadingMore = true;
				this.$api.get('/api/gas-cylinder-status', {
					page: this.Pagination.PageIndex,
					pageSize: this.Pagination.PageSize,
					status: this.current,
				}).then(res => {
					if (res.code == 200) {
						const data = res.data.list
						if (this.loadingMore == true && data) {
							this.list = this.list.concat(data);
						}
						if (data.length < this.Pagination.PageSize) {
							this.loadingMore = true
						} else {
							this.loadingMore = false
							this.Pagination.PageIndex++
						}
					}
				})
			},
			getColor() {
				if (this.current == 1) {
					return '#19be6b'
				} else if (this.current == 2) {
					return '#ff9900'
				} else if (this.current == 3) {
					return '#fa3534'
				}
			},
			// 添加钢瓶
			addCylinder() {
				uni.navigateTo({
					url: '/pages/information/cylinder?status=' + this.current
				});
			},
			// 调拨钢瓶
			transferCylinders() {
				uni.navigateTo({
					url: '/pages/information/transfer?status=' + this.current
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.head_mine_title {
		display: flex;
		align-items: center;
		justify-content: center;
		padding-top: 20rpx;
		font-size: 36rpx;
		font-weight: 600;
	}

	.head_sticky {
		position: -webkit-sticky;
		position: sticky;
		top: 0;
		/* 设置吸顶的位置 */
		background: #fff;
		z-index: 1000;
		padding-top: var(--status-bar-height);
	}

	.card_dinay {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: calc(100% - 40rpx);
		margin-top: 20rpx;
		border-bottom: 1rpx solid #d7d7d7;
		padding: 30rpx 20rpx;
	}

	.item_current {
		min-width: 40rpx;
		color: #82848a;
	}

	.item_title1 {
		margin-left: 10rpx;
	}

	.icon_cylinder {
		font-size: 50rpx;
	}

	.card_button_bottom {
		position: fixed;
		bottom: 20rpx;
		left: 0;
		right: 0;
		background-color: #fff;
		height: 120rpx;
		margin-bottom: 80rpx;
		padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
		padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
		display: flex;
		align-items: flex-start;
	}

	.bottom_btn_flex {
		margin-top: 20rpx;
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.but_allot {
		width: 80%;
		background-color: #3C9CFE;
		padding: 20rpx;
		color: #fff;
		border-radius: 10rpx;
	}

	.empty_information {
		margin-top: 30%;
	}
</style>