<template>
	<view class="content">
		<view class="flex gs-item">
			<view class="item-name">
				参考价格
			</view>
			<input type="text" class="item-val val-red" disabled v-model="pUser.points_transaction" />
		</view>
		<!-- //挂售价格(元) -->
		<view class="flex gs-item">
			<view class="item-name">
				{{type == 1?'挂售': '买入'}}价格(元)
			</view>
			<input type="text" class="item-val" :placeholder="'请输入您的' + (type == 1?'挂售': '买入') + '价(单价)'" v-model="total_price" />
		</view>
		<view class="flex gs-item">
			<view class="item-name">
				{{type == 1?'挂售': '买入'}}数量
			</view>
			<input type="text" class="item-val" :placeholder="'请输入' + (type == 1?'挂售': '买入') + '数量'" v-model="amount" />
		</view>
		<view class="flex gs-item" v-if="type !=1 && type != 3">
			<view class="item-name">
				联系方式
			</view>
			<input type="text" class="item-val" placeholder="请输入联系方式" v-model="phone" />
		</view>
		<view class="fwf" v-if="type != 1 && type != 3">
			服务费：<text>{{(total_price * amount * pUser.fee_ratio / 100).toFixed(2) || 0}} 阅读积分</text>
		</view>
		<view class="fwf" v-if="type == 1">
			服务费：<text>{{( amount * 0.05).toFixed(4) || 0}} 余额宝</text>
		</view>
		<view class="fwf" v-if="type == 3">
			<!-- 服务费：<text>{{( amount * 0.05).toFixed(4) || 0}} 余额宝</text> -->
			买入价格不得低于参考价
		</view>
		<view class="btn" @click="createGs">
			确认
		</view>
	</view>
</template>

<script>
	import {
		createGs,
		passUser,
		createBuy
	} from '@/api/zero.js'
	export default {
		data() {
			return {
				type: 0,
				total_price: '',
				amount: '',
				phone: '',
				pUser: {}
			}
		},
		onLoad(opt) {
			if (opt.type) {
				this.type = opt.type
			}
			if(opt.type == 3) {
				uni.setNavigationBarTitle({
					title: '买入'
				})
			}
		},
		onShow() {
			this.passUser()
		},
		onReachBottom() {

		},
		onReady() {

		},
		methods: {
			passUser() {
				passUser().then(res => {
					this.pUser = res.data
				})
			},
			createGs() {
				let that = this
				if(!that.total_price) {
					return that.$api.msg('请输入挂售单价')
				}
				if(!that.amount) {
					return that.$api.msg('请输入挂售数量')
				}
				if(that.type == 1) {
					createGs({
						total_price: that.total_price * that.amount,
						amount: that.amount,
						phone: that.phone,
						type: that.type
					}).then(res => {
						uni.showToast({
							title: '挂售成功',
							duration: 2000
						});
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					})
				}else {
					createBuy({
						total_price: that.total_price * that.amount,
						amount: that.amount,
					}).then(res => {
						uni.showToast({
							title: '提交成功',
							duration: 2000
						});
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					})
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.gs-item {
		height: 135rpx;
		background-color: #fff;
		padding: 0 65rpx;

		.item-val {
			width: 405rpx;
			height: 87rpx;
			background: #F4F4F4;
			border-radius: 10rpx;
			text-align: center;
			font-size: 36rpx;
			font-weight: bold;

		}

		.val-red {
			color: #FD3B39;
		}
	}

	.fwf {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
		text-align: right;
		padding-right: 65rpx;
		background-color: #fff;
		padding-bottom: 62rpx;

		text {
			color: #FD3B39;
		}
	}

	.btn {
		width: 616rpx;
		height: 88rpx;
		background: #ff4c4c;
		border-radius: 10rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		margin: 60rpx auto;
	}
</style>