<template>
	<view>
		<view class="product_detail">
			<!-- <image src="../../../static/news.jpg" mode="widthFix" class="pic"></image> -->
			<view class="box">
				<view class="title">{{ item.goodsName }}</view>
				<view class="clear"></view>
				<u-divider text="详情"></u-divider>
				<view class="item">
					<text class="desc">车牌号：</text>
					<text>{{ item.veNo }}</text>
					<view class="clear"></view>
				</view>
				<view class="item">
					<text class="desc">商品重量：</text>
					<text v-if="type==1">{{ item.goodsNames }} </text>
					<text v-if="type==2">{{ item.goodsName }} </text>
				</view>
				<view class="item">
					<text class="desc">商品名称：</text>
					<text v-if="type==1">{{ item.sumNetWt }} kg</text>
					<text v-if="type==2">{{ item.netWet }} kg</text>
				</view>
				<view class="item">
					<text class="desc">货主：</text>
					<text v-if="type==1">{{ item.shopName }}</text>
					<text v-if="type==2">{{ item.leaderName }}</text>
				</view>
				<view class="item">
					<text class="desc">互市区：</text>
					<text v-if="type==2">{{ item.tradeAreaName }}</text>
					<text v-if="type==1">{{ item.fieldName }}</text>
					<view class="clear"></view>
				</view>

				<view class="item">
					<text class="desc">发布时间：</text>
					<text>{{ item.createTime }}</text>
					<view class="clear"></view>
				</view>
				<view class="item">
					<text class="desc">总金额：</text>
					<text v-if="type==2" class="price">￥ {{ item.resalePrice }}</text>
					<text v-if="type==1" class="price">￥ {{ item.sumUpPrice }}</text>
					<view class="clear"></view>
				</view>
			</view>
		</view>
		<view class="mfooter">
			<view class="flex">
				<view class="f">
					<button class="btn" v-if="user.userType == 3" @click="pay()">立即购买</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: this.getUser(),
				item: {},
				id: '',
				type: 1
			};
		},
		onLoad(e) {
			if (e.id) {
				this.id = e.id;
				this.type = e.type
				this.getDetail()
			}
		},
		methods: {
			getDetail() {
				if (this.type == 1) {
					this.getWholeDetails();
				} else {
					this.getOrdersDetails()
				}
			},
			getOrdersDetails() {
				this.http.request({
					url: '/level-two-server/app/TbOrders/getDetailById',
					method: 'POST',
					data: {
						ids: this.id
					},
					success: res => {
						let data = res.data.data;
						this.item = data[0];
					}
				});
			},
			getWholeDetails() {
				this.http.request({
					url: '/level-one-server/app/HtTradeSettlement/getByIds',
					method: 'POST',
					data: {
						ids: this.id
					},
					success: res => {
						this.item = res.data.data[0];
					}
				});
			},
			buyOrder() {
				this.http.request({
					url: '/level-two-server/app/TbOrders/purchaserBuy',
					method: 'POST',
					data: {
						ids: this.id
					},
					success: res => {
						uni.navigateTo({
							url: '/pages/market/two/leader/success'
						});
					}
				});
			},
			buyWhole() {
				this.http.request({
					url: '/level-two-server/app/TbOrders/purchaserBuyWhole',
					method: 'POST',
					data: {
						ids: this.id
					},
					success: res => {
						uni.navigateTo({
							url: '/pages/market/two/leader/success'
						});
					}
				});
			},
			pay() {
				uni.showModal({
					title: '提示',
					content: '确定下单购买？',
					success: res => {
						if (res.confirm) {
							if (this.type == 1) {
								this.buyWhole()
							} else {
								this.buyOrder()
							}
						}
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	page {
		.price {
			color: red;
			font-weight: bold;
		}

		background-color: $pg;
	}
</style>