<template>
	<view class="allot-ex-page">
		<view class="tabs">
			<Tabs
				:tabs="tabs"
				:currentTab="tabIndex"
				@change="changeTabEvent"
				@add="addEvent"
				:itemWidth="'33.33%'"
			></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="gotoDetailsEvent(item)"
				>
					<view class="info">
						<view class="info-order">{{ item.orderSn }}</view>
						<view class="info-name">{{ item.remark }}</view>
						<view style="margin-bottom: 10rpx">
							<text class="info-time">人员：{{ item.adminName }}</text>
						</view>
						<view style="margin-bottom: 10rpx">
							<text class="info-time" style="margin: 0">数量：{{item.bigNum}}/</text>
							<text class="info-time" style="margin: 0">{{ item.smallNum }}</text>件
						</view>
						<view>
							<text class="info-time">时间：{{ item.updateTime }}</text>
						</view>
					</view>
					<view
						:class="[
							'status',
							item.status == INVENTORY_STATUS.DRAFT ? 'primary' : 'gray'
						]"
					>
						<view
							:class="[
								'iconfont',
								item.status == INVENTORY_STATUS.DONE ? 'iconxuanzhong' : 'iconbianji'
							]"
						></view>
					</view>
				</view>
			</block>
			<block v-else>
				<AppWrapperEmpty title="暂无记录" :is-empty="$util.isEmpty(list.data)" />
			</block>
		</scroll-view>
		<div class="app-footer open_btn">
			<div @click="addEvent" class="admin-button-com middle blue">新增盘点</div>
		</div>
	</view>
</template>
<script>
import Tabs from "@/components/plugin/tabs";
import AppWrapperEmpty from "@/components/app-wrapper-empty";
import { INVENTORY_STATUS } from "@/utils/declare";
import { getCheckOrderListApi } from "@/api/inventory/index";

import { list } from "@/mixins";
export default {
	name: "盘点",
	components: { Tabs, AppWrapperEmpty },
	mixins: [list],
	data() {
		return {
			listLoading: false,
			INVENTORY_STATUS,
			tabIndex: 0,
			tabs: [
				{
					name: "全部",
					key: ""
				},
				{
					name: "草稿",
					key: INVENTORY_STATUS.DRAFT
				},
				{
					name: "已盘点",
					key: INVENTORY_STATUS.DONE
				}
			]
		};
	},
	onShow() {
		if (!this.listLoading) {
			this.resetList();
			this.init();
		}
	},
	onPullDownRefresh() {
		this.resetList();
		this._list().then(res => {
			uni.stopPullDownRefresh();
		});
	},
	methods: {
		async init() {
			this._list();
		},
		_list() {
			this.listLoading = true;
			return getCheckOrderListApi(this.tabs[this.tabIndex].key)
				.then(res => {
					this.completes(res);
					this.listLoading = false;
				})
				.catch(err => {
					this.listLoading = false;
				});
		},
		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 OUT_STATUS.CONFIRM:
					name = "待出库";
					break;
				case OUT_STATUS.DONE:
					name = "已出库";
					break;

				default:
					break;
			}
			return name;
		},
		addEvent() {
			uni.navigateTo({
				url: `/pagesStorehouse/inventory/update`,
				success: result => {},
				fail: () => {},
				complete: () => {}
			});
		},
		gotoDetailsEvent(item) {
			if (item.status == INVENTORY_STATUS.DONE) {
				uni.navigateTo({
					url: `/pagesStorehouse/inventory/details?orderSn=${item.orderSn}`,
					success: result => {},
					fail: () => {},
					complete: () => {}
				});
			} else {
				uni.navigateTo({
					url: `/pagesStorehouse/inventory/update?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;
				}
				.iconxuanzhong {
					font-size: 46upx;
				}
				.iconbianji {
					font-size: 36upx;
				}
				&.primary {
					color: #3385ff;
				}
				&.gray {
					color: #cccccc;
				}
				&.warn {
					color: #ffaf1d;
				}
			}
		}
	}
}
</style>
