<template>
	<view class="card_order_management">
		<view class="card_order" v-for="(item,index) in datalist" :key="index" v-if="datalist.length > 0">
			<view @click="goDetails(item)">
				<view class="space_between">
					<view class="item_headline" v-if="item.goods && item.spec">{{item.goods.name}}{{item.spec.name}}
					</view>
					<view v-if="item.state == 5">
						<view class="item_tag" v-if="item.customer.isSyncProv">
							<u-tag text="已完善" plain size="mini" type="success"></u-tag>
						</view>
						<view class="item_tag" v-else>
							<u-tag text="补全客户信息" plain size="mini" @click="goCompletionTasks(item)"></u-tag>
						</view>
					</view>
					<view v-if="item.state == 3 || item.state == 4">
						<view class="details_title" style="color: #5ac725;" v-if="item.state == 3">已送达</view>
						<view class="details_title" style="color: #f56c6c;" v-else-if="item.state == 4">已取消</view>
					</view>
				</view>
				<view class="item_num">×{{item.quantity}}</view>
				<view class="item_address">配送地址:{{item.address}}</view>
				<view class="item_address" v-if="item.state == 5">联系电话:{{item.phone}}
					<u-icon color="#70B603" size="26" name="phone-fill" @click.native.stop="phone(item.phone)"></u-icon>
				</view>
				<view class="item_address">下单时间:{{item.orderTime}}</view>
				<view class="item_address" v-if="item.state == 3">送达时间:{{item.arriveTime}}</view>
			</view>
			<view v-if="item.state == 2">
				<u-button type="primary" @click="toDeliver(item)">去配送</u-button>
			</view>
			<view class="card_delivery" v-if="item.state == 5">
				<view style="margin-right: 10rpx;flex: 1;">
					<u-button type="warning" @click="goSecurityCheck(item)">入户安全检查</u-button>
				</view>
				<view style="margin-left: 10rpx;flex: 1;">
					<u-button type="primary" @click="confirmedDelivery(item)">确认送达</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			datalist: {
				type: Array,
				default: []
			}
		},
		data() {
			return {}
		},
		methods: {
			goDetails(value) {
				uni.setStorageSync('detailsData', value);
				uni.navigateTo({
					url: '/pages/order/orderDetails'
				});
			},
			// 入户安全检查
			goSecurityCheck(row) {
				uni.navigateTo({
					url: '/pages/order/securityCheck?orderId=' + row.orderId + '&customerId=' + row.customerId
				});
			},
			// 确认送达
			confirmedDelivery(row) {
				if (row.customer.isSyncProv) {
					uni.navigateTo({
						url: '/pages/order/delivery?id=' + '99' + '&title=' + '确定送达' + '&orderId=' + row.id
					});
				} else {
					uni.$u.toast('请先完善客户信息')
				}
			},
			// 补全用户信息
			goCompletionTasks(row) {
				uni.navigateTo({
					url: '/pages/order/completionTasks?customerId=' + row.customerId
				});
			},
			// 去配送
			toDeliver(row) {
				this.$emit('toDeliver', row)
			},
			phone(phone) {
				console.log(phone, 66)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card_order_management {
		margin: 0rpx 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.card_order {
		width: calc(100% - 40rpx);
		margin-top: 20rpx;
		border: 1rpx solid rgba(215, 215, 215, 1);
		border-radius: 8rpx;
		padding: 30rpx 20rpx;
	}

	.item_headline {
		font-size: 40rpx;
		font-weight: 800;
	}

	.item_num {
		margin: 20rpx 0rpx;
		font-size: 26rpx;
	}

	.details_title {
		font-size: 30rpx;
		font-weight: 500;
	}
	.item_address {
		display: flex;
		align-items: center;
		font-size: 30rpx;
		color: #7f7f7f;
		margin-bottom: 20rpx;
	}

	.card_delivery {
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>