<template>
	<view>
		<view class="cmain" style="padding-bottom: 80px;">
			<view class="box order_detail">
				<view class="item">
					<text class="label">订单编号</text>
					<text class="desc omit">{{ item.tradeNo }}</text>
				</view>
				<view class="item">
					<text class="label">商品名称</text>
					<text class="desc omit">{{ item.goodsNames }}</text>
				</view>
				<view class="item">
					<text class="label">商品重量</text>
					<text class="desc">{{ item.totalWeight }}</text>
				</view>
				<view class="item">
					<text class="label">净重</text>
					<text class="desc">{{ item.netWt }}</text>
				</view>
				<view class="item">
					<text class="label">毛重</text>
					<text class="desc">{{ item.grossWt }}</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.totalPrice }}</text>
				</view>
				<view class="item">
					<text class="label">预上架金额</text>
					<text class="desc">¥ {{ item.totalPrice }}</text>
				</view>

				<view style="font-size: 16px;padding: 5px;height: 100px;line-height: 30px;">*注：
					<view>本次上架需扣除服务1点数，</view>
					<view>重复上架只收取一次。剩余服务点数：<text style="font-weight: bold;color: blue;">{{user.wallet}}</text>
					</view>
				</view>
			</view>

		</view>
		<view class="mfooter" v-if="item.upStatus != 2">
			<view class="flex">
				<view class="f">
					<button class="btn" v-if="user.wallet>0" @click="ok()">确定上架</button>
					<button class="btn" v-else @click="toCharge()" style="background-color: chocolate;">前往充值</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item: {},
				resalePrice: '',
				weight: '',
				price: '',
				user: {},
				newRuleList: [],
				fee: {
					totalFee: 0,
					feeList: []
				}
			};
		},
		onLoad(e) {
			if (e.item) {
				this.item = JSON.parse(e.item);
				this.price = this.item.totalPrice;
				this.weight = this.item.totalWeight;
				this.user = this.getUser();
				//this.countPrice();
			}
		},
		onShow() {
			this.http.request({
				url: '/level-one-server/app/TbPeople/getById',
				data: {
					id: this.user.fkId
				},
				success: res => {
					this.user.wallet = res.data.data.wallet;
					uni.setStorageSync('info', this.user);
				}
			});
		},
		methods: {
			toCharge() {
				uni.navigateTo({
					url: '/pages/wallet/topup/edit'
				});
			},
			fetchItemList() {
				this.http.request({
					url: '/level-two-server/app/TbOrders/fetchItemList',
					data: {
						id: this.item.id
					},
					success: res => {
						this.resalePrice = (res.data.data.sumPrice + 50).toFixed(2)
						this.newRuleList = res.data.data.newRuleList
					}
				});
			},
			//费项合计
			countPrice() {
				this.http.request({
					url: '/level-two-server/app/TbOrders/countPrice',
					data: {
						id: this.item.id
					},
					success: res => {
						this.fee = res.data.data;
						this.resalePrice = (this.fee.totalFee + this.item.totalPrice).toFixed(2);
					}
				});
			},
			ok() {
				let resalePrice = this.resalePrice;
				uni.showModal({
					title: '提示',
					content: '确定上架？',
					success: res => {
						if (res.confirm) {
							let that = this;
							this.http.request({
								url: '/level-one-server/app/TbOrder/up',
								data: {
									id: this.item.id,
									upPrice: this.item.totalPrice
								},
								success: res => {
									let resp = res.data;
									uni.showToast({
										title: resp.data
									});
									if (resp.code == 200) {
										let user = that.user;
										user.wallet = user.wallet - resp.data;
										uni.setStorageSync('info', user);
										uni.navigateBack();
									}

								}
							});
						}
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: $pg;
	}

	.item {
		input {
			margin-top: 0px !important;
		}
	}
</style>