<template>
	<view>
		<view class="box">
			<view class="top">
				<text class="title">业务详情</text>
			</view>
		</view>
		<view class="card-box">
			<view class="card">
				<view class="t">
					订单号：
					<text class="title">{{businessItem.no}}</text>
				</view>
				<view class="c">
					<view class="item car-num-item">
						<text class="car-num">{{businessItem.goodsName}}</text>
					</view>
				</view>
				<view class="c">
					<view class="item">
						<text class="p1">类型:</text>
						<text class="p2">{{businessItem.itemTypeName}}</text>
					</view>
				</view>
				<view class="c">
					<view class="item">
						<text class="p1">作业项:</text>
						<text class="p2">{{businessItem.itemName}}</text>
					</view>
				</view>
				<view class="c" v-if="businessItem.cardNo">
					<view class="item">
						<text class="p1">越南车:</text>
						<text class="p2">{{businessItem.cardNo}}</text>
					</view>
				</view>
				<view class="c" v-if="businessItem.chinaCarNo">
					<view class="item">
						<text class="p1">中国车:</text>
						<text class="p2">{{businessItem.chinaCarNo}}</text>
					</view>
				</view>
				<view class="c">
					<view class="item">
						<text class="p1">录入时间:</text>
						<text class="p2">{{businessItem.createTime}}</text>
					</view>
				</view>
				<view class="c">
					<view class="item">
						<text class="p1">状态:</text>
						<text class="p2">
							<text v-if="businessItem.pick==1">已接单</text>
							<text v-else>未接单</text>
						</text>
					</view>
				</view>
				<view class="c">
					<view class="item" v-if="businessItem.pickTime">
						<text class="p1">接单时间:</text>
						<text class="p2">
							<text>{{businessItem.pickTime}}</text>
						</text>
					</view>
				</view>
				<view class="c" v-if="businessItem.pick==1">
					<view class="item">
						<text class="p1">确认状态:</text>
						<text class="p2">
							<text v-if="businessItem.confirm==1">已确认</text>
							<text v-else>未确认</text>
						</text>
					</view>
				</view>
				<view class="c" v-if="businessItem.confirm==1">
					<view class="item">
						<text class="p1">确认时间:</text>
						<text class="p2">
							<text>{{businessItem.confirmTime}}</text>
						</text>
					</view>
				</view>
				<view class="b">
					<view class="btn b3" v-if="businessItem.pick==0" @click="pickFn">
						接单</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				openid: '',
				businessItem: {}
			}
		},
		onLoad(option) {
			this.businessItem.id = option.itemId;
			this.openid = option.openid;
			this.getBusinessItem();
		},
		onBackPress() {
			this.$common.to('/pages/index/index')
			return true;
		},
		methods: {
			getBusinessItem() {
				this.$api.getBusinessItem({
					id: this.businessItem.id
				}).then(resp => {
					let data = resp.data;
					if (!data) {
						this.$common.toast('该业务已取消或删除');
						setTimeout(() => {
							this.$common.to('/pages/index/index')
						}, 2000)
						return;
					}
					this.businessItem = resp.data;
				})
			},
			pickFn() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否确认接单？',
					success(resp) {
						if (resp.confirm) {
							that.surePick();
						}
					}
				})
			},
			surePick() {
				let obj = {
					openid: this.openid,
					id: this.businessItem.id
				};
				this.$api.pickBusinessItem(obj).then(resp => {
					if (resp.code == 200) {
						this.$common.toast('已接单');
						this.getBusinessItem();
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.card-box {
		display: flex;
		width: 100%;
		flex-direction: column;

		.card {
			background-color: #fff;
			border-radius: 20rpx;
			margin: 20rpx 20rpx 0 20rpx;
			padding: 30rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;

			.t {
				width: 100%;
				display: flex;
				align-items: center;
				padding-bottom: 30rpx;
				border-bottom: 1rpx solid #f5f5f5;

				.icon {
					width: 40rpx;
					height: 40rpx;
				}

				.title {
					font-size: 35rpx;
					font-weight: bold;
					margin-left: 20rpx;
				}
			}

			.c {
				padding: 15rpx 0 30rpx 0;
				display: flex;
				flex-wrap: wrap;
				border-bottom: 1rpx solid #f5f5f5;

				.item {
					padding: 20rpx 0;

					.car-num {
						background-color: #edf6ff;
						color: #0080ff;
						font-size: 38rpx;
						padding: 15rpx 0;
						text-align: center;
						width: 100%;
						border-radius: 10rpx;
						font-weight: bold;
					}

					.p1 {
						font-size: 28rpx;
						color: #999;
					}

					.p2 {
						font-size: 28rpx;
						color: #191919;
						font-weight: bold;
						margin-left: 20rpx;
					}
				}

				.car-num-item {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			.b {
				display: flex;
				width: 100%;
				align-items: center;
				justify-content: space-between;

				.btn {
					height: 70rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					width: calc(100% - 15rpx);
					margin: 30rpx 0 0 0;
					border-radius: 10rpx;
					border-width: 1rpx;
					box-sizing: border-box;
				}

				.b1 {
					background-color: #0080ff;
					color: #fff;
				}

				.b2 {
					background-color: #f7f7f7;
					color: #191919;
				}

				.b3 {
					background-color: #fff;
					color: #0080ff;
					border: 1rpx solid #0080ff;
				}

				.b4 {
					background-color: #ff0000;
					color: #fff;
				}
			}
		}
	}

	@import '@/common/common.scss'
</style>
