<template>
	<view style="padding: 15rpx;">
		<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="button"
			activeColor="#007AFF"></uni-segmented-control>
		<view class="content">
			<view v-show="current === 0">
				<win-empty-view v-if="dataList.length==0"></win-empty-view>
				<view class="" v-for="(item, index) in dataList">
					<view class="device-detail">
						<view>物料:</view>
						<view>零件:</view>
						<button type="primary"  style="width: 140rpx; font-size: 32rpx; float: right;" >完成</button>
					</view>
				</view>
				选项卡1的内容
			</view>
			<view v-show="current === 1">
				<win-empty-view v-if="dataList.length==0"></win-empty-view>
				<view class="" v-for="(item, index) in dataList">
					<view class="" v-for="(item, index) in dataList">
						<view class="device-detail">
							<view>物料:</view>
							<view>零件:</view>
							<button type="primary"  style="width: 140rpx; font-size: 32rpx; float: right;" >完成</button>
						</view>
					</view>
				</view>
				选项卡2的内容
			</view>
		</view>
		<uni-load-more :status="loadingType" v-if="dataList.length>0" />
	</view>
</template>
<script>
	import {
		getPlasticsList,
	} from '@/api/index.js';
	import {
		goHome
	} from '@/common/basic.js';
	import winEmptyView from '@/mycomponents/wincom/winEmptyView.vue'
	export default {
		components: {
			winEmptyView
		},
		data() {
			return {
				items: ['已完成', '未完成'],
				current: 0,
				pageSize: this.modelConfig,
				pageIndex: 1,
				loadingType: "nomore",
				dataList:[]
			};
		},

		onShow() {
			this.getList('refresh');
		},
		onReachBottom() {
			//避免多次触发
			if (this.loadingType == 'loading' || this.loadingType == 'nomore') {
				return;
			}
			this.getList("more");
		},
		onPullDownRefresh() {
			this.getList('refresh');
		},
		//后退按钮
		onBackPress(options) {
			if (options.from === 'navigateBack') {
				return false;
			}
			goHome();
			return true;
		},
		//返回首页
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				goHome();
			} else if (e.index === 1) {
				window.location.reload();
			}
		},
		methods: {
			onClickItem(item){
				this.current = item.currentIndex;
				console.log("点击",this.current)
				this.getList("refresh");
			},
			openScanPopup() {
				this.$refs.scanPopup.openScanPopup();
			},

			//查询发货任务
			getList(type) {
				let that = this;
				uni.showLoading({
					title: "加载中....",
					mask: true
				});
				this.loadingType = "loading";
				if (type === "refresh") {
					this.pageIndex = 1;
					this.dataList = [];
				}
				let params = {
					pageSize: that.pageSize,
					pageIndex: that.pageIndex,
					// isCreationTimeSorting: that.isTimeWindowSorting,
					// isToday: that.isToday
				};
				getPlasticsList(params)
					.then(res => {
						uni.hideLoading();
						if (type === "refresh") {
							uni.stopPullDownRefresh();
						}
						var list = res.items;
						this.loadingType = "loadmore";
						if (list == null || list.length == 0) {
							//没数据了
							this.loadingType = "nomore";
							return;
						}
						// that.dataList = [...that.dataList, ...list];
						that.dataList = type === "refresh" ? list : this.dataList.concat(list);
						that.pageIndex++;
					})
					.catch(err => {
						this.loadingType = "";
						this.showMessage(err.message);
						uni.hideLoading();
						if (type === "refresh") {
							uni.stopPullDownRefresh();
						}
					});
			},

			getScanResult(type, result) {
				if (type == '任务编号') {
					this.getByNumber(type, result.data.code);
				}
			},

			getByNumber(type, code) {
				let that = this;
				uni.showLoading({
					title: "加载中....",
					mask: true
				});
				getDeliverJobByNumber(code).then(res => {
					uni.hideLoading();
					if (res != null) {
						that.openDetail(res);
					} else {
						that.showMessage('未查找到' + type + '为【' + code + '】的盘点任务');
					}
				}).catch(err => {
					that.showMessage(err.message);
					uni.hideLoading();
				});
			},

			openDetail(item) {
				uni.navigateTo({
					url: './plasticsInventoryMoveDetail?id=' + item.id + '&jobStatus=' + item.jobStatus
				});
			},
			showMessage(message) {
				this.$refs.comMessage.showMessage(message);
			},
		}
	};
</script>