<template>
	<view class="uni-column" style="padding: 24rpx">
		<view class="box-bg uni-row">
			<view class="input-view uni-row">
				<uni-icons class="input-uni-icon" type="search" size="18" color="#999" />
				<input class="nav-bar-input" type="text" v-model="keywords" placeholder="输入搜索关键词" />
			</view>
			<view class="search" @click="handleSearch">
				搜索
			</view>
		</view>
		<view v-for="(item, index) in listData" :key="index" @click="handleToBatchReporting(item)" class="list-item">
			<view class="title-container uni-row">
				<view class="title uni-row">
					<text class="label">生产计划单号</text>
					<text class="label code">{{ item['productionPlanNo'] }}</text>
				</view>
				<view v-if="item['dayWorkList'].length > 0" class="tag"><text class="label">进行中</text></view>
				<view v-else type="default" class="tag not-start"><text class="label">未开始</text></view>
			</view>
			<!-- 			<view class="item-info uni-row">
				<text class="label">当前工序</text>
				<text class="label right">{{ item['process'] }}</text>
			</view> -->
			<view class="item-info uni-row">
				<text class="label">产品描述</text>
				<text class="label right">{{ item['productDescription'] }}</text>
			</view>
			<view class="item-info uni-row">
				<text class="label">总批数</text>
				<text class="label right">{{ item['lotNumber'] }}</text>
			</view>
			<view class="item-info uni-row">
				<text class="label">完成批数</text>
				<text class="label right">{{ item['equiment'] }}</text>
			</view>
			<view class="item-info uni-row">
				<text class="label">投产数/合格数</text>
				<text class="label right">{{ item['productionQuantity'] }}/{{ item['invest'] }}</text>
			</view>
			<view class="item-info uni-row">
				<text class="label">设备</text>
				<text class="label right">{{ item['equipmentName'] }}</text>
			</view>
			<!-- 			<view class="item-info uni-row">
				<text class="label">操作人</text>
				<text class="label right">{{ item['operator'] }}</text>
			</view> -->
		</view>
	</view>
</template>

<script setup>
	import {
		getListByUserEquipment
	} from '@/api/business/subPlanDetails'
	import {
		ref
	} from 'vue'
	import {
		onReady,
		onLoad,
		onPullDownRefresh
	} from '@dcloudio/uni-app'
	import {
		getToken
	} from '@/utils/auth'
	import { store } from '@/store/index.js'
	
	const listData = ref([])
	const keywords = ref('')

	onLoad(() => {
		init()
	})

	/**
	 * 监听下拉刷新
	 */
	onPullDownRefresh(() => {
		init();
		setTimeout(function() {
			uni.stopPullDownRefresh();
		}, 3000);
	})

	function init(data={}) {
		uni.showLoading({
			title: '加载中'
		});
		getListByUserEquipment(data).then((res) => {
			console.log(res)
			if (res.code === 200) {
				listData.value = res.rows;
				uni.hideLoading()
			} else if (res.code === 401) {
				uni.showToast({
					icon: 'none',
					title: '未登录或登录状态已超时',
					duration: 1500
				})
			} else if (res.code === 500) {
				uni.showToast({
					icon: 'none',
					title: '系统错误，请联系管理员',
					duration: 1500
				})
			} else {
				uni.showToast({
					icon: 'none',
					title: res.msg,
					duration: 1500
				})
			} 
		})
	}

	function handleToBatchReporting(item) {
		store.planSubDetails = item
		uni.navigateTo({
			url: '/pages/batchReporting/index' 
		})
	}
	
	function handleSearch(){
		let reqParam = {
			keywords: keywords.value
		}
		init(reqParam)
	}
</script>

<style lang="scss">
	$nav-height: 60rpx;

	.box-bg {
		width: 100%;
		background-color: #F5F5F5;
		padding: 5rpx 0;
		justify-content: space-around;
		align-items: center;

		.input-view {
			width: 100%;
			flex: 4;
			background-color: #f8f8f8;
			height: $nav-height;
			border: 1rpx solid #999;
			border-radius: 15rpx;
			padding: 0 15rpx;
			flex-wrap: nowrap;
			margin: 20rpx 10rpx;
			line-height: $nav-height;

			.input-uni-icon {
				line-height: $nav-height;
			}

			.nav-bar-input {
				width: 80%;
				height: $nav-height;
				line-height: $nav-height;
				padding: 0 5rpx;
				background-color: #f8f8f8;
			}
		}

		.search {
			width: 20%;
			text-align: center;
			color: #808080;
		}
	}
	.uni-column {
		background-color: rgba(245, 245, 245, 1);
		height: 100%;
		overflow: auto;
	}

	.list-item {
		background-color: #fff;
		position: relative;
		padding: 16rpx;
		padding-bottom: 24rpx;
		margin-bottom: 24rpx;

		.title-container {
			justify-content: space-between;
			margin-top: 8rpx;
			margin-bottom: 16rpx;

			.title {
				height: 48rpx;
				align-items: center;

				.label {
					font-size: 32rpx;
					font-weight: bold;

					&.code {
						margin-left: 8rpx;
					}
				}
			}

			.tag {
				border: 1px solid #1ce5b0;
				background-color: #f6fffd;
				padding: 8rpx;
				border-radius: 8rpx;

				.label {
					color: #1ce5b0;
					font-size: 24rpx;
				}

				&.not-start {
					border: 1px solid #bbbbbb;
					background-color: #f5f5f5;

					.label {
						color: #bbbbbb;
					}
				}
			}
		}

		.item-info {
			margin-bottom: 8rpx;

			.label {
				font-size: 28rpx;
				width: 220rpx;
				color: #808080;

				&.right {
					flex: 1;
					color: #000000;
				}
			}
		}
	}
</style>