<template>
	<view>
		<view class="cmain">
			<view class="box order_detail">
				<view class="item">
					<text class="label">收购商品</text>
					<text class="desc omit">{{ item.goodsName }}</text>
				</view>
				<view class="item">
					<text class="label">商品编号</text>
					<text class="desc">{{ item.goodsNo }}</text>
				</view>
				<view class="item">
					<text class="label">计价单位</text>
					<text class="desc">{{ item.goodsUnit }}</text>
				</view>
				<view class="item">
					<text class="label">数量</text>
					<text class="desc">{{ item.goodsQuantity }}</text>
				</view>
				<view class="item">
					<text class="label">到货日期</text>
					<text class="desc">{{ item.arrivalTime }}</text>
				</view>
				<view class="item">
					<text class="label">创建时间</text>
					<text class="desc">{{ item.goodsDemandTime }}</text>
				</view>
				<view class="item">
					<text class="label">状态</text>
					<text class="desc" v-if="item.isRelease == 0">未发布</text>
					<text class="desc" v-if="item.isRelease == 1 && item.isOrders == 0">未接单</text>
					<text class="desc" v-if="item.isOrders == 1 && item.isConfirm == 0">已接单</text>
					<text class="desc" v-if="item.isConfirm == 1">已确认</text>
				</view>
				<view class="item" v-if="item.createName">
					<text class="label">接单人</text>
					<text class="desc">{{ item.createName }}</text>
				</view>
				<view class="item" v-if="item.quotation">
					<text class="label">出价金额</text>
					<text class="desc" style="color: #f44336; font-weight: bold">¥ {{ item.quotation }}</text>
				</view>
				<view class="item" v-if="item.createTime">
					<text class="label">接单时间</text>
					<text class="desc">{{ item.createTime }}</text>
				</view>
			</view>
			<u-divider text="收货地址"></u-divider>
			<view class="box order_detail">
				<view class="item">
					<text class="label">收件人</text>
					<text class="desc omit">{{ item.name }}</text>
				</view>
				<view class="item">
					<text class="label">联系电话</text>
					<text class="desc">{{ item.phone }}</text>
				</view>
				<view class="item">
					<text class="label">收件地址</text>
					<text class="desc">{{ item.addressName }}</text>
				</view>
			</view>
			<button class="btn" @click.stop="confirm()" v-if="item.isRelease == 1 && item.isOrders == 1 && item.isConfirm == 0">同意接单并支付</button>
			<button class="btn" @click.stop="refuse()" style="background-color: #f44336" v-if="item.isRelease == 1 && item.isOrders == 1 && item.isConfirm == 0">拒绝接单</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {}
		};
	},
	onLoad(e) {
		if (e.id) {
			this.http.request({
				url: '/level-two-server/app/TbGoodsDemand/goodsDemandDetail?id=' + e.id,
				success: res => {
					this.item = res.data.data;
				}
			});
		}
	},
	methods: {
		confirm() {
			uni.showModal({
				title: '提示',
				content: '确定同意接单并支付?',
				success: res => {
					if (res.confirm) {
						this.http.request({
							url: '/level-two-server/app/TbOrders/add',
							data: this.item,
							success: res => {
								console.log('asd:');
								uni.showModal({
									title: '提示',
									content: '处理成功,等待组长发货',
									showCancel: false,
									success: res => {
										uni.navigateBack();
										uni.$emit('purchaser_buy_list');
									}
								});
							}
						});
					}
				}
			});
		},
		refuse() {
			uni.showModal({
				title: '提示',
				content: '确定取消该接单?',
				success: res => {
					if (res.confirm) {
						this.http.request({
							url: '/level-two-server/app/TbGoodsDemand/refuse',
							data: { id: this.item.goodsDemandId, goodsName: this.item.goodsName },
							success: res => {
								uni.showModal({
									title: '提示',
									content: '取消成功',
									showCancel: false,
									success: res => {
										uni.navigateBack();
										uni.$emit('purchaser_buy_list');
									}
								});
							}
						});
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: $pg;
}
.btn {
	margin-top: 20px;
	width: 70%;
}
</style>
