<template>
	<view class="">
		<view class="info">
			<view class="bg"></view>
			<view class="card">
				<view class="title">店铺保证金信息</view>
				<view class="item">
					<text>已缴纳保证金</text>
					<text>{{merchant_Data.paid_margin}}</text>
				</view>
				<view class="item">
					<text>剩余缴纳保证金</text>
					<text>{{merchant_Data.unpaid_margin}}</text>
				</view>
				<view class="item">
					<text>缴纳店铺账户</text>
					<text>{{merchant_Data.mer_name}}</text>
				</view>
			</view>
		</view>
		<view class="price">
			<view class="title">缴纳金额</view>
			<view class="tab">
				<view class="item active" style="margin: 0;">{{merchant_Data.margin}}元</view>
			</view>
			<button class="btn" @click="paydecimal">缴纳</button>
		</view>
		<!--    <view class="tip">
      <view class="title">注意事项</view>
      <view class="text">充值后帐户的金额不能提现，可用于商城消费使用佣金导入账户之后不能再次导出、不可提现账户充值出现问题可联系商城客服，也可拨打商城客服热线<text @click="copyPhone('4008888888')">4008888888</text>
      </view>
    </view> -->

		<view class="content-order" v-for="(item,i ) in productList">
			<view class="">订单编号：{{item.order_sn}}</view>
			<view class="">支付金额：{{item.total_price}}</view>
			<view class="">支付状态：{{item.paid==1?'已支付':'待支付'}}</view>
			<view class="">支付时间：{{item.pay_time}}</view>
		</view>
		<view class='loadingicon acea-row row-center-wrapper' v-if='productList.length > 0'>
			<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
		</view>
		
	</view>
</template>

<script>
	import {
		merchant,
		paymerchant,
		marginlist
	} from '@/api/api.js'
	export default {
		data() {
			return {
				mer_id: 0,
				merchant_Data: {},
				where: {
					page: 1,
					limit: 10
				},
				productList: [],
				loadend: false,
				loading: false,
				loadTitle: '加载更多',
			}
		},
		onLoad(e) {
			this.mer_id = e.mer_id
			this.decimal()
			this.list(true)

		},
		onReachBottom() {
			if (this.productList.length > 0) {
				setTimeout(() => {
					this.list(false);
				}, 1000)
			}
		},
		methods: {
			list(isPage) {
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				if (isPage === true) that.$set(that, 'productList', []);

				that.loading = true;
				that.loadTitle = '';
				marginlist(that.where).then(res => {
					let list = res.data.list;
					let productList = that.$util.SplitArray(list, that.productList);
					let loadend = list.length < that.where.limit;
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? '已全部加载' : '加载更多';
					setTimeout(() => {
						that.$set(that, 'productList', productList);
					}, 500)

				
					that.$set(that.where, 'page', that.where.page + 1);
					if (that.where.page == 1 && res.data.list.length <= 0) that.emptyShow = true
				}).catch(err => {
					that.loading = false;
					that.loadTitle = '加载更多';
				});

			},
			//获取保证金信息
			decimal() {
				merchant({
					id: this.mer_id
				}).then((res) => {
					
					this.merchant_Data = res.data
				});
			},
			//缴纳保证金
			paydecimal() {
			
					let that = this
					uni.showModal({
						title: '提示',
						content: '商户' + this.merchant_Data.mer_name + '是否同意缴纳保证金',
						success: (res) => {
							if (res.confirm) {

								// console.log('用户点击确定');
								paymerchant().then((res) => {

									uni.requestPayment({
										provider: 'wxpay',
										orderInfo: res.data
											.config, //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
										success: (res) => {
											that.$util.Tips({
												title: '支付成功'
											});
											that.decimal()
											that.list(true)
										},
										fail: (err) => {
											that.$util.Tips({
												title: '支付失败'
											});

											console.log('fail:' + JSON.stringify(err));
										}
									});
								}).catch((err) => {
									console.log(err)
									this.$util.Tips(()=>{
										
									})
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});

				}

		}
	}
</script>

<style>

</style>
<style lang="scss">
	page {
		background-color: #fff;
	}

	.content-order {
		background: #F4F4F4;
		border-radius: 21rpx 21rpx;
		margin-top: 30rpx;
		padding: 10rpx;
		margin-left: 10rpx;
		margin-right: 10rpx;

		view {
			font-size: 30rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			margin: 20rpx;

		}
	}

	.info {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		height: 250rpx;

		.bg {
			background-color: #FF5C2D;
			height: 170rpx;
			width: 100vw;
			border-radius: 0rpx 0rpx 28rpx 28rpx;
			position: absolute;
			top: 0;
			left: 0;
		}

		.card {
			width: 694rpx;
			min-height: 180rpx;
			background: #FFFFFF;
			margin-top: 38.55rpx;
			box-shadow: 0rpx 0rpx 18rpx 2rpx rgba(50, 116, 249, 0.1);
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			opacity: 1;
			padding: 31.5rpx 28rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			position: absolute;
			top: 0;

			.title {
				font-size: 32rpx;
				font-weight: 600;
				color: #333333;
				padding-bottom: 10rpx;
			}

			.item {
				display: flex;
				justify-content: space-between;
				font-size: 32rpx;
				font-weight: 400;
				color: #333333;
				margin-bottom: 10rpx;

				text:nth-child(1) {
					flex-shrink: 0;
					margin-right: 18rpx;
				}
			}
		}
	}

	.price {
		display: flex;
		flex-direction: column;
		padding: 0 28rpx;
		margin-top: 85rpx;

		.title {
			font-size: 32rpx;
			font-weight: 600;
			color: #333333;
			line-height: 39rpx;
			margin-bottom: 42rpx;
		}

		.tab {
			display: flex;
			flex-wrap: wrap;
			justify-content: left;
			width: 694rpx;

			.item {
				width: 217rpx;
				height: 131rpx;
				margin: 0 auto;
				margin-bottom: 20rpx;
				border-radius: 7rpx 7rpx 7rpx 7rpx;
				border: 2rpx solid #F5F5F5;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 32rpx;
				font-weight: 500;
				line-height: 32rpx;
			}

			.active {
				border: 2rpx solid #FF5C2D;
				color: #FF5C2D;
			}
		}

		.input {
			width: 100%;
			height: 112rpx;
			background: #F5F5F5;
			border-radius: 56rpx 56rpx 56rpx 56rpx;
			opacity: 1;
			padding: 0 45.56rpx;
			box-sizing: border-box;
			font-size: 28rpx;
			font-weight: 400;
			color: #333;
			line-height: 35rpx;
		}

		.btn {
			width: 694rpx;
			height: 84rpx;
			margin-top: 73.6rpx;
			background: #FF5C2D;
			box-shadow: 0rpx 14rpx 44rpx 2rpx #E9EFF5;
			border-radius: 42rpx 42rpx 42rpx 42rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 32rpx;
			font-weight: 400;
			color: #FFFFFF;
		}
	}

	.tip {
		display: flex;
		flex-direction: column;
		padding: 0 28rpx;
		margin-top: 84rpx;

		.title {
			font-size: 32rpx;
			font-weight: 500;
			color: #FF5C2D;
			line-height: 32rpx;
			margin-bottom: 21rpx;
		}

		.text {
			font-size: 28rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.6);
			line-height: 42rpx;
			-webkit-background-clip: text;
		}
	}
</style>