<template>
	<!-- 出库列表 -->
	<view class="allot-ex-page">
		<view class="tabs">
			<Tabs
				:tabs="tabs"
				:currentTab="tabIndex"
				@change="changeTabEvent"
				@add="addEvent"
				:addText="'新增'"
				:isAdd="false"
			></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.inShopName }}</view>
						<view class="info-name">数量：{{ item.bigNum || "-" }}/{{ item.smallNum || "-" }}</view>
            <view class="info-name">时间：{{ item.updateTime }}</view>
					</view>
					<view
						:class="[
							'status',
							item.status == OUT_STATUS.DONE
								? 'primary'
								: item.status == OUT_STATUS.CONFIRM
								? 'warn'
								: 'gray'
						]"
					>
						<view
							:class="[
								'iconfont',
								item.status == OUT_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>
	</view>
</template>
<script>
import Tabs from "@/components/plugin/tabs";
import AppWrapperEmpty from "@/components/app-wrapper-empty";

import { list } from "@/mixins";
import { getStockOutListApi } from "@/api/storehouse/stock";
import { OUT_STATUS } from "@/utils/declare";
export default {
	components: { Tabs, AppWrapperEmpty },
	mixins: [list],
	data() {
		return {
			OUT_STATUS,
			tabIndex: 0,
			tabs: [
				{
					name: "全部",
					key: ""
				},
				{
					name: "待出库",
					key: OUT_STATUS.CONFIRM
				},
				{
					name: "已出库",
					key: OUT_STATUS.DONE
				},
				{
					name: "已取消",
					key: OUT_STATUS.CANCEL
				}
			]
		};
	},
	onPullDownRefresh() {
		this.resetList();
		this._list().then(res => {
			uni.stopPullDownRefresh();
		});
	},
	onShow() {
		this.resetList();
		this.initData();
	},
	methods: {
		async initData() {
			this._list();
		},
		_list() {
			return getStockOutListApi(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 OUT_STATUS.CONFIRM:
					name = "待出库";
					break;
				case OUT_STATUS.DONE:
					name = "已出库";
					break;

				default:
					break;
			}
			return name;
		},
		addEvent() {
			uni.navigateTo({
				url: `/pagesStorehouse/allot/addExDetails`,
				success: result => {},
				fail: () => {},
				complete: () => {}
			});
		},
		gotoDetails(item) {
			uni.navigateTo({
				url: `/pagesStorehouse/allot/exDetails?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: 20upx 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>
