<template>
	<gui-page :custom-header="true" :header-class="['gui-theme-background-color']">
		<template #gHeader>
			<view style="height:44px;" class="gui-flex gui-nowrap gui-rows gui-align-items-center">
				<!-- 使用组件实现返回按钮及返回首页按钮 -->
				<text style="font-size:44rpx;" class="gui-header-leader-btns gui-color-white font-icons"
					@tap="goBack">&#xe6c5;</text>
				<!-- 导航文本此处也可以是其他自定义内容 -->
				<text class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text"
					style="font-size: 1rem;">已出库列表</text>
				<!-- 此处加一个右侧展位元素与左侧同宽，实现标题居中 -->
				<!-- 实际宽度请根据自己情况设置 -->
				<view style="width:40px;" />
				<!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
			</view>
		</template>
		<template #gBody>
			<view class="list-content">
				<view v-if="cardList?.length > 0" class="list-panel">
					<div v-for="(item, key) in cardList" :key="key" class="panel">
						<div class="panel-row">
							<span>{{ item.batchNumber }}</span>
							<!-- <span class="font-icons">前往备料&#xe66b;</span> -->
						</div>
						<div class="panel-row">
							<span>产品编码</span>
							<span>{{ item.productCode }}</span>
						</div>
						<div class="panel-row">
							<span>产品名称</span>
							<span>{{ item.productName }}</span>
						</div>
						<div class="panel-row">
							<span>数量</span>
							<span>{{ item.boxQty }}</span>
						</div>
						<div class="panel-row">
							<span>日期</span>
							<span>{{ $parseTime(item.createTime) }}</span>
						</div>
						<div class="panel-row">
							<span>生产日期</span>
							<span>{{ $parseTime(item.produceDate) }}</span>
						</div>
						<div class="panel-row">
							<span>过期日期</span>
							<span>{{ $parseTime(item.validTill) }}</span>
						</div>
						<div class="panel-row">
							<span>保质期天数</span>
							<span>{{ item.shelfLifeDays }}</span>
						</div>
						<div class="panel-row">
							<span>生产单号</span>
							<span>{{ item.workOrderNo }}</span>
						</div>
						<div class="panel-row">
							<span>工单号</span>
							<span>{{ item.erpWorkOrderNo }}</span>
						</div>
						<div class="panel-row">
							<span>是否确认</span>
							<!-- <span><DictTag :value='item.signStatus' type='success' dict-type='audit_status' /></span> -->
							<span>{{ item.signStatus }}</span>
						</div>
						<div class="panel-row">
							<span>确认人</span>
							<span>{{ item.signPerson }}</span>
						</div>
						<div class="panel-row">
							<span>确认时间</span>
							<span>{{ $parseTime(item.signTime) }}</span>
						</div>
						<div class="panel-row">
							<span>是否出库</span>
							<span>{{ item.outStatus }}</span>
						</div>
						<div class="panel-row">
							<span>出库人</span>
							<span>{{ item.outPerson }}</span>
						</div>
						<div class="panel-row">
							<span>出库时间</span>
							<span>{{ $parseTime(item.outTime) }}</span>
						</div>
					</div>
				</view>
				<view v-else>
					<view class="bg-image">
						<image src="@/static/empty.png" mode="heightFix" />
						<text>这里什么都没有...</text>
					</view>
				</view>
			</view>
		</template>
	</gui-page>
</template>

<script>
	import {
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		ref,
		defineComponent,
		computed,
		onMounted
	} from 'vue'
	export default defineComponent({
		setup() {
			const easyinput = ref()
			const queryParams = ref({
				pageSize: 10,
				pageNo: 1,
				signStatus: 1
			})
			const cardList = ref([])

			const computedState = computed(() => {
				return item => {
					switch (item) {
						case 0:
							return '待备料'
						case 1:
							return '已备料'
						case 2:
							return '已发料'
					}
				}
			})
			
			// 发料时间
			const computedCreateTime = computed(() => {
			  return item => {
			    if (![NaN, null, undefined, ''].includes(item)) {
			      return parseTime(item)
			    }
			    return ''
			  }
			})

			const search = function() {
				uni.$reqGet('getProductMiddleDetailPage', queryParams.value)
					.then(({
						data,
						msg
					}) => {
						cardList.value = data?.list ?? []
					})
			}

			onMounted(() => {
				search()
			})

			const goBack = function() {
				uni.$goBack("/pages/workbranch/warehouse/SemiFinishedProducts/indexPage")
			}

			// 禁用软键盘
			const handleInputFocus = function() {
				setTimeout(() => {
					uni.hideKeyboard()
				}, 100)
			}

			// uniapp移动端触底事件
			onReachBottom(() => {
				queryParams.value.pageNo += 1
				uni.$reqGet('getProductMiddleDetailPage', queryParams.value)
					.then(({
						data
					}) => {
						Array.prototype.push.call(cardList.value, ...data?.list ?? [])
					})
			})
			return {
				goBack,
				cardList,
				search,
				easyinput,
				computedState,
				queryParams,
				handleInputFocus,
				computedCreateTime
			}
		}
	})
</script>

<style lang="scss" scoped>
	.gui-header-leader-btns {
		color: black;
		font-size: 24px !important;
		margin-left: 24rpx;
	}

	.list-content {
		margin-top: 80px;
		min-height: calc(100vh - 80px);
		background-color: #edeeee;
	}

	span,
	text {
		font-size: 12px;
	}
</style>