<template>
	<view class="body">
		<view class="background"></view>
		<view class="content">
			<view class="userInfo">
				<view class="userInfo-box">
					<view class="userInfo-img"><image class="portrait" :src="image || '../../../static/error/missing-face.png'"></image></view>
					<view class="userInfo-xinxi">
						<view class="title clamp">
							<text>{{ name }}</text>
						</view>
						<view class="phone">
							<text>{{ phone }}</text>
						</view>
					</view>
					<view class="balance clamp">{{ address }}</view>
				</view>
			</view>
			<view class="userInfoList">
				<view class="userInfoList-bottom" @click="smsh()">
					<view class="bottom"><image src="../../static/icon/saoma.png" mode=""></image></view>
					扫码核销
				</view>
				<view class="userInfoList-bottom" @click="navTo('/pages/merchant/finance')">
					<view class="bottom"><image src="../../static/icon/money.png" mode=""></image></view>
					店铺财务
				</view>
				<view class="userInfoList-bottom" @click="navTo('/pages/merchant/order')">
					<view class="bottom"><image src="../../static/icon/order.png" mode=""></image></view>
					订单管理
				</view>
				<view class="userInfoList-bottom" @click="navTo('/pages/merchant/money?id=' + id)">
					<view class="bottom"><image src="../../static/icon/dianpu.png" mode=""></image></view>
					付款记录
				</view>
			</view>
		</view>
		<uni-popup ref="popuphx" class="agree-wrapper">
			<view class="hx-wrapper">
				<view class="hx-img"><image src="../../static/img/hxbg.png" mode=""></image></view>
				<view class="hx-body">
					<view class="hx-title">输入核销码核销</view>
					<input type="text" v-model="code" placeholder="请输入核销码" placeholder-class="hx-placeholder" />
					<view class="hx-btn" @click="qhx">立即核销</view>
				</view>
				<view class="hx-close" @click="close"><image src="../../static/icon/close.png" mode=""></image></view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import { my, verific } from '@/api/merchant.js';
import { orderVerific } from '@/api/user.js';
import uniPopup from '@/components/uni-popup/uni-popup.vue';
export default {
	components: {
		uniPopup
	},
	data() {
		return {
			image: '',
			name: '',
			phone: '',
			address: '',
			code: '',
			id: ''
		};
	},
	onLoad() {
		my({}).then(({ data }) => {
			this.id = data.info.id;
			this.image = data.info.image;
			this.name = data.info.name;
			this.phone = data.info.phone;
			this.address = data.info.detailed_address;
		});
	},
	methods: {
		//跳转
		navTo(url) {
			uni.navigateTo({
				url
			});
		},
		close() {
			this.$refs.popuphx.close();
			this.code = '';
		},
		//调取扫描二维码
		smsh() {
			let obj = this;
			// #ifdef H5
			let wx = require('@/plugin/jweixin-module');

			wx.scanQRCode({
				needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
				scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码，默认二者都有
				success: function(res) {
					this.code = res.result;
					this.srhx();
				}
			});
			// #endif
			// #ifndef H5
			uni.scanCode({
				success: res => {
					this.code = res.result;
					this.srhx();
				}
			});
			// #endif
		},
		srhx() {
			this.$refs.popuphx.open();
		},
		close() {
			this.$refs.popuphx.close();
		},
		qhx() {
			if (this.code == '') {
				return this.$api.msg('请输入核销码');
			}
			uni.showLoading({
				title: '核销中...',
				mask: true
			});
			orderVerific({
				verify_code: this.code,
				is_confirm: 1 //1是核销，0是查看
			})
				.then(res => {
					uni.hideLoading();
					// this.$api.msg(res.msg)

					console.log(res, '++++++++++++++++++++++++++++++');
					this.$refs.popuphx.close();
					this.code = '';
					this.page = 1;
					this.loadingType = 'more';
					this.goodList = [];
					uni.showToast({
						title: '核销成功',
						duration: 2000
					});
					this.loadData();
				})
				.catch(err => {
					console.log('dddd');
				});
		}
	}
};
</script>

