<template>
	<page-meta root-font-size="18px"></page-meta>
	<view class="">
		<win-empty-view v-if="returnList.length==0"></win-empty-view>
		<view v-for="(item, index) in returnList" :key="index" @click="openDetail(item)">
			<com-transfer-receipt :dataContent='item'></com-transfer-receipt>
		</view>
		<win-scan-button @goScan='openScanPopup' v-if="returnList.length>0"></win-scan-button>
		<win-scan-by-code ref="scanPopup" title="扫描调拨单" @getScanCode='getScanCode'></win-scan-by-code>
		<comMessage ref="comMessage"></comMessage>
	</view>
</template>

<script>
	import {
		list,
		getReturnJobList
	} from '@/api/index.js';
	import {
		getJobStatuStyle,
		getJobStatuDesc,
		goHome
	} from '@/common/basic.js';

	import winEmptyView from '@/mycomponents/wincom/winEmptyView.vue'
	import comTransferReceipt from '@/mycomponents/transfer/comTransferReceipt.vue'
	import winScanButton from '@/mycomponents/wincom/winScanButton.vue'
	import winScanByCode from '@/mycomponents/wincom/winScanByCode.vue'
	import comScanReturn from '@/mycomponents/return/comScanReturn.vue'
	import comMessage from '@/mycomponents/common/comMessage.vue'

	export default {
		name: 'transferIssue',
		components: {
			winEmptyView,
			comTransferReceipt,
			winScanButton,
			winScanByCode,
			comMessage,
		},
		data() {
			return {
				returnList: [],
				reload: false,
				status: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				pageSize: 1000,
				pageIndex: 1,
				isTimeWindowSorting: false,
				isToday: true,
			};
		},

		onShow() {
			this.getList();
		},

		onPullDownRefresh() {
			console.log('refresh');
			this.pageIndex = 1;
			this.returnList = []
			this.getList();
		},

		//返回首页
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				goHome();
			}
		},
		filters: {
			statusStyle: function(val) {
				return getJobStatuStyle(val);
			},
			statusColor: function(val) {
				return getJobStatuDesc(val);
			},

		},
		methods: {
			openScanPopup() {
				this.$refs.scanPopup.openScanPopup();
			},
			getList() {
				let that = this;
				uni.showLoading({
					title: "加载中....",
					mask: true
				});
				let params = {
					pageSize: that.pageSize,
					pageIndex: that.pageIndex,
				};
				getReturnJobList(params)
					.then(res => {
						that.returnList = res.items;
						uni.hideLoading();
					})
					.catch(err => {
						this.showMessage(err.message);
						uni.hideLoading();
					});
			},

			getScanCode(code) {
				if (code == "") {
					this.showMessage('扫描内容不能为空')
					return;
				}
				this.getScanItems(code);
			},

			openDetail(item) {
				uni.navigateTo({
					url: './transferIssue_detail?id=' + item.id + '&jobStatus=' + item.jobStatus
				});
			},

			getScanItems(code) {
				let items = this.returnList.filter(r => {
					return r.number === code;
				});

				if (items.length > 1) {
					this.returnList = items;
					this.$forceUpdate();
				} else {
					let item = items[0];
					if (item != null) {
						this.openDetail(item);
					} else {
						this.showMessage('未查找到' + code);
					}
				}
			},

			showMessage(message) {
				this.$refs.comMessage.showMessage(message);
			},
		},
	}
</script>

<style scoped lang="scss">
	movable-view {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 150rpx;
		width: 150rpx;
	}

	movable-area {
		height: 500rpx;
		width: 100%;
		overflow: hidden;
	}

	.movable-max {
		width: 500rpx;
		height: 500rpx;
	}
</style>
