<template>
	<!-- 入库列表 -->
	<view class="allot-ex-page">
		<view class="tabs">
			<Tabs
				:tabs="tabs"
				:currentTab="tabIndex"
				@change="changeTabEvent"
				@add="addEvent"
			></Tabs>
		</view>
		<scroll-view scroll-y class="allot-list">
			<block v-if="!$util.isEmpty(list.data)">
				<view
					class="allot-item"
					v-for="(item, index) in list.data"
					:key="index"
					@click="gotoDetails(item)"
				>
					<view class="info">
						<view class="info-order">{{ item.orderSn }}</view>
						<view class="info-name">{{ item.adminName }}</view>
						<view
							><text class="info-time">{{ item.updateTime }}</text
							><text>{{ item.bigNum}}/{{item.smallNum}}</text
							>件</view
						>
					</view>
					<view
						:class="[
							'status',
							item.status == PUT_STATUS.DONE
								? 'primary'
								: item.status == PUT_STATUS.CONFIRM
								? 'warn'
								: 'gray'
						]"
					>
						<view
							:class="[
								'iconfont',
								item.status == PUT_STATUS.CANCEL ? 'iconcaozuojihuo' : 'icondairuku'
							]"
						></view>
						<view :class="['status-name']">{{ item.statusName }}</view>
					</view>
				</view>
			</block>
			<block v-else>
				<AppWrapperEmpty title="暂无数据" :is-empty="$util.isEmpty(list.data)" />
			</block>
		</scroll-view>
		<!--<view class="app-footer open_btn">-->
			<!--<view @click="addEvent" class="admin-button-com middle blue">新增入库</view>-->
		<!--</view>-->
    <kd-entrance></kd-entrance>
	</view>
</template>
<script>
import Tabs from "@/components/plugin/tabs";
import AppWrapperEmpty from "@/components/app-wrapper-empty";

import { list } from "@/mixins";
import { getStockInListApi } from "@/api/storehouse/stock";
import { PUT_STATUS } from "@/utils/declare";

export default {
	name: "inStockList",
	components: { Tabs, AppWrapperEmpty },
	mixins: [list],
	data() {
		return {
			PUT_STATUS,
			tabIndex: 0,
			tabs: [
				{
					name: "全部",
					key: ""
				},
				{
					name: "待入库",
					key: PUT_STATUS.CONFIRM
				},
				{
					name: "已入库",
					key: PUT_STATUS.DONE
				},
				{
					name: "已取消",
					key: PUT_STATUS.CANCEL
				}
			]
		};
	},
	onPullDownRefresh() {
		this.resetList();
		this._list().then(res => {
			uni.stopPullDownRefresh();
		});
	},
	onLoad() {
		// this.init();
	},
	methods: {
		async init() {
			this._list();
		},
		_list() {
			return getStockInListApi(this.tabs[this.tabIndex].key)
				.then(res => {
					this.completes(res);
				})
				.catch(err => {});
		},
		changeTabEvent(info) {
			const { index } = info;
			if (this.tabIndex == index) {
				return false;
			} else {
				this.tabIndex = index;
				this.resetList();
				this._list();
			}
		},
		getItemStatusName(status) {
			let name = "";
			switch (status) {
				case PUT_STATUS.CONFIRM:
					name = "待入库";
					break;
				case PUT_STATUS.DONE:
					name = "已入库";
					break;
				case PUT_STATUS.CANCEL:
					name = "已取消";
					break;

				default:
					break;
			}
			return name;
		},
		addEvent() {
			uni.navigateTo({url:'/pagesStorehouse/allot/addExDetails'})
		},
		gotoDetails(item) {
			uni.navigateTo({
				url: `/pagesStorehouse/allot/putDetails?orderSn=${item.orderSn}`,
				success: result => {},
				fail: () => {},
				complete: () => {}
			});
		}
	}
};
</script>
<style lang="scss" scoped>
.allot-ex-page {
	height: 100%;
	display: flex;
	flex-direction: column;
	background-color: #f9fbfc;
	.allot-list {
		margin-top: 20upx;
		flex: 1;
		padding-bottom: 150upx;
		.allot-item {
			margin-bottom: 1px;
			padding: 30upx;
			display: flex;
			align-items: center;

			box-shadow: 0px 1px 0px 0px #eeeeee;
			background-color: #fff;
			.info {
				flex: 1;
				margin-right: 20px;
				.info-order {
					font-size: 32upx;
					font-weight: 600;
					color: #333333;
				}
				.info-name {
					margin: 40upx 0 20upx;
					font-size: 28upx;
					font-weight: 400;
					color: #666666;
				}
				.info-time {
					margin-right: 30upx;
					font-size: 28upx;
					font-weight: 400;
					color: #666666;
				}
			}
			.status {
				display: flex;
				flex-direction: column;
				align-items: center;
				flex-shrink: 0;
				width: 100upx;
				color: #cccccc;
				.status-name {
					margin-top: 10upx;
					font-size: 24upx;
				}
				.iconfont {
					font-size: 46upx;
				}
				&.primary {
					color: #3385ff;
				}
				&.gray {
					color: #cccccc;
				}
				&.warn {
					color: #ffaf1d;
				}
			}
		}
	}
}
</style>