<style lang="scss">
page {
	height: 100%;
	background-color: #eeeded;
	padding: 0;
	margin: 0;
}
// 弹窗
.hx-wrapper {
	width: 536rpx;
	height: 630rpx;
	position: relative;

	// background-color: #fff;
	.hx-img {
		width: 536rpx;
		height: 281rpx;

		image {
			width: 536rpx;
			height: 281rpx;
		}
	}

	.hx-close {
		position: absolute;
		left: 243rpx;
		bottom: -80rpx;
		width: 52rpx;
		height: 52rpx;

		image {
			width: 52rpx;
			height: 52rpx;
		}
	}

	.hx-body {
		width: 536rpx;
		height: 349rpx;
		background-color: #fff;
		border-radius: 0 0 10rpx 10rpx;

		.hx-title {
			width: 536rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #333333;
			line-height: 1;
			padding-top: 42rpx;
			text-align: center;
		}

		input {
			width: 439rpx;
			height: 68rpx;
			background: #dbf3e9;
			border-radius: 10rpx;
			margin: 39rpx auto 0;
			padding-left: 26rpx;

			.hx-placeholder {
				font-size: 26rpx;
				font-weight: 500;
				color: #52c696;
			}
		}

		.hx-btn {
			margin: 44rpx auto 0;
			width: 353rpx;
			height: 71rpx;
			background: #f75022;
			border-radius: 34rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #f8f9f9;
			line-height: 71rpx;
			text-align: center;
		}
	}
}

.content {
	background-color: #eeeded;
	margin: 0 30rpx;
	display: flex;
	flex-direction: column;
}

.background {
	width: 100%;
	height: 220rpx;
	background-color: #f75022;
}

.userInfo {
	margin-top: -110rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	background-color: #f9f9f9;
	border-radius: 19rpx;
	width: 100%;
	height: 300rpx;

	.userInfo-box {
		display: flex;
		flex-direction: column;
		align-items: center;

		.userInfo-img {
			margin: -65rpx 0 0 0;
			width: 130rpx;
			height: 130rpx;
			border: 5rpx solid #fff;
			border-radius: 50%;

			image {
				border-radius: 50%;
				width: 100%;
				height: 100%;
			}
		}

		.userInfo-xinxi {
			.title {
				margin: 20rpx 0;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				text-align: center;
			}

			.phone {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
				line-height: 21rpx;
			}
		}

		.balance {
			margin-top: 10rpx;
			text-align: center;
			width: 500rpx;
			height: 60rpx;
			background: #f75022;
			border-radius: 30rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			line-height: 60rpx;
		}
	}
}

.userInfoList {
	margin-top: 20rpx;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	.userInfoList-top {
		position: relative;
		margin: 15rpx 0;
		display: flex;

		justify-content: center;
		align-items: center;
		width: 340rpx;
		height: 100rpx;
		background: #ffffff;
		border-radius: 20rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #4d4d4d;
		line-height: 21rpx;

		.top {
			position: absolute;
			top: 50%;
			left: 30rpx;
			margin-top: -25rpx;
			width: 50rpx;
			height: 50rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
	.userInfoList-bottom {
		margin-bottom: 15rpx;
		width: 340rpx;
		height: 250rpx;
		background: #f9f9f9;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		.bottom {
			margin-bottom: 20rpx;
			width: 68rpx;
			height: 68rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
}
.hx-wrapper {
	width: 536rpx;
	height: 630rpx;
	position: relative;

	// background-color: #fff;
	.hx-img {
		width: 536rpx;
		height: 281rpx;

		image {
			width: 536rpx;
			height: 281rpx;
		}
	}

	.hx-close {
		position: absolute;
		left: 243rpx;
		bottom: -80rpx;
		width: 52rpx;
		height: 52rpx;

		image {
			width: 52rpx;
			height: 52rpx;
		}
	}

	.hx-body {
		width: 536rpx;
		height: 349rpx;
		background-color: #fff;
		border-radius: 0 0 10rpx 10rpx;

		.hx-title {
			width: 536rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #333333;
			line-height: 1;
			padding-top: 42rpx;
			text-align: center;
		}

		input {
			width: 439rpx;
			height: 68rpx;
			background: #eeddde;
			border-radius: 10rpx;
			margin: 39rpx auto 0;
			padding-left: 26rpx;

			.hx-placeholder {
				font-size: 26rpx;
				font-weight: 500;
				color: #901b21;
			}
		}

		.hx-btn {
			margin: 44rpx auto 0;
			width: 353rpx;
			height: 71rpx;
			background: #901b21;
			border-radius: 34rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #f8f9f9;
			line-height: 71rpx;
			text-align: center;
		}
	}
}
</style>
