<template>
	<view class="receive-listBox">
		<scroll-view id="scroll-box" class="scroll-box" scroll-y="true"
			:style="{'height':state.scrollHeight+'px'}" @scrolltolower="fnScrollBottom()">
			<view class="list-box-list" v-if="state.dataList.length > 0">
				<view class="data-item" @click.stop="fnToUrl(item)"
					v-for="(item, index) in state.dataList" :key="index">
					<view class="tit">销售出库单单号：{{item.FBillNo}}</view>
					<view class="line-p"></view>
					<view class="b-font">{{ t('receive.rq') }}：{{item.FDateFormat}}</view>
				</view>
			</view>
			<view  v-if="state.dataList.length==0">
				<up-empty mode="list"></up-empty>
			</view>
		</scroll-view>
	</view>
</template>

<script lang="ts" setup>
	import { reactive, nextTick, onMounted,watch, ref,computed,defineProps } from 'vue';
	import { useI18n } from 'vue-i18n'
	import { parseTime } from '../../utils/tools.js';
	import { PRD_MORPTList, SAL_OUTSTOCKList, receiveBillList } from '../../common/request/api/api';
	const getI18n = useI18n()
	const { t, locale } = getI18n
	const props = defineProps({
		queryString: {
			type: String,
			default: () => {
				return ''
			}
		}
	})
	const state = reactive({
		queryString: '',
		dataList: [],
		scrollHeight: 0,
		tabsIndex:'1',
		page: {
			pageIndex: 1,
			pageSize: 200,
			totalCount: 0
		},
	})
	watch(() => props.queryString, () => {
		if (props.queryString !== ''){
			state.page.pageIndex = 1
			state.queryString = props.queryString
			fnDataList()
		}
	})
	onMounted(() => {
		initialization()
	})
	const initialization = () => {
		const query = uni.createSelectorQuery().in(this);
		query.select(".receive-listBox").boundingClientRect((data:any) => {
			state.scrollHeight = data.height
		}).exec();
		fnDataList()
	}
	const upTabsItemFun = (e:any) => {
		state.tabsIndex = e.type
	}
	const fnScrollBottom = () => {
		console.log(state.page.pageIndex * state.page.pageSize,state.page.totalCount);
		if (state.page.pageIndex * state.page.pageSize <= state.page.totalCount) {
			state.page.pageIndex ++;
			uni.showLoading({ mask: true });
			setTimeout(() => {
				fnDataList();
			}, 500);
		}
	}
	const fnToUrl = (item : any) => {
		toPages('/pages/BatchOutOftock/material',{id:item.FID,fBillNo:item.FBillNo})
	}
	const fnDataList = () => {
		let param = {
			queryString: state.queryString,
			pageIndex: state.page.pageIndex,
			pageSize: state.page.pageSize,
		};
		if (state.page.pageIndex == 1) {
			uni.showLoading({ mask: true });
		}
    SAL_OUTSTOCKList(param).then(res => {
			uni.hideLoading();
			if (res.code == 200) {
				let result = res.data;
				let dataArray = result.list;
				dataArray.forEach(p => {
					p.FDateFormat = parseTime(p.FDate, '{y}-{m}-{d}');
				});

				if (state.page.pageIndex == 1) {
					state.dataList = dataArray;
				}
				else {
					state.dataList = state.dataList.concat(dataArray);
				}
				state.page.totalCount = result.total;

				if (state.dataList.length == state.page.totalCount) {
					// more_status.value = 'nomore';
				}
			}
		});
	}
	const toPages = (url : string, data : any = {}) => {
		uni.$u.route({
			url: url,
			params: data
		})
	}
</script>

<style lang="scss">
	.receive-listBox {
		flex: 1;
	
		.list-box-list{
			width: 100%;
			// margin: 20rpx auto;
			.data-item{
				border: 1px solid #efeaea;
				border-radius: 20rpx;
				box-shadow: 0rpx 15rpx 15rpx  #efeaea;
				padding: 20rpx 20rpx 0;
				margin-bottom: 20rpx;
				background-color: #ffffff;
				.tit{
					font-size: 30rpx;
					font-weight: bold;
					padding: 20rpx 0;
				}
				.line-p{
					border: 1px solid #efeaea;
				}
				.b-font{
					font-size: 25rpx;
					padding: 20rpx 0;
				}
			}
		}
	}
</style>