<template>
	<div class="app-main app-content">
		<app-tabs :tabs="tabs" :isFixed="true" :currentTab="tabIndex" :height="100" @change="change" itemWidth="20%" />
		<div class="list-wrap">
			<block v-if="!$util.isEmpty(list.data)">
				<div class="list" v-for="(item, index) in list.data" :key="index" @click="pageTo({
					url: '/admin/order/detail',
					query: {
						id: item.id
					}
				})">
					<div class="list-top flex-center-between">
						<div class="app-color-3">订单编号：{{ item.sendNum }}</div>
						<div class="app-price">{{ item.status | constantfilter('ORDER_STATUS') }}</div>
					</div>
					<div class="list-blo">
						<block v-if="!$util.isEmpty(item.goodsInfoList)">
							<list-module v-for="(items, subIndex) in item.goodsInfoList" :key="subIndex" :info="items" />
						</block>
					</div>
					<div class="list-bottom">
						<div>
							<span class="freight-text">运费：￥{{ item.sendCost }}</span>
							<span>应付金额：</span>
							<span class="app-size-30 app-bold">¥{{ item.actPrice }}</span>
						</div>
						<div class="list-button">
							<!-- 待配送 -->
							<div v-if="item.status == 2" class="admin-button-com" @click="freeShippingFn(item)">免发货</div>
							<div v-if="item.status == 2" class="admin-button-com" @click="pageTo({
						url: '/admin/order/ship',
						query: {
							id: item.id,
							pageStatus: 0
						}
					})">发货</div>
							<!-- 配送中 -->
							<div v-if="item.status == 2" class="admin-button-com">继续</div>
							<!-- 已完成 -->
							<div v-if="item.status == 5" class="admin-button-com default" @click.stop="seeSendFn(item)">查看快递</div>
						</div>
					</div>
				</div>
			</block>
			<block v-else>
				<app-wrapper-empty title="暂无数据" :is-empty="$util.isEmpty(list.data)" />
			</block>
		</div>
		<!-- 免发货弹窗 -->
		<modal-module :show="freeShipModal" @cancel="modalCancel" @click="freeShipModalClick" content="确认不需要发货？" color="#333" :size="32" padding="30rpx 30rpx"></modal-module>
	</div>
</template>

<script>
import AppTabs from '@/components/plugin/tabs'
import ListModule from '@/components/module/app-order-list'
import AppWrapperEmpty from '@/components/app-wrapper-empty'
import ModalModule from '@/components/plugin/modal'
import { list } from '@/mixins'
// api
import { getListB, freeShipping } from '@/api/order'
export default {
	name: 'order-list',
	components: {
		ListModule,
		AppTabs,
		AppWrapperEmpty,
		ModalModule
	},
	mixins: [list],
	data() {
		return {
			tabIndex: 0,
			tabs: [
				{
					name: '全部',
					value: 0
				},
				{
					name: '待付款',
					value: 0
				},
				{
					name: '待配送',
					value: 0
				},
				{
					name: '配送中',
					value: 0
				},
				{
					name: '已完结',
					value: 0
				}
			],
			// operate
			operateIndex: null,
			operateData: {},
			// 免发货
			freeShipModal: false
		}
	},
	onPullDownRefresh() {
		console.log('fasdfasdf')
	},
	// 加载更多
	onReachBottom() {
		console.log('5151')
	},
	onLoad: function() {
		// this.init()
	},
	methods: {
		async init() {
			this._list()
		},
		_list() {
			let status = JSON.parse(JSON.stringify(this.tabIndex))
			status = status == 4 ? 5 : status - 1
			return getListB({
				status: status,
				search: '',
				page: this.list.page
			}).then(res => {
				this.completes(res)
				if (this.$util.isEmpty(res.data)) return false
				this.tabs[0].value = res.data.asset.totalOrder
				this.tabs[1].value = res.data.asset.unPayOrder
				this.tabs[2].value = res.data.asset.unSendOrder
				this.tabs[3].value = res.data.asset.sendingOrder
				this.tabs[4].value = res.data.asset.finishOrder
			})
		},
		change(e) {
			if (this.tabIndex == e.index) {
				return false
			} else {
				this.tabIndex = e.index
				this.resetList()
				this._list()
			}
		},
		// 免发货
		freeShippingFn(item, index) {
			this.operateIndex = index
			this.operateData = item
			this.freeShipModal = true
		},
		// 免发货
		freeShipModalClick(e) {
			if (e.index === 0) {
				this.modalCancel()
			} else {
				this.list.data[this.operateIndex].status = 2
			}
		},
		// 查看配送
		seeSendFn(item) {
			this.$util.pageTo({
				url: '/admin/order/ship',
				query: {
					id: item.id,
					pageStatus: 5
				}
			})
		},
		// 关闭弹窗
		modalCancel() {
			this.freeShipModal = false
		}
	}
}
</script>

<style lang="scss" scoped>
</style>

<style lang="scss" scoped>
	.app-content {
		padding-top: 120px;
		padding-bottom: 1px;
		.list-wrap {
			.list {
				padding: 0 30px;
				background-color: #fff;
				margin-bottom: 20px;
				.list-top,
				.list-bottom {
					padding: 26px 0;
					border-bottom: 1px solid $borderColor;
					color: $fontColor3;
					.app-bold {
						color: #333;
					}
					.freight-text {
						margin-right: 60px;
					}
				}
				.list-bottom {
					& > div {
						@include disFlex(center, flex-end);
					}
					.list-button {
						margin-top: 26px;
						.admin-button-com {
							margin-left: 20px;
						}
					}
				}
			}
		}
	}
</style>
