<template>
	<mobile-frame>
		<view class="main">
			<view class="one"></view>
			<view class="two">
				<view class="two_1">
					<view class="two_1_1">
						<text>订单状态：</text>
						<text>{{is_check}}</text>
					</view>
					<view class="two_1_1">
						<text>物流单号：</text>
						<text>{{no}}</text>
					</view>
				</view>
				<view class="two_2">
					<uni-section title="物流记录" type="line" padding>
						<uni-steps :options="list" active-color="#007AFF" :active="active" direction="column" />
					</uni-section>
				</view>
			</view>
		</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				type: '',
				user: {},
				info: {},
				is_check: '',
				no: '',
				list: []
			};
		},
		onLoad: function(e) {
			const that = this;
			that.$set(that, `id`, e.id || '');
			that.$set(that, `type`, e.type || '');
			that.watchLogin()
		},
		methods: {
			watchLogin() {
				const that = this;
				uni.getStorage({
					key: 'token',
					success: function(res) {
						let user = that.$jwt(res.data);
						if (user) that.$set(that, `user`, user);
						that.searchInfo();
					}
				})
			},
			async searchInfo() {
				const that = this;
				if (that.id) {
					let res;
					if (that.type == 'integral') {
						res = await that.$api(`/zrOrder/${that.id}`, `GET`, {}, `integral`)
					} else if (that.type == 'afterSale') {
						res = await that.$api(`/afterSale/${that.id}`, `GET`)
					} else {
						res = await that.$api(`/orderDetail/${that.id}`, 'GET')
					}
					if (res.errcode == '0') {
						that.$set(that, `info`, res.data);
						that.search();
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none'
						})
					}
				}
			},
			async search() {
				const that = this;
				if (that.type == 'afterSale') {
					let arr = await that.$api(`/afterSale/getTransportInfo/${that.info.id}`, `GET`)
					if (arr.errcode == '0') {
						that.$set(that, `is_check`, arr.data.shop.is_check);
						let list = arr.data.shop.list.map((i) => ({
							desc: i.time,
							title: i.context
						}))
						that.$set(that, `list`, list);
						that.$set(that, `no`, arr.data.shop.no);
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none'
						})
					}
				} else {
					let res;
					if (that.type == 'integral') {
						res = await that.$api(`/zrOrder/sot/${that.info._id}`, `GET`, {}, `integral`);
					} else {
						res = await that.$api(`/orderDetail/sot/${that.info._id}`, `GET`);
					}
					if (res.errcode == '0') {
						that.$set(that, `is_check`, res.data.is_check);
						let list = res.data.list.map((i) => ({
							desc: i.time,
							title: i.context
						}))
						that.$set(that, `list`, list);
						that.$set(that, `no`, res.data.no);
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none'
						})
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			position: relative;
			width: 100vw;
			height: 100vh;
			background-color: #ff0000;
		}

		.two {
			position: absolute;
			bottom: 0;
			width: 92vw;
			height: 60vh;
			overflow-y: auto;
			background: #fff;
			margin: 0 2vw;
			border-top-left-radius: 5px;
			border-top-right-radius: 5px;
			padding: 2vw;

			.two_1 {
				margin: 0 0 2vw 0;

				.two_1_1 {
					padding: 1vw 0;
				}
			}
		}

	}

	.uni-section .uni-section-header {
		padding: 1vw !important;
	}

	.uni-section .uni-section-content {
		padding: 0 !important;
	}
</style>
